PAT Authentication for REST API (SZ-117)
rk@tigase.net opened 2 days ago

Problem

I woke up to this problem today when discussing the Bot testing approach over email with Artur. PATs only work for git operations (via Caddy forward_auth). REST API consumers — CI/CD pipelines, third-party integrations, authorized bots — have no way to authenticate programmatically without simulating browser session login, which is fragile and stateful.

Expected Behavior

Any REST API call with Authorization: Bearer <token> should be validated against PersonalAccessTokenRepository and granted access with the token owner's identity and roles, identical to a session-authenticated user.

Current Behavior

Spring Security ignores the Authorization: Bearer header on REST endpoints. Only session cookies (JSESSIONID) are recognized. PATs are validated by Caddy only for /git/* routes.

Fix

Implement a PATAuthenticationFilter in Spring Security:

  1. Extract Authorization: Bearer <token> from the request header
  2. Look up the token in PersonalAccessTokenRepository
  3. Validate — not expired, not revoked
  4. Set the SecurityContext with the token owner's identity and roles
  5. Wire into SessionAuthSecurityConfig before UsernamePasswordAuthenticationFilter

Estimate

2-3h

Worklog

StepTaskEst
1Create PATAuthenticationFilter extending OncePerRequestFilter1h
2Wire filter into SessionAuthSecurityConfig30m
3Test with curl using a real PAT against staging30m
4Update stress test script to use PAT instead of session cookie30m

Notes

  • Industry standard: browser uses session cookie, everything else uses PAT as Bearer token
  • GitHub, GitLab, Jira all follow this pattern
  • This is a prerequisite for authorized bot access (SZ-73 Layer 4)
  • PersonalAccessTokenRepository and PATHashService already exist — filter is the missing piece
issue 1 of 1
Type
New Feature
Priority
Normal
Assignee
Version
none
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
SZ-117
Please wait...
Page is in error, reload to recover