Repository navigation
Fixes #38241: Allocate a fresh secret id when another list element still references the default id - #38497
Fixes #38241: Allocate a fresh secret id when another list element still references the default id#38497iamkiayun wants to merge 11 commits into
Conversation
…st element still references the default id
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| if (savedOwnRef != null | ||
| && manager.isFreshIdFor(savedOwnRef, defaultSecretId, root) | ||
| && !isReferencedByOther(savedOwnRef, defaultSecretId)) { | ||
| return savedOwnRef; |
There was a problem hiding this comment.
User-managed secrets can be changed
isFreshIdFor treats a name’s shape as proof that OpenMetadata created it. For example, save alpha.apiKey as a user-supplied reference to its default ID plus /abcdefghijklm. A later plaintext replacement reuses and overwrites that external secret; clearing the field deletes it. Neither path checks the recorded ownership, even though the original reference was never recorded as owned.
Require recorded ownership before reusing or deleting a suffixed reference.
| String targetId = scope.selectWriteSecretId(defaultSecretId); | ||
| String storedRef = storeWithFreshFallback(fieldName, targetId, defaultSecretId, value, scope); |
There was a problem hiding this comment.
Failed saves leave unused secrets
A fresh secret written before a failed database save is never tracked for cleanup. write.accept runs before recordWrite, and rollback only restores the entity in memory. Each retry allocates a new random suffix, so later saves cannot recover these IDs, and hard delete cannot find them. Failed saves can therefore leave credentials in the vault indefinitely, adding storage costs and manual cleanup.
Track newly created IDs outside the rolled-back ownership write, or remove them on failure without touching committed references.
Knowledge Base Used: Metadata entity lifecycle
pmbrull
left a comment
There was a problem hiding this comment.
Thanks for tracking down the secret ID collision.
- 🔴 Stage replacements for committed fresh IDs. A later edit can reuse a slot’s fresh ID and overwrite its vault value before the entity save commits. If the save fails, the committed config still points to that ID with the changed value. The rollback hook only cleans up newly allocated IDs. Write the replacement under a new ID and retire the prior ID after commit when it has no remaining references. Add a regression that rejects the second save and checks both the committed reference and its original vault value. ID reuse, Vault write, Rollback hook.
- 🔴 Clean up owned secrets when a renamed item is cleared. Renaming retains the fresh ID. A later clear checks the ID against the new slot name, so it misses post-commit cleanup and leaves the secret in the vault until hard delete. Use recorded ownership and remaining references to schedule cleanup after commit. Extend the rename test to clear the secret and verify its removal. Clear path.
pmbrull
left a comment
There was a problem hiding this comment.
❌ Changes needed · 1 🔴 · 0 🟡
| Blockers | ❌ 1 🔴 |
| Nits | ✅ none |
| Tests | ❌ gaps in shared-reference cleanup coverage across configs |
| Cross-repo | ✅ checked the ingestion secret resolver |
| Trade-off | ✅ none |
| Auto-approved | ➖ changes needed |
Thanks for addressing the previous review. The new tests cover preserving the committed credential when a replacement fails and cleaning up a renamed entry after it is cleared.
- 🔴
SecretMapOwnership.java:202— Post-commit cleanup only checks references recorded under the owning root. Another persisted service or pipeline config can still use the same credential when the owner rotates or clears it. Delete the key only when all persisted references have been removed. Add a regression that reads the credential through a second config after the owner changes.
A maintainer also needs to add #38241 to Shipping and rerun the metadata check. Metadata check details
What I checked
Reviewed the changes since the previous review, including fresh-key allocation, rollback, post-commit cleanup, and resolution of stored secret references in ingestion. The follow-up integration tests pin the earlier findings within one service. I read the Java tests. The current check results do not show a Java test run for this commit.
claude-verdict {"sha":"2fc20743b9c902f798c87555b37d43cf90969bf5","recommendation":"request_changes","blocking":1,"nits_to_fix":0,"human_decision":false,"tradeoff":"none","cross_repo":"checked","tests_ok":false}
| for (var iterator = scalars.iterator(); iterator.hasNext(); ) { | ||
| String name = iterator.next(); | ||
| if (generatedNames.contains(manager.canonicalSecretName(name))) { | ||
| state.owned().add(name); |
There was a problem hiding this comment.
🔴 Moving generated IDs into post-commit cleanup makes an ordinary credential edit eligible to delete the old key. The cleanup at line 222 only sees references in the owning root, so an independent config that still uses the credential loses it. Retire a key only after confirming the last persisted reference is gone. Add a regression that keeps reading through a second config after the owner rotates or clears the credential.
|
I ran the list-secret scenarios against a real Kubernetes secrets manager: the suite server switched to a K3s-backed Problem.
Proposed fix (A + B). Neither part needs a migration: the ledger stores secret names, never slots, and slots only exist in memory during a write.
Hashing the overflow in Tests. Please add tests that pin this down, for example in
|
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findingsChanging secret allocation and cross-entity cleanup could overwrite or delete vault credentials still referenced by persisted services, pipelines, or workflows. Adds fresh secret id allocation for list elements whose default id is still referenced by another slot, along with shared credential retention and rollback cleanup for owned secrets. Resolved the ADR omission of the compact fresh-id format and the per-deletion scan across all service, pipeline and workflow tables. No open issues found. ✅ 2 closed✅ Quality: ADR v4 omits the compact fresh-id format and the 8-attempt budget
✅ Performance: Each vault deletion scans every service, pipeline and workflow table
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Fixes #38241
Summary
When a list element (such as an MCP server in
McpConnection.servers) is renamed while its credential stays masked, or shifts position after an earlier position-keyed element is deleted, its storedsecret:reference still points at its old id. Adding a new element under that old name or position previously overwrote (or, when cleared, deleted) the secret the renamed or shifted element still referenced.Instead of reading or moving secrets in the vault, this fix decides whether a list element's secret id may be written or deleted strictly from the references held by the locked stored entity and the incoming request:
SecretsManager): Before encrypting password fields on an external secrets manager,ReferenceScopecollects everysecret:reference in both the locked stored config and the incoming config, compared viacanonicalSecretName(handling Azure case-insensitivity and AWS/SSM ARNs).<defaultId><sep><13-char base32>, with a compact hashed fallback under the entity root when a provider's max secret name length would be exceeded). Soft-deleted name conflicts (such as Azure Key Vault 409) also fall back to a fresh id."null"placeholder before any vault writes or deletes run.ServiceEntityRepository,IngestionPipelineRepository): Pass the row-locked stored entity already loaded inwriteWithSecretOwnershiptoencryptServiceConnectionConfig/encryptIngestionPipelineacross single, versioned, and bulk writes.SecretMapOwnership,SecretsManager.SecretInventory): Record the actual secret id written for each plaintext slot (including fresh ids) and recognize fresh ids instoredSecretName, so hard delete removes every owned secret while leaving user-supplied external references untouched.SecretMapOwnership.cleanalso compares references bycanonicalSecretName.docs/decisions/2026-11-11-mcp-service-server-names-are-unique-and-masks-need-a-stored-value.md.Verification
openmetadata-service): 592/592 passed (0 failures, 0 errors, 0 skipped), including:SecretMapEntriesExternalStoreTest(31/31): rename + reuse (later save and same save in both element orders), rename back after a key change, swap names + edit one/both keys + clear one key, delete position-keyed element (unnamed & duplicate names, same save and later save) + fresh-id reuse + hard-delete cleanup.ListSecretReferenceAllocationTest(10/10): failed DB save after swap/edit, failed batchupdateMany, direct 4-arg call withoutoriginal+deleteSecretsFromServiceConnectionConfig, Azure Key Vault (-separator, case-insensitivity, 409 soft-delete, 127-char max-length compact fallback), AWS ARN spelling, GCP_separator, Kubernetes 253-char compact fallback, DB secrets manager, prepare/approval path, refused"null"pre-validation, clearing safety, and user-supplied external references.AWSSecretsManagerLocalStackTest(7/7),AWSSSMSecretsManagerLocalStackTest(6/6),AzureKVSecretsManagerTest(5/5),GCPSecretsManagerTest(14/14),KubernetesSecretsManagerTest(21/21),OwnedSecretsTest(32/32),ServiceEntitySecretsTest(18/18),PasswordEntityMaskerTest(40/40),IngestionPipelineRepositoryTest(83/83).openmetadata-integration-tests, MySQL + Elasticsearch):SecretsManagerNullSecretIT: 35/35 passed (including new end-to-endrenamedMcpServerKeepsItsApiKeyWhenOldNameIsReusedAndSwapped).McpServiceResourceIT: 170 ran, 0 failed (25 skipped by base-class flags).SecretsManagerUpdateSoftDeletedIT: 1/1 passed.mvn spotless:check,python3 scripts/harness/check_decision_records.py, andpython3 .github/scripts/plan_local_java_tests.py --base upstream/main --check-branchall passed.Do not merge until fresh-ID reuse and clearing preserve user-managed secrets.
Findings
Summary
The PR protects list credentials when names or positions are reused:
Two gaps remain: suffixed user references can be mistaken for owned secrets, and failed saves leave newly allocated IDs outside cleanup.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Lock stored entity] --> B[Collect saved and incoming references] B --> C{Another slot uses the default ID?} C -->|Yes| D[Allocate fresh ID] C -->|No| E[Use default or saved fresh ID] D --> F[Write secret to vault] E --> F F --> G[Write entity to database] G --> H[Record actual owned IDs] H --> I[Commit and clean unused owned secrets]Reviews (1) · Last reviewed commit: "Fixes #38241: Allocate a fresh secret id..." · Reviewed by Greptile
Summary by Gitar
SharedSecretReferencesand workflow ownership wiring for bulk and hard-delete pathsThis will update automatically on new commits.