Repository navigation
ref(auth): Read actor contexts through one ViewerContext (reader) - #128080
Conversation
f79a656 to
5a5516b
Compare
ebf233b to
4a436fe
Compare
0f1210f to
43fe642
Compare
43fe642 to
0eadcfc
Compare
…lers Keep one actor-backed ViewerContext, read both wire formats, and continue emitting V1 until reader rollout. Temporarily accept the constructor arguments and token replacement used by current GetSentry; remove that bridge after its caller migration deploys. Co-Authored-By: Codex <[email protected]>
0eadcfc to
bf9263d
Compare
There was a problem hiding this comment.
First pass. The mechanical migration looks right to me, and I checked the GetSentry bridge against the current callers: ViewerContext(actor_type=...), ViewerContext(user_id=..., actor_type=USER), replace(ctx, ..., token=...), and reading ctx.token all still work, and getsentry / backend is green. Nothing in src/ still reads ViewerContext.token. Two things to look at before this lands:
_resolve_viewer_contextinsigned_seer_api.py:AGENTcontexts already exist in prod (agent tokens, and now JWT agent callbacks through the new middleware branch). For those contexts, a legacySeerViewerContextmismatch used to log, merge, and strip elevation. Now it raisesValueError. That raise happens before theencode_viewer_contexttry inmake_signed_seer_api_request, so the outbound Seer call fails instead of degrading, which goes beyond a mechanical change for an existing actor type. No test covers this branch. In the normal path, the org binding inbind_organization_contextshould keep the orgs aligned, so I expect this to be rare. Still, I'd either keep log + metric + strip elevation forAGENTin this reader PR and save the hard failure for later in the stack, or add a test and some evidence (for example,seer.viewer_context_mismatchvolume for agent contexts) that the raise can't fire today.- Re-emitting actors that V1 can't represent: after a V2
SERVICE_ACCOUNT(orAGENTwith anactor_id) context has been read, the three V1 writers behave differently.ViewerContextHook.on_dispatchand the hybrid-cloud RPCmeta["viewer_context"] = vc.serialize()raise, so task enqueue and cross-silo calls fail.make_signed_seer_api_requestcatches the error asviewer_context_jwt.no_signing_keyand sends the request with no header. The rollout order in the description guards against this, but if that order slips, the first symptom will be crashes plus a log line that points at the wrong cause. A dedicated log/metric for "V1 cannot represent actor" in the Seer path would make a violation easy to spot. Making the other two paths consistent would also help.
The rest (actor-backed user_id, V2 rejecting V1 identity keys, ValueError added to the task-hook catch, and the JWT-wins branch for viewer-context-authenticated requests) looks good to me.
| jwt_ctx = _viewer_context_from_jwt_header(request) | ||
|
|
||
| if jwt_ctx is not None and request_ctx.user_id is not None: | ||
| if jwt_ctx is not None and getattr(request, "user_from_viewer_context", False): |
There was a problem hiding this comment.
"user_from_viewer_context" might be better as a const somewhere?
Agent contexts already exist in prod; a legacy SeerViewerContext mismatch now logs, merges and strips elevation as on master, keeping the agent actor. The middleware reuses is_user_from_viewer_context.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9e02fb8. Configure here.
| if actor.type == ActorType.USER: | ||
| actor = replace(actor, actor_id=explicit_user_id) | ||
| elif actor.type == ActorType.AGENT: | ||
| actor = replace(actor, delegated_user_id=explicit_user_id) |
There was a problem hiding this comment.
Service-account identity rewritten to user
Medium Severity
Removing the typed-actor guard lets a legacy SeerViewerContext user_id replace a SERVICE_ACCOUNT with a USER actor. SERVICE_ACCOUNT has no delegated_user_id, so no mismatch is recorded and the service-account actor_id is discarded. Outbound Seer calls would then carry the wrong caller identity.
Reviewed by Cursor Bugbot for commit 9e02fb8. Configure here.
…r-local-caches Resolves the import conflict in tests/sentry/taskworker/test_adapters.py with getsentry#128080.
…128250) Step 5 of the service accounts database design. `POST .../service-accounts/:id/viewer-context/` now reads the account from the cell's `ServiceAccountReplica` instead of returning canned scopes. - It returns 404 when the account doesn't exist, is in another org, or is inactive. The replica query filters on org and `is_active`. - It returns the account's own scopes. - Changes reach the next request once the account's outbox replicates to the cell. A deleted account fails once the tombstone cascade removes its replica. The tests check narrowing scopes, disabling the account and deleting it. The returned ViewerContext is still Seer's org-only one. Issuing a `SERVICE_ACCOUNT` actor (the type landed in #128080) comes in the next step. Builds on #128239. Refs ENG-8829 <!-- junior-request-attribution:start --> via **shaun.kaasten**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA89MBDQB%3A1792779329.027059 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA89MBDQB%3A1792779329.027059) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA89MBDQB%3A1792779329.027059/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Shaun Kaasten <[email protected]>
**4/7 — WRITER: Sentry. Deploy after [GetSentry migration #22613](getsentry/getsentry#22613 Change the serialization default to the V2 actor envelope. Keep dual-format reads, explicit V1 serialization, and the temporary Sentry compatibility bridge. The production diff changes one default. Stacked on [Sentry reader #128080](#128080). Both that reader and [Seer reader #8941](getsentry/seer#8941) must already be fully deployed across web, workers, consumers, and all silos. Fully deploy, then deploy [5/7: Seer writer #8988](getsentry/seer#8988). Enable newly identified actors after both writers deploy. Roll back writers while retaining dual readers; queued or persisted V2 work still needs those readers. Co-authored-by: Codex <[email protected]>


1/7 — READER: Sentry. Deploy first; current GetSentry keeps working.
Use one frozen, actor-backed
ViewerContext. Actor owns identity, delegation, and elevation.actor.idis anActorId(type, id)named tuple;actor.actor_idis the scalar ID. Construction sites migrate mechanically without changing endpoint authorization policy.Read V1 and V2 into this model, while continuing to write V1. Temporarily preserve the human
user_idaccessor and the constructor/token replacement API used by current GetSentry. Legacy token input is discarded. The bridge is removed together in Sentry cleanup #128112, after the GetSentry migration deploys.Fully deploy across web, workers, consumers, and all silos, then deploy 2/7: Seer reader #8941. DB models and service-account issuance are separate work; new actor producers wait until both writer PRs deploy.