Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
run: |
docker build \
-f apps/gateway/Dockerfile.enclave \
--build-arg VERSION=v0.0.0-ci \
--build-arg SOURCE_REVISION="$(git rev-parse HEAD)" \
--build-arg AWS_REGION=eu-central-1 \
--build-arg KMS_KEY_ARN=arn:aws:kms:eu-central-1:111122223333:key/12345678-1234-1234-1234-123456789012 \
Expand Down
10 changes: 7 additions & 3 deletions apps/gateway/Dockerfile.enclave
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# Pin upstream build inputs by digest. Together with SOURCE_DATE_EPOCH and
# rewrite-timestamp (see deploy/nitro/build-release-assets.sh) this builds
# reproducibly: the same revision yields the same PCR0/PCR1/PCR2 on any x86_64
# machine, so a published release can be independently rebuilt and checked with
# deploy/nitro/verify-build.sh. Build this image with `docker buildx build`
# reproducibly: the same revision and release version yield the same
# PCR0/PCR1/PCR2 on any x86_64 machine, so a published release can be
# independently rebuilt and checked with deploy/nitro/verify-build.sh. Build this image with `docker buildx build`
# only -- a plain `docker build` skips the timestamp normalisation and silently
# produces different measurements.
FROM golang:1.26.11-alpine3.24@sha256:ae52b5bc6ed045a9ed26ab03dc19327a802a9cc9aa8b27ed57f5c6b60579b0bb AS builder

ARG VERSION
ARG SOURCE_REVISION
ARG AWS_REGION
ARG KMS_KEY_ARN
Expand All @@ -21,6 +22,7 @@ RUN go mod download
COPY . .

# Reject values that could break linker-flag tokenization.
RUN printf '%s' "$VERSION" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$'
RUN printf '%s' "$SOURCE_REVISION" | grep -Eq '^[0-9a-f]{40}$'
RUN printf '%s' "$AWS_REGION" | grep -Eq '^[a-z]{2}(-gov)?-[a-z]+-[0-9]+$'
RUN printf '%s' "$KMS_KEY_ARN" | grep -Eq '^arn:(aws|aws-us-gov|aws-cn):kms:[a-z0-9-]+:[0-9]{12}:key/[0-9a-fA-F-]{36}$'
Expand All @@ -30,6 +32,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build \
-trimpath \
-tags nitro_enclave \
-ldflags="-s -w -buildid= \
-X github.com/dappnode/dappnode-nexus-gateway/pkg/buildinfo.Version=${VERSION} \
-X github.com/dappnode/dappnode-nexus-gateway/pkg/buildinfo.Commit=${SOURCE_REVISION} \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.SourceRevision=${SOURCE_REVISION} \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.AWSRegion=${AWS_REGION} \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.KMSKeyARN=${KMS_KEY_ARN}" \
Expand Down
1 change: 1 addition & 0 deletions deploy/nitro/build-release-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ build_enclave_image() {
--label "org.opencontainers.image.source=https://github.com/${SOURCE_REPOSITORY}" \
--label "org.opencontainers.image.revision=${SOURCE_REVISION}" \
--label "org.opencontainers.image.version=${VERSION}" \
--build-arg "VERSION=${VERSION}" \
--build-arg "SOURCE_REVISION=${SOURCE_REVISION}" \
--build-arg "AWS_REGION=${AWS_REGION}" \
--build-arg "KMS_KEY_ARN=${KMS_KEY_ARN}" \
Expand Down
18 changes: 13 additions & 5 deletions deploy/nitro/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ mapfile -t manifest_fields < <(
jq -r '
.schema_version, .source.revision, .build.aws_region, .build.kms_key_arn,
.build.source_date_epoch, .build.nitro_cli_version, .build.architecture,
.enclave.measurements.pcr0, .enclave.measurements.pcr1, .enclave.measurements.pcr2
.enclave.measurements.pcr0, .enclave.measurements.pcr1, .enclave.measurements.pcr2,
.release.version
' "$manifest_path"
)

if [[ "${#manifest_fields[@]}" -ne 10 ]]; then
if [[ "${#manifest_fields[@]}" -ne 11 ]]; then
printf 'not a Gateway release manifest: %s\n' "$manifest_path" >&2
exit 1
fi
Expand All @@ -79,6 +80,7 @@ architecture="${manifest_fields[6]}"
expected_pcr0="${manifest_fields[7]}"
expected_pcr1="${manifest_fields[8]}"
expected_pcr2="${manifest_fields[9]}"
version="${manifest_fields[10]}"

if [[ ! "$schema" =~ ^[0-9]+$ ]]; then
printf 'manifest has no usable schema_version: %s\n' "$manifest_path" >&2
Expand All @@ -93,7 +95,8 @@ fi

for pair in "revision:$revision" "aws_region:$region" "kms_key_arn:$kms_key_arn" \
"source_date_epoch:$source_date_epoch" "architecture:$architecture" \
"pcr0:$expected_pcr0" "pcr1:$expected_pcr1" "pcr2:$expected_pcr2"; do
"pcr0:$expected_pcr0" "pcr1:$expected_pcr1" "pcr2:$expected_pcr2" \
"release.version:$version"; do
[[ -n "${pair#*:}" && "${pair#*:}" != "null" ]] || {
printf 'manifest is missing %s\n' "${pair%%:*}" >&2; exit 1; }
done
Expand Down Expand Up @@ -144,7 +147,11 @@ docker buildx build --pull -q --load \
-t "$nitro_cli_image" \
"$context/deploy/nitro" >>"$build_log" 2>&1 || fail

# VERSION is compiled into the binary, so it is part of the measurements. Older
# revisions' Dockerfiles do not declare it; BuildKit only warns about an unused
# build argument, so passing it unconditionally leaves their rebuild unchanged.
SOURCE_DATE_EPOCH="$source_date_epoch" docker buildx build --pull --no-cache --provenance=false \
--build-arg "VERSION=${version}" \
--build-arg "SOURCE_REVISION=${revision}" \
--build-arg "AWS_REGION=${region}" \
--build-arg "KMS_KEY_ARN=${kms_key_arn}" \
Expand All @@ -154,15 +161,16 @@ SOURCE_DATE_EPOCH="$source_date_epoch" docker buildx build --pull --no-cache --p

# The image labels carry the version and repository. They live in the image
# config rather than the filesystem, so they do not reach the measurements and
# are deliberately not reproduced here.
# are deliberately not reproduced here. (The version also reaches the binary, as
# the VERSION build argument above.)
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "${artifacts}:/artifacts" \
"$nitro_cli_image" build-enclave \
--docker-uri "$enclave_image" \
--output-file /artifacts/verify.eif \
--name nexus-gateway \
--version "$(jq -r '.release.version' "$manifest_path")" >>"$build_log" 2>&1 || fail
--version "$version" >>"$build_log" 2>&1 || fail

describe="$(docker run --rm -v "${artifacts}:/artifacts" "$nitro_cli_image" \
describe-eif --eif-path /artifacts/verify.eif 2>>"$build_log")" || fail
Expand Down
Loading