Public: anyone can read this; the crew can change it.

An org secret reaches an app only through the org its grant names, and a transfer drops grants of the old org #14923

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

An org secret now reaches an app only through the org its grant names, and moving a repository to another owner drops the grants the old org gave it.

Notes

shipped production is serving it deploy 15342fb

opened this

An org secret now reaches an app only through the org its grant names, and moving a repository to another owner drops the grants the old org gave it.

  • Resolving (src/core/app_secrets.ts): resolveAppSecrets looks up an org grant in the org stored on the grant, as crew/grant.ts already does, and records the start against that org. Before, it used the repository's owner at that moment, so a moved repository could pick up a secret from an org that never granted it.
  • Granting (src/actions/secrets.ts): grantToRepo refuses an org grant to a repository that org does not own. The refusal comes back as not_found, so no new error type reaches the web and terminal callers. Both callers already pass the repository's own owner, so they keep working.
  • Moving (src/core/transfer.ts): moveNow deletes the repository's org grants from any org other than the new owner, inside the same transaction as the move. Grants of forge-wide secrets stay.

The three tests are in test/org-secret-grant-scope.test.ts, and all three fail on main. The second one fails on main partly because the first one already wrote a grant on main. They pass with the fix, along with the existing secrets and transfer tests (51 pass). The gate and the type check are clean.

Not done:

  • The transfer receipt does not yet say that grants were dropped, which the issue's risk note asked for.
  • I did not tick this finding off in #14766.
  • I did not record a plan with keep_plan.

Try: as an admin, create an app, move its repository into org A and grant one of A's secrets on its app secrets page. Move the repository to org B: the grant is gone. Granting one of A's secrets to it now is refused.

🤖 Generated with Claude Code

Closes #14902

2 earlier comments · 1 event
commented

An org secret now reaches an app only through the org its grant names, and moving a repository to another owner drops the grants the old org gave it.

  • Resolving (src/core/app_secrets.ts): resolveAppSecrets looks up an org grant in the org stored on the grant, as crew/grant.ts already does, and records the start against that org. Before, it used the repository's owner at that moment, so a moved repository could pick up a secret from an org that never granted it.
  • Granting (src/actions/secrets.ts): grantToRepo refuses an org grant to a repository that org does not own. The refusal comes back as not_found, so no new error type reaches the web and terminal callers. Both callers already pass the repository's own owner, so they keep working.
  • Moving (src/core/transfer.ts): moveNow deletes the repository's org grants from any org other than the new owner, inside the same transaction as the move. Grants of forge-wide secrets stay.

The three tests are in test/org-secret-grant-scope.test.ts, and all three fail on main. The second one fails on main partly because the first one already wrote a grant on main. They pass with the fix, along with the existing secrets and transfer tests (51 pass). The gate and the type check are clean.

Not done:

  • The transfer receipt does not yet say that grants were dropped, which the issue's risk note asked for.
  • I did not tick this finding off in #14766.
  • I did not record a plan with keep_plan.

Try: as an admin, create an app, move its repository into org A and grant one of A's secrets on its app secrets page. Move the repository to org B: the grant is gone. Granting one of A's secrets to it now is refused.

🤖 Generated with Claude Code

commented

An org secret now reaches an app only through the org its grant names. Moving a repository to another owner drops the grants the old org gave it, so it can no longer pick up a secret from an org that never granted it.

  • Resolving (src/core/app_secrets.ts): resolveAppSecrets looks up an org grant in the org stored on the grant, as crew/grant.ts already does, and records the start against that org. Before, it used whoever owned the repository at that moment.
  • Granting (src/actions/secrets.ts): grantToRepo refuses an org grant to a repository that org does not own. The refusal comes back as not_found, so no new error type reaches the web and terminal callers.
  • Moving (src/core/transfer.ts): moveNow deletes the repository's grants from any org other than the new owner, inside the same transaction as the move. Grants of forge-wide secrets stay.

The three tests are in test/org-secret-grant-scope.test.ts, and all three fail on main. On main the second one also fails partly because the first one leaves a grant behind. With the fix they pass, along with the existing secrets and transfer tests (51 pass), and the gate and type check are clean.

A "No door:" commit line answers the gate's "both doors" rule. The terminal's app secrets screen already calls grantToRepo with the repository's own org, so nothing new is reachable there.

Not done:

  • The transfer receipt does not yet say that grants were dropped, which the issue's risk note asked for.
  • I did not tick this finding off in #14766.
  • I did not record a plan with keep_plan.

Try: as an admin, create an app, move its repository into org A and grant one of A's secrets on its app secrets page. Then move the repository to org B. The grant is gone, and granting one of A's secrets to it is now refused.

🤖 Generated with Claude Code

Changes requested — before the latest push

The three code changes are right and match the issue. One high finding: grants already stored from past transfers are not cleaned up. Because resolving now trusts the grant's own scope_id, a repo that was moved out of org A before this lands still holds a grant naming A, and will now receive A's secret. Before, it resolved under the new owner. Fix first: add a forge migration (following the repo's migration pattern, pinned as the gate expects) that deletes org-scope secret_grant rows whose scope_id differs from the owning repo's owner_id. Add a test that seeds such a stale row and asserts it is gone and not resolved. Minor: remove the stray blank line before the closing of the describe block in the test file. Left unmet: box 1 is not ticked, because the stale-grant case above still leaks.

commented

An org secret now reaches an app only through the org its grant names. Moving a repository to another owner drops the grants the old org gave it. A migration also deletes grants left behind by earlier moves, so a repository can no longer pick up a secret from an org that never granted it.

  • Resolving (src/core/app_secrets.ts): resolveAppSecrets looks up an org grant in the org stored on the grant, as crew/grant.ts already does, and records the start against that org. Before, it used whoever owned the repository at that moment.
  • Granting (src/actions/secrets.ts): grantToRepo refuses an org grant to a repository that org does not own. The refusal comes back as not_found, so no new error type reaches the web and terminal callers. They already pass the repository's own org, which is what the "No door:" commit line says.
  • Moving (src/core/transfer.ts): moveNow deletes the repository's grants from any org other than the new owner, inside the same transaction as the move. Grants of forge-wide secrets stay.
  • Old grants (src/core/migrations/20261121120000-org-grant-owner.ts, pinned): deletes stored org grants whose org is not the repository's owner. Without it, a repository moved out of an org before this change would now receive that org's secret. That was review's high finding.

The tests are in test/org-secret-grant-scope.test.ts, which no longer has the stray blank line. The grant, resolve and transfer tests each fail on main. The fourth seeds a leftover grant, runs the migration, and checks the row is gone and resolves to nothing.

The covering tests pass, as do the gate and the type check. test/schema-migrations.test.ts failed once when run alongside other files: its "two pulls' migrations land in either order" test took 6.2 s, which looks like a timeout under load. It passed 26 of 26 run alone.

Not done:

  • The transfer receipt does not yet say that grants were dropped, which the issue's risk note asked for.
  • I did not tick this finding off in #14766.
  • I did not record a plan with keep_plan.

Try: as an admin, create an app, move its repository into org A and grant one of A's secrets on its app secrets page. Then move the repository to org B. The grant is gone, and granting one of A's secrets to it is now refused.

🤖 Generated with Claude Code

Approved

Earlier ask met: a pinned migration (20261121120000-org-grant-owner) deletes org grants whose org is not the repo owner, so repositories moved before this change no longer receive the old org secret. A test seeds a leftover grant, runs the migration, and checks it is gone and resolves to nothing. Resolve now uses the grant scope_id, grantToRepo refuses a foreign org, and moveNow drops old-org grants in its transaction. No new dependency, no secrets, no new door. Non-blocking: the transfer receipt does not mention dropped grants.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs