Skip to content

refactor(proxy): Use jmespath to extract claim values#2558

Open
rhafer wants to merge 1 commit into
opencloud-eu:mainfrom
rhafer:claim-extract-jmespath
Open

refactor(proxy): Use jmespath to extract claim values#2558
rhafer wants to merge 1 commit into
opencloud-eu:mainfrom
rhafer:claim-extract-jmespath

Conversation

@rhafer
Copy link
Copy Markdown
Member

@rhafer rhafer commented Apr 1, 2026

Replace the custom dot-path walking implementation (SplitWithEscaping + WalkSegments) in the proxy service's JWT middleware with github.com/jmespath-community/go-jmespath. extractRoles in oidcroles.go and readUserIDClaim in account_resolver.go now uses jmespath.Search()

NOTE: This change is backwards-incompatible for some corner cases. While simple dot-separated paths like 'realm_access.roles' are unchanged, claim paths containing literal dots (i.e. where the dot does not indicate a hierarchy) must now be quoted ('"sub.roles"' instead of 'sub.roles').

@rhafer rhafer requested a review from micbar April 1, 2026 10:16
@rhafer rhafer self-assigned this Apr 1, 2026
@rhafer rhafer added Type:Maintenance E.g. technical debt, packaging, etc. Type:Breaking-Change labels Apr 1, 2026
@rhafer rhafer force-pushed the claim-extract-jmespath branch 2 times, most recently from fee1d1c to 91641c6 Compare April 1, 2026 11:34
@rhafer rhafer force-pushed the claim-extract-jmespath branch 2 times, most recently from 01f5f0d to 74dc6f8 Compare April 15, 2026 08:38
@sonarqubecloud
Copy link
Copy Markdown

Replace the custom dot-path walking implementation (SplitWithEscaping +
WalkSegments) in the proxy service's JWT middleware with
github.com/jmespath-community/go-jmespath. extractRoles in oidcroles.go
and readUserIDClaim in account_resolver.go now uses jmespath.Search()

NOTE: This change is backwards-incompatible for some corner cases. While
simple dot-separated paths like 'realm_access.roles' are unchanged,
claim paths containing literal dots (i.e. where the dot does not
indicate a hierarchy) must now be quoted ('"sub.roles"' instead of
'sub\.roles').
@rhafer rhafer force-pushed the claim-extract-jmespath branch from 74dc6f8 to 0687bd2 Compare May 11, 2026 09:27
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to refactor the proxy's JWT claim extraction to use JMESPath. While this improves query flexibility, the following issues prevent a complete review and safe merge:

  • Missing Code Changes: The review analysis detected an empty diff, making it impossible to verify the logic in oidcroles.go and account_resolver.go or the removal of legacy functions.
  • Breaking Change: The transition to JMESPath requires literal dots in claim paths to be enclosed in double quotes. This will break existing configurations that rely on the previous escaping mechanism.
  • Test Coverage Gap: No unit or integration tests were provided to validate the new extraction logic, specifically for nested roles and literal dot scenarios.
  • Acceptance Criteria Unverified: Due to the missing code, verification of the core implementation requirements is currently blocked.

About this PR

  • The pull request context provided for review does not contain the actual code changes. Please ensure the commits are pushed and the diff is available for verification.
  • This refactor introduces a breaking change: claim paths containing literal dots now require double-quoted JMESPath syntax (e.g., '"sub.id"'). Ensure this change is documented and that a migration path or notice is provided for existing configurations.

Test suggestions

  • Extract nested roles using standard dot notation (e.g., 'realm_access.roles')
  • Extract claims containing literal dots using new quoted syntax (e.g., '"sub.id"')
  • Handle invalid JMESPath expressions during claim extraction
  • Verify removal of legacy SplitWithEscaping and WalkSegments utility functions
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Extract nested roles using standard dot notation (e.g., 'realm_access.roles')
2. Extract claims containing literal dots using new quoted syntax (e.g., '"sub.id"')
3. Handle invalid JMESPath expressions during claim extraction
4. Verify removal of legacy SplitWithEscaping and WalkSegments utility functions

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type:Breaking-Change Type:Maintenance E.g. technical debt, packaging, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant