Repository navigation
feat: adopt an existing user on internal provision by exact Google subject - #1105
Merged
Merged
Conversation
…ubject ProvisionUserAdopting is ProvisionUser plus one evidence-gated exception to "never attach on an email conflict": when the caller supplies a Google subject and the requested email belongs to a live user whose google_subject is exactly that value, the provision maps the caller's (issuer, external_ref) to that user instead of failing. The user row is never changed. A missing, different or trashed match is still ErrEmailConflict, indistinguishable from a request with no subject. A new mapping gets the same read-only and tombstone checks AttachExternalPrincipal applies, a pair already mapped elsewhere is still ErrExternalPrincipalConflict, and a synthetic bootstrap: subject is never accepted as evidence. The check runs before the insert because the insert's unique violation would abort the transaction. ProvisionUser keeps its signature and behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…doption
POST /api/internal/users/provision takes an optional google_subject,
honored only with external_issuer. On an email conflict the store adopts
the existing user when that user's google_subject equals it exactly, and
the response is 200 {"user_id", "adopted": true}. Every other response
is byte-identical to before, including the email_conflict a wrong
subject gets, so the field cannot be used to probe accounts.
A subject that is over 255 bytes, contains control characters, starts
with bootstrap:, or arrives without an issuer is 400
invalid_google_subject. Adopting an abuse-paused account is 403
account_read_only, the rule attach already applies. The provisioning
metric gains the bounded outcome "adopted"; deployment.md and
observability.md describe the contract and the label.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…adoption by mapping Review findings on the adoption path: - A mismatched or trashed holder returned email_conflict before the evidence-less path's tombstone check, so with tombstones on it could answer 409 where a request without a subject answers 403/503. The adoption check now returns "no evidence" and the request continues on exactly that path, so the bytes are identical by construction. - An adoption replay re-derived the user by email, so a replay after the adopted user's e2a email changed fell through to a fresh create and then external_principal_conflict. A replay now resolves by the existing (issuer, ref) mapping first, and only while the subject still matches. - The subject bound moves into identity.ValidGoogleSubject so the store enforces the same rule as the handler. Adds tests for the tombstoned mapping subject, the missing tombstone key, a replay after pause, a replay with a different subject, the handler's external_principal_conflict, and two concurrency cases (an adoption waiting on a trash, and concurrent adoptions of one pair). deployment.md now states the replay rule and every adoption error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ce per issuer Adversarial review found two ways to adopt an account that is not the caller's person: - Seeded accounts carry public, non-"bootstrap:" subjects (the prober's and the conformance fixtures'), so a caller that knew one could adopt a system account. google_subject must now be 1..255 ASCII digits, the shape of a Google subject, and only account_class = 'standard' is adoptable; any other class answers exactly as a mismatch. - A second external_ref presenting the same subject added a second live mapping to an account the issuer already maps, a delegated binding the control plane can never use. A new adoption now refuses with external_principal_conflict when the holder already has a mapping from that issuer. deployment.md states both rules and names the answers that reveal a matching subject (HMAC-only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
Independent + adversarial review: dispositionsFixed in
Deferred, with reasons:
Verification after the fixes: 🤖 Generated with Claude Code |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An existing direct signup can block control-plane provisioning with
email_conflict. The HMAC-authenticatedPOST /api/internal/users/provisionnow accepts optionalgoogle_subjectand links the existing account only on an exact Google subject match. Email alone never authorizes a link.Final behavior
user_idandadopted: true, preserving identity fields.adoptedfield.external_principal_conflict; existing mappings cannot be repointed.ProvisionUsercallers retain their signature. Deployment and observability docs are updated.Verification
Application source verified at
f198e4fb0132cf11dba6f6cc43eee54b9b958a64. Current head:78dde6233a875c2d9432e285172679b3ba31f157, which merges the coverage fix from #1106 without application changes.ad9eb1384andf198e4fb0with regression tests; detailed dispositions remain in the follow-up comment.Follow-up
The control plane must send verified Google subjects, retry eligible conflicts at sign-in, handle refusal codes and reconcile the design's retry wording. This PR alone does not fix the end-to-end login flow.