Repository navigation
TASK-706: staging walk signs in to the shared account #3126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
572667d
TASK-706: staging walk signs in to the shared account
lilyshen0722 8d5d7fa
TASK-706: harden staging sign-in after review
lilyshen0722 1f5fd80
TASK-706: address CodeRabbit on #3126
lilyshen0722 2eca900
TASK-706: close review gaps on #3126
lilyshen0722 2a1808d
fix(walk): recoverRunPods reports unresolved when no pod matches
lilyshen0722 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // How the walk gets its account (TASK-706). Prod signs up a fresh account every | ||
| // run. Staging needs a verified email, which a walk address cannot receive, so | ||
| // SRE pre-verifies one shared walk account there and the walk signs in to it | ||
| // instead. Its credentials come from env only, and that account is never deleted. | ||
| // Exact host and https only: a substring match would send the shared password to | ||
| // any host whose name contains "staging". | ||
| const STAGING_HOSTS = new Set(['api-staging.commonly.me']); | ||
|
|
||
| // `deleteAccount` is the one value main() hands to cleanup, so the mode decides | ||
| // the account's fate here and nowhere else. | ||
| export const chooseWalkMode = ({ base, env }) => { | ||
| const email = env.COMMONLY_WALK_EMAIL || ''; | ||
| if (!email) return { mode: 'signup', deleteAccount: true }; | ||
| const url = new URL(base); | ||
| if (url.protocol !== 'https:' || !STAGING_HOSTS.has(url.hostname)) { | ||
| throw new Error('COMMONLY_WALK_EMAIL is set but the target is not the staging API over https; the shared sign-in account exists on staging only'); | ||
| } | ||
| return { mode: 'signin', email, deleteAccount: false }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Run: node --test scripts/first-user-walk-mode.test.mjs | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { chooseWalkMode } from './first-user-walk-mode.mjs'; | ||
|
|
||
| const STAGING = 'https://api-staging.commonly.me'; | ||
| const PROD = 'https://api.commonly.me'; | ||
|
|
||
| test('staging with COMMONLY_WALK_EMAIL takes the sign-in path', () => { | ||
| assert.deepEqual(chooseWalkMode({ base: STAGING, env: { COMMONLY_WALK_EMAIL: 'walk@commonly.me' } }), { mode: 'signin', email: 'walk@commonly.me', deleteAccount: false }); | ||
| }); | ||
|
|
||
| test('no COMMONLY_WALK_EMAIL signs up a fresh account, on any target, and that account is deleted', () => { | ||
| assert.deepEqual(chooseWalkMode({ base: PROD, env: {} }), { mode: 'signup', deleteAccount: true }); | ||
| assert.deepEqual(chooseWalkMode({ base: STAGING, env: {} }), { mode: 'signup', deleteAccount: true }); | ||
| }); | ||
|
|
||
| test('the shared sign-in account is refused on prod', () => { | ||
| assert.throws(() => chooseWalkMode({ base: PROD, env: { COMMONLY_WALK_EMAIL: 'walk@commonly.me' } }), /staging only/); | ||
| }); | ||
|
|
||
| test('a host that merely contains "staging" never receives the shared account', () => { | ||
| for (const base of ['https://staging.attacker.example', 'https://api-staging.commonly.me.attacker.example', 'https://evil-staging.example']) { | ||
| assert.throws(() => chooseWalkMode({ base, env: { COMMONLY_WALK_EMAIL: 'walk@commonly.me' } }), /staging API over https/, base); | ||
| } | ||
| }); | ||
|
|
||
| test('the shared sign-in account is refused over plain http, even on the staging host', () => { | ||
| assert.throws(() => chooseWalkMode({ base: 'http://api-staging.commonly.me', env: { COMMONLY_WALK_EMAIL: 'walk@commonly.me' } }), /over https/); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.