From 486eea6e5e2ff6c7781ed4f42848873f13c003dc Mon Sep 17 00:00:00 2001 From: Ryan Ahearn Date: Mon, 19 Aug 2024 12:34:47 -0400 Subject: [PATCH 1/2] Add a helper script to prune obsolete evidence --- bin/prune-helper | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 2 +- requirements.txt | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 bin/prune-helper diff --git a/bin/prune-helper b/bin/prune-helper new file mode 100755 index 0000000..eb621eb --- /dev/null +++ b/bin/prune-helper @@ -0,0 +1,58 @@ +#! /usr/bin/env bash + +usage=" +$0: Prune obsolete evidence from the evidence locker + +Usage: + $0 -h + $0 -c PRUNE_CONFIG -l LOCKER_URL [-b LOCKER_BRANCH] [-e EMAIL_ADDRESS] [-d] + +Options: +-h: show help and exit +-c: prune config. ex: '{\"path/to/filename.json\":\"Reason it is being pruned\"}' +-l: https version of locker repository +-b: main branch used in locker repository. Default: 'main' +-e: your email address. Defaults to '$GIT_EMAIL' +-d: Dry run mode +" + +echo "Calling prune-helper script" + +set -e + +mode="push-remote" +branch="main" +config="" +email="$GIT_EMAIL" +locker="" + +while getopts "hc:e:l:b:d" opt; do + case "$opt" in + c) + config=${OPTARG} + ;; + e) + email=${OPTARG} + ;; + l) + locker=${OPTARG} + ;; + b) + branch=${OPTARG} + ;; + d) + mode="dry-run" + ;; + h) + echo "$usage" + exit 0 + ;; + esac +done + +if [ "$config" = "" ] || [ "$locker" = "" ] || [ "$email" = "" ]; then + echo "$usage" + exit 1 +fi + +prune "$mode" --config "$config" --git-config "{\"user\":{\"email\":\"$email\"}}" --branch "$branch" "$locker" diff --git a/entrypoint.sh b/entrypoint.sh index 9dde45f..b605024 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ if [ "$1" != "init" ]; then exit 1 fi if [ -z "$GIT_EMAIL" ]; then - echo "Must pass email address for git config to script" + echo "Must pass email address for git config to script as GIT_EMAIL" exit 1 fi diff --git a/requirements.txt b/requirements.txt index 55d83db..0927059 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ auditree-framework @ git+https://github.com/ComplianceAsCode/auditree-framework.git auditree-arboretum ~= 0.17 +auditree-prune @ git+https://github.com/rahearn/auditree-prune.git compliance-to-policy @ git+https://github.com/rahearn/compliance-to-policy.git From 90841e4603ca864feb39e4aef6677f91fd134147 Mon Sep 17 00:00:00 2001 From: Ryan Ahearn Date: Mon, 19 Aug 2024 12:41:24 -0400 Subject: [PATCH 2/2] Auto-publish new auditree images --- .github/workflows/docker-publish.yml | 96 ++++++++++++++++++++++++++++ README.md | 13 ++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..4c4d9f7 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +name: Docker + +on: + push: + branches: [ "main" ] + paths-ignore: + - README.md + + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: gsa-tts/auditree + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: latest=true + tags: | + type=raw,value={{date 'YYYYMMDD'}},priority=850 + type=ref,event=branch + type=sha + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/arm64,linux/amd64 + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/README.md b/README.md index dbbea28..2f747dd 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,16 @@ for DevTools-flavored applications. 1. Initialize the config file: `docker run --rm ghcr.io/gsa-tts/auditree init > path/to/auditree.template.json` 1. Edit the generated config to insert the proper repository addresses for both your evidence locker repo and code repo. 1. TKTK instructions for actual use coming soon. + +### Updating the Docker image: + +1. Make required changes +1. Push to GitHub and create a PR +1. On merging to main, a new docker image will be built, tagged, and pushed to the github container registry. + +Each published image will be tagged with: + +1. `latest` +1. The publication date: `YYYYMMDD` +1. The branch it was created on: `main` +1. The short git sha: `sha-c9f60e2`