-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add SLSA provenance generator to release; closes #222 #223
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
50c7f71
feat: split release workflows into different jobs with different perm…
diogoteles08 88583f0
feat: add workflow_dispatch trigger for release action
diogoteles08 9926aa6
feat: add provenance generation to release workflow
diogoteles08 ba05380
fix: wrong line breaking on sign step of release
diogoteles08 ef17cc5
docs: update README to add SLSA 3 badge and instructions to verify bu…
diogoteles08 055231a
fix: issue downloading artifacts for release on pypi
diogoteles08 a271a40
Revert "feat: add workflow_dispatch trigger for release action"
diogoteles08 beee99d
fix: wrong URL being reffered on README
diogoteles08 009ac66
feat: change provenance name to have the version number
diogoteles08 ede0539
Merge branch 'main' into main
woodruffw 3c59263
feat: remove unnecessary permission on job workflow
diogoteles08 74f678b
Update README.md
woodruffw 8fbd1d7
Update README.md
woodruffw 5747562
docs: explain why not using hash pinning in a GHA
diogoteles08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,131 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
name: release | ||
|
||
permissions: | ||
# Needed to access the workflow's OIDC identity. | ||
id-token: write | ||
|
||
# Needed to upload release assets. | ||
contents: write | ||
|
||
jobs: | ||
pypi: | ||
name: Build, sign and publish release to PyPI | ||
build: | ||
name: Build and sign artifacts | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
outputs: | ||
hashes: ${{ steps.hash.outputs.hashes }} | ||
steps: | ||
- uses: actions/checkout@d171c3b028d844f2bf14e9fdec0c58114451e4bf | ||
|
||
- uses: actions/setup-python@7f80679172b057fc5e90d70d197929d454754a5a | ||
|
||
- name: deps | ||
run: python -m pip install -U build | ||
|
||
- name: build | ||
run: python -m build | ||
|
||
- name: sign | ||
run: | | ||
mkdir -p smoketest-artifacts | ||
|
||
# we smoke-test sigstore by installing each of the distributions | ||
# we've built in a fresh environment and using each to sign and | ||
# verify for itself, using the ambient OIDC identity | ||
for dist in dist/*; do | ||
dist_base="$(basename "${dist}")" | ||
|
||
python -m venv smoketest-env | ||
|
||
./smoketest-env/bin/python -m pip install "${dist}" | ||
|
||
# NOTE: signing artifacts currently go in a separate directory, | ||
# to avoid confusing the package uploader (which otherwise tries | ||
# to upload them to PyPI and fails). Future versions of twine | ||
# and the gh-action-pypi-publish action should support these artifacts. | ||
./smoketest-env/bin/python -m \ | ||
sigstore sign "${dist}" \ | ||
--output-signature smoketest-artifacts/"${dist_base}.sig" \ | ||
--output-certificate smoketest-artifacts/"${dist_base}.crt" | ||
|
||
./smoketest-env/bin/python -m \ | ||
sigstore verify "${dist}" \ | ||
--cert "smoketest-artifacts/${dist_base}.crt" \ | ||
--signature "smoketest-artifacts/${dist_base}.sig" \ | ||
--cert-oidc-issuer https://token.actions.githubusercontent.com | ||
|
||
rm -rf smoketest-env | ||
done | ||
|
||
- name: Generate hashes for provenance | ||
shell: bash | ||
id: hash | ||
run: | | ||
# sha256sum generates sha256 hash for all artifacts. | ||
# base64 -w0 encodes to base64 and outputs on a single line. | ||
# sha256sum artifact1 artifact2 ... | base64 -w0 | ||
echo "::set-output name=hashes::$(sha256sum ./dist/* | base64 -w0)" | ||
|
||
- name: Upload built packages | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: built-packages | ||
path: ./dist/ | ||
if-no-files-found: warn | ||
|
||
- name: Upload smoketest-artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: smoketest-artifacts | ||
path: smoketest-artifacts/ | ||
if-no-files-found: warn | ||
|
||
generate-provenance: | ||
needs: [build] | ||
name: Generate build provenance | ||
permissions: | ||
actions: read # To read the workflow path. | ||
id-token: write # To sign the provenance. | ||
contents: write # To add assets to a release. | ||
# Currently this action needs to be referred by tag. More details at: | ||
# https://github.com/slsa-framework/slsa-github-generator#verification-of-provenance | ||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.0 | ||
with: | ||
attestation-name: provenance-sigstore-${{ github.event.release.tag_name }}.intoto.jsonl | ||
base64-subjects: "${{ needs.build.outputs.hashes }}" | ||
upload-assets: true | ||
|
||
release-pypi: | ||
needs: [build, generate-provenance] | ||
runs-on: ubuntu-latest | ||
permissions: {} | ||
steps: | ||
- name: Download artifacts diretories # goes to current working directory | ||
uses: actions/download-artifact@v3 | ||
|
||
- name: publish | ||
uses: pypa/gh-action-pypi-publish@717ba43cfbb0387f6ce311b169a825772f54d295 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_TOKEN }} | ||
packages_dir: built-packages/ | ||
|
||
release-github: | ||
needs: [build, generate-provenance] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# Needed to upload release assets. | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@d171c3b028d844f2bf14e9fdec0c58114451e4bf | ||
|
||
- uses: actions/setup-python@7f80679172b057fc5e90d70d197929d454754a5a | ||
|
||
- name: deps | ||
run: python -m pip install -U build | ||
|
||
- name: build | ||
run: python -m build | ||
|
||
- name: sign | ||
run: | | ||
mkdir -p smoketest-artifacts | ||
|
||
# we smoke-test sigstore by installing each of the distributions | ||
# we've built in a fresh environment and using each to sign and | ||
# verify for itself, using the ambient OIDC identity | ||
for dist in dist/*; do | ||
dist_base="$(basename "${dist}")" | ||
|
||
python -m venv smoketest-env | ||
|
||
./smoketest-env/bin/python -m pip install "${dist}" | ||
|
||
# NOTE: signing artifacts currently go in a separate directory, | ||
# to avoid confusing the package uploader (which otherwise tries | ||
# to upload them to PyPI and fails). Future versions of twine | ||
# and the gh-action-pypi-publish action should support these artifacts. | ||
./smoketest-env/bin/python -m \ | ||
sigstore sign "${dist}" \ | ||
--output-signature smoketest-artifacts/"${dist_base}.sig" \ | ||
--output-certificate smoketest-artifacts/"${dist_base}.crt" | ||
|
||
./smoketest-env/bin/python -m \ | ||
sigstore verify "${dist}" \ | ||
--cert "smoketest-artifacts/${dist_base}.crt" \ | ||
--signature "smoketest-artifacts/${dist_base}.sig" \ | ||
--cert-oidc-issuer https://token.actions.githubusercontent.com \ | ||
|
||
rm -rf smoketest-env | ||
done | ||
|
||
- name: publish | ||
uses: pypa/gh-action-pypi-publish@717ba43cfbb0387f6ce311b169a825772f54d295 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_TOKEN }} | ||
|
||
- name: upload artifacts to github | ||
# Confusingly, this action also supports updating releases, not | ||
# just creating them. This is what we want here, since we've manually | ||
# created the release that triggered the action. | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
# dist/ contains the built packages, which smoketest-artifacts/ | ||
# contains the signatures and certificates. | ||
files: | | ||
dist/* | ||
smoketest-artifacts/* | ||
- name: Download artifacts diretories # goes to current working directory | ||
uses: actions/download-artifact@v3 | ||
|
||
- name: Upload artifacts to github | ||
# Confusingly, this action also supports updating releases, not | ||
# just creating them. This is what we want here, since we've manually | ||
# created the release that triggered the action. | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
# smoketest-artifacts/ contains the signatures and certificates. | ||
files: | | ||
built-packages/* | ||
smoketest-artifacts/* |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nonblocking: for consistency with the other actions in this workflow, we should probably use a hash rev instead of a symbolic (tag) rev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, let's update this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hash is not supported for the builder, due to a lack of GH support to map a hash to a branch. This is an intentional design decision we have made. We aim to change that once the relevant GitHub support is there. See the reasoning at slsa-framework/slsa-verifier#12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it would maintain the consistency and also follow the best practice rules, but currently SLSA generator does not support hash pinning, although there already is an issue about that. More details here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However I think it would be a good idea to add a comment on code explaining this decision, because it's indeed contradictory and more people can question that. Will work on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, with a link to the documentation. We can add a link to the tracking issue in the documentation of our repo.