Skip to content

feat(auth): Add structured logging for AuthIdentity updates and deletes#108688

Merged
michelletran-sentry merged 2 commits intomasterfrom
feat/update-auth-identity-audit-logs
Feb 20, 2026
Merged

feat(auth): Add structured logging for AuthIdentity updates and deletes#108688
michelletran-sentry merged 2 commits intomasterfrom
feat/update-auth-identity-audit-logs

Conversation

@michelletran-sentry
Copy link
Copy Markdown
Contributor

Security-relevant changes to SSO identities (user reassignment, ident changes, data updates, deletions) were happening silently. Override update() and delete() on AuthIdentity to emit logger.info for meaningful field changes, filtering out timestamp-only updates.

I'm a bit unsure if this will be too noisy, but I suspect that identity changes aren't common(?)

Security-relevant changes to SSO identities (user reassignment, ident
changes, data updates, deletions) were happening silently. Override
`update()` and `delete()` on `AuthIdentity` to emit `logger.info` for
meaningful field changes, filtering out timestamp-only updates.

Co-Authored-By: Claude <[email protected]>
@michelletran-sentry michelletran-sentry requested a review from a team February 20, 2026 16:37
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 20, 2026

logger = logging.getLogger("sentry.auth.identity")

_MEANINGFUL_UPDATE_FIELDS = frozenset({"user", "user_id", "ident", "data"})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffg-sentry Is there anything else that you think we should log here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expose other meta for these. Maybe token_type and expiry but hard to image that would be helpful, since it's almost always type bearer with an expected short expiry anyway. Looks good!

Capture user_id before super().update() so the log always reflects the
prior owner. When user reassignment occurs, a new_user_id field is
added to identify the target user.

Co-Authored-By: Claude <[email protected]>
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

if self.user_id != old_user_id:
extra["new_user_id"] = self.user_id
logger.info("auth_identity.update", extra=extra)
return result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update logs even when values unchanged

Medium Severity

AuthIdentity.update() logs whenever a “meaningful” field appears in kwds, even if the new value equals the existing value (e.g., re-saving identical data/ident). This can generate misleading security/audit logs that claim an identity change occurred when nothing actually changed.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... we can see how noisy it is before we do more to tune the logs.

if self.user_id != old_user_id:
extra["new_user_id"] = self.user_id
logger.info("auth_identity.update", extra=extra)
return result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update logs despite failed DB update

Low Severity

AuthIdentity.update() can log an update even when super().update() affects 0 rows (e.g., the row was deleted concurrently), because logging is gated only on changed_fields, not on the returned affected-row count.

Fix in Cursor Fix in Web

@michelletran-sentry michelletran-sentry merged commit 0d70c0c into master Feb 20, 2026
80 checks passed
@michelletran-sentry michelletran-sentry deleted the feat/update-auth-identity-audit-logs branch February 20, 2026 18:54
priscilawebdev pushed a commit that referenced this pull request Feb 24, 2026
…es (#108688)

Security-relevant changes to SSO identities (user reassignment, ident
changes, data updates, deletions) were happening silently. Override
`update()` and `delete()` on `AuthIdentity` to emit `logger.info` for
meaningful field changes, filtering out timestamp-only updates.

I'm a bit unsure if this will be too noisy, but I suspect that identity
changes aren't common(?)

---------

Co-authored-by: Claude <[email protected]>
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
…es (#108688)

Security-relevant changes to SSO identities (user reassignment, ident
changes, data updates, deletions) were happening silently. Override
`update()` and `delete()` on `AuthIdentity` to emit `logger.info` for
meaningful field changes, filtering out timestamp-only updates.

I'm a bit unsure if this will be too noisy, but I suspect that identity
changes aren't common(?)

---------

Co-authored-by: Claude <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants