diff --git a/.github/release/cloudflare-token.sh b/.github/release/cloudflare-token.sh index 1a3cbd48863..bc8e59d80c4 100755 --- a/.github/release/cloudflare-token.sh +++ b/.github/release/cloudflare-token.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -# Mints a short-lived Cloudflare token for the current release job from the token issuer +# Mints a short-lived Cloudflare token for the current job from the token issuer # (anomalyco/secrets). Run after aws-actions/configure-aws-credentials has assumed -# arn:aws:iam::604439173067:role/github/opencode-release: the Lambda identifies the role from the -# SigV4 signature and mints only the `opencode/release` token. No repo, stage, permission or TTL -# is sent in the request, and the token is pinned to the runner's IP for 30 minutes. +# arn:aws:iam::604439173067:role/github/opencode- (release, dev or production): the Lambda +# identifies the role from the SigV4 signature and mints only that stage's token. No repo, stage, +# permission or TTL is sent in the request, and the token is pinned to the runner's IP. # # Step-scoped by default: the token goes to $GITHUB_OUTPUT and only steps that list # `CLOUDFLARE_API_TOKEN: ${{ steps..outputs.token }}` in their env receive it. diff --git a/.github/workflows/deploy-files.yml b/.github/workflows/deploy-files.yml index 062da7d6890..d26dcbbb5de 100644 --- a/.github/workflows/deploy-files.yml +++ b/.github/workflows/deploy-files.yml @@ -38,12 +38,18 @@ jobs: role-session-name: opencode-${{ github.run_id }} aws-region: us-east-1 - - name: Read deploy secrets - uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2 - with: - secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN - parse-json-secrets: false + # A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role + # above. It is a step output, so only the Deploy step gets it. + - name: Cloudflare token + id: cloudflare-token + run: bash .github/release/cloudflare-token.sh + env: + CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }} + # wrangler.jsonc has no account id, and the token can't list accounts. - name: Deploy working-directory: services/files run: bun run deploy --env ${{ github.ref_name == 'production' && 'production' || 'dev' }} + env: + CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968 + CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }} diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 722344f0efe..7e9735bf625 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -42,12 +42,16 @@ jobs: role-session-name: opencode-${{ github.run_id }} aws-region: us-east-1 - - name: Read deploy secrets - uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2 - with: - secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN - parse-json-secrets: false + # A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role + # above. It is a step output, so only the Deploy step gets it. + - name: Cloudflare token + id: cloudflare-token + run: bash .github/release/cloudflare-token.sh + env: + CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }} - name: Deploy working-directory: services/site run: bunx cf deploy --prebuilt --mode ${{ github.ref_name }} + env: + CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }} diff --git a/.github/workflows/deploy-update.yml b/.github/workflows/deploy-update.yml index 36dbcbca2f8..621d96e08d0 100644 --- a/.github/workflows/deploy-update.yml +++ b/.github/workflows/deploy-update.yml @@ -37,12 +37,18 @@ jobs: role-session-name: opencode-${{ github.run_id }} aws-region: us-east-1 - - name: Read deploy secrets - uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2 - with: - secret-ids: CLOUDFLARE_API_TOKEN,opencode/production/CLOUDFLARE_API_TOKEN - parse-json-secrets: false + # A 15-minute token for the production Workers only, minted by the token issuer (anomalyco/secrets) from the role + # above. It is a step output, so only the Deploy step gets it. + - name: Cloudflare token + id: cloudflare-token + run: bash .github/release/cloudflare-token.sh + env: + CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }} + # wrangler.jsonc has no account id, and the token can't list accounts. - name: Deploy working-directory: services/update run: bun run deploy + env: + CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968 + CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 595d4814855..cf86c6e27ec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,18 +32,21 @@ jobs: role-session-name: opencode-${{ github.run_id }} aws-region: us-east-1 - - name: Read deploy secrets - uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2 - with: - secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN - parse-json-secrets: false + # A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role + # above. It is a step output, so only the Deploy step gets it. + - name: Cloudflare token + id: cloudflare-token + run: bash .github/release/cloudflare-token.sh + env: + CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }} - # The GitHub App secrets are read here, not in the step above, so only this step ever has them. They reach cf - # through a file in the runner's temp directory, never argv, and the file is removed when the step ends. + # The GitHub App secrets are read here, so only this step ever has them. They reach cf through a file in the + # runner's temp directory, never argv, and the file is removed when the step ends. - name: Deploy working-directory: services/legacy env: STAGE: ${{ github.ref_name }} + CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }} # An explicit bash runs with pipefail, so a failed secret read fails the step. shell: bash run: | @@ -80,18 +83,19 @@ jobs: role-session-name: opencode-${{ github.run_id }} aws-region: us-east-1 - - name: Read deploy secrets - uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2 - with: - secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN - parse-json-secrets: false + - name: Cloudflare token + id: cloudflare-token + run: bash .github/release/cloudflare-token.sh + env: + CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }} - # The Workers' secrets are read here, not in the step above, so only this step ever has them. They reach cf - # through files in the runner's temp directory, never argv, and are removed when the step ends. + # The Workers' secrets are read here, so only this step ever has them. They reach cf through files in the + # runner's temp directory, never argv, and are removed when the step ends. - name: Deploy working-directory: services/data env: STAGE: ${{ github.ref_name }} + CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }} # An explicit bash runs with pipefail, so a failed secret read fails the step. shell: bash run: |