Repository navigation
fix(security): one owner per GCP workload identity pool #2905
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
simple-agent-manager
merged 13 commits into
main
from
sam/security-high-production-stop-m74x61
Nov 19, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bec4577
fix(security): one owner per GCP workload identity pool
raphaeltm 1f8cceb
fix(security): sticky GCP WIF pool claims and owner user_id claim
raphaeltm d7a6529
fix(security): namespace fallback project_id; fail closed on WIF inde…
raphaeltm cff61fc
test(security): composable exact-path owner test; revert unrelated lo…
raphaeltm 138116d
task: archive gcp-wif-cross-owner-pool-impersonation
raphaeltm 2e5db67
test: give each resave Workers test its own GCP pool (claims are sticky)
raphaeltm cc67c15
fix(security): CodeRabbit round on GCP WIF pool ownership
raphaeltm aa73b64
fix(security): claim stored WIF credentials unconditionally; withhold…
raphaeltm c422b72
fix(security): narrow the unreadable-row withhold to GCP rows; fix fi…
raphaeltm b7545da
test: keep a reviewed secret-scan fixture line in place
raphaeltm 5dff4f1
fix(security): unconditional WIF grant check; deployment owner on per…
raphaeltm a162c1a
fix: reconcile WIF pools only before deleting a credential that can n…
raphaeltm cdffcc9
fix(security): record GCP pools before a project deletion cascades it…
raphaeltm 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| -- One owner per Google Cloud workload identity pool. See services/gcp-wif-pool-ownership.ts. | ||
| -- No secret material is stored: an IV identifies a ciphertext generation, and a pool key is | ||
| -- `<projectNumber>/<poolId>`. No foreign keys: an index row references one of three tables, and | ||
| -- a claim deliberately outlives the credential that made it. | ||
| -- | ||
| -- Existing credentials: pool identities are inside encrypted payloads, which SQL cannot read. | ||
| -- The Worker indexes every existing cloud credential, and claims the pools they name, on the first | ||
| -- ownership check after deploy (a token exchange or a GCP credential save). Until then the tables | ||
| -- are empty and no check trusts them: each check indexes unseen rows before it reads. | ||
|
|
||
| -- The pool each stored cloud credential names, keyed by source row and indexed IV. | ||
| CREATE TABLE IF NOT EXISTS gcp_wif_pool_index ( | ||
| source_table TEXT NOT NULL CHECK (source_table IN ('credentials', 'platform_credentials', 'cc_credentials')), | ||
| source_id TEXT NOT NULL, | ||
| iv TEXT NOT NULL, | ||
| owner_kind TEXT NOT NULL CHECK (owner_kind IN ('user', 'platform')), | ||
|
Check failure on line 16 in apps/api/src/db/migrations/0262_gcp_wif_pool_index.sql
|
||
| owner_user_id TEXT, | ||
| pool_key TEXT, | ||
| -- 1 when the row could not be decrypted; retried after gcpWif.poolIndexUnreadableRetryMinutes. | ||
| unreadable INTEGER NOT NULL DEFAULT 0 CHECK (unreadable IN (0, 1)), | ||
| indexed_at TEXT NOT NULL, | ||
| PRIMARY KEY (source_table, source_id), | ||
| CHECK ((owner_kind = 'user' AND owner_user_id IS NOT NULL) OR (owner_kind = 'platform' AND owner_user_id IS NULL)) | ||
| ) WITHOUT ROWID; | ||
| CREATE INDEX IF NOT EXISTS idx_gcp_wif_pool_index_pool | ||
| ON gcp_wif_pool_index (pool_key) WHERE pool_key IS NOT NULL; | ||
| -- Unreadable rows withhold first claims for other owners; keep that lookup off a table scan. | ||
| CREATE INDEX IF NOT EXISTS idx_gcp_wif_pool_index_unreadable | ||
| ON gcp_wif_pool_index (source_table, source_id) WHERE unreadable = 1; | ||
|
|
||
| -- The first owner whose credential named a pool. Never released by deleting or re-pointing a | ||
| -- credential: the trust an earlier setup granted in Google outlives the SAM row. An operator | ||
| -- releases a claim by deleting its row once that Google-side trust is gone. | ||
| CREATE TABLE IF NOT EXISTS gcp_wif_pool_claims ( | ||
| pool_key TEXT PRIMARY KEY NOT NULL, | ||
| owner_kind TEXT NOT NULL CHECK (owner_kind IN ('user', 'platform')), | ||
| owner_user_id TEXT, | ||
| claimed_at TEXT NOT NULL, | ||
| CHECK ((owner_kind = 'user' AND owner_user_id IS NOT NULL) OR (owner_kind = 'platform' AND owner_user_id IS NULL)) | ||
| ) WITHOUT ROWID; | ||
|
simple-agent-manager[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| -- Deployment credentials store their pool in plaintext, so their claims are recorded here, before | ||
| -- any check runs: deleting a deployment credential must not free its pool. A pool named by more | ||
| -- than one owner gets no claim; the live rows keep refusing every owner until an operator decides. | ||
| INSERT INTO gcp_wif_pool_claims (pool_key, owner_kind, owner_user_id, claimed_at) | ||
| SELECT trim(gcp_project_number) || '/' || lower(trim(wif_pool_id)), 'user', min(user_id), | ||
| strftime('%Y-%m-%dT%H:%M:%fZ', 'now') | ||
| FROM project_deployment_credentials | ||
| WHERE provider = 'gcp' | ||
| GROUP BY trim(gcp_project_number) || '/' || lower(trim(wif_pool_id)) | ||
| HAVING count(DISTINCT user_id) = 1 | ||
| ON CONFLICT (pool_key) DO NOTHING; | ||
|
|
||
| -- Keep the unindexed-row probe proportional to cloud credentials, not to every stored | ||
| -- credential (agent keys share these tables). | ||
| CREATE INDEX IF NOT EXISTS idx_credentials_gcp_cloud | ||
| ON credentials (id) WHERE provider = 'gcp' AND credential_type = 'cloud-provider'; | ||
| CREATE INDEX IF NOT EXISTS idx_cc_credentials_cloud | ||
|
simple-agent-manager[bot] marked this conversation as resolved.
Resolved
|
||
| ON cc_credentials (id) WHERE kind = 'cloud-provider'; | ||
| -- Deployment credentials store their pool in plaintext; the ownership check reads them directly. | ||
| CREATE INDEX IF NOT EXISTS idx_project_deployment_creds_gcp_project_number | ||
| ON project_deployment_credentials (gcp_project_number); | ||
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
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
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.