8000 [OID4VCI] Cache issued verifiable credentials by forkimenjeckayang · Pull Request #53332 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[OID4VCI] Cache issued verifiable credentials - #53332

Open
forkimenjeckayang wants to merge 9 commits into
keycloak:mainfrom
adorsys:issue-49335
Open

forkimenjeckayang wants to merge 9 commits into
keycloak:mainfrom
adorsys:issue-49335

Conversation

@forkimenjeckayang
Copy link
Copy Markdown
Contributor

Summary

Add caching support for issued verifiable credentials.

Issued credential collections are now cached per user using dedicated
revisioned cache entries. Empty collections are cached as well, avoiding
repeated storage queries for users without issued credentials.

Cache entries are invalidated when:

  • an issued credential is added or removed;
  • a configured user credential is removed;
  • a user is invalidated or deleted;
  • expired issued credentials are removed;
  • a client is deleted;
  • a client scope is deleted.

Unscoped issued-credential removal now resolves the owning user before
deletion, allowing the correct per-user cache entry to be invalidated.

Cluster invalidation

Introduce a ProtoStream-marshalled user-cache event supporting targeted
and all-users invalidation.

All-users invalidation advances a dedicated global revision marker.
Each cached collection records the marker revision observed when it was
loaded. This prevents an in-flight cache load from reintroducing stale
data after a bulk invalidation event.

Invalidations are propagated through Keycloak's existing user-cache
invalidation channel for clustered and cross-DC deployments.

Testing

Added integration coverage for:

  • invalidating cached empty collections when credentials are issued;
  • invalidating the owning user's cache during unscoped removal;
  • cascading issued-credential invalidation when a configured credential
    is removed;
  • propagating user-scoped invalidation between two cluster nodes;
  • propagating global expiration-cleanup invalidation between two cluster
    nodes;
  • exercising both node directions as writer and reader.

closes #49335

Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
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.

Copilot review overview

🟡 Changes recommended

Pending global invalidations can return stale data within a transaction, while no-op cleanup unnecessarily invalidates the cluster-wide cache.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds per-user caching and cluster-aware invalidation for issued OID4VCI credentials.

Changes:

  • Adds revisioned issued-credential cache entries and invalidation events.
  • Invalidates caches after credential changes, cleanup, user changes, and related resource deletion.
  • Adds local and clustered integration coverage.
File Description
tests/​clustering/​.../​IssuedVerifiableCredentialCacheInvalidationTest.java Tests two-node invalidation.
tests/​base/​.../​IssuedVerifiableCredentialTest.java Tests add and unscoped-remove invalidation.
test-framework/​.../​IssuedVerifiableCredentialTestHelper.java Provides clustered-test operations.
server-spi/​.../​UserProvider.java Adds credential lookup by ID.
model/​storage/​.../​UserVerifiableCredentialFederatedStorage.java Adds federated lookup contract.
model/​storage-private/​.../​UserStorageManager.java Resolves credentials across storage types.
model/​jpa/​.../​JpaUserFederatedStorageProvider.java Implements federated ID lookup.
model/​jpa/​.../​JpaUserProvider.java Implements local ID lookup.
model/​infinispan/​.../​UserCacheSession.java Implements caching and invalidation behavior.
model/​infinispan/​.../​UserCacheManager.java Manages cache keys and global revisions.
model/​infinispan/​.../​UserIssuedVerifiableCredentialsUpdatedEvent.java Defines clustered invalidation events.
model/​infinispan/​.../​CachedUserIssuedVerifiableCredentials.java Stores cached credential collections.
model/​infinispan/​.../​CachedUserIssuedVerifiableCredential.java Stores cached credential values.
model/​infinispan/​.../​Marshalling.java Allocates the event type ID.
model/​infinispan/​.../​KeycloakModelSchema.java Registers event marshalling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 12:34
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.

Copilot review overview

🟢 Approval recommended

The cache lifecycle, storage implementations, marshalling registration, and clustered invalidation paths are consistent and adequately tested.

Review effort: Balanced
Findings: None

Resolved since last review (2)

Copilot AI balanced review requested due to automatic review settings October 1, 2026 07:11
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.

Copilot review overview

🔵 Needs a closer look

Distributed cache consistency and cross-DC invalidation semantics warrant final human review despite the added coverage.

Review effort: Balanced
Findings: None

< 8000 a class="avatar avatar-user" style="width:20px;height:20px;" data-test-selector="commits-avatar-stack-avatar-link" data-hovercard-type="user" data-hovercard-url="/users/forkimenjeckayang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="/forkimenjeckayang"> @forkimenjeckayang
Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:38
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.

Copilot review overview

🟡 Changes recommended

Event equality can suppress bulk cluster invalidation for a valid colliding user ID.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:17
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.

Copilot review overview

🟡 Changes recommended

The SPI change is binary-incompatible, and mixed-version clusters can retain stale cached credentials.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Resolved since last review (1)

Signed-off-by: forkimenjeckayang <forkimenjeckayang@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 12:20
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.

Copilot review overview

🔵 Needs a closer look

Distributed cache revisioning, cross-DC invalidation, and storage SPI changes warrant final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (2)

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.

[OID4VCI] Caching support for issued verifiable credentials

2 participants

0