From 8d6aa5c91c779d92fceaa02f80eb808d7ac271cf Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Mon, 27 Jul 2026 23:46:53 +0530 Subject: [PATCH] =?UTF-8?q?feat(worker-turbo):=20secrets-live=20v2=20?= =?UTF-8?q?=E2=80=94=20runtime=20worker=20secrets=20from=20orun,=20not=20t?= =?UTF-8?q?he=20AWS=20escrow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The secrets-live step no longer fetches the worker-secrets escrow document from AWS Secrets Manager: the component declares its runtime keys in optionalSecretEnv (resolved best-effort into the job env by orun) and names them in the new runtimeSecrets parameter. Names with values present are pushed via wrangler secret bulk after deploy; unseeded names are skipped and reported by name only. jq -Rs per value keeps multiline material (PEM keys) intact; the runner's redactor scrubs any resolved value from captured output. secretsWorker + the escrow/fingerprint flow are retired. Stack 0.15.0 -> 0.16.0. Requires orun >= v2.41.0 (optionalSecretEnv). Co-Authored-By: Claude Fable 5 --- .../cloudflare-worker-turbo/README.md | 4 +- ...cloudflare-worker-turbo-verify-deploy.yaml | 65 +++++++++---------- .../cloudflare-worker-turbo-deploy.yaml | 2 +- .../cloudflare-worker-turbo/schema.yaml | 4 +- stack.yaml | 2 +- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/compositions/cloudflare-worker-turbo/README.md b/compositions/cloudflare-worker-turbo/README.md index 03cd92d..43a7e4a 100644 --- a/compositions/cloudflare-worker-turbo/README.md +++ b/compositions/cloudflare-worker-turbo/README.md @@ -27,7 +27,7 @@ be hydrated from an escrow after deploy. - **Optional wiring parameters:** `wranglerTemplate` (empty means a legacy committed config and the wiring steps no-op), `wiringComponents`, `wiringEnvs` (default `stage,prod`), `wiringFixture` (default - `wiring.fixture.json`), `secretsWorker`, `awsAccountId`, `awsRegion` (default + `wiring.fixture.json`), `runtimeSecrets`, `awsAccountId`, `awsRegion` (default `us-east-1`), `orgName`, `owner`, `repo` ## Profiles @@ -42,7 +42,7 @@ Each file in `profiles/` selects steps from the job by capability. `wire-credentials` and `wire-live` are deploy-only by design so verify lanes stay credential-free; both no-op for components without a `wranglerTemplate`, and -`secrets-live` no-ops for components without `secretsWorker`. +`secrets-live` pushes the component's orun-resolved runtime secrets (`runtimeSecrets` names, best-effort via `optionalSecretEnv`) and no-ops for components without them. ## Verification diff --git a/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml b/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml index fac23d5..f1c8d7b 100644 --- a/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml +++ b/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml @@ -169,45 +169,42 @@ spec: capability: cloudflare-worker-turbo.secrets-live shell: bash run: | - {{- if .parameters.secretsWorker }} - # SS2: hydrate this worker's runtime secrets from the AWS Secrets - # Manager escrow document (//worker-secrets/). Runs - # after deploy so a first-boot worker exists before secrets are - # pushed; `wrangler secret bulk` rolls a new version immediately, so - # smoke still observes the synced state. No escrow document at all = - # pre-SS3 state: existing manually-put secrets are left untouched. + {{- if .parameters.runtimeSecrets }} + # Runtime worker secrets from orun (wire-now-seed-later): the component + # declares its runtime keys in optionalSecretEnv — resolved best-effort + # into THIS job's env by the runner — and names them in the + # runtimeSecrets parameter. Every name with a value present is pushed + # via `wrangler secret bulk` after deploy (first boot creates the + # worker before secrets are pushed; bulk rolls a new version + # immediately, so smoke observes the synced state). Unseeded names are + # skipped and reported by NAME only — values never reach the log, and + # the runner's redactor additionally scrubs any resolved value from + # captured output. set -euo pipefail env_name="{{ .orun.environment.name }}" - escrow_id="{{ .parameters.orgName }}/{{ .parameters.repo }}/worker-secrets/${env_name}" - record_id="{{ .parameters.orgName }}/{{ .parameters.repo }}/worker-secrets-fingerprints/${env_name}" - work_dir=$(mktemp -d) - if ! aws secretsmanager get-secret-value --secret-id "${escrow_id}" \ - --query SecretString --output text > "${work_dir}/escrow.json" 2>/dev/null; then - echo "secrets-live: no escrow document at ${escrow_id} (SS3 not seeded) — leaving existing worker secrets untouched." - exit 0 + bulk="$(mktemp)" + present=(); missing=() + IFS=',' read -ra names <<< "{{ .parameters.runtimeSecrets }}" + for name in "${names[@]}"; do + name="$(echo "$name" | xargs)" + [ -z "$name" ] && continue + if [ -n "${!name:-}" ]; then present+=("$name"); else missing+=("$name"); fi + done + if [ "${#present[@]}" -eq 0 ]; then + echo "secrets-live: none of the declared runtime secrets are seeded in orun yet — leaving existing worker secrets untouched." + rm -f "$bulk"; exit 0 fi - aws secretsmanager get-secret-value --secret-id "${record_id}" \ - --query SecretString --output text > "${work_dir}/record.json" 2>/dev/null \ - || echo '{}' > "${work_dir}/record.json" - node {{ .parameters.workspaceDir }}/tooling/secrets-sync/sync.mjs \ - --manifest {{ .parameters.workspaceDir }}/tooling/secrets-sync/secrets.manifest.json \ - --worker "{{ .parameters.secretsWorker }}" \ - --env "${env_name}" \ - --escrow "${work_dir}/escrow.json" \ - --record "${work_dir}/record.json" \ - --out-bulk "${work_dir}/bulk.json" \ - --out-record "${work_dir}/record.next.json" - if [ "$(cat "${work_dir}/bulk.json")" != "{}" ]; then - pnpm exec wrangler secret bulk "${work_dir}/bulk.json" \ - --config {{ .parameters.wranglerConfig }} --env "${env_name}" - aws secretsmanager put-secret-value --secret-id "${record_id}" \ - --secret-string "file://${work_dir}/record.next.json" >/dev/null 2>&1 \ - || aws secretsmanager create-secret --name "${record_id}" \ - --secret-string "file://${work_dir}/record.next.json" >/dev/null + for name in "${present[@]}"; do + printf '%s' "${!name}" | jq -Rs --arg k "$name" '{($k): .}' + done | jq -s 'add' > "$bulk" + pnpm exec wrangler secret bulk "$bulk" --config {{ .parameters.wranglerConfig }} --env "${env_name}" + rm -f "$bulk" + echo "secrets-live: pushed ${#present[@]} runtime secret(s): ${present[*]}" + if [ "${#missing[@]}" -gt 0 ]; then + echo "secrets-live: not seeded yet (skipped): ${missing[*]}" fi - rm -rf "${work_dir}" {{- else }} - echo "secrets-live: component has no managed runtime secrets; skipping." + echo "secrets-live: component declares no runtime secrets; skipping." {{- end }} onFailure: stop diff --git a/compositions/cloudflare-worker-turbo/profiles/cloudflare-worker-turbo-deploy.yaml b/compositions/cloudflare-worker-turbo/profiles/cloudflare-worker-turbo-deploy.yaml index 4555666..9e5f3e4 100644 --- a/compositions/cloudflare-worker-turbo/profiles/cloudflare-worker-turbo-deploy.yaml +++ b/compositions/cloudflare-worker-turbo/profiles/cloudflare-worker-turbo-deploy.yaml @@ -44,6 +44,6 @@ spec: - cloudflare-worker-turbo.deploy # SS2: hydrate runtime secrets from the worker-secrets escrow after # deploy (first boot creates the worker first); no-op for components - # without secretsWorker, clean skip until the escrow is seeded (SS3). + # without runtimeSecrets, clean skip until keys are seeded in orun. - cloudflare-worker-turbo.secrets-live - cloudflare-worker-turbo.smoke diff --git a/compositions/cloudflare-worker-turbo/schema.yaml b/compositions/cloudflare-worker-turbo/schema.yaml index d1892bc..81b4d26 100644 --- a/compositions/cloudflare-worker-turbo/schema.yaml +++ b/compositions/cloudflare-worker-turbo/schema.yaml @@ -66,10 +66,10 @@ spec: type: string default: wiring.fixture.json description: Committed placeholder wiring map used for offline verify/dry-run rendering - secretsWorker: + runtimeSecrets: type: string default: "" - description: Manifest key in tooling/secrets-sync/secrets.manifest.json naming this worker's managed runtime secrets; empty = the secrets-live step skips (SS2) + description: Comma-separated env var names the secrets-live step pushes as the worker's runtime secrets. Each name resolves from orun secrets via the component's optionalSecretEnv (best-effort — unseeded names are skipped and reported); empty = the step skips. awsAccountId: type: string description: AWS account ID hosting the GitHub-OIDC role wire-live assumes to read wiring secrets diff --git a/stack.yaml b/stack.yaml index 27fd706..7b06b40 100644 --- a/stack.yaml +++ b/stack.yaml @@ -3,7 +3,7 @@ kind: Stack metadata: name: stack-tectonic title: Stack Tectonic - version: 0.15.0 + version: 0.16.0 description: Versioned OCI-hosted catalog of Cloudflare, Terraform and monorepo compositions for Sourceplane repositories. owner: sourceplane tags: