Skip to content

Commit

Permalink
Merge pull request #2 from GSA-TTS/add-prune-tool
Browse files Browse the repository at this point in the history
Add prune tool
  • Loading branch information
rahearn authored Aug 19, 2024
2 parents c45005f + 90841e4 commit f159602
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 1 deletion.
96 changes: 96 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -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}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
58 changes: 58 additions & 0 deletions bin/prune-helper
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f159602

Please sign in to comment.