Skip to content

feat: add KVStoreWrapper with owner migration adapter for vault org_id migration#21691

Merged
prashantkumar1982 merged 6 commits intodevelopfrom
feat/pr5-owner-migration-adapter
Apr 1, 2026
Merged

feat: add KVStoreWrapper with owner migration adapter for vault org_id migration#21691
prashantkumar1982 merged 6 commits intodevelopfrom
feat/pr5-owner-migration-adapter

Conversation

@prashantkumar1982
Copy link
Copy Markdown
Contributor

@prashantkumar1982 prashantkumar1982 commented Mar 25, 2026

Summary

  • Adds KVStoreWrapper in core/services/ocr2/plugins/vault/kvstore_wrapper.go — a migration-aware layer over the vault KVStore that handles the transition from workflow_owner-keyed entries to org_id-keyed entries.
  • KVStoreWrapper is the public abstraction the plugin will interact with. Internally it delegates to an unexported ownerMigrationAdapter that contains the dual-owner migration logic.
  • orgID and workflowOwner are passed per method call (not stored in the struct), matching the plugin's one-store-per-call pattern where a single instance processes batches with different owners.
  • Reads perform dual-owner lookup (org_id first, workflow_owner fallback); writes always go under org_id with lazy migration of legacy entries; list operations merge and deduplicate metadata across both owners.
  • Critical error log on unexpected duplicate detection during metadata merge.
  • Includes 42 comprehensive unit tests covering all operations, migration scenarios, edge cases, and error propagation.

This is a standalone component in the JWT auth rollout plan — not wired into the plugin yet. No behavior change.

Add a transparent adapter layer (OwnerMigrationReadStore / OwnerMigrationWriteStore)
that sits between the vault plugin and the KV store to handle the migration of
secrets from workflow_owner-keyed entries to org_id-keyed entries.

The adapter implements the same ReadKVStore / WriteKVStore interfaces and provides:
- Dual-owner lookup on reads (org_id first, workflow_owner fallback)
- Metadata merging and deduplication across both owners for list operations
- org_id-based writes for all new/updated secrets
- Lazy migration: deletes legacy workflow_owner entries on update
- Dual-owner deletion with cleanup of both owners
- Pass-through for pending queue operations (not owner-scoped)

This is a standalone component (not wired into the plugin yet) with comprehensive
unit tests covering all operations and migration scenarios.
@github-actions
Copy link
Copy Markdown
Contributor

👋 prashantkumar1982, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 25, 2026

✅ No conflicts with other open PRs targeting develop

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Mar 25, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs


var _ ReadKVStore = (*OwnerMigrationReadStore)(nil)

func NewOwnerMigrationReadStore(inner ReadKVStore, orgID, workflowOwner string) *OwnerMigrationReadStore {
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.

I'm not sure how this would be transparent since this implies that we'll have one read store per owner/org ID. Atm we typically instantiate one readStore for every plugin function call

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.

Yes makes sense. Let me change it

}

// org_id entries take priority in deduplication.
addEntries(orgMd)
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.

Is there a risk that the merged list will end up having more than the max allowed number of secrets?

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.

No — the merged list cannot exceed the max. mergeMetadata deduplicates entries by namespace::key, so a secret that temporarily exists under both org_id and workflow_owner (transient mid-migration state) is counted only once. The deduplicated count reflects the true number of unique secrets the owner has, which is what MaxSecretsPerOwner was originally enforced against during creation.

Added a clarifying comment on GetMetadata in the updated code.

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.

Basically the enforcement of max secrets will be done in CreateSecrets flow.

Restructure the owner migration layer into two types:
- KVStoreWrapper (exported): the abstraction the plugin interacts with
- ownerMigrationAdapter (unexported): internal migration logic

orgID/workflowOwner are passed per method call rather than stored in
the struct, matching the plugin's one-store-per-call pattern where a
single instance processes batches with different owners.

Add Criticalw log on unexpected duplicate during metadata merge.
Rename files: owner_migration_store.go → kvstore_wrapper.go.

Made-with: Cursor
@prashantkumar1982 prashantkumar1982 changed the title feat: add OwnerMigrationStore adapter for vault org_id migration feat: add KVStoreWrapper with owner migration adapter for vault org_id migration Mar 25, 2026
Add migrationEnabled bool to KVStoreWrapper constructor. When false,
all methods pass through directly to the inner KVStore, bypassing the
ownerMigrationAdapter entirely. The caller resolves the gate from
cresettings.Default.VaultOrgIdAsSecretOwnerEnabled.

Add 14 unit tests verifying passthrough behavior when disabled.

Made-with: Cursor
timothyF95
timothyF95 previously approved these changes Apr 1, 2026
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
…r develop merge

- Add context.Context as first param to all KVStoreWrapper and adapter methods
- Rename test helper to newMigrationTestStore to avoid redeclaration with kvstore_test.go
- Update NewWriteStore calls to include pluginMetrics parameter

Made-with: Cursor
@prashantkumar1982 prashantkumar1982 force-pushed the feat/pr5-owner-migration-adapter branch from 2cbdcec to cbf9999 Compare April 1, 2026 21:28
@cl-sonarqube-production
Copy link
Copy Markdown

}

func TestKVStoreWrapper_CreateOldFlow_ListNewFlow(t *testing.T) {
ctx := context.Background()
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.

Should use the test context for these:

Suggested change
ctx := context.Background()
ctx := t.Context()

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into develop with commit 6bf7d2c Apr 1, 2026
203 of 204 checks passed
@prashantkumar1982 prashantkumar1982 deleted the feat/pr5-owner-migration-adapter branch April 1, 2026 22:27
prashantkumar1982 added a commit that referenced this pull request Apr 2, 2026
…d migration (#21691)

* feat: add OwnerMigrationStore adapter for vault org_id migration

Add a transparent adapter layer (OwnerMigrationReadStore / OwnerMigrationWriteStore)
that sits between the vault plugin and the KV store to handle the migration of
secrets from workflow_owner-keyed entries to org_id-keyed entries.

The adapter implements the same ReadKVStore / WriteKVStore interfaces and provides:
- Dual-owner lookup on reads (org_id first, workflow_owner fallback)
- Metadata merging and deduplication across both owners for list operations
- org_id-based writes for all new/updated secrets
- Lazy migration: deletes legacy workflow_owner entries on update
- Dual-owner deletion with cleanup of both owners
- Pass-through for pending queue operations (not owner-scoped)

This is a standalone component (not wired into the plugin yet) with comprehensive
unit tests covering all operations and migration scenarios.

* refactor: rename to KVStoreWrapper with internal ownerMigrationAdapter

Restructure the owner migration layer into two types:
- KVStoreWrapper (exported): the abstraction the plugin interacts with
- ownerMigrationAdapter (unexported): internal migration logic

orgID/workflowOwner are passed per method call rather than stored in
the struct, matching the plugin's one-store-per-call pattern where a
single instance processes batches with different owners.

Add Criticalw log on unexpected duplicate during metadata merge.
Rename files: owner_migration_store.go → kvstore_wrapper.go.

Made-with: Cursor

* feat: gate KVStoreWrapper with migrationEnabled flag

Add migrationEnabled bool to KVStoreWrapper constructor. When false,
all methods pass through directly to the inner KVStore, bypassing the
ownerMigrationAdapter entirely. The caller resolves the gate from
cresettings.Default.VaultOrgIdAsSecretOwnerEnabled.

Add 14 unit tests verifying passthrough behavior when disabled.

Made-with: Cursor

* fix: update KVStoreWrapper for context.Context interface changes after develop merge

- Add context.Context as first param to all KVStoreWrapper and adapter methods
- Rename test helper to newMigrationTestStore to avoid redeclaration with kvstore_test.go
- Update NewWriteStore calls to include pluginMetrics parameter

Made-with: Cursor
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.

5 participants