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

Use keyless cosign approach #152

Closed
wants to merge 2 commits into from
Closed
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
40 changes: 25 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jobs:
container_repos: ${{ steps.container_info.outputs.container_repos }}

runs-on: ubuntu-20.04
permissions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to set for the entire workflow as all jobs require it.

packages: write
id-token: write
contents: write

steps:
- name: Set up Go
Expand Down Expand Up @@ -124,6 +128,7 @@ jobs:
LDFLAGS: ${{ steps.release-vars.outputs.LDFLAGS }}
GIT_HASH: ${{ steps.release-vars.outputs.GIT_HASH }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
COSIGN_EXPERIMENTAL: 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also move this to the job level.


- name: Get container info
id: container_info
Expand All @@ -149,6 +154,10 @@ jobs:
needs: [release]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
permissions:
packages: write
id-token: write
contents: write
env:
TAGS: "${{ needs.release.outputs.container_tags }}"

Expand All @@ -172,30 +181,31 @@ jobs:

- name: Attach SBOM
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
COSIGN_EXPERIMENTAL: 1
run: |
echo '${{ secrets.COSIGN_PUBLIC_KEY }}' > cosign.pub
echo '${{ secrets.COSIGN_PRIVATE_KEY }}' > cosign.key
IFS=,
for t in ${TAGS}; do
cosign verify --key cosign.pub ${{ matrix.repo }}:${t}
cosign verify ${{ matrix.repo }}:${t}
syft ${{ matrix.repo }}:${t} -o spdx-json > sbom-spdx.json
cosign attest --predicate sbom-spdx.json --type spdx --key cosign.key ${{ matrix.repo }}:${t}
cosign verify-attestation -o verified-sbom-spdx.json --key cosign.pub ${{ matrix.repo }}:${t}
cosign attest --predicate sbom-spdx.json --type spdx ${{ matrix.repo }}:${t}
cosign verify-attestation -o verified-sbom-spdx.json ${{ matrix.repo }}:${t}
done

- name: Clean up & Logout from Container registries
if: ${{ always() }}
run: |
docker logout
docker logout ghcr.io
rm -f cosign.key

provenance:
name: provenance
needs: [release]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
permissions:
packages: write
id-token: write
contents: write

steps:
- name: Generate provenance for Release
Expand All @@ -214,8 +224,7 @@ jobs:

- name: Sign provenance
run: |
echo '${{ secrets.COSIGN_PRIVATE_KEY }}' > cosign.key
cosign sign-blob --key cosign.key --output-signature "${SIGNATURE}" provenance.att
cosign sign-blob --output-signature "${SIGNATURE}" provenance.att
cat "${SIGNATURE}"

curl_args=(-s -H "Authorization: token ${GITHUB_TOKEN}")
Expand All @@ -229,14 +238,18 @@ jobs:
"https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=${SIGNATURE}"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
COSIGN_EXPERIMENTAL: 1
SIGNATURE: provenance.att.sig

container-provenance:
name: container-provenance
needs: [release]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
permissions:
packages: write
id-token: write
contents: write

strategy:
matrix:
Expand Down Expand Up @@ -269,19 +282,16 @@ jobs:

- name: Attach provenance to image
run: |
echo '${{ secrets.COSIGN_PRIVATE_KEY }}' > cosign.key
cosign attest --predicate provenance-predicate.att --type slsaprovenance --key cosign.key ${{ matrix.repo }}@${{ needs.release.outputs.container_digest }}
cosign attest --predicate provenance-predicate.att --type slsaprovenance ${{ matrix.repo }}@${{ needs.release.outputs.container_digest }}
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}

- name: Verify attestation
run: |
echo '${{ secrets.COSIGN_PUBLIC_KEY }}' > cosign.pub
cosign verify-attestation --key cosign.pub ${{ matrix.repo }}@${{ needs.release.outputs.container_digest }}
cosign verify-attestation ${{ matrix.repo }}@${{ needs.release.outputs.container_digest }}

- name: Logout from Container registries
if: ${{ always() }}
run: |
docker logout
docker logout ghcr.io
rm -f cosign.key
13 changes: 1 addition & 12 deletions .goreleaser.draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ before:

env:
- CGO_ENABLED=0
- COSIGN_EXPERIMENTAL=1

builds:
- id: binary
Expand Down Expand Up @@ -82,8 +83,6 @@ signs:
artifacts: checksum
args:
- sign-blob
- --key
- cosign.key
- '--output-certificate=${certificate}'
- '--output-signature=${signature}'
- '${artifact}'
Expand All @@ -94,8 +93,6 @@ signs:
artifacts: binary
args:
- sign-blob
- --key
- cosign.key
- '--output-certificate=${certificate}'
- '--output-signature=${signature}'
- '${artifact}'
Expand All @@ -106,8 +103,6 @@ signs:
artifacts: archive
args:
- sign-blob
- --key
- cosign.key
- '--output-certificate=${certificate}'
- '--output-signature=${signature}'
- '${artifact}'
Expand All @@ -118,8 +113,6 @@ signs:
artifacts: sbom
args:
- sign-blob
- --key
- cosign.key
- '--output-certificate=${certificate}'
- '--output-signature=${signature}'
- '${artifact}'
Expand All @@ -130,8 +123,6 @@ docker_signs:
output: true
args:
- 'sign'
- --key
- cosign.key
- '${artifact}'

snapshot:
Expand All @@ -150,7 +141,5 @@ changelog:
release:
draft: true
prerelease: auto
extra_files:
- glob: "./cosign.pub"
footer: |
**Full Changelog**: https://github.com/philips-labs/slsa-provenance-action/compare/{{ .PreviousTag }}...{{ .Tag }}
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ docker_signs:
output: true
args:
- 'sign'
- --key
- cosign.key
- '${artifact}'

snapshot:
Expand Down