Test new GitHub Artifact Attestations #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Commit Stage | |
on: push | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: thomasvitale/policy-demo | |
VERSION: ${{ github.sha }} | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-22.04 | |
permissions: | |
attestations: write | |
contents: read | |
id-token: write | |
packages: write | |
security-events: write | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v4 | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 21 | |
distribution: liberica | |
cache: gradle | |
- name: Compile and test | |
run: | | |
cd policies/gradle | |
./gradlew clean build | |
- name: Upload SBOM | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sbom.json | |
path: policies/gradle/build/reports/application.cdx.json | |
- name: SBOM vulnerability scanning | |
uses: aquasecurity/trivy-action@master | |
with: | |
scan-type: 'sbom' | |
scan-ref: 'policies/gradle/build/reports/application.cdx.json' | |
format: 'sarif' | |
output: 'trivy-results-source-code.sarif' | |
- name: Upload SBOM vulnerability report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: trivy-results-source-code.sarif | |
path: trivy-results-source-code.sarif | |
- name: Upload vulnerability report | |
uses: github/codeql-action/upload-sarif@v3 | |
if: success() || failure() | |
with: | |
sarif_file: 'trivy-results-source-code.sarif' | |
category: "source-code" | |
- name: Package as OCI image | |
run: | | |
cd policies/gradle | |
./gradlew bootBuildImage --imageName ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
- name: OCI image vulnerability scanning | |
uses: aquasecurity/trivy-action@master | |
with: | |
scan-type: 'image' | |
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
format: 'sarif' | |
output: 'trivy-results-oci-image.sarif' | |
- name: Upload vulnerability report | |
uses: github/codeql-action/upload-sarif@v3 | |
if: success() || failure() | |
with: | |
sarif_file: 'trivy-results-oci-image.sarif' | |
category: "oci-image" | |
- name: Authenticate with the container registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.IMAGE_PUSH_TOKEN }} | |
registry: ${{ env.REGISTRY }} | |
- name: Publish OCI image | |
run: | | |
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
- name: Get OCI image digest | |
run: | | |
image_reference=$(docker inspect --format='{{index .RepoDigests 0}}' ${REGISTRY}/${IMAGE_NAME}:${VERSION}) | |
echo $image_reference | |
image_digest=$(echo "$image_reference" | awk -F '@' '{print $2}') | |
echo $image_digest | |
echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV | |
- name: Sign and Attest | |
uses: actions/attest-build-provenance@v1 | |
id: attest | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
subject-digest: ${{ env.IMAGE_DIGEST }} | |
github-token: ${{ secrets.IMAGE_PUSH_TOKEN }} | |
push-to-registry: true | |
# | |
# sign: | |
# name: Sign | |
# runs-on: ubuntu-22.04 | |
# needs: [build] | |
# permissions: | |
# contents: read | |
# packages: write | |
# id-token: write | |
# outputs: | |
# image-digest: ${{ steps.image-info.outputs.digest }} | |
# image-name: ${{ steps.image-info.outputs.name }} | |
# steps: | |
# - name: Install Cosign | |
# uses: sigstore/cosign-installer@v3 | |
# | |
# - uses: redhat-actions/podman-login@v1.6 | |
# with: | |
# username: ${{ github.actor }} | |
# password: ${{ secrets.IMAGE_PUSH_TOKEN }} | |
# registry: ${{ env.REGISTRY }} | |
# | |
# - name: Fetch OCI image | |
# run: podman pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
# | |
# - name: Get OCI image digest | |
# id: image-info | |
# run: | | |
# image_digest=$(podman inspect --format='{{.Digest}}' ${REGISTRY}/${IMAGE_NAME}:${VERSION}) | |
# echo $image_digest | |
# echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV | |
# echo "digest=${image_digest}" >> $GITHUB_OUTPUT | |
# echo "name=${REGISTRY}/${IMAGE_NAME}" >> $GITHUB_OUTPUT | |
# | |
# - name: Sign image | |
# run: | | |
# cosign sign --yes "${REGISTRY}/${IMAGE_NAME}@${IMAGE_DIGEST}" | |
# | |
# provenance: | |
# needs: [sign] | |
# permissions: | |
# actions: read | |
# id-token: write | |
# packages: write | |
# uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v1.9.0 | |
# with: | |
# image: ${{ needs.sign.outputs.image-name }} | |
# digest: ${{ needs.sign.outputs.image-digest }} | |
# registry-username: ${{ github.actor }} | |
# secrets: | |
# registry-password: ${{ secrets.IMAGE_PUSH_TOKEN }} |