Skip to content

Commit d01d966

Browse files
committed
Preserve live OAuth credentials on deploy
1 parent 603e41d commit d01d966

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,27 @@ jobs:
4949
env:
5050
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
5151
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
52+
ORBIT_LIVE_OAUTH_CLIENT_ID: ${{ secrets.ORBIT_LIVE_OAUTH_CLIENT_ID }}
53+
ORBIT_LIVE_OAUTH_CLIENT_SECRET: ${{ secrets.ORBIT_LIVE_OAUTH_CLIENT_SECRET }}
5254
run: |
55+
if [[ -z "$ORBIT_LIVE_OAUTH_CLIENT_ID" || -z "$ORBIT_LIVE_OAUTH_CLIENT_SECRET" ]]; then
56+
echo 'Live GitHub OAuth deployment secrets are missing.' >&2
57+
exit 1
58+
fi
59+
60+
oauth_secrets_file="$(mktemp)"
61+
trap 'rm -f "$oauth_secrets_file"' EXIT
62+
chmod 600 "$oauth_secrets_file"
63+
jq -n '{
64+
GITHUB_OAUTH_CLIENT_ID: env.ORBIT_LIVE_OAUTH_CLIENT_ID,
65+
GITHUB_OAUTH_CLIENT_SECRET: env.ORBIT_LIVE_OAUTH_CLIENT_SECRET
66+
}' > "$oauth_secrets_file"
67+
unset ORBIT_LIVE_OAUTH_CLIENT_ID ORBIT_LIVE_OAUTH_CLIENT_SECRET
68+
5369
short_sha="${GITHUB_SHA::12}"
5470
npx wrangler deploy \
5571
--config wrangler.production.live.jsonc \
72+
--secrets-file "$oauth_secrets_file" \
5673
--tag "main-${short_sha}" \
5774
--message "Automatic production deploy from main ${short_sha}"
5875

‎scripts/orbit-production-config-tests.mjs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isDeepStrictEqual } from 'node:util';
44
const files = {
55
live: new URL('../wrangler.production.live.jsonc', import.meta.url),
66
darkLaunch: new URL('../wrangler.production.dark-launch.jsonc', import.meta.url),
7+
deployWorkflow: new URL('../.github/workflows/deploy-production.yml', import.meta.url),
78
};
89

910
let assertions = 0;
@@ -179,6 +180,7 @@ function normalizeModeDifferences(config) {
179180

180181
const live = await readConfig(files.live, 'live config');
181182
const darkLaunch = await readConfig(files.darkLaunch, 'dark-launch config');
183+
const deployWorkflow = await readFile(files.deployWorkflow, 'utf8');
182184

183185
validateConfig(live, {
184186
label: 'live config',
@@ -200,4 +202,21 @@ assertDeepEqual(
200202
'live and dark-launch configs differ outside the reviewed mode surface',
201203
);
202204

205+
assert(
206+
deployWorkflow.includes('ORBIT_LIVE_OAUTH_CLIENT_ID: ${{ secrets.ORBIT_LIVE_OAUTH_CLIENT_ID }}'),
207+
'production deploy does not source the live OAuth client ID from the production environment',
208+
);
209+
assert(
210+
deployWorkflow.includes('ORBIT_LIVE_OAUTH_CLIENT_SECRET: ${{ secrets.ORBIT_LIVE_OAUTH_CLIENT_SECRET }}'),
211+
'production deploy does not source the live OAuth client secret from the production environment',
212+
);
213+
assert(
214+
deployWorkflow.includes('--secrets-file "$oauth_secrets_file"'),
215+
'production deploy does not upload the live OAuth pair with the Worker version',
216+
);
217+
assert(
218+
deployWorkflow.includes("trap 'rm -f \"$oauth_secrets_file\"' EXIT"),
219+
'production deploy does not clean up its temporary OAuth secrets file',
220+
);
221+
203222
process.stdout.write(`Orbit production config tests: ${assertions} assertions passed\n`);

0 commit comments

Comments
 (0)