Skip to content

Replace webhook.Principal with auth.Identity#4316

Merged
JAORMX merged 2 commits intomainfrom
replace-webhook-principal-with-auth-identity
Mar 23, 2026
Merged

Replace webhook.Principal with auth.Identity#4316
JAORMX merged 2 commits intomainfrom
replace-webhook-principal-with-auth-identity

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented Mar 23, 2026

Summary

  • The webhook package (merged in Add foundational webhook package (Phase 1 of dynamic webhook middleware) #3840) defined its own Principal struct, but auth.Identity already represents the same concept with a superset of fields. Maintaining two parallel identity types creates sync burden and will require conversion logic when the middleware layer wires them together.
  • Remove webhook.Principal and change Request.Principal to use *auth.Identity directly. Update all test fixtures accordingly.

Closes #4315

Type of change

  • Refactoring (no behavior change)

Test plan

  • Unit tests (task test)

Changes

File Change
pkg/webhook/types.go Remove Principal struct, change Request.Principal type to *auth.Identity, add pkg/auth import
pkg/webhook/client_test.go Replace &Principal{Sub: "user1"} with &auth.Identity{Subject: "user1"} (5 instances), add pkg/auth import

Special notes for reviewers

  • No import cycle: pkg/auth imports only stdlib.
  • The JSON field name changes from "sub" to "subject" in the webhook payload. This is acceptable because the webhook API is pre-release (v0.1.0) with no external consumers yet.
  • auth.Identity has a custom MarshalJSON that redacts Token — this is a feature, not a problem, since tokens should never leak into webhook payloads.
  • auth.Identity.MarshalJSON emits all fields (including empty ones) rather than using omitempty. This is slightly more verbose but consistent with how identity is serialized elsewhere.

Generated with Claude Code

The webhook package defined its own Principal struct, but auth.Identity
already represents the same concept with a superset of fields. Maintaining
two parallel identity types creates sync burden and will require conversion
logic in the middleware layer. Since the webhook package has no external
consumers yet (v0.1.0), consolidate now before the API solidifies.

Closes #4315

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Mar 23, 2026
@JAORMX
Copy link
Copy Markdown
Collaborator Author

JAORMX commented Mar 23, 2026

@Sanskarzz did this one as a follow up of your previous PR introducing the webhook fundamentals.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.10%. Comparing base (949ae42) to head (278bad7).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4316      +/-   ##
==========================================
+ Coverage   69.07%   69.10%   +0.02%     
==========================================
  Files         477      477              
  Lines       48074    48146      +72     
==========================================
+ Hits        33207    33269      +62     
- Misses      12284    12294      +10     
  Partials     2583     2583              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sanskarzz
Copy link
Copy Markdown
Contributor

@Sanskarzz did this one as a follow up of your previous PR introducing the webhook fundamentals.

@JAORMX, thanks for the ping! Great catch on the duplicate identity types. Unifying them into auth.Identity definitely simplifies things and avoids the sync burden you mentioned in the issue. I've taken a quick look at the PR, and the approach looks solid. Thank you for the cleanup!

Address review feedback on the webhook wire format: auth.Identity
carries Token, TokenType, and Metadata fields that have no business
in external webhook payloads — even redacted.

Extract the credential-free subset (Subject, Name, Email, Groups,
Claims) into auth.PrincipalInfo and embed it in Identity. This gives
structural safety: webhook.Request.Principal is now *auth.PrincipalInfo,
so tokens can never enter the webhook payload. The JSON wire format
uses "sub" with omitempty, matching the original webhook.Principal
contract from #3840.

Field access on Identity (e.g., identity.Subject) continues to work
transparently via Go embedding — only struct literals needed updating.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 23, 2026
@JAORMX
Copy link
Copy Markdown
Collaborator Author

JAORMX commented Mar 23, 2026

@jhrozek I changed the approach to add a subset of the principal to the auth package itself and make the Identity struct take that into use. I believe this is more re-usable.

Copy link
Copy Markdown
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

very nice thank you

@JAORMX JAORMX merged commit b57cd15 into main Mar 23, 2026
40 checks passed
@JAORMX JAORMX deleted the replace-webhook-principal-with-auth-identity branch March 23, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace webhook.Principal with auth.Identity

3 participants