Skip to content

Fixes #28299: keep secret keys of list elements distinct - #38190

Closed
Khairajani wants to merge 2 commits into
mainfrom
secret-collection-keys
Closed

Khairajani wants to merge 2 commits into
mainfrom
secret-collection-keys

Conversation

@Khairajani

@Khairajani Khairajani commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #28299

Follow-up to #33477, from the review of #38118.

  • What: each element of a list of secrets (for example MCP servers[].apiKey) is keyed by its name when that name is unique, and by position (#0, #1, ...) otherwise. Two cases still gave two elements the same key, so one server's key could overwrite another's:
    • a name like #1 matched a position key;
    • names like Prod and prod, or prod-1 and prod_1, were unique but map to one secret id in AWS, Azure, GCP and Kubernetes secrets managers, which lowercase the id and drop or replace other characters.
  • Fix: the two uses get separate keys.
    • Restoring a masked key still matches the exact name, so Prod and prod (or servers 1 and 2) keep their own keys through a reorder or a delete. A name starting with # gets one more #, so it never equals a position key.
    • The secret id uses a name only when it is unique lowercased and reduced to letters and digits, and has a letter; otherwise the position. A reference to an existing secret is kept on save, so a reorder never moves one server's secret onto another.
  • Decision record: ADR:2026-11-11-mcp-service-server-names-are-unique-and-masks-need-a-stored-value gets a v3 amendment with both rules.
  • ReflectionUtilCollectionKeysTest failed first on the three collisions. New PasswordEntityMaskerTest cases (reorder of Prod/prod, deleting server 1, a #1 name next to repeated names) failed on the first version of this fix. All pass now, with the other secrets tests.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The changes appear safe to merge.

Summary

Separates how list elements are matched during secret restoration from how their secret-store IDs are built.

  • List secrets keep distinct keys even when names clean alike.

The previous finding is addressed. No new actionable issues were found in the changes since the last review. Tests were inspected, not run.

Reviews (2) · Last reviewed commit: "Match masked list secrets by exact name,..." · Reviewed by Greptile

@Khairajani
Khairajani requested a review from a team as a code owner November 19, 2026 08:47
@Khairajani
Khairajani requested a review from manerow November 19, 2026 08:47
@gitar-bot

gitar-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findings

Changing MCP collection secret-key derivation and mask matching affects stored secret integrity; a key collision could overwrite or misassign a server's API key.

Fixes secret key collisions for list elements by keying restores on exact names and using a separate, normalized secret id that falls back to position when names clash. The MCP exact-match check that could swap positional keys and the ADR wording that still described the old rule were both addressed. No open issues found.

✅ 2 closed
✅ Bug: MCP name check still exact-match, so positional names can swap keys

📄 openmetadata-service/src/main/java/org/openmetadata/service/util/ReflectionUtil.java:122-133
After this change, servers named Prod and prod, prod-1 and prod_1, or digit-only names like 1 and 2 get positional keys (#0, #1). But McpServiceRepository.validateUniqueServerNames still compares names with an exact HashSet match, so it accepts these lists. The ADR 2026-11-11-mcp-service-server-names-are-unique... refuses duplicate names with 400 precisely because position-keyed servers "could not be told apart after a reorder". With this change a client can create [Prod, prod] and then send a reorder PUT that carries masked apiKeys. That request passes validation, and each masked key is restored from the stored value at the same position, so the two servers silently swap API keys. This is the overwrite this PR is meant to prevent. Fix: validate MCP server names with the same rule as the keys. Expose a shared helper from ReflectionUtil (for example secretIdForm plus the no-letters check), and in validateUniqueServerNames reject names whose cleaned form repeats or has no letters.

✅ Quality: Keying rule changes, but the ADR still says 'name when it occurs once'

📄 openmetadata-service/src/main/java/org/openmetadata/service/util/ReflectionUtil.java:111-114 📄 openmetadata-service/src/main/java/org/openmetadata/service/util/ReflectionUtil.java:129-133
docs/decisions/2026-11-11-mcp-service-server-names-are-unique-and-masks-need-a-stored-value.md currently says an element is matched "by its name when that name occurs once in the list, and by position otherwise." This PR changes that derived secret-key format, which is a contract the secret store and stored service configs depend on. The description puts the new rule only in prose ("a name is checked for uniqueness lowercased and reduced to letters and digits, and a name with no letters falls back to position"), and the record was not revised. The sentence the record should assert: "A list element is keyed by its name only when the name, lowercased and reduced to ASCII letters and digits, contains a letter and occurs once in the list; otherwise it is keyed by #<index>." The Consequences section should also say which server names are now refused, or still accepted, by the uniqueness check.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Khairajani

Copy link
Copy Markdown
Contributor Author

Folded into #38117.

@Khairajani Khairajani closed this Nov 19, 2026
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.

Sftp Service connection details contain unmasked password

1 participant