Repository navigation
Let a manager link for everyone an account already serving an app they edit - #103
Conversation
…y edit appLink refused every account but the caller's own (OrganizationForbidden), so an admin or agent could not fill another app's slot with an org credential that already serves an app they edit, and had to save the same key again. An account may now be linked for everyone by its owner, or by someone who can edit an app it is already linked to for everyone, whose owner is still a member. Editing that app already lets them run code with the account, so this grants no use they lack. The account stays its owner's: no direct use, no user links, no reads; appGet offers these accounts for app requirements only. The lock-time recheck share-locks the source app link rows until commit. An account's owner may now unlink it from any app, since someone else may have linked it to one they cannot edit. Both routes record security.audit events (app_account.link / app_account.unlink) naming the authority used. Refs #99
|
Review status (lead: executor). Round 1: Astra (security pass) MERGE; Opus (primary) FIX FIRST. A fix round is running for:
Needs Lauren's explicit decision before deploy (Opus M2). This PR widens whom an account owner implicitly trusts. An admin who edits an app the account already serves can link that account into another app for everyone, including a member's own app. That member can then edit their app to read the credential and reuse the account in their other apps. The owner isn't notified; after the fix they can unlink, but only after the fact. Options:
Lead's pick: 2. It keeps the fix for the pebble-index → latitudes-kb case, where the owner edits both apps, and closes the reuse-by-member path. |
PR review (MED): an admin's reuse into a member-created app let that member chain the owner's account into their own apps, read its secret, and keep it after the admin unlinked it. Reuse (app_link) now needs an organization owner or admin, and is refused when the target app's creator is a member other than the account's owner. Members never reuse, so nothing a member edits holds another person's account unless its owner linked it there, and no chain can outlive an unlink. The lock-time recheck also share-locks the target's access row. LOWs: - Reuses serialize on a per-organization advisory lock taken before any app lock, so two admins swapping accounts cannot deadlock (40P01 -> 500). - removeAppLinksOf reads again until no app link is left, so a reuse that committed during user deletion is removed too. - appLink/appUnlink audit through `audited` (failures and interrupts recorded, `changed` noted), and a connection completing for an app requirement records app_account.link (via=connect). Refs #99
…unt's owner may now unlink it anywhere
|
Lead (executor) fix-check: Opus round 2 says FIX FIRST. No blocker, but two majors remain against the new admin-only rule. B1, M1 and most of M2 are resolved. By the charter's review budget there is no third patch round from the lead, so here are the invariants for whoever finishes this (author thread or Lauren): Invariant: nothing a member can edit holds another person's account unless that person linked it there, at link time and for as long as the link lasts.
Minors are in the review: the failure audit takes the app id from the request, the connect-path audit is logged before its commit, Not merging until G1 is fixed and G2 is decided. Deploy waits on Lauren's sign-off regardless. |
…er commit with the app found, and serialize app-link removal with reuse - A target app whose creator is no longer a member counts as a member's (G1). - removeAppLinksOf takes the organization's reuse lock first and fails instead of returning with links left behind; appUnlinkOwned takes that lock before the app's. - Audit records name the app only once it was found; connection links are recorded once their save commits. - E2E: departed creator and departed owner, demotion during and after a reuse, and the audit records themselves.
|
Lead (executor): fresh Opus review of G2: the target-creator check runs only when the link is made. If an admin or owner reuses O's account into an app created by admin A2, and A2 is later demoted, or leaves and is re-invited as a member, A2 still edits that app. A2 can then read O's credential, including refreshed OAuth tokens, with no end date. O isn't notified. The comment at Not merging until Lauren decides:
Review: |
|
Deploy sign-off: approved by the user, Nov 17 18:5x PST (relayed by the PM). This covers the sign-off this PR asks for. It holds only after the G2 use-time fix lands, a fresh Opus fix-check says MERGE on the exact head and CI is green. It doesn't cover deploying with G2 open. |
|
Lead (executor) final fix-check: fresh Opus high review of Non-blocking minors noted for follow-up / Lauren's call:
Merging under the user's deploy sign-off relayed earlier tonight. |
Refs #99 (related, but a separate root cause; see below). Lauren asked for this fix on Nov 17, 4:18 PM PT. Do not deploy without Lauren's sign-off.
Problem
appAccounts.appLinkaccepted only the caller's own account. Every account is personal (hosted_account_access.personal_user_id), so an admin or agent could not fill another app's slot with an org credential that already serves an app. For example, pebble-index's Workers AI accountacc_e2013e11…could not go into latitudes-kb'sworkersAislot. The call returned 403OrganizationForbidden, andappGetoffered 0 accounts. The only workaround was to save the same key again (acc_29ea2764…"Default 2").Change
appLinkableAccountsAs(resource-policy) still lets an owner link their own account. Reuse (app_link) is allowed only when all of these hold:pg_advisory_xact_lockbefore any app lock, so two admins swapping accounts at once can't deadlock (40P01 → 500).removeAppLinksOfre-reads until no app link is left, so a reuse that commits during user deletion doesn't leave a link behind.appLink/appUnlinknow audit throughaudited(failures and interrupts too, pluschangedandauthority). An app-scope connect completion recordsapp_account.linkwithvia=connect.Not covered here: #99
The cause is in
versionAccounts/requireConnectionAccounts, notappLink. #86 already returnsConnectionAccountUnlinked, and #86 is in prod build a87d49c. This PR does not close #99.Tests
hostedAppLinkReuseChain(new): the reviewer's chain.AccountRequired); the admin's unlink finds nothing (404); M → M4 is refused (403).expected 200 to be 403at the admin's reuse into M1. With an observation probe on 0e50c17, every chain step returned 200, and M2 and M4 returnedOWNER-SECRET-TOKEN. Passes on this head.hostedAppLinkReuse: an admin reuses into owner-created apps; refusals for an unlinked account, a member, and self-linking; owner-unlink; the delete guard.hostedAppLinkHeldAccess: the unlink phase now unlinks the owner's account. The admin's own account can be unlinked by its owner regardless of role, which is the new rule.bun run checkpassed.Deploy / rollback
There is no schema or migration change. The previous image (a87d49c, sha256:0d42f6b5…) ignores reuse provenance and serves those links as ordinary app links. Rolling back also removes the G2 use-time enforcement.
Fix round 1
permittedAppIds(CurrentPolicy)and requires the credential'sreadandmanageactions, alongside live user authority. The shared helper coversappGet, the pre-lock link check, and the under-lock link check. A scoped caller cannot gain an account through a source app outside its selection.appAccounts.appUnlinkOwned(DELETE /api/organizations/:organization/apps/:app/accounts/app/:account). It removes all of that account's app links from one app under the existing locks, without needing or returning requirement names or reading the app. Missing, unrelated, already-unlinked and arbitrary app ids receiveOrganizationForbidden. Success is audited asapp_account.unlink, authorityowner; failures and interruptions use the existing audit wrapper.AccountLinkedToApprepair instructions and both account docs to point owners at the new route.hostedAppLinkReuse: a connection-narrowed admin session cannot list or link an account sourced only outside its selection, while the same admin's unscoped session can. This fork refuses connection keys at the HTTP API, so this exercises the supported host-attached calling-connection path used by agent API calls. An owner cannot read a private app or discover its requirement names, but can remove their account from both requirements by app id alone.7a436f53bduring this work. Integrated those existing commits without rewriting history, retaining their administrator-only reuse restrictions, target-editor restrictions, locking and audit improvements.Round 1 verification
nice -n 19, one heavy run at a time, with at most four build jobs and one E2E worker.TYPECHECK_CONCURRENCY=2 RAYON_NUM_THREADS=2and reported existing warnings. Format/lint/typecheck passed again for the different, integrated tree;e2e:checkpassed before integration.expected [[account, false]] to deeply equal []). Restored it before the passing runs.e2e:self-host --test-name '^(hosted app requirements use|a hosted app requirement links for everyone|a hosted manager links for everyone|a hosted administrator cannot reuse)' --workers 1gave 3 passed (hostedAppLinks,hostedAppLinkConnections,hostedAppLinkReuseChain). The concurrent commit renamed "manager" to "administrator", so the reuse scenario was filtered out; a separate--test-name '^a hosted administrator links for everyone' --workers 1then gave 1 passed (hostedAppLinkReuse). Four distinct scenarios passed, with no repeat of a passing scenario on that tree..local/e2e/2026-11-18T01-17-58.387Z-self-host-8a7fb4and.local/e2e/2026-11-18T01-18-29.611Z-self-host-8161ac.ratstack://skills/security-audit,ratstack://systems/auth,ratstack://lore/errors-are-part-of-the-interface.e2e:check-description --file .local/pr103-body.md --base v2: blocked by the unrelated, unchangedcloudOAuthProxyRefusalscenario being scheduled on Cloud without a CI job. The existinge2eblock remains intact and names both PR spec files; this round does not change CI scheduling.1593aeb912538bbd53a120d879388bdb3c1397a3(fix commiteda1f2f1eplus the integration commit).The PR remains open; no deployment was performed. Lauren's deployment sign-off is still required. On rollback to a87d49c, reused links remain but the owner-only consent routes disappear; app managers must unlink those accounts.
Round 3 (e4d9f51), after the lead's fix-check
appUnlinkOwnedtakes the same lock first, keeping one lock order.withCommittedAuditsaround submit/startOAuth/completeOAuth).Fix round (G2)
d442a132c,1d9fa8898, and65b9de186are retained: deleting a user unlinks reuses in apps they created, including in organizations they already left, and a creator-less app cannot accept or serve a reused link even if a row remains. The existinglinked_bycolumn marks reuses; no migration. Owner-made and pre-PR links keep serving under their prior rules. An account owner with app edit access can take over a reuse by linking it directly.AppLinkCreatorNotAuthorized(HTTP 409) applies both to initial account selection and to the credential rechecks around OAuth refresh. It explains that the app's creator is missing or no longer an organization admin or owner, and tells the caller to ask an admin to relink an eligible account or ask the account's owner to link directly.security.auditrecordsapp_account.use_refused, outcomefailure, target kindaccountand ID, app ID, requirement, and reasoncreator_not_admin_or_owner. No credentials or tokens. A bounded per-process/isolate cache deduplicates by link and stored membership revision; it does not cache authorization. Restarts or eviction can repeat a best-effort log. Creator deletion also audits each unlink withauthority: creator_removal.hostedAppLinkCreatorDemotionandhostedAppLinkCreatorDemotionDuringRefreshfailed as expected: the tool returned HTTP 200 rather than 409. Both passed once the check was restored. The OAuth issuer holds the refresh response until demotion commits, so that test reaches the credential recheck after refresh. Both scenarios verify a secret-free refusal audit; the demotion scenario verifies dedupe, promotion, and that an owner-made link still serves.--workers 1.e2e:prepare, format, lint, typecheck (9 projects), andactionlintpassed. Fullbun run checkwas not run locally because of the known install-store issue..local/e2e/2026-11-18T06-29-26.765Z-self-host-3d17c8(negative);.local/e2e/2026-11-18T06-30-21.095Z-self-host-85e9c0(self-host);.local/e2e/2026-11-18T06-32-25.229Z-cloud-76a572(three Cloud passes);.local/e2e/2026-11-18T06-35-15.333Z-cloud-ce56a4(creator-removal pass).cloudOAuthProxyRefusalschedule/job mismatch. Not merged or deployed.Known design limits (from round 2 review, kept as is):