-
Notifications
You must be signed in to change notification settings - Fork 54
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
e2e: check measurements reproducibility test for images #3654
Open
miampf
wants to merge
32
commits into
main
Choose a base branch
from
miampf/e2e/test-release-reproducibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d00ad8c
started implementation
miampf 3303b07
only build measured boot cmd
miampf 1feaccd
fix workflow
miampf 2068506
compute measurements for single image
miampf 66155cb
install systemdUkify tools
miampf 253a9ae
use `sudo -E` and add a check if `systemd-dissect` is in PATH
miampf 20c78af
Carry over `PATH` explicitly using `env`
miampf c209d44
fix typo
miampf 5377d81
Download v2.20.0 release measurements and check
miampf f440427
Compare all measurements against respective targets
miampf 827f290
Add info echo
miampf dbb758e
pipefail + extglob
miampf 04ea3c7
Explicitly install jq over nix
miampf 3549a15
Actually only compare measurements
miampf bda1678
Delete `warnOnly` fields + debug logs
miampf 48b1e82
improve jq filter
miampf a0b9963
delete expected zeroes from own measurements as well
miampf f3cf8be
Add some comments that explain the `jq` filters
miampf a154182
reference selection
miampf 4482c38
Rename env var to RELEASETAG
miampf 785e549
use correct ternary syntax
miampf 8d73e31
Make workflow workflow_call
miampf 8bc12b0
Call workflow in release
miampf df04e7b
split jq command into multiple lines
miampf 4c94dfb
fix shellcheck issues
miampf b384971
split workflow into multiple steps
miampf 730a532
`set -euo pipefail` & use github outputs
miampf bc58333
Set extglob at correct step
miampf 72a3c90
Only select required field
miampf 1a3ccb0
Collect all errors before exiting
miampf 5c55142
Please shellcheck
miampf d480781
Remove test error
miampf 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
114 changes: 114 additions & 0 deletions
114
.github/workflows/check-measurements-reproducibility.yml
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Check measurements reproducibility | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
releasetag: | ||
type: string | ||
description: The release to checkout and download. | ||
required: true | ||
workflow_call: | ||
inputs: | ||
releasetag: | ||
type: string | ||
description: The release to checkout and download. | ||
required: true | ||
|
||
jobs: | ||
check-reproducibility: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
ref: ${{ github.event.inputs.releasetag }} | ||
- name: Set up bazel | ||
uses: ./.github/actions/setup_bazel_nix | ||
with: | ||
useCache: "false" | ||
nixTools: | | ||
systemdUkify | ||
jq | ||
jd-diff-patch | ||
moreutils | ||
- name: Build images | ||
id: build-images | ||
run: | | ||
set -euo pipefail | ||
|
||
# Build required binaries | ||
bazel build //image/system:stable | ||
bazel build //image/measured-boot/cmd | ||
echo "buildPath=$PWD/bazel-bin/image" | tee -a "$GITHUB_OUTPUT" | ||
cd "$(mktemp -d)" | ||
|
||
- name: Download measurements | ||
run: | | ||
curl -O https://cdn.confidential.cloud/constellation/v2/ref/-/stream/stable/${{ github.event.inputs.releasetag }}/image/measurements.json | ||
|
||
- name: Cleanup release measurements and generate our own | ||
run: | | ||
set -euo pipefail | ||
shopt -s extglob | ||
|
||
for directory in ${{ steps.build-images.outputs.buildPath }}/system/!(mkosi_wrapper.sh); do | ||
dirname="$(basename "$directory")" | ||
csp="$(echo "$dirname" | cut -d_ -f1)" | ||
attestationVariant="$(echo "$dirname" | cut -d_ -f2)" | ||
|
||
echo "Comparing measurements of CSP $csp with attestation variant $attestationVariant" | ||
# This jq filter selects the measurements for the correct CSP and attestation variant | ||
# and then removes all `warnOnly: true` measurements. | ||
jq --arg attestation_variant "$attestationVariant" --arg csp "$csp" \ | ||
' | ||
.list.[] | ||
| select( | ||
.attestationVariant == $attestation_variant | ||
) | ||
| select((.csp | ascii_downcase) == $csp) | ||
| .measurements | ||
| walk( | ||
if ( | ||
type=="object" and .warnOnly | ||
) | ||
then del(.) else . end | ||
) | ||
| del(..|nulls) | ||
| del(.[] .warnOnly) | ||
' \ | ||
measurements.json > "$attestationVariant"_their-measurements.json | ||
|
||
sudo env "PATH=$PATH" "${{ steps.build-images.outputs.buildPath }}/measured-boot/cmd/cmd_/cmd" "$directory/constellation" ./"$attestationVariant"_own-measurements.json | ||
jq '.measurements' ./"$attestationVariant"_own-measurements.json | sponge ./"$attestationVariant"_own-measurements.json | ||
done | ||
|
||
- name: Compare measurements | ||
run: | | ||
# no -e since we need to collect errors later | ||
set -uo pipefail | ||
shopt -s extglob | ||
|
||
declare -A errors | ||
|
||
for directory in ${{ steps.build-images.outputs.buildPath }}/system/!(mkosi_wrapper.sh); do | ||
dirname="$(basename "$directory")" | ||
attestationVariant="$(echo "$dirname" | cut -d_ -f2)" | ||
|
||
echo "Their measurements for $attestationVariant:" | ||
ts " " < "$attestationVariant"_their-measurements.json | ||
echo "Own measurements for $attestationVariant:" | ||
ts " " < "$attestationVariant"_own-measurements.json | ||
|
||
# TODO: cache errors and return them later. | ||
if ! jd ./"$attestationVariant"_their-measurements.json ./"$attestationVariant"_own-measurements.json; then | ||
errors["$attestationVariant"]="$(!!)" | ||
fi | ||
done | ||
|
||
for attestationVariant in "${!errors[@]}"; do | ||
echo "Failed to reproduce measurements for $attestationVariant:" | ||
echo "${errors["$attestationVariant"]}" | ts " " | ||
done | ||
|
||
if [[ "${#errors[@]}" -ne 0 ]]; then | ||
exit 1 | ||
fi |
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
Oops, something went wrong.
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.
We only create a release tag when publishing the release, so this won't work when calling this workflow during the release pipeline.
Instead, we should accept a
version
andref
as input.Where
version
is the version of the measurements to download from the CDN,and
ref
the git ref to check out and build the images from.For the release workflow this should be the working branch, for
workflow_dispatch
this can be the same asversion
, i.e. the tag of the release