From b13193ff5de961d81824e80b5f1fac57a19fc596 Mon Sep 17 00:00:00 2001 From: w3irdrobot Date: Wed, 25 Nov 2026 00:38:29 +0000 Subject: [PATCH 1/2] Add gated Production release approvals Production legacy signing moves from the EIF build workflow to the Production release statement workflow. Build and attest the selected environment first, then dispatch its approval workflow with that successful build run ID. One protected approval signs both formats and verifies public publication before proposing the legacy approval branch. Create and protect pcr-signing-prod before filling its identity placeholders. Until it is configured, Production CI approvals and release statements are unavailable; the existing manual update-pcr-prod recipe remains available. Older artifacts add missing history without replacing current measurements. Logs name that classification and omit the current-release deployment handoff for history-only approvals. Public storage settings are checked and publisher credentials are resolved before signing, and each environment refuses the other's signing key. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/opensecret-eif-release.yml | 77 +--- .../opensecret-release-statement-dev.yml | 34 +- .../opensecret-release-statement-prod.yml | 140 +++++++ docs/ci.md | 6 + docs/repository-workflows.md | 2 +- scripts/ci/lanes.py | 16 +- scripts/ci/opensecret_change_detection.py | 26 +- scripts/ci/opensecret_release_statement.py | 42 +- scripts/ci/publish_opensecret_approval.sh | 74 +++- scripts/ci/signing-test-tools.nix | 18 + scripts/ci/test_contracts.py | 147 ++++--- .../ci/test_opensecret_change_detection.py | 31 +- scripts/ci/test_opensecret_eif_scripts.py | 28 +- scripts/ci/test_opensecret_legacy_signing.py | 369 ++++++++++++++++++ .../ci/test_opensecret_release_statement.py | 163 ++++++-- scripts/ci/test_plan.py | 37 +- scripts/ci/test_workflow_policy.py | 8 +- services/opensecret/docs/nitro-deploy.md | 35 +- services/opensecret/docs/pcr-compatibility.md | 7 +- .../opensecret/docs/release-statements.md | 134 ++++--- services/opensecret/scripts/ci_sign_pcr.sh | 29 +- services/opensecret/secretspec/README.md | 19 +- 22 files changed, 1162 insertions(+), 280 deletions(-) create mode 100644 .github/workflows/opensecret-release-statement-prod.yml create mode 100644 scripts/ci/signing-test-tools.nix create mode 100644 scripts/ci/test_opensecret_legacy_signing.py diff --git a/.github/workflows/opensecret-eif-release.yml b/.github/workflows/opensecret-eif-release.yml index 711ec733f..103a30fda 100644 --- a/.github/workflows/opensecret-eif-release.yml +++ b/.github/workflows/opensecret-eif-release.yml @@ -1,28 +1,18 @@ name: OpenSecret EIF release -# Builds one environment's EIF candidate and attests it. For prod, behind the -# reviewer-gated pcr-signing environment, it signs and appends the approval with -# the same recipe operators use; the result is a review branch for an ordinary -# pull request. A dev build is approved by opensecret-release-statement-dev.yml, -# whose one gated job signs both the release statement and the legacy approval. -# This workflow never creates a GitHub Release or tag: /releases/latest and the -# desktop updater metadata belong to the Maple app. -# Deployment stays manual. The legacy repository copy of the signed PCR files -# is retired (services/opensecret/docs/pcr-compatibility.md). +# Builds and attests one environment's EIF candidate. Approval happens in the +# corresponding opensecret-release-statement workflow, where one reviewer-gated +# job signs both the legacy PCR0 approval and the Sigstore release statement. +# Deployment stays manual; this workflow never creates a Release or tag. on: workflow_dispatch: inputs: environment: - description: Measurement set to build and approve + description: Measurement set to build type: choice options: [dev, prod] required: true - dry_run: - description: Build, attest and compare only; uncheck to sign prod after environment approval (dev is signed by the Dev release statement workflow) - type: boolean - default: true - required: true permissions: contents: read @@ -90,60 +80,3 @@ jobs: uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-checksums: eif-artifact/SHA256SUMS - - sign: - name: Sign and append approval (${{ inputs.environment }}) - needs: build - # Dev approvals come only from the Dev release statement workflow, so one - # review covers both of its signatures and nothing signs Dev twice. - if: inputs.environment == 'prod' && inputs.dry_run == false && needs.build.outputs.approval_needed == 'true' - runs-on: ubuntu-latest - timeout-minutes: 30 - # Required reviewer approval and the master-only branch policy live on the - # environment; the only secret it holds is a read-only BWS machine token. - environment: pcr-signing - permissions: - contents: write - env: - APPROVAL_ARTIFACT: ${{ needs.build.outputs.artifact }} - EXPECTED_EIF_SHA256: ${{ needs.build.outputs.eif_sha256 }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - submodules: recursive - fetch-depth: 0 - - - name: Install pinned Nix - uses: DeterminateSystems/determinate-nix-action@16f94ba7aae399b9f9077c254b6719ec6de7e3e3 # v3.24.2 - with: - source-tag: v3.24.2 - github-token: "" - - - name: Verify pinned Nix runtime - run: bash scripts/ci/verify-nix-runtime.sh - - - name: Download the attested EIF candidate - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: ${{ env.APPROVAL_ARTIFACT }} - path: eif-artifact - - - name: Resolve the existing signing key from Bitwarden Secrets Manager - id: signing-key - uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 - with: - access_token: ${{ secrets.OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN }} - secrets: | - ${{ vars.OPENSECRET_PCR_SIGNING_KEY_ID }} > SIGNING_PRIVATE_KEY - set_env: false - - - name: Sign PCR0 and append the verified approval - env: - SIGNING_PRIVATE_KEY: ${{ steps.signing-key.outputs.SIGNING_PRIVATE_KEY }} - run: nix develop --no-update-lock-file './services/opensecret?submodules=1#signing' -c bash services/opensecret/scripts/ci_sign_pcr.sh "$EIF_MODE" eif-artifact - - - name: Push the approval branch for review - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bash scripts/ci/publish_opensecret_approval.sh "$EIF_MODE" eif-artifact diff --git a/.github/workflows/opensecret-release-statement-dev.yml b/.github/workflows/opensecret-release-statement-dev.yml index d1fc0a7f3..91f084638 100644 --- a/.github/workflows/opensecret-release-statement-dev.yml +++ b/.github/workflows/opensecret-release-statement-dev.yml @@ -7,7 +7,8 @@ run-name: Dev release statement for build run ${{ inputs.build_run_id }} # Sigstore release statement with the Dev KMS key and the legacy PCR0 approval # with the existing key, so one review covers both; publishes the bundle to the # Dev attestation host; and pushes the legacy approval branch for review. The -# environment, key, bucket and host are fixed here, never inputs. See +# environment and key are fixed here; bucket and host are fixed per mode in +# scripts/ci/opensecret_release_statement.py. None are inputs. See # services/opensecret/docs/release-statements.md. on: @@ -61,9 +62,12 @@ jobs: - uses: ./.github/actions/setup-nix - - name: Refuse to run with an incomplete signing identity + - name: Check the signing identity and public storage settings + env: + ATTESTATIONS_R2_ACCOUNT_ID: ${{ vars.ATTESTATIONS_R2_ACCOUNT_ID }} + ATTESTATIONS_R2_BUCKET: ${{ vars.ATTESTATIONS_R2_BUCKET }} run: >- - nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#yq-go -c python3 -I scripts/ci/opensecret_release_statement.py preflight dev - name: Verify the selected Dev build and prepare its statement @@ -79,6 +83,16 @@ jobs: nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 -c python3 -I scripts/ci/opensecret_release_statement.py install-cosign "$RUNNER_TEMP/cosign" + - name: Resolve the Dev bucket publisher credential + id: publisher + uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 + with: + access_token: ${{ secrets.OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN }} + secrets: | + ${{ vars.ATTESTATIONS_R2_ACCESS_KEY_ID_SECRET_ID }} > AWS_ACCESS_KEY_ID + ${{ vars.ATTESTATIONS_R2_SECRET_ACCESS_KEY_SECRET_ID }} > AWS_SECRET_ACCESS_KEY + set_env: false + - name: Resolve the existing PCR signing key id: signing-key uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 @@ -96,7 +110,7 @@ jobs: - name: Sign the release statement with the Dev KMS key run: >- - nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#yq-go -c python3 -I scripts/ci/opensecret_release_statement.py sign dev candidate release "$RUNNER_TEMP/cosign/cosign" - name: Retain the EIF with its original bundle @@ -109,16 +123,6 @@ jobs: if-no-files-found: error retention-days: 90 - - name: Resolve the Dev bucket publisher credential - id: publisher - uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 - with: - access_token: ${{ secrets.OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN }} - secrets: | - ${{ vars.ATTESTATIONS_R2_ACCESS_KEY_ID_SECRET_ID }} > AWS_ACCESS_KEY_ID - ${{ vars.ATTESTATIONS_R2_SECRET_ACCESS_KEY_SECRET_ID }} > AWS_SECRET_ACCESS_KEY - set_env: false - - name: Publish the bundle and verify the public bytes env: AWS_ACCESS_KEY_ID: ${{ steps.publisher.outputs.AWS_ACCESS_KEY_ID }} @@ -133,4 +137,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} EXPECTED_SOURCE_SHA: ${{ steps.candidate.outputs.source_sha }} - run: bash scripts/ci/publish_opensecret_approval.sh dev candidate + run: nix develop --no-update-lock-file './services/opensecret?submodules=1#signing' -c bash scripts/ci/publish_opensecret_approval.sh dev candidate diff --git a/.github/workflows/opensecret-release-statement-prod.yml b/.github/workflows/opensecret-release-statement-prod.yml new file mode 100644 index 000000000..a2b62109d --- /dev/null +++ b/.github/workflows/opensecret-release-statement-prod.yml @@ -0,0 +1,140 @@ +name: OpenSecret Production release statement +# Shown on the run list and the reviewer's approval screen, so the reviewer can +# see which build they are approving. +run-name: Production release statement for build run ${{ inputs.build_run_id }} + +# Approves one verified Production EIF build. Its single reviewer-gated job signs the +# Sigstore release statement with the Production KMS key and the legacy PCR0 approval +# with the existing key, so one review covers both; publishes the bundle to the +# Production attestation host; and pushes the legacy approval branch for review. The +# environment and key are fixed here; bucket and host are fixed per mode in +# scripts/ci/opensecret_release_statement.py. None are inputs. See +# services/opensecret/docs/release-statements.md. + +on: + workflow_dispatch: + inputs: + build_run_id: + description: Run ID of a successful master OpenSecret EIF release run built for prod + type: string + required: true + +permissions: + contents: read + +concurrency: + group: opensecret-release-statement-prod + cancel-in-progress: false + +jobs: + sign: + name: Verify, sign and publish the Production release statement + if: github.repository == 'MaplePrivacyLabs/Maple' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + timeout-minutes: 60 + # Required reviewers and the master-only branch rule live on the environment. + # It also scopes the AWS role (its OIDC subject names this environment) and + # holds this environment's own BWS machine token, which reads only the legacy + # signing key and the Production bucket's publisher credential. + environment: pcr-signing-prod + permissions: + contents: write + actions: read + attestations: read + id-token: write + env: + OPENSECRET_DEV_POSTGRES: "0" + OPENSECRET_DEV_ENV: "0" + OPENSECRET_DEV_CONTAINERS: "0" + BUILD_RUN_ID: ${{ inputs.build_run_id }} + # The Production approval key, by full ARN (never an alias), and the only role its + # policy lets sign. The preflight step fails the job while these are + # placeholders or the reviewed public key below is not committed. + SIGNING_KEY_ARN: REPLACE_ME_PROD_KMS_KEY_ARN + SIGNER_ROLE_ARN: REPLACE_ME_PROD_SIGNER_ROLE_ARN + SIGNING_PUBLIC_KEY: scripts/ci/opensecret-release/prod-signing-key.pem + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: recursive + fetch-depth: 0 + + - uses: ./.github/actions/setup-nix + + - name: Check the signing identity and public storage settings + env: + ATTESTATIONS_R2_ACCOUNT_ID: ${{ vars.ATTESTATIONS_R2_ACCOUNT_ID }} + ATTESTATIONS_R2_BUCKET: ${{ vars.ATTESTATIONS_R2_BUCKET }} + run: >- + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#yq-go + -c python3 -I scripts/ci/opensecret_release_statement.py preflight prod + + - name: Verify the selected Production build and prepare its statement + id: candidate + env: + GH_TOKEN: ${{ github.token }} + run: >- + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#gh + -c python3 -I scripts/ci/opensecret_release_statement.py prepare prod "$BUILD_RUN_ID" candidate release + + - name: Install the pinned Cosign release + run: >- + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 + -c python3 -I scripts/ci/opensecret_release_statement.py install-cosign "$RUNNER_TEMP/cosign" + + - name: Resolve the Production bucket publisher credential + id: publisher + uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 + with: + access_token: ${{ secrets.OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN }} + secrets: | + ${{ vars.ATTESTATIONS_R2_ACCESS_KEY_ID_SECRET_ID }} > AWS_ACCESS_KEY_ID + ${{ vars.ATTESTATIONS_R2_SECRET_ACCESS_KEY_SECRET_ID }} > AWS_SECRET_ACCESS_KEY + set_env: false + + - name: Resolve the existing PCR signing key + id: signing-key + uses: bitwarden/sm-action@1238aae8fc64b212641190a9227c8a734ab1a793 # v3.0.1 + with: + access_token: ${{ secrets.OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN }} + secrets: | + ${{ vars.OPENSECRET_PCR_SIGNING_KEY_ID }} > SIGNING_PRIVATE_KEY + set_env: false + + - name: Sign the same candidate for legacy clients + env: + SIGNING_PRIVATE_KEY: ${{ steps.signing-key.outputs.SIGNING_PRIVATE_KEY }} + EXPECTED_EIF_SHA256: ${{ steps.candidate.outputs.eif_sha256 }} + run: nix develop --no-update-lock-file './services/opensecret?submodules=1#signing' -c bash services/opensecret/scripts/ci_sign_pcr.sh prod candidate + + - name: Sign the release statement with the Production KMS key + run: >- + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#yq-go + -c python3 -I scripts/ci/opensecret_release_statement.py sign prod candidate release "$RUNNER_TEMP/cosign/cosign" + + - name: Retain the EIF with its original bundle + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: opensecret-approved-prod-${{ steps.candidate.outputs.source_sha }}-${{ github.run_id }}-${{ github.run_attempt }} + path: | + candidate + release + if-no-files-found: error + retention-days: 90 + + - name: Publish the bundle and verify the public bytes + env: + AWS_ACCESS_KEY_ID: ${{ steps.publisher.outputs.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ steps.publisher.outputs.AWS_SECRET_ACCESS_KEY }} + ATTESTATIONS_R2_ACCOUNT_ID: ${{ vars.ATTESTATIONS_R2_ACCOUNT_ID }} + ATTESTATIONS_R2_BUCKET: ${{ vars.ATTESTATIONS_R2_BUCKET }} + run: >- + nix shell --no-update-lock-file --inputs-from . nixpkgs#python3 nixpkgs#awscli2 + -c python3 -I scripts/ci/opensecret_release_statement.py publish prod candidate release "$RUNNER_TEMP/cosign/cosign" + + - name: Push the legacy approval branch for review + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + EXPECTED_SOURCE_SHA: ${{ steps.candidate.outputs.source_sha }} + run: nix develop --no-update-lock-file './services/opensecret?submodules=1#signing' -c bash scripts/ci/publish_opensecret_approval.sh prod candidate diff --git a/docs/ci.md b/docs/ci.md index 9e97e4eda..f3c47173b 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -51,6 +51,12 @@ from stdin. It applies no labels, and it lists `os-eif` for any EIF input without the same-repository and base-`master` checks (it does drop it for a PCR approval edit). +The `repo` lane also runs the legacy signing regressions with explicitly listed +binary-cache tools from the root's locked nixpkgs. It does not enter the +OpenSecret development shell or build a patched Git. Missing tools fail this +CI step. Tests use local fixtures; local harness verification additionally cuts +off networking. The lane uses an ordinary shallow checkout and no submodules. + ## Tiers | When | What runs | diff --git a/docs/repository-workflows.md b/docs/repository-workflows.md index 5e70d48d6..32fae43a7 100644 --- a/docs/repository-workflows.md +++ b/docs/repository-workflows.md @@ -112,7 +112,7 @@ the other side of each contract. A failure means the workflow change is wrong: 1. `release.yml` and the publishers (`pages-publish`, `proxy-publish`, `updates-publish`, `sdk-publish-npm`, `sdk-publish-rust`, `auth-pages-publish`, `opensecret-eif-release`, - `opensecret-release-statement-dev`) + `opensecret-release-statement-dev`, `opensecret-release-statement-prod`) change only with owner review. Exactly one workflow is named `Release`, and every `workflow_run` listener names its producer and checks the head repository, conclusion and event. diff --git a/scripts/ci/lanes.py b/scripts/ci/lanes.py index ff6ea9acd..bc509be00 100644 --- a/scripts/ci/lanes.py +++ b/scripts/ci/lanes.py @@ -33,6 +33,12 @@ def cache_store(label: str) -> str: return "blacksmith" if label.startswith("blacksmith-") else "github" +SIGNING_TEST_RUN = ( + "nix shell --no-update-lock-file --impure --file scripts/ci/signing-test-tools.nix" + " -c env CI=true PYTHONDONTWRITEBYTECODE=1 python3 -B -I -m unittest discover" + " -s scripts/ci -p test_opensecret_legacy_signing.py" +) + # The override variables are unset; set one to fail over during an outage. LINUX = Runner("blacksmith-8vcpu-ubuntu-2404", "CI_LINUX_RUNNER") LINUX_HEAVY = Runner("blacksmith-32vcpu-ubuntu-2404", "CI_LINUX_HEAVY_RUNNER") @@ -307,14 +313,18 @@ def deny(manifest: str, component: str) -> str: run=WINDOWS_PACKAGE, env=(("MAPLE_WINDOWS_ARCH", "aarch64"), ("RUSTFLAGS", "-D warnings -C target-feature=+crt-static")) + FAST_RELEASE, timeout=120, gate=False), - # Every root flake check: actionlint, workflow policy and contracts, CI script - # tests, the release gates, and release metadata (read from the version files). + # Root flake checks cover workflows, CI contracts, release gates and metadata. + # Legacy signing also runs with explicit cached tools; missing tools fail CI. Lane("repo", ( ".github/**", "scripts/ci/**", ".githooks/**", "flake.nix", "flake.lock", "justfile", "setup-hooks.sh", ".agents/skills/release-maple/scripts/**", "scripts/update-version.py", "proxy/Cargo.toml", "proxy/justfile", RESEARCH + "package.json", TAURI + "Cargo.toml", TAURI + "tauri.conf.json", - ), runner=GITHUB, run="nix flake check --no-update-lock-file --print-build-logs", timeout=15, hook="repo"), + "services/opensecret/scripts/ci_sign_pcr.sh", "services/opensecret/justfile", + "services/opensecret/scripts/pcr_compatibility.py", "services/opensecret/pcr_sign.js", + ), runner=GITHUB, + run="nix flake check --no-update-lock-file --print-build-logs && " + SIGNING_TEST_RUN, + timeout=15, hook="repo"), # The SDKs, proxy and container. build-sdk-publish.sh is the publishers' own builder. Lane("sdk-ts", SDK_TS + ("sdk/.prettierrc.json", "sdk/eslint.config.js", "sdk/justfile", "sdk/.env.example", diff --git a/scripts/ci/opensecret_change_detection.py b/scripts/ci/opensecret_change_detection.py index b869f74e1..a32787da2 100644 --- a/scripts/ci/opensecret_change_detection.py +++ b/scripts/ci/opensecret_change_detection.py @@ -1,13 +1,17 @@ #!/usr/bin/env python3 -"""Select backend checks and SDK compatibility without rebuilding desktop apps.""" +"""Classify backend CI paths and EIF input differences for release approvals.""" from __future__ import annotations import argparse +import json from collections.abc import Iterable import sys +EIF_CHECK = "eif" +PCR_APPROVAL_OUTPUT = "pcr_approvals" + CHECK_OUTPUTS = ("rust", "nix", "integration", "audit", "eif", "helpers") OUTPUTS = (*CHECK_OUTPUTS, "pcr_approvals") ALL_CHECKS = frozenset(CHECK_OUTPUTS) @@ -115,6 +119,17 @@ def classify_paths(paths: Iterable[str]) -> dict[str, bool]: return {name: name in selected for name in OUTPUTS} +def eif_input_paths(paths: Iterable[str]) -> list[str]: + """Paths conservatively routed to EIF builds, excluding approval-only edits.""" + inputs = [] + for path in paths: + checks = classify_path(path) + is_eif_input = EIF_CHECK in checks and PCR_APPROVAL_OUTPUT not in checks + if is_eif_input: + inputs.append(path) + return inputs + + def classify_pcr(path: str) -> bool: """The `pcr` output for ci.yml's os-pcr lane: the offline PCR tooling and the approvals it verifies. Kept out of OUTPUTS, so the approval workflow's outputs @@ -126,12 +141,21 @@ def classify_pcr(path: str) -> bool: def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--all", action="store_true", help="Select all checks without claiming approvals changed") + parser.add_argument("--eif-input-paths", action="store_true", help="List EIF input paths as JSON") + parser.add_argument("--eif-inputs", action="store_true", help="Report EIF input changes, excluding approval files") args = parser.parse_args() if args.all: result = {name: name in ALL_CHECKS for name in OUTPUTS} else: paths = (path.decode("utf-8", errors="surrogateescape") for path in sys.stdin.buffer.read().split(b"\0") if path) + if args.eif_inputs or args.eif_input_paths: + inputs = eif_input_paths(paths) + if args.eif_input_paths: + print(json.dumps(inputs)) + else: + print("true" if inputs else "false") + return 0 result = classify_paths(paths) for name in OUTPUTS: print(f"{name}={'true' if result[name] else 'false'}") diff --git a/scripts/ci/opensecret_release_statement.py b/scripts/ci/opensecret_release_statement.py index 6386ff618..995f6a97c 100644 --- a/scripts/ci/opensecret_release_statement.py +++ b/scripts/ci/opensecret_release_statement.py @@ -1,9 +1,9 @@ """Verify one OpenSecret EIF build, sign its release statement and publish the bundle. -The reviewer-gated job in opensecret-release-statement-dev.yml runs these +Each reviewer-gated release statement workflow runs these subcommands in order. Each one re-checks what it relies on and fails closed: - preflight MODE the fixed signing identity is complete + preflight MODE signing identity and public storage settings are valid prepare MODE RUN_ID CANDIDATE RELEASE the build run, artifact and build provenance are the selected master release build; writes @@ -275,6 +275,30 @@ def reviewed_public_key(environ): return path, public_key_der(committed.decode(errors="replace")) +def workflow_signing_identity(mode): + """Read the other workflow's reviewed literals without a second identity table.""" + workflow = f".github/workflows/opensecret-release-statement-{mode}.yml" + committed = committed_file(workflow) + require(committed is not None, f"The signing workflow {workflow} is not committed") + parsed = subprocess.run(["yq", "-o=json", ".jobs.sign.env"], input=committed, + check=True, stdout=subprocess.PIPE) + return json_object(strict_json(parsed.stdout), "Workflow signing identity") + + +def require_distinct_identity(target, key_arn, path, der): + opposite_mode = "dev" + if target.mode == "dev": + opposite_mode = "prod" + opposite = workflow_signing_identity(opposite_mode) + require(key_arn != opposite["SIGNING_KEY_ARN"], "Signing key ARN belongs to the other environment") + opposite_path = ROOT / opposite["SIGNING_PUBLIC_KEY"] + require(path != opposite_path.resolve(), "Reviewed public key file belongs to the other environment") + opposite_key = committed_file(opposite["SIGNING_PUBLIC_KEY"]) + if opposite_key is not None: + opposite_der = public_key_der(opposite_key.decode(errors="replace")) + require(der != opposite_der, "Reviewed public key matches the other environment's key") + + def signing_identity(target, environ): """Validate the workflow's fixed key and role. Placeholders and aliases never pass.""" key_arn = environ.get("SIGNING_KEY_ARN", "") @@ -288,12 +312,14 @@ def signing_identity(target, environ): f"SIGNER_ROLE_ARN must be the {target.signer_role} role") require(role["account"] == key["account"], "Signer role and key must be in the same account") path, der = reviewed_public_key(environ) + require_distinct_identity(target, key_arn, path, der) return key_arn, role_arn, path, der def preflight(mode): target = target_for(mode) key_arn, role_arn, path, der = signing_identity(target, os.environ) + storage_settings(target, os.environ) print(f"Signing identity for {target.environment}: {key_arn} via {role_arn}; " f"reviewed key {path.relative_to(ROOT)} (SPKI SHA-256 {hashlib.sha256(der).hexdigest()}).") @@ -864,11 +890,17 @@ def public_get(url): return body -def upload(target, bundle, key): - account = os.environ.get("ATTESTATIONS_R2_ACCOUNT_ID", "") +def storage_settings(target, environ): + """Check public storage configuration before signing and again before upload.""" + account = environ.get("ATTESTATIONS_R2_ACCOUNT_ID", "") require(is_hex(account, 32), "ATTESTATIONS_R2_ACCOUNT_ID must be a Cloudflare account ID") - require(os.environ.get("ATTESTATIONS_R2_BUCKET") == target.bucket, + require(environ.get("ATTESTATIONS_R2_BUCKET") == target.bucket, f"This workflow publishes only to {target.bucket}") + return account + + +def upload(target, bundle, key): + account = storage_settings(target, os.environ) access_key, secret_key = os.environ.get("AWS_ACCESS_KEY_ID"), os.environ.get("AWS_SECRET_ACCESS_KEY") require(access_key and secret_key, "Missing the bucket publisher credential") # The CLI adds its own checksums only where an operation requires them; diff --git a/scripts/ci/publish_opensecret_approval.sh b/scripts/ci/publish_opensecret_approval.sh index 5507afa55..4e86dea66 100755 --- a/scripts/ci/publish_opensecret_approval.sh +++ b/scripts/ci/publish_opensecret_approval.sh @@ -70,6 +70,32 @@ git_bot() { -c user.email='41898282+github-actions[bot]@users.noreply.github.com' "$@" } +branch_approves_candidate() { + local tip=$1 + local baseline=$2 + local handoff=$3 + local history=$4 + local approved + approved=$(mktemp -d) + mkdir -- "$approved/baseline" + for file in pcrDev.json pcrProd.json pcrDevHistory.json pcrProdHistory.json; do + git show "$tip:services/opensecret/$file" > "$approved/$file" + git show "$baseline:services/opensecret/$file" > "$approved/baseline/$file" + done + # A pending branch may already approve this build. Verify its signatures and + # preservation of this checkout's history before accepting it on a rerun. + local valid=false + if python3 services/opensecret/scripts/pcr_compatibility.py check "$approved" \ + --baseline-dir "$approved/baseline" > /dev/null; then + valid=$(jq --slurpfile handoff "$handoff" \ + 'any(.[]; .PCR0 == $handoff[0].measurements.PCR0 and + .PCR1 == $handoff[0].measurements.PCR1 and + .PCR2 == $handoff[0].measurements.PCR2)' "$approved/${history##*/}") + fi + rm -rf -- "$approved" + [[ "$valid" == true ]] +} + pcr0=$(jq -r .measurements.PCR0 "$handoff") eif_sha256=$(jq -r .eif_sha256 "$handoff") git add -- "$snapshot" "$history" @@ -83,7 +109,9 @@ git_bot commit --quiet \ # Land this commit on top of whatever the branch already holds for this build # commit and checkout. A push loses the race only to the other environment's # run, which touches different files, so refetch and replay once and try again. -pushed=0 +approval_ready=false +reused=false +approval_tip=HEAD for attempt in 1 2 3 4 5; do if git_auth fetch --quiet origin "refs/heads/$branch:refs/remotes/origin/$branch" 2>/dev/null; then tip=$(git rev-parse "refs/remotes/origin/$branch") @@ -91,46 +119,72 @@ for attempt in 1 2 3 4 5; do echo "Branch $branch does not descend from $checkout_sha; inspect it before rerunning." >&2 exit 1 } + own_approval=false while read -r path; do [[ -n "$path" ]] || continue case "$path" in "$snapshot" | "$history") - echo "Branch $branch already carries the $mode approval; merge or delete it before rerunning." >&2 - exit 1 ;; + own_approval=true + ;; services/opensecret/pcrDev.json | services/opensecret/pcrDevHistory.json | \ services/opensecret/pcrProd.json | services/opensecret/pcrProdHistory.json) ;; *) echo "Branch $branch changes more than approval files: $path" >&2; exit 1 ;; esac done <<< "$(git diff --name-only "$checkout_sha" "$tip")" + if [[ "$own_approval" == true ]]; then + if ! branch_approves_candidate "$tip" "$checkout_sha" "$handoff" "$history"; then + echo "Branch $branch already carries the $mode approval but does not verify for this artifact." >&2 + exit 1 + fi + approval_ready=true + reused=true + approval_tip=$tip + break + fi if [[ "$(git rev-parse HEAD~1)" != "$tip" ]]; then git_bot rebase --quiet "$tip" >/dev/null fi fi if git_auth push --quiet origin "HEAD:refs/heads/$branch" 2>/dev/null; then - pushed=1 + approval_ready=true break fi echo "Push of $branch was rejected (attempt $attempt); refetching." >&2 sleep 2 done -[[ "$pushed" == 1 ]] || { +[[ "$approval_ready" == true ]] || { echo "Could not push $branch after five attempts; the approval commit is at $(git rev-parse HEAD) in this checkout." >&2 exit 1 } +updates_snapshot=false +if ! git diff --quiet "$checkout_sha" "$approval_tip" -- "$snapshot"; then + updates_snapshot=true +fi compare="https://github.com/${GITHUB_REPOSITORY}/compare/master...${branch}?expand=1" if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then { - echo "## Approval branch pushed ($mode)" + echo "## Approval branch ($mode)" echo echo "Open the pull request: $compare" echo echo "The branch is shared by every environment approved for this build commit from" echo "the same checkout; an existing pull request for it simply gains this approval." echo - echo "After it merges, hand deployment the merge commit as \`OPENSECRET_SOURCE_REF\`," - echo "the artifact directory added to the Nix store as \`OPENSECRET_EIF_DIR\`, and" - echo "\`OPENSECRET_EIF_SHA256=${eif_sha256}\`." + if [[ "$updates_snapshot" == true ]]; then + echo "After it merges, hand deployment the merge commit as \`OPENSECRET_SOURCE_REF\`," + echo "the artifact directory added to the Nix store as \`OPENSECRET_EIF_DIR\`, and" + echo "\`OPENSECRET_EIF_SHA256=${eif_sha256}\`." + else + echo "History-only approval: the current snapshot is unchanged." + fi } >> "$GITHUB_STEP_SUMMARY" fi -echo "Pushed $branch; open the pull request at $compare" +if [[ "$reused" == true ]]; then + echo "Branch $branch already approves this artifact; keeping its existing history." +else + echo "Pushed $branch; open the pull request at $compare" +fi +if [[ "$updates_snapshot" == false ]]; then + echo "History-only approval: the current snapshot is unchanged." +fi diff --git a/scripts/ci/signing-test-tools.nix b/scripts/ci/signing-test-tools.nix new file mode 100644 index 000000000..d3bc562a0 --- /dev/null +++ b/scripts/ci/signing-test-tools.nix @@ -0,0 +1,18 @@ +let + root = builtins.getFlake (toString ../..); + # Use upstream packages: the signing shells' patched Git needs a source build. + pkgs = import root.inputs.nixpkgs { + system = builtins.currentSystem; + config = {}; + overlays = []; + }; +in with pkgs; [ + bash + coreutils + diffutils + just + jq + git + yq-go + (python3.withPackages (ps: [ ps.cryptography ])) +] diff --git a/scripts/ci/test_contracts.py b/scripts/ci/test_contracts.py index 60e9dba06..ecf751d13 100644 --- a/scripts/ci/test_contracts.py +++ b/scripts/ci/test_contracts.py @@ -57,7 +57,8 @@ def module(name: str, path: str): ("desktop-build.yml", "build-macos"), ("desktop-build.yml", "build-linux"), ("desktop-build.yml", "build-windows"), ("dev-credential-requester-image.yml", "build"), ("ios-dev-testflight.yml", "build-ios-dev"), ("mobile-build.yml", "build-ios"), ("opensecret-eif-release.yml", "build"), - ("opensecret-release-statement-dev.yml", "sign"), # assumes the Dev signer role + ("opensecret-release-statement-dev.yml", "sign"), + ("opensecret-release-statement-prod.yml", "sign"), # assumes the Production signer role ("ci.yml", "os-eif"), ("opensecret-eif.yml", "eif-trusted"), *(("release.yml", job) for job in ("build-tauri", "build-windows", "build-android", "build-ios", "build-web", "publish-proxy-release-artifacts", "update-latest-json", @@ -83,7 +84,7 @@ def module(name: str, path: str): ("ios-dev-testflight.yml", "submit-ios-dev-testflight"): "apple-signing", ("mobile-build.yml", "build-ios"): "apple-signing", ("mobile-build.yml", "submit-ios-testflight"): "apple-signing", - ("opensecret-eif-release.yml", "sign"): "pcr-signing", + ("opensecret-release-statement-prod.yml", "sign"): "pcr-signing-prod", ("opensecret-release-statement-dev.yml", "sign"): "pcr-signing-dev", ("pages-publish.yml", "preview"): "pages-preview", ("pages-publish.yml", "production"): "pages-production", @@ -626,33 +627,80 @@ def test_c5_oidc_and_flakehub_stay_in_their_jobs_on_one_builder_class(self): def test_c5_eif_release_is_manual_reviewed_and_never_tags(self): config = workflows()["opensecret-eif-release.yml"] self.assertEqual(set(config["on"]), {"workflow_dispatch"}) - self.assertIs(config["on"]["workflow_dispatch"]["inputs"]["dry_run"]["default"], True) + self.assertEqual(set(config["jobs"]), {"build"}) self.assertNotRegex(json.dumps(config), r"gh release|git tag|refs/tags|releases/|latest\.json") - build, sign = config["jobs"]["build"], config["jobs"]["sign"] + build = config["jobs"]["build"] self.assertEqual(build["if"], "github.ref == 'refs/heads/master'") self.assertEqual(build["permissions"], {"contents": "read", "id-token": "write", "attestations": "write"}) self.assertNotIn("environment", build) self.assertFalse(re.search(r"\bsecrets\b|github\.token|\bGH_TOKEN\b", json.dumps(build))) - self.assertEqual(sign["needs"], "build") - # Only prod is signed here; the Dev release statement workflow signs dev. - for mode, dry_run, needed in itertools.product(("dev", "prod"), (True, False), ("true", "false")): - context = {"inputs.environment": mode, "inputs.dry_run": dry_run, - "needs.build.outputs.approval_needed": needed} - self.assertEqual(evaluate(expression(sign), context), - mode == "prod" and dry_run is False and needed == "true", context) - self.assertEqual(sign["permissions"], {"contents": "write"}) - self.assertNotRegex(json.dumps(sign), r"id-token|flakehub-cache") - key = [step for step in sign["steps"] if "outputs.SIGNING_PRIVATE_KEY" in json.dumps(step)] - self.assertEqual(len(key), 1) # the signing key reaches exactly one step - self.assertEqual(key[0]["env"], {"SIGNING_PRIVATE_KEY": "${{ steps.signing-key.outputs.SIGNING_PRIVATE_KEY }}"}) - - def test_c5_dev_release_statement_is_one_gated_job_with_a_fixed_target(self): - config = workflows()["opensecret-release-statement-dev.yml"] + + def test_c5_release_statement_workflows_differ_only_by_target(self): + def normalize(value, mode): + if isinstance(value, dict): + result = {key: normalize(item, mode) for key, item in value.items()} + for name in ("SIGNING_KEY_ARN", "SIGNER_ROLE_ARN"): + if name in result: + result[name] = "FIXED_IDENTITY" + return result + if isinstance(value, list): + return [normalize(item, mode) for item in value] + if not isinstance(value, str): + return value + opposite_words = r"\b(?:prod|Production)\b" + if mode == "prod": + opposite_words = r"\b(?:dev|Dev)\b" + self.assertNotRegex(value, opposite_words) + value = re.sub(r"\b(?:dev|prod)\b", "mode", value) + return re.sub(r"\b(?:Dev|Production)\b", "Environment", value) + + dev = workflows()["opensecret-release-statement-dev.yml"] + prod = workflows()["opensecret-release-statement-prod.yml"] + self.assertEqual(normalize(dev, "dev"), normalize(prod, "prod")) + + def test_c6_protected_environments_have_fixed_consumers(self): + self.assertEqual({(name, job_id): environment(job) for name, job_id, job in jobs() if environment(job)}, + CONSUMERS) + self.assertLessEqual(set(CONSUMERS.values()), set(ENVIRONMENTS)) + for (name, job_id), granted in CONSUMERS.items(): + if granted == "windows-signing": # the Azure OIDC subject is a GitHub-hosted runner + labels = runner_labels(name, job_id, workflows()[name]["jobs"][job_id]) + self.assertTrue(labels and all(GITHUB_HOSTED.fullmatch(label) for label in labels), job_id) + + def test_c7_docs_name_only_existing_workflows_and_files(self): + files = plan.tracked_files() + names = {Path(path).name for path in files} + titles = {config.get("name") for config in workflows().values()} # display names + dangling = [] + for path in files: + if not (path.endswith(".md") and plan.matches(path, DOCS)): + continue + text = (ROOT / path).read_text(encoding="utf-8", errors="replace") + for match in re.finditer(r"(?` recipe operators use. The key reaches only - the `node pcr_sign.js` child; the verifier checks the signature against the - pinned public key before the history is rewritten atomically. Setup is in - [`secretspec/README.md`](../secretspec/README.md). -3. The job commits the two changed approval files to +2. After environment approval, the selected release statement workflow verifies + the artifact and its build provenance, then uses the existing key + for the legacy signature plus the environment KMS key for the statement. + The protected job verifies and retains the bundle before publication. +3. The job commits any changed approval files to `opensecret/pcr-approval-` and prints the compare link. That branch is shared by both environments' runs for the same source commit: when both measurement sets change, the second run lands its commit on top of the diff --git a/services/opensecret/docs/pcr-compatibility.md b/services/opensecret/docs/pcr-compatibility.md index 201da2332..c826c51bf 100644 --- a/services/opensecret/docs/pcr-compatibility.md +++ b/services/opensecret/docs/pcr-compatibility.md @@ -71,7 +71,7 @@ Build first without credentials, review measurements, then resolve only the existing signing key around the signer. Deployment consumes the resulting reviewed immutable artifact; it must not rebuild or sign implicitly. -After an approval branch from the `OpenSecret EIF release` or +After an approval branch from the `OpenSecret Production release statement` or `OpenSecret Dev release statement` workflow has merged, or after running the operator `update-pcr-*` recipes locally, run the following from `services/opensecret/`: @@ -83,6 +83,11 @@ OPENSECRET_DEV_POSTGRES=0 OPENSECRET_DEV_ENV=0 OPENSECRET_DEV_CONTAINERS=0 \ --baseline-dir /absolute/path/to/services/opensecret/at/the/previous/master ``` +CI signs the artifact measurements directly. If EIF inputs differ between its +source and the signing checkout, approval adds only a missing history entry and +leaves the current snapshot alone; see +[release statements](release-statements.md). + The `update-pcr-dev` and `update-pcr-prod` recipes copy measurements and append a verified signature. This additional check verifies all four files, every PCR0 signature against the SDK's existing public key, snapshot membership in the appropriate diff --git a/services/opensecret/docs/release-statements.md b/services/opensecret/docs/release-statements.md index 8cfa5e25c..240f394f6 100644 --- a/services/opensecret/docs/release-statements.md +++ b/services/opensecret/docs/release-statements.md @@ -8,11 +8,11 @@ public Rekor v2 transparency log, timestamped by Sigstore's public timestamp authority, and published as a standard Sigstore bundle at a fixed public URL keyed by PCR0. -Only Dev statements exist so far. They are produced by -[`opensecret-release-statement-dev.yml`](../../../.github/workflows/opensecret-release-statement-dev.yml) -(`OpenSecret Dev release statement`). Production approvals still use the -legacy signing job in `opensecret-eif-release.yml`; see -[EIF release workflow](nitro-deploy.md#eif-release-workflow). +Dev and Production use separate reviewer-gated workflows: +`opensecret-release-statement-dev.yml` and +`opensecret-release-statement-prod.yml`. Each approves both the legacy PCR0 +signature and the release statement. Production refuses to start until its +placeholder signing identity is replaced with reviewed resources. ## Statement @@ -50,49 +50,78 @@ verified build artifact and its provenance, never from operator input. The build's `handoff.json` is internal to CI. It appears in no statement or bundle. -## Running the Dev workflow +## Running a release statement workflow -Dispatch `opensecret-release-statement-dev.yml` on `master` with one input, -the run ID of a successful `OpenSecret EIF release` run built for `dev`. Its -single job waits for approval of the protected `pcr-signing-dev` environment -(required reviewers, `master` only). That one approval covers both signatures -for the same artifact. The job then: +Create and protect `pcr-signing-prod` with required reviewers and the master-only +rule **before** committing its filled identity. GitHub creates an unprotected +environment when a workflow names an environment that does not exist. + +Until the Production identity is filled, builds and Dev approvals work, but +Production CI approval and Production release statements are unavailable. +The separately authorized `just update-pcr-prod` recipe remains a manual legacy +approval path: it builds locally, uses the operator's Bitwarden login and always +copies the snapshot. It does not approve a CI artifact or create a release statement. + +Dispatch the workflow for the intended environment on `master`, with the run +ID of a successful `OpenSecret EIF release` build for that environment. The +single job waits for approval of `pcr-signing-dev` or `pcr-signing-prod`. +One approval covers both signatures for the same verified artifact. The +build workflow itself never signs. The signing job then: 1. **Refuses to start** if the fixed signing identity in the workflow is incomplete: the KMS key ARN or signer role ARN is a placeholder or not the expected shape, or the reviewed public key file is not a file the checked-out commit tracks, differs from that commit's content, is reached - through a symlink, or is not a P-384 public key. + through a symlink, or is not a P-384 public key. It also refuses a key ARN, + public key file or key material shared with the other environment. The bucket + must match the mode's fixed target, and the storage account ID must be valid. 2. **Verifies the build.** The run must be `opensecret-eif-release.yml`, dispatched on `master` in this public repository, completed successfully, and its commit must be in the checked-out `master` history. The artifact - `opensecret-eif-dev-` must belong to that run and contain exactly + `opensecret-eif--` must belong to that run and contain exactly `image.eif`, `pcr.json`, `handoff.json` and `SHA256SUMS`, all matching. GitHub's build attestation from that workflow, commit and run must cover - all three files, and `handoff.json` must say `dev` and agree with the EIF - digest and measurements. Any earlier successful master build qualifies, + all three files. `handoff.json` must say the selected mode and agree with + the EIF digest and measurements. Any earlier successful master build qualifies, but its artifact is never substituted or rebuilt. Builds from before `handoff.json` was listed in `SHA256SUMS` have no attested build mode and are refused. -3. **Signs the legacy PCR0 approval** with the existing key, exactly as the - release workflow's signing job does, so installed clients keep working. -4. **Signs the release statement** with `cosign attest-blob` and the Dev KMS - key, using the pinned Cosign release and signing configuration below. AWS + The job resolves the publisher credential before either signature. Only the + publication step receives it; an unreadable credential stops approval before + any KMS signing or public log write. +3. **Signs the legacy PCR0 approval** with the existing key, so installed + clients keep working. + It signs the artifact's measurements directly and appends only a missing + history entry. The source must be an ancestor of the signing checkout. + The existing OpenSecret change classifier examines the tree diff from the + authenticated source to the signing checkout. If no EIF input differs, the + candidate is current and may update `pcrDev.json` or `pcrProd.json` after the + append succeeds. Docs, approval-file changes and fully reverted changes do + not make the candidate older. An EIF-input difference adds history without + touching the snapshot. Neither history order nor timestamps choose the + current measurements. + The classifier is conservative: CI-only changes it routes as EIF inputs, + such as the EIF workflow or build script, also make an already-built release + count as older. Rebuild that release before proposing a current approval. + The log and step summary name the classification and the paths that made a + build older. History-only approvals omit the current-release deployment handoff. +4. **Signs the release statement** with `cosign attest-blob` and the + environment KMS key, using the pinned Cosign release and signing configuration below. AWS access comes from the job's GitHub OIDC token, exchanged for short-lived - credentials of the Dev signer role; it reaches only the Cosign process. + credentials of the environment signer role; it reaches only the Cosign process. Before signing, the job compares the KMS public key with the reviewed key and stops on a mismatch. 5. **Verifies the bundle** before anything is published: Cosign verifies it against the reviewed public key, the pinned trusted root and the exact EIF, and the producer requires the evidence profile below. 6. **Retains** the EIF, its build files and the original bundle as the - workflow artifact `opensecret-approved-dev---`. + workflow artifact `opensecret-approved----`. GitHub keeps it for 90 days at most, so it is not durable rollback retention; copy the EIF and its bundle to deployment storage for that. -7. **Publishes** the bundle to the `maple-attestations-dev` bucket as +7. **Publishes** the bundle to the fixed environment bucket as `.json` with `Content-Type: application/json` and `Cache-Control: public, max-age=300`, reads it back from - `https://attestations-dev.maple.ai/.json` with a browser `Origin`, + the fixed environment host with a browser `Origin`, checks the bytes, content type, cache policy and CORS header, and verifies the downloaded copy again. 8. **Pushes the legacy approval branch** for an ordinary review pull request, @@ -125,7 +154,9 @@ measurements are already approved is accepted: the legacy step finds nothing to sign, and its statement replaces the object for those PCRs. The replaced bundle stays with its EIF in the earlier run's retained artifact, so deployment can still check the exact EIF digest while that artifact lasts. -A failed upload or a readback that never returns the uploaded bytes fails the +An existing pending legacy branch is reused only after verifying all of its +signatures, history preservation and the candidate measurements. A failed +upload or a readback that never returns the uploaded bytes fails the job and is not reported as published. Every signing attempt that reaches Rekor makes a permanent public entry, even @@ -149,41 +180,52 @@ producer then fails closed until they are updated. The producer in [`opensecret_release_statement.py`](../../../scripts/ci/opensecret_release_statement.py) holds the Cosign digests, environment mapping, bucket and host. -## Configuration before the first Dev run +After the move, remove the retired `pcr-signing` GitHub environment and revoke +its old BWS machine token. Keep the separate Dev and Production environments +and their tokens. + +## Signing configuration The workflow fails closed until all of the following exist. -Committed to this repository once the Dev signing resources exist: +Each workflow fixes its own identity. Production currently has `REPLACE_ME` +ARNs and no public key; preflight refuses before credentials or signing. +Commit the reviewed Production resources before using it: | Value | Where | | --- | --- | -| Dev KMS key's full ARN, `arn:aws:kms:us-east-1::key/` (never an alias) | `SIGNING_KEY_ARN` in the workflow's job `env` | -| Dev signer role ARN, `arn:aws:iam:::role/maple-pcr-signer-dev` | `SIGNER_ROLE_ARN` in the workflow's job `env` | -| Reviewed Dev public key, SPKI PEM (P-384) | `scripts/ci/opensecret-release/dev-signing-key.pem` | +| Environment KMS key's full ARN, `arn:aws:kms:us-east-1::key/` (never an alias) | `SIGNING_KEY_ARN` in the workflow's job `env` | +| Environment signer role ARN, `arn:aws:iam:::role/maple-pcr-signer-` | `SIGNER_ROLE_ARN` in the workflow's job `env` | +| Reviewed environment public key, SPKI PEM (P-384) | `scripts/ci/opensecret-release/-signing-key.pem` | -The protected GitHub environment `pcr-signing-dev`: required reviewers, -deployment branches limited to `master`, administrator bypass disabled. It +Each protected GitHub environment (`pcr-signing-dev` and `pcr-signing-prod`) +requires reviewers, deployment branches limited to `master`, and administrator +bypass disabled. It holds exactly this one secret and these five variables, all set on the environment, not the repository: | Name | Kind | Value | | --- | --- | --- | -| `OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN` | Secret | A Bitwarden Secrets Manager machine token for Dev only. It can read the existing legacy PCR signing key item and the Dev bucket's two publisher items, and nothing for Production. Same name as the secret in `pcr-signing`, but its own value and grants. | +| `OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN` | Secret | A Bitwarden Secrets Manager machine token for that environment only. It can read the existing legacy signing key and its own bucket publisher items, never the opposite publisher credential. | | `OPENSECRET_PCR_SIGNING_KEY_ID` | Variable | BWS item ID of the existing legacy PCR signing key | | `ATTESTATIONS_R2_ACCOUNT_ID` | Variable | Cloudflare account ID that owns the bucket (32 hex characters) | -| `ATTESTATIONS_R2_BUCKET` | Variable | `maple-attestations-dev` | -| `ATTESTATIONS_R2_ACCESS_KEY_ID_SECRET_ID` | Variable | BWS item ID of the Dev bucket publisher's access key ID | -| `ATTESTATIONS_R2_SECRET_ACCESS_KEY_SECRET_ID` | Variable | BWS item ID of the Dev bucket publisher's secret access key | - -Outside this repository: the signer role can be assumed only by a job whose -OIDC token matches this repository's `pcr-signing-dev` environment subject, the -`master` ref, and this workflow file at `master`, and it may sign only with the -Dev key. Renaming this workflow file therefore stops signing until the role is -updated; -the Dev publisher credential can write only `maple-attestations-dev`; and the -bucket's `attestations-dev.maple.ai` custom domain serves public `GET`/`HEAD` -with CORS. No zone cache setting may replace the object's -`Cache-Control: public, max-age=300`, or the readback check fails. +| `ATTESTATIONS_R2_BUCKET` | Variable | `maple-attestations-dev` or `maple-attestations-prod`, matching the workflow | +| `ATTESTATIONS_R2_ACCESS_KEY_ID_SECRET_ID` | Variable | BWS item ID of the environment bucket publisher's access key ID | +| `ATTESTATIONS_R2_SECRET_ACCESS_KEY_SECRET_ID` | Variable | BWS item ID of the environment bucket publisher's secret access key | + +| Mode | Protected environment | Bucket | Public host | +| --- | --- | --- | --- | +| `dev` | `pcr-signing-dev` | `maple-attestations-dev` | `attestations-dev.maple.ai` | +| `prod` | `pcr-signing-prod` | `maple-attestations-prod` | `attestations.maple.ai` | + +Outside this repository, each signer role must accept only its protected +environment subject, the `master` ref and its exact workflow file at `master`. +The Production trust pins +`MaplePrivacyLabs/Maple/.github/workflows/opensecret-release-statement-prod.yml@refs/heads/master`. +Each role may sign only its own KMS key; each publisher may write only its own +bucket. Required reviewers, no administrator bypass, signing alerts, BWS grants, +public domains and CORS require operator configuration and live verification. +No zone cache setting may replace `Cache-Control: public, max-age=300`. ## Verifying a published bundle @@ -191,7 +233,7 @@ With the reviewed Dev public key and the EIF: ```sh curl -fsS -o bundle.json "https://attestations-dev.maple.ai/.json" -cosign verify-blob-attestation --bundle bundle.json \ +COSIGN_MAX_ATTACHMENT_SIZE=2147483648 cosign verify-blob-attestation --bundle bundle.json \ --key scripts/ci/opensecret-release/dev-signing-key.pem \ --type https://maple.ai/attestations/enclave-release/v1 \ --use-signed-timestamps \ diff --git a/services/opensecret/scripts/ci_sign_pcr.sh b/services/opensecret/scripts/ci_sign_pcr.sh index ab56dd0c4..94a6465c7 100755 --- a/services/opensecret/scripts/ci_sign_pcr.sh +++ b/services/opensecret/scripts/ci_sign_pcr.sh @@ -34,10 +34,35 @@ fi exit 1 } -cp -- "$artifact/pcr.json" "./$snapshot" +# An older build may add history but must leave the current snapshot alone. +# Docs and approval edits do not make the authenticated build older. +source_sha=$(jq -er .source_sha "$artifact/handoff.json") +checkout_sha=$(git rev-parse HEAD) +if ! git merge-base --is-ancestor "$source_sha" "$checkout_sha"; then + echo "Artifact source is outside this checkout's history." >&2 + exit 1 +fi +eif_input_changes=$(git diff --name-only --no-renames -z "$source_sha" "$checkout_sha" | + python3 ../../scripts/ci/opensecret_change_detection.py --eif-input-paths) +candidate_is_current=$(jq -r 'length == 0' <<< "$eif_input_changes") +if [[ "$candidate_is_current" == true ]]; then + classification="Current build: the EIF inputs match this checkout; updating $snapshot." +else + changed_paths=$(jq -r '.[] | @json' <<< "$eif_input_changes") + classification=$(printf 'Older build: leaving %s unchanged; approving history only.\nEIF input differences:\n%s' \ + "$snapshot" "$changed_paths") +fi +printf '%s\n' "$classification" +if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + printf '## Legacy approval (%s)\n\n%s\n\n' "$mode" "$classification" >> "$GITHUB_STEP_SUMMARY" +fi # The recipe validates the files, skips already approved measurements before # any signing, signs PCR0 only inside the node child, verifies the signature, # and appends atomically. Everything else runs under its credential-free env. -just --no-dotenv --set pcr_signer 'node pcr_sign.js sign-pcr0' "append-pcr-$mode" +history="${snapshot%.json}History.json" +just --no-dotenv --set pcr_signer 'node pcr_sign.js sign-pcr0' _append-pcr-file "$artifact/pcr.json" "$history" +if [[ "$candidate_is_current" == true ]]; then + cp -- "$artifact/pcr.json" "./$snapshot" +fi unset SIGNING_PRIVATE_KEY python3 scripts/pcr_compatibility.py check . diff --git a/services/opensecret/secretspec/README.md b/services/opensecret/secretspec/README.md index 1a8d40a5e..c1175db3f 100644 --- a/services/opensecret/secretspec/README.md +++ b/services/opensecret/secretspec/README.md @@ -80,12 +80,15 @@ may still access that user's keyring and credential files. ## CI signing -The `OpenSecret EIF release` workflow signs with the same key and recipe behind -the protected `pcr-signing` GitHub environment (required reviewer, `master` -only). Its one-time setup, performed by an owner: - -- A `pcr-signing-ci` BWS machine account with read access to only the signing - project, and an access token with an expiry date. +The Dev and Production release statement workflows sign with the same legacy +key and recipe behind their separate `pcr-signing-dev` and `pcr-signing-prod` +GitHub environments (required reviewer, `master` only). See +[release statements](../docs/release-statements.md) for the environment-specific +KMS identity and publisher configuration. An owner sets up each environment: + +- A separate BWS machine account for each protected environment, with read + access to the existing signing key and only that environment's publisher + items, and an access token with an expiry date. - Environment secret `OPENSECRET_PCR_SIGNING_BWS_ACCESS_TOKEN` holding that token. GitHub never holds the key itself: a leaked token is revoked in Bitwarden, while a leaked key could not be rotated without a client update. @@ -94,8 +97,8 @@ only). Its one-time setup, performed by an owner: Bitwarden's Secrets Manager action resolves the key as a masked step output that only the signing step receives. `scripts/ci_sign_pcr.sh` then runs the -`append-pcr-*` recipe with `--set pcr_signer 'node pcr_sign.js sign-pcr0'`, so -the key still reaches only the node signer and the verification and atomic +`_append-pcr-file` recipe against the verified artifact measurements with +`--set pcr_signer 'node pcr_sign.js sign-pcr0'`, so the key still reaches only the node signer and the verification and atomic append are unchanged. Laptops keep the keyring alias; never use that override locally. See [the Nitro runbook](../docs/nitro-deploy.md#eif-release-workflow). From f5fee5ee5cef91f8136cf97defd33fbcae84e5c4 Mon Sep 17 00:00:00 2001 From: w3irdrobot Date: Wed, 25 Nov 2026 05:32:58 +0000 Subject: [PATCH 2/2] Run operator signing fixtures in a real Git repository The signer checks commit ancestry and EIF input differences. Give the operator fixture a repository and a real source commit so it reaches the credential and signature checks. Keep its classifier stand-in restricted to the empty diff used by this current-build scenario. Assert checksum and environment refusal reasons in the sibling test to prevent unrelated setup failures from satisfying negative cases. --- .../scripts/test_operator_boundaries.py | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/services/opensecret/scripts/test_operator_boundaries.py b/services/opensecret/scripts/test_operator_boundaries.py index d7b65c8f1..b334c47dc 100644 --- a/services/opensecret/scripts/test_operator_boundaries.py +++ b/services/opensecret/scripts/test_operator_boundaries.py @@ -25,8 +25,8 @@ def setUp(self): self.temp = tempfile.TemporaryDirectory(prefix="pcr-operator-") self.addCleanup(self.temp.cleanup) self.root = Path(self.temp.name) - self.backend = self.root / "backend" - self.backend.mkdir() + self.backend = self.root / "services/opensecret" + self.backend.mkdir(parents=True) (self.backend / "scripts").mkdir() (self.backend / "secretspec").mkdir() for relative in ("justfile", "pcr_sign.js", "scripts/pcr_compatibility.py", "scripts/ci_sign_pcr.sh", @@ -46,6 +46,7 @@ def setUp(self): self.env = { "PATH": os.environ["PATH"], "HOME": str(self.home), "XDG_CONFIG_HOME": str(self.home / ".config"), + "PYTHONDONTWRITEBYTECODE": "1", } for name in ("SIGNING_PRIVATE_KEY", "BWS_ACCESS_TOKEN", "SECRETSPEC_FILE", "SECRETSPEC_PROVIDER", "BWS_CONFIG_FILE", "AWS_SECRET_ACCESS_KEY", @@ -114,7 +115,29 @@ def test_wrong_key_signature_never_changes_history(self): self.assertEqual((self.backend / "pcrDevHistory.json").read_bytes(), before) self.assertNotIn(encoded, result.stdout + result.stderr) + def fixture_git(self, *arguments): + result = subprocess.run( + ["git", "-C", str(self.root), "-c", "user.name=fixture", + "-c", "user.email=fixture@example.invalid", "-c", "commit.gpgsign=false", *arguments], + env=self.env, text=True, capture_output=True, check=True, + ) + return result.stdout.strip() + def ci_artifact(self): + scripts = self.root / "scripts/ci" + scripts.mkdir(parents=True) + # This fixture tests the key boundary at the build commit. The backend + # check has no monorepo classifier; refuse any nonempty diff in its place. + (scripts / "opensecret_change_detection.py").write_text( + "import sys\n" + "assert sys.argv[1:] == ['--eif-input-paths']\n" + "assert sys.stdin.buffer.read() == b''\n" + "print('[]')\n" + ) + self.fixture_git("init", "--quiet", "--initial-branch=master") + self.fixture_git("add", "services", "scripts") + self.fixture_git("commit", "--quiet", "-m", "fixture build") + source_sha = self.fixture_git("rev-parse", "HEAD") artifact = self.root / "artifact" artifact.mkdir() (artifact / "pcr.json").write_bytes(fixture(2)["pcrDev.json"]) @@ -122,7 +145,7 @@ def ci_artifact(self): (artifact / "SHA256SUMS").write_text("".join( f"{hashlib.sha256((artifact / name).read_bytes()).hexdigest()} {name}\n" for name in ("image.eif", "pcr.json"))) - (artifact / "handoff.json").write_text(json.dumps({"environment": "dev", "source_sha": "0" * 40})) + (artifact / "handoff.json").write_text(json.dumps({"environment": "dev", "source_sha": source_sha})) return artifact def run_ci_signing(self, artifact, **env): @@ -163,10 +186,13 @@ def test_ci_signing_entrypoint_rejects_tampered_or_mismatched_candidates(self): (artifact / "image.eif").write_bytes(b"tampered after attestation") result = self.run_ci_signing(artifact, SIGNING_PRIVATE_KEY="fixture_ci_key") self.assertNotEqual(result.returncode, 0) + self.assertIn("did NOT match", result.stderr) (artifact / "image.eif").write_bytes(b"public synthetic EIF fixture") - (artifact / "handoff.json").write_text(json.dumps({"environment": "prod", "source_sha": "0" * 40})) + source_sha = self.fixture_git("rev-parse", "HEAD") + (artifact / "handoff.json").write_text(json.dumps({"environment": "prod", "source_sha": source_sha})) result = self.run_ci_signing(artifact, SIGNING_PRIVATE_KEY="fixture_ci_key") self.assertNotEqual(result.returncode, 0) + self.assertIn("different environment", result.stderr) self.assertEqual({name: (self.backend / name).read_bytes() for name in before}, before) def test_build_does_not_receive_any_operator_credentials(self):