Skip to content

Commit 3950278

Browse files
committed
ci(deploy): mint short-lived cloudflare tokens from the token issuer
1 parent 6b1db27 commit 3950278

5 files changed

Lines changed: 55 additions & 35 deletions

File tree

‎.github/release/cloudflare-token.sh‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
2-
# Mints a short-lived Cloudflare token for the current release job from the token issuer
2+
# Mints a short-lived Cloudflare token for the current job from the token issuer
33
# (anomalyco/secrets). Run after aws-actions/configure-aws-credentials has assumed
4-
# arn:aws:iam::604439173067:role/github/opencode-release: the Lambda identifies the role from the
5-
# SigV4 signature and mints only the `opencode/release` token. No repo, stage, permission or TTL
6-
# is sent in the request, and the token is pinned to the runner's IP for 30 minutes.
4+
# arn:aws:iam::604439173067:role/github/opencode-<stage> (release, dev or production): the Lambda
5+
# identifies the role from the SigV4 signature and mints only that stage's token. No repo, stage,
6+
# permission or TTL is sent in the request, and the token is pinned to the runner's IP.
77
#
88
# Step-scoped by default: the token goes to $GITHUB_OUTPUT and only steps that list
99
# `CLOUDFLARE_API_TOKEN: ${{ steps.<id>.outputs.token }}` in their env receive it.

‎.github/workflows/deploy-files.yml‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ jobs:
3838
role-session-name: opencode-${{ github.run_id }}
3939
aws-region: us-east-1
4040

41-
- name: Read deploy secrets
42-
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
43-
with:
44-
secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN
45-
parse-json-secrets: false
46-
41+
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
42+
# above. It is a step output, so only the Deploy step gets it.
43+
- name: Cloudflare token
44+
id: cloudflare-token
45+
run: bash .github/release/cloudflare-token.sh
46+
env:
47+
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
48+
49+
# wrangler.jsonc has no account id, and the token can't list accounts.
4750
- name: Deploy
4851
working-directory: services/files
4952
run: bun run deploy --env ${{ github.ref_name == 'production' && 'production' || 'dev' }}
53+
env:
54+
CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968
55+
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}

‎.github/workflows/deploy-site.yml‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ jobs:
4242
role-session-name: opencode-${{ github.run_id }}
4343
aws-region: us-east-1
4444

45-
- name: Read deploy secrets
46-
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
47-
with:
48-
secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN
49-
parse-json-secrets: false
45+
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
46+
# above. It is a step output, so only the Deploy step gets it.
47+
- name: Cloudflare token
48+
id: cloudflare-token
49+
run: bash .github/release/cloudflare-token.sh
50+
env:
51+
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
5052

5153
- name: Deploy
5254
working-directory: services/site
5355
run: bunx cf deploy --prebuilt --mode ${{ github.ref_name }}
56+
env:
57+
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}

‎.github/workflows/deploy-update.yml‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ jobs:
3737
role-session-name: opencode-${{ github.run_id }}
3838
aws-region: us-east-1
3939

40-
- name: Read deploy secrets
41-
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
42-
with:
43-
secret-ids: CLOUDFLARE_API_TOKEN,opencode/production/CLOUDFLARE_API_TOKEN
44-
parse-json-secrets: false
45-
40+
# A 15-minute token for the production Workers only, minted by the token issuer (anomalyco/secrets) from the role
41+
# above. It is a step output, so only the Deploy step gets it.
42+
- name: Cloudflare token
43+
id: cloudflare-token
44+
run: bash .github/release/cloudflare-token.sh
45+
env:
46+
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
47+
48+
# wrangler.jsonc has no account id, and the token can't list accounts.
4649
- name: Deploy
4750
working-directory: services/update
4851
run: bun run deploy
52+
env:
53+
CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968
54+
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}

‎.github/workflows/deploy.yml‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ jobs:
3232
role-session-name: opencode-${{ github.run_id }}
3333
aws-region: us-east-1
3434

35-
- name: Read deploy secrets
36-
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
37-
with:
38-
secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN
39-
parse-json-secrets: false
35+
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
36+
# above. It is a step output, so only the Deploy step gets it.
37+
- name: Cloudflare token
38+
id: cloudflare-token
39+
run: bash .github/release/cloudflare-token.sh
40+
env:
41+
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
4042

41-
# The GitHub App secrets are read here, not in the step above, so only this step ever has them. They reach cf
42-
# through a file in the runner's temp directory, never argv, and the file is removed when the step ends.
43+
# The GitHub App secrets are read here, so only this step ever has them. They reach cf through a file in the
44+
# runner's temp directory, never argv, and the file is removed when the step ends.
4345
- name: Deploy
4446
working-directory: services/legacy
4547
env:
4648
STAGE: ${{ github.ref_name }}
49+
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
4750
# An explicit bash runs with pipefail, so a failed secret read fails the step.
4851
shell: bash
4952
run: |
@@ -80,18 +83,19 @@ jobs:
8083
role-session-name: opencode-${{ github.run_id }}
8184
aws-region: us-east-1
8285

83-
- name: Read deploy secrets
84-
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
85-
with:
86-
secret-ids: CLOUDFLARE_API_TOKEN,opencode/${{ github.ref_name }}/CLOUDFLARE_API_TOKEN
87-
parse-json-secrets: false
86+
- name: Cloudflare token
87+
id: cloudflare-token
88+
run: bash .github/release/cloudflare-token.sh
89+
env:
90+
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
8891

89-
# The Workers' secrets are read here, not in the step above, so only this step ever has them. They reach cf
90-
# through files in the runner's temp directory, never argv, and are removed when the step ends.
92+
# The Workers' secrets are read here, so only this step ever has them. They reach cf through files in the
93+
# runner's temp directory, never argv, and are removed when the step ends.
9194
- name: Deploy
9295
working-directory: services/data
9396
env:
9497
STAGE: ${{ github.ref_name }}
98+
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
9599
# An explicit bash runs with pipefail, so a failed secret read fails the step.
96100
shell: bash
97101
run: |

0 commit comments

Comments
 (0)