Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds Personal Access Token (PAT) support to access-token authentication: JWT PAT subtype is recognized, PAT is loaded and expiry-checked, the PAT owner user is loaded, and a PATPrincipal is returned. Also adds a user_id token claim and service/repo accessors for PAT retrieval. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/authenticate/authenticators.go (1)
137-159: Consider usings.Now()for time consistency.The PAT expiration check uses
time.Now()directly, while the rest of the service usess.Now()(which returnstime.Now().UTC()). This inconsistency could cause subtle issues in tests wheres.Nowis mocked, or if PAT expiration times are stored in UTC.Suggested fix for consistency
- if pat.ExpiresAt.Before(time.Now()) { + if pat.ExpiresAt.Before(s.Now()) {Otherwise, the PAT principal resolution logic is correct:
- Correctly treats JWT
subas PAT ID- Validates PAT exists and is not expired
- Loads the owning user for downstream handlers
- Returns appropriate
Principalwith both PAT and User populated
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c955c7ba-80ae-4f4d-8695-d22b2c81a117
📒 Files selected for processing (4)
core/authenticate/authenticators.gocore/authenticate/service.gocore/authenticate/token/service.gocore/userpat/validator.go
Summary
Add PAT-specific claims to the JWT minted during AuthToken so that upstream services can identify the PAT owner and Frontier can enforce PAT scope when upstream services call back with the JWT.
What changed
Frontier
sub= PAT ID (the authenticating token)sub_type=app/patuser_id= owner's user ID (new claim)org_ids= PAT's org onlyapp/pattype, loads the full PAT, and enforces scope intersectionKong plugin
user_idtoDEFAULT_TOKEN_HEADERSso Kong forwards it asX-Frontier-user_idheader to upstream servicesWhy
Upstream services need the user ID for "created by" logging. They can't use
subfor this when auth is via PAT becausesubis the PAT ID. Theuser_idclaim gives them the human identity without an extra RPC call.Frontier needs to know it's a PAT when the JWT comes back, so it can enforce the PAT's scope (only allow access to resources the PAT is scoped to, not everything the user has access to).
Upstream usage
X-Frontier-user_idif present, elseX-Frontier-subX-Frontier-sub(Frontier handles scopeTest plan
user_idclaim for PAT sub type