feat(ledger): enforce per-endpoint keycloak scope authorization - #138
Merged
Conversation
added 2 commits
June 15, 2026 20:26
map the jwt scope claim to authorities and require ledger:read on read endpoints and ledger:write on mutating /v1 endpoints. a valid token with the wrong scope now returns 403, which activates the dormant denied audit path. configure the resource server issuer-uri and update the existing tests to carry the required scopes. Closes #47 Closes #48
the scope matrix it used the scope string as the bearer token value, but a colon is not a valid bearer token character so the resolver rejected it and every request returned 401. use colon-free token values and build the scope claim in the decoder. also raise the shared test postgres max_connections so the added springboottest context does not exhaust the connection ceiling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds per-endpoint scope authorization to the ledger resource server:
scopeclaim toSCOPE_-prefixed authorities viaJwtAuthenticationConverterGET /v1/**requiresSCOPE_ledger:read; mutating/v1/**(POST/PUT/PATCH/DELETE) requiresSCOPE_ledger:writePUBLIC_PATHS(api-docs, swagger, actuator/health) stay anonymous; everything else falls to the authenticated backstopspring.security.oauth2.resourceserver.jwt.issuer-uri(required envKEYCLOAK_ISSUER_URI) so the prod context boots (closes the Configure Spring Security resource server (Keycloak JWT) #47 residual)A valid token with the wrong scope now returns 403, which activates the previously dormant DENIED audit path from #133 with no audit-code change.
Scope taxonomy
Tests
ScopeAuthorizationMatrixIT: full 9-endpoint matrix, allowed-with-correct-scope vs 403-with-opposite-scope, side-effect-light on the shared container@WebMvcTestcross-scope 403 guards in both controller testsDeniedAuditITsimplified to assert the real 403 rule instead of a test-only denyAll chain/actuator/healthcoverage added401 (unauthenticated, no audit) vs 403 (authenticated wrong scope, DENIED audit) split preserved.
Closes #47
Closes #48