Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CI workflow on branch push #60

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 46 additions & 56 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Main - Attests to https://app.kosli.com

on:
push:
branches:
- main

env:
KOSLI_DRY_RUN: ${{ vars.KOSLI_DRY_RUN }} # false
Expand Down Expand Up @@ -58,6 +56,7 @@ jobs:


pull-request:
if: ${{ github.ref == 'refs/heads/main' }}
needs: []
runs-on: ubuntu-latest
permissions:
Expand All @@ -70,13 +69,11 @@ jobs:
fetch-depth: 1

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest pull-request evidence to Kosli
if: ${{ github.ref == 'refs/heads/main' }}
run:
kosli attest pullrequest github
--github-token=${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -110,6 +107,43 @@ jobs:
--name=runner.lint


snyk-code-scan:
runs-on: ubuntu-latest
needs: []
env:
SARIF_FILENAME: snyk.code.scan.json
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Snyk
uses: snyk/actions/setup@master

- name: Run Snyk code scan
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run:
snyk code test
--sarif
--sarif-file-output="${SARIF_FILENAME}"
--policy-path=.snyk
.

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest evidence to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
run:
kosli attest snyk
--name=runner.snyk-code-scan
--scan-results="${SARIF_FILENAME}"


build-image:
runs-on: ubuntu-latest
needs: [setup]
Expand Down Expand Up @@ -161,6 +195,12 @@ jobs:
path: ${{ env.IMAGE_TAR_FILENAME }}
key: ${{ env.IMAGE_NAME }}

- name: Make Artifact fingerprint available to following jobs
id: variables
run: |
FINGERPRINT=$(echo ${{ steps.docker_build.outputs.digest }} | sed 's/.*://')
echo "artifact_digest=${FINGERPRINT}" >> ${GITHUB_OUTPUT}

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' }}
uses: kosli-dev/setup-cli-action@v2
Expand All @@ -174,12 +214,6 @@ jobs:
--artifact-type=docker
--name=runner

- name: Make Artifact fingerprint available to following jobs
id: variables
run: |
FINGERPRINT=$(kosli fingerprint "${{ env.IMAGE_NAME }}" --artifact-type=docker)
echo "artifact_digest=${FINGERPRINT}" >> ${GITHUB_OUTPUT}


unit-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -319,7 +353,7 @@ jobs:
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest Snyk container scan results to Kosli
- name: Attest evidence to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
env:
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
Expand All @@ -329,57 +363,17 @@ jobs:
--scan-results="${SARIF_FILENAME}"


snyk-code-scan:
runs-on: ubuntu-latest
needs: [setup, build-image]
env:
SARIF_FILENAME: snyk.code.scan.json
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Snyk
uses: snyk/actions/setup@master

- name: Run Snyk code scan
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run:
snyk code test
--sarif
--sarif-file-output="${SARIF_FILENAME}"
--policy-path=.snyk
.

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest Snyk code scan results to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
env:
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
run:
kosli attest snyk
--name=runner.snyk-code-scan
--scan-results="${SARIF_FILENAME}"


sdlc-control-gate:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: [setup, build-image, pull-request, lint, unit-tests, integration-tests, snyk-container-scan, snyk-code-scan]
steps:
- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Kosli SDLC gate to short-circuit the workflow
if: ${{ github.ref == 'refs/heads/main' }}
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
Expand All @@ -399,13 +393,11 @@ jobs:
fetch-depth: 0

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest approval of deployment to Kosli
if: ${{ github.ref == 'refs/heads/main' }}
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
Expand Down Expand Up @@ -436,13 +428,11 @@ jobs:
fetch-depth: 0

- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest approval of deployment to Kosli
if: ${{ github.ref == 'refs/heads/main' }}
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
- An http service (rack based) for running `cyber-dojo.sh` inside a docker container for at most 20 seconds and returning `[stdout,stderr,status,timed_out,colour]`
- A [Kosli CI flow](https://app.kosli.com/cyber-dojo/flows/runner-ci/trails/)
deploying, with Continuous Compliance, to [staging](https://app.kosli.com/cyber-dojo/environments/aws-beta/snapshots/) and [production](https://app.kosli.com/cyber-dojo/environments/aws-prod/snapshots/) AWS environments.

- Demonstrates a [Kosli](https://www.kosli.com/) instrumented [GitHub CI workflow](https://app.kosli.com/cyber-dojo/flows/runner-ci/trails/)
deploying, with Continuous Compliance, to [staging](https://app.kosli.com/cyber-dojo/environments/aws-beta/snapshots/) and [production](https://app.kosli.com/cyber-dojo/environments/aws-prod/snapshots/) AWS environments.
- Uses patterns from https://www.kosli.com/blog/using-kosli-attest-in-github-action-workflows-some-tips/

***
API
Expand Down