Skip to content

Add JWT-SVID audience policy configuration with JTI claim support - #6514

Merged
sorindumitru merged 7 commits into
spiffe:mainfrom
srikalyan:feature/jwt-jti-claim
May 27, 2026
Merged

sorindumitru merged 7 commits into
spiffe:mainfrom
srikalyan:feature/jwt-jti-claim

Conversation

@srikalyan

Copy link
Copy Markdown
Contributor

Summary

Implements issue #6043 - JWT JTI Attribute support with per-audience policy configuration.

This PR introduces a flexible JWT-SVID policy system that allows operators to control:

  • Whether JTI (JWT ID) claims are included in tokens
  • Whether agent-side caching is used

New JWTSVIDAudiencePolicy enum with three modes:

  • DEFAULT (0): No JTI claim, caching enabled. Backwards compatible behavior.
  • AUDITABLE (1): JTI claim included for audit trails, caching still enabled. Verifiers can optionally enforce replay protection.
  • UNIQUE (2): JTI claim included, caching disabled. Each request gets a fresh token for strict replay protection.

Configuration options:

  • jwt_svid_default_audience_policy: Default policy for audiences not explicitly configured
  • jwt_svid_audience_policies: Per-audience policy overrides (map of audience → policy)

Key behaviors:

  • Most restrictive wins: When multiple audiences are requested, the strictest policy applies
  • Backwards compatible: DEFAULT policy preserves existing behavior
  • Database schema v24: Adds entry_audience_policies table for per-audience configuration

What's included in this PR:

  • Proto definitions for new enum and entry fields
  • Server-side JTI generation based on effective policy
  • Agent-side cache bypass for UNIQUE policy
  • Database migration and CRUD operations
  • Comprehensive tests

What's NOT included (requires spire-api-sdk update):

  • Entry API conversion logic
  • CLI commands for configuring policies

These will follow in a separate PR after the spire-api-sdk is updated with the new types.

Test plan

  • Unit tests for JTI generation with all policy modes
  • Unit tests for "most restrictive wins" multi-audience behavior
  • Unit tests for per-audience policy overrides
  • Database migration tests
  • Agent cache bypass tests for UNIQUE policy

Fixes #6043

@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 6e39f46 to f45e5a4 Compare December 26, 2025 05:06
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 1d8392e to f45e5a4 Compare December 26, 2025 18:35
srikalyan added a commit to srikalyan/spire that referenced this pull request Dec 26, 2025
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
@sorindumitru

Copy link
Copy Markdown
Member

Thanks @srikalyan for opening this! We discussed this today and we think it might be good to start with something simple at first by having just the entry level policy (maybe called something like jwt_svid_jti_policy). We think that should cover most uses. If it turns out there's still a need for the per audience version, we can add something like that later on.

We also think we should combine this flag with the changes in #6360. This avoid the need to have these seldomly used flags as individual columns in the database. I don't know what's the current state of the work from @ValFadeev, but maybe you can continue from where he left off?

@srikalyan

Copy link
Copy Markdown
Contributor Author

Thanks @srikalyan for opening this! We discussed this today and we think it might be good to start with something simple at first by having just the entry level policy (maybe called something like jwt_svid_jti_policy). We think that should cover most uses. If it turns out there's still a need for the per audience version, we can add something like that later on.

We also think we should combine this flag with the changes in #6360. This avoid the need to have these seldomly used flags as individual columns in the database. I don't know what's the current state of the work from @ValFadeev, but maybe you can continue from where he left off?

@ValFadeev let me know if you are ok in me making the necessary change?

@ValFadeev

Copy link
Copy Markdown
Contributor

@srikalyan yes, I am happy for you to do so and to discuss if necessary. I was still aiming to allocate the time to finish that work, but would not want to hold the progress

@sorindumitru

Copy link
Copy Markdown
Member

Hi, @srikalyan We'll be merging github.com//pull/6360 in SPIRE 1.15.0, which will be the next release after 1.14.3. If you want, you can rebase this on top of that PR or wait until it gets merged into main.

@srikalyan

Copy link
Copy Markdown
Contributor Author

Thank you @sorindumitru Will do it soon.

srikalyan added a commit to srikalyan/spire that referenced this pull request Mar 9, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from f45e5a4 to 101e2c9 Compare March 9, 2026 20:56
@srikalyan

Copy link
Copy Markdown
Contributor Author

Rebased the branch and will wait for your merge to finish.

@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 101e2c9 to 3b3ed71 Compare April 16, 2026 15:55
srikalyan added a commit to srikalyan/spire that referenced this pull request Apr 16, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
srikalyan added a commit to srikalyan/spire that referenced this pull request Apr 16, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 3b3ed71 to b195d56 Compare April 16, 2026 16:29
@srikalyan

Copy link
Copy Markdown
Contributor Author

@sorindumitru now that the other feature is merged, can we get this PR rolling?

@sorindumitru

Copy link
Copy Markdown
Member

Yes, I hope I can have a run over this over the weekend and provide some feedback.

@sorindumitru

Copy link
Copy Markdown
Member

Thanks @srikalyan for opening this! We discussed this today and we think it might be good to start with something simple at first by having just the entry level policy (maybe called something like jwt_svid_jti_policy). We think that should cover most uses. If it turns out there's still a need for the per audience version, we can add something like that later on.

Had a look through the code for a bit, I'll look some more, but I notice we still have both the flag + the audience map. I don't think it's that likely to configure things per audience so in the interest of keeping the configuration simple we should start with a simple flag, maybe just jws_svid_include_jti?

You'll also have to add the flag to the new AdditionalAttributes structure instead of directly to the entry (this will also fix some issues around parsing the field in this PR, i think listing entries doesn't currently parse the fields).

srikalyan added a commit to srikalyan/spire that referenced this pull request Apr 21, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
@sorindumitru

Copy link
Copy Markdown
Member

Hi @srikalyan, just checking in to see if you're still planning on updating this to use the new field added in the SDK.

srikalyan added a commit to srikalyan/spire that referenced this pull request May 20, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514
sorindumitru
sorindumitru previously approved these changes May 26, 2026

@sorindumitru sorindumitru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks @srikalyan! Would you mind fixing up the DCO?

srikalyan added a commit to srikalyan/spire that referenced this pull request May 26, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514

Signed-off-by: Srikalyan Swayampakula <[email protected]>
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 9224847 to e57ff00 Compare May 26, 2026 17:44
srikalyan added a commit to srikalyan/spire that referenced this pull request May 26, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514

Signed-off-by: Srikalyan Swayampakula <[email protected]>
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from e57ff00 to 2b99b45 Compare May 26, 2026 18:25
@sorindumitru
sorindumitru enabled auto-merge May 26, 2026 18:26
@sorindumitru
sorindumitru added this pull request to the merge queue May 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 26, 2026
srikalyan added a commit to srikalyan/spire that referenced this pull request May 26, 2026
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514

Signed-off-by: Srikalyan Swayampakula <[email protected]>
Copilot AI review requested due to automatic review settings May 26, 2026 20:27
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 2b99b45 to 201051c Compare May 26, 2026 20:27

Copilot AI left a comment

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR introduces a per-registration-entry option to include a unique jti claim in issued JWT-SVIDs and ensures those JWT-SVIDs are not served from (or written to) the agent-side JWT-SVID cache.

Changes:

  • Added jwt_svid_include_jti to RegistrationEntry.AdditionalAttributes and wired it through server signing/minting paths.
  • Implemented agent behavior to bypass JWT-SVID cache when jwt_svid_include_jti is enabled.
  • Updated CLI create/update flows and expanded tests across server/agent to validate jti presence and cache bypass behavior.

Reviewed changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
proto/spire/common/common.proto Adds jwt_svid_include_jti flag to entry AdditionalAttributes and documents expected behavior.
pkg/server/credtemplate/builder.go Adds IncludeJTI param and emits jti claim when requested.
pkg/server/credtemplate/builder_test.go Adds test coverage for jti generation and verifies it’s absent by default.
pkg/server/ca/ca.go Threads IncludeJTI through CA signing parameters.
pkg/server/api/svid/v1/service.go Plumbs per-entry jwt_svid_include_jti into JWT-SVID minting path.
pkg/server/api/svid/v1/service_test.go Adds cases asserting jti presence/absence based on entry attributes.
pkg/server/api/entry.go Maps JwtSvidIncludeJti between datastore/common and API types.
pkg/server/api/entry_test.go Updates clone test to include new AdditionalAttributes field.
pkg/server/api/entry/v1/service.go Extends registration entry mask to include AdditionalAttributes.
pkg/server/api/entry/v1/service_test.go Adds batch update coverage for AdditionalAttributes updates/no-ops.
pkg/agent/manager/manager.go Bypasses JWT-SVID cache when jwt_svid_include_jti is set.
pkg/agent/manager/manager_test.go Adds test asserting cache bypass behavior when jwt_svid_include_jti is enabled.
cmd/spire-server/cli/entry/create.go Adds -jwtSVIDIncludeJTI and emits it into AdditionalAttributes.
cmd/spire-server/cli/entry/create_test.go Updates expected JSON to include jwt_svid_include_jti.
cmd/spire-server/cli/entry/update.go Adds -jwtSVIDIncludeJTI and merges AdditionalAttributes to avoid clobbering siblings.
cmd/spire-server/cli/entry/update_test.go Adds tests ensuring AdditionalAttributes merge/preservation behavior.
cmd/spire-server/cli/entry/util.go Prints JwtSvidIncludeJti when enabled.
cmd/spire-server/cli/entry/util_posix_test.go Updates usage/help text expectations to include new flag.
cmd/spire-server/cli/entry/util_windows_test.go Updates usage/help text expectations to include new flag.
go.mod Bumps github.com/spiffe/spire-api-sdk to a newer pseudo-version.
go.sum Updates checksums for the bumped spire-api-sdk version.
Files not reviewed (1)
  • proto/spire/common/common.pb.go: Language not supported

Comment thread pkg/agent/manager/manager.go Resolved
Comment thread cmd/spire-server/cli/entry/update.go Resolved
srikalyan added 7 commits May 26, 2026 21:59
…iffe#6043)

Introduces per-audience JWT-SVID policy configuration to control JTI
(JWT ID) claim inclusion and agent-side caching behavior.

New JWTSVIDAudiencePolicy enum with three modes:
- DEFAULT (0): No JTI, caching enabled (backwards compatible)
- AUDITABLE (1): JTI included, caching enabled
- UNIQUE (2): JTI included, caching disabled

Features:
- Per-entry default policy via jwt_svid_default_audience_policy
- Per-audience overrides via jwt_svid_audience_policies map
- "Most restrictive wins" for multi-audience tokens
- Database schema v24 with entry_audience_policies table
- Agent cache bypass for UNIQUE policy

Note: API SDK and CLI integration will follow in a separate commit
after spire-api-sdk is updated.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514

Signed-off-by: Srikalyan Swayampakula <[email protected]>
Replaces local-path replace directive with the merged upstream SDK
pseudo-version so CI can resolve the new jwt_svid_include_jti field
from the public module proxy.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
The updateEntry mask translation in the entry v1 service was missing the
AdditionalAttributes field, so masked updates targeting that field were
silently dropped before reaching the datastore. Map the input mask bit
through and add coverage for both the honored and ignored cases.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
The protobuf AdditionalAttributes message has no per-field mask, so a
CLI update that set only one of -disableX509SVIDPrefetch or
-jwtSVIDIncludeJTI would clobber the unset sibling bit with its zero
value. Track each flag's set state independently and, when exactly one
is supplied (and -data is not in use), fetch the existing entry to
merge the unspecified bit before BatchUpdateEntry. GetEntry failures
short-circuit before any update is attempted.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
- pkg/server/api/svid/v1/service.go: add explicit nil check for
  GetAdditionalAttributes() before reading JwtSvidIncludeJti; add
  test cases covering nil attrs, JTI false, and JTI true paths.
- pkg/server/credtemplate/builder.go: return error from jti UUID
  generation instead of panicking via uuid.Must; encode the 16
  random bytes as base64url for a more compact claim value.
- cmd/spire-server/cli/entry/update.go: gate the existing-entry
  fetch on a single additionalAttributesSet flag, then merge each
  AdditionalAttributes field individually so unspecified flags
  preserve the existing value.
- pkg/agent/manager/manager_test.go: add TestFetchJWTSVIDWithJTIBypassesCache
  proving JwtSvidIncludeJti bypasses both the cache read and write.
- pkg/server/api/entry_test.go: only add JwtSvidIncludeJti: true
  in TestReadOnlyEntryClone; revert unintended prefetch change.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
Switch mergeAdditionalAttributes to proto.Clone the existing message and
override only fields explicitly set on the command line. This preserves
unknown fields and any future AdditionalAttributes the binary does not
know about, so the merge does not need editing when new fields are added.

Also harden the agent's bypassCache read with a nil-safe chained getter.

Signed-off-by: Srikalyan Swayampakula <[email protected]>
@srikalyan
srikalyan force-pushed the feature/jwt-jti-claim branch from 792ca83 to c14b0d8 Compare May 27, 2026 05:00
@srikalyan

Copy link
Copy Markdown
Contributor Author

@sorindumitru can you give one more ship it, had to address copilot review

@sorindumitru sorindumitru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

re-LGTM

@sorindumitru
sorindumitru enabled auto-merge May 27, 2026 07:13
@sorindumitru
sorindumitru added this pull request to the merge queue May 27, 2026
Merged via the queue into spiffe:main with commit f70cc65 May 27, 2026
96 of 98 checks passed
@srikalyan
srikalyan deleted the feature/jwt-jti-claim branch May 27, 2026 17:08
MikeZappa87 pushed a commit to MikeZappa87/spire that referenced this pull request May 29, 2026
…iffe#6514)

* Add JWT-SVID audience policy configuration with JTI claim support (spiffe#6043)

Introduces per-audience JWT-SVID policy configuration to control JTI
(JWT ID) claim inclusion and agent-side caching behavior.

New JWTSVIDAudiencePolicy enum with three modes:
- DEFAULT (0): No JTI, caching enabled (backwards compatible)
- AUDITABLE (1): JTI included, caching enabled
- UNIQUE (2): JTI included, caching disabled

Features:
- Per-entry default policy via jwt_svid_default_audience_policy
- Per-audience overrides via jwt_svid_audience_policies map
- "Most restrictive wins" for multi-audience tokens
- Database schema v24 with entry_audience_policies table
- Agent cache bypass for UNIQUE policy

Note: API SDK and CLI integration will follow in a separate commit
after spire-api-sdk is updated.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Add CLI and entry conversion support for JWT-SVID audience policies

This commit adds support for the new JWT-SVID audience policy configuration
in the SPIRE server CLI and entry conversion logic:

CLI changes:
- Add -jwtSVIDDefaultAudiencePolicy flag for default audience policy
- Add -jwtSVIDAudiencePolicy flag for per-audience policy configuration
- Update entry create, update, and show commands to handle new fields
- Add AudiencePolicyFlag custom type for parsing audience:policy pairs

Entry conversion:
- Add JwtSvidDefaultAudiencePolicy and JwtSvidAudiencePolicies to
  EntryToProto and ProtoToEntry conversion functions
- Add audiencePolicyToInternal helper for enum conversion

Policy options: default, auditable, unique
- default: No JTI claim, caching enabled (current behavior)
- auditable: JTI claim included, caching enabled
- unique: JTI claim included, caching disabled (unique tokens)

Part of spiffe#6043

NOTE: Only merge after these dependent PRs are merged:
- spire-api-sdk: spiffe/spire-api-sdk#84
- spire: spiffe#6514

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Bump spire-api-sdk to merged JTI commit (PR spiffe#95)

Replaces local-path replace directive with the merged upstream SDK
pseudo-version so CI can resolve the new jwt_svid_include_jti field
from the public module proxy.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Persist AdditionalAttributes through entry update mask

The updateEntry mask translation in the entry v1 service was missing the
AdditionalAttributes field, so masked updates targeting that field were
silently dropped before reaching the datastore. Map the input mask bit
through and add coverage for both the honored and ignored cases.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Preserve sibling AdditionalAttributes on partial CLI entry update

The protobuf AdditionalAttributes message has no per-field mask, so a
CLI update that set only one of -disableX509SVIDPrefetch or
-jwtSVIDIncludeJTI would clobber the unset sibling bit with its zero
value. Track each flag's set state independently and, when exactly one
is supplied (and -data is not in use), fetch the existing entry to
merge the unspecified bit before BatchUpdateEntry. GetEntry failures
short-circuit before any update is attempted.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Address review feedback for JWT-SVID JTI claim

- pkg/server/api/svid/v1/service.go: add explicit nil check for
  GetAdditionalAttributes() before reading JwtSvidIncludeJti; add
  test cases covering nil attrs, JTI false, and JTI true paths.
- pkg/server/credtemplate/builder.go: return error from jti UUID
  generation instead of panicking via uuid.Must; encode the 16
  random bytes as base64url for a more compact claim value.
- cmd/spire-server/cli/entry/update.go: gate the existing-entry
  fetch on a single additionalAttributesSet flag, then merge each
  AdditionalAttributes field individually so unspecified flags
  preserve the existing value.
- pkg/agent/manager/manager_test.go: add TestFetchJWTSVIDWithJTIBypassesCache
  proving JwtSvidIncludeJti bypasses both the cache read and write.
- pkg/server/api/entry_test.go: only add JwtSvidIncludeJti: true
  in TestReadOnlyEntryClone; revert unintended prefetch change.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

* Clone existing AdditionalAttributes on partial CLI entry update

Switch mergeAdditionalAttributes to proto.Clone the existing message and
override only fields explicitly set on the command line. This preserves
unknown fields and any future AdditionalAttributes the binary does not
know about, so the merge does not need editing when new fields are added.

Also harden the agent's bypassCache read with a nil-safe chained getter.

Signed-off-by: Srikalyan Swayampakula <[email protected]>

---------

Signed-off-by: Srikalyan Swayampakula <[email protected]>
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.

JWT JTI Attribute

4 participants