Skip to content

Vault: enforce JWT OAuth scope per JSON-RPC method#22314

Merged
prashantkumar1982 merged 5 commits intodevelopfrom
fix/vault-jwt-scope-method-auth
May 6, 2026
Merged

Vault: enforce JWT OAuth scope per JSON-RPC method#22314
prashantkumar1982 merged 5 commits intodevelopfrom
fix/vault-jwt-scope-method-auth

Conversation

@prashantkumar1982
Copy link
Copy Markdown
Contributor

@prashantkumar1982 prashantkumar1982 commented May 6, 2026

Summary

Vault JWT path previously validated only request digest binding, not whether the token OAuth scope authorizes the requested JSON-RPC method.

Changes

  • Parse OAuth scopes from JWT scope (space-separated) and Auth0-style permissions array claims.
  • Enforce a fixed allowlist: create:secrets / update:secrets / delete:secrets / list:secrets mapped to vault.secrets.* methods. Fail closed on missing or non-matching scope.
  • System tests: mint JWTs with the scope derived from the request method.

@prashantkumar1982 prashantkumar1982 requested review from a team as code owners May 6, 2026 02:38
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

Reject Vault JWT auth when scope/permissions do not match the requested
method (create/update/delete/list secrets). Keeps digest binding as
integrity control. Aligns with CRE OAuth scopes used by GraphQL.

Updates system-test JWT minting to include the correct scope per method.

Co-authored-by: Cursor <cursoragent@cursor.com>
@prashantkumar1982 prashantkumar1982 force-pushed the fix/vault-jwt-scope-method-auth branch from 23fd54f to 284135a Compare May 6, 2026 02:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

✅ No conflicts with other open PRs targeting develop

@prashantkumar1982 prashantkumar1982 changed the title fix(vault): enforce JWT OAuth scope per JSON-RPC method Vault: enforce JWT OAuth scope per JSON-RPC method May 6, 2026
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 6, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

mchain0
mchain0 previously approved these changes May 6, 2026

// OAuthScopeForVaultRPCMethod returns the OAuth scope required to authorize the given
// Vault JSON-RPC method over the JWT path.
func OAuthScopeForVaultRPCMethod(method string) (string, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is exported but lacks direct unit-test coverage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is called from here:

oauthScope, err := vaultjwt.OAuthScopeForVaultRPCMethod(req.Method)

Added more unit-tests too.

return scopes[0], nil
}

func extractOAuthScopesFromClaims(claims jwt.MapClaims) []string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

only 67% of test coverage in cases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now have all test-cases

},
}

if len(claims.Scopes) > 0 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

q: There shouldn't be more than 1 scope per token, should we check for that and possibly err?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I am validating that request token only has 1 vault scope. Other scopes not vault related are ignored but not errored upon.

timothyF95
timothyF95 previously approved these changes May 6, 2026
prashantkumar1982 and others added 2 commits May 6, 2026 11:39
Enforce exactly one known Vault secret scope per token (ignore non-Vault
claims). Add OAuthScopeForVaultRPCMethod unit tests and JWT auth tests
for multi-scope and openid+vault cases.

Co-authored-by: Cursor <cursoragent@cursor.com>
@prashantkumar1982 prashantkumar1982 dismissed stale reviews from timothyF95 and mchain0 via 8e878ad May 6, 2026 18:40
@cl-sonarqube-production
Copy link
Copy Markdown

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue May 6, 2026
Merged via the queue into develop with commit 5a1731f May 6, 2026
213 checks passed
@prashantkumar1982 prashantkumar1982 deleted the fix/vault-jwt-scope-method-auth branch May 6, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants