Skip to content

🐛 fix(adminmcp): reads stop masking values that cannot be a credential - #16889

Merged
hivecommons-hive[bot] merged 3 commits into
hivecommons:v6from
Danathar:fix/adminmcp-read-scrub-false-positives
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 3 commits into
hivecommons:v6from
Danathar:fix/adminmcp-read-scrub-false-positives

Conversation

@Danathar

@Danathar Danathar commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Admin MCP reads mask any value whose key contains token, secret, password, credential or authorization. That rule is too wide: it hides settings an operator needs and that cannot hold a credential, and it makes a secret that is not set look the same as one that is. This PR keeps the rule and adds a short list of values it must not mask. Real secrets are masked exactly as before, and the stricter rule for what a write preview may store is not touched.

What an operator saw

Read through settings_read and contributors_list on a live v6 hive:

field real value shown as
work_source.gitlab.token_env empty, nothing set [masked:token]
work_source.external.auth_token empty, nothing set [masked:token]
budget.coins.bob.tokens_per_coin a number [masked:token]
repoSelfAuthorizationHold per-repo merge policy [masked:authorization]
security.credentialWarnings an empty list (no warnings) [masked:secret]
token_expires_at, token_issued_at (contributor) timestamps [masked:token]

What changes

A value under one of those keys is now shown when it is one of these:

  • nothing: null, an empty string, an empty list or object. So [masked:token] now means a value is there and was withheld.
  • a timestamp.
  • a token count or rate with the unit after the word, such as tokens_per_coin. (totalTokens and input_tokens were already shown.)
  • the self-authorization hold settings (selfAuthorizationHold, repoSelfAuthorizationHold, self_authorization_hold). They are a merge policy, not an Authorization header.

Anything kept this way still goes through the shape scrub (GitHub tokens, JWTs, bearer tokens, private keys), and keys inside a shown block are judged by the same rules.

What stays masked

  • Any other string under those keys. That includes the name of an environment variable under a key such as token_env. Showing those names was part of this PR at first; the review asked for the owner's decision on it, so it is taken out here and will be proposed on its own.
  • A number under password, secret, or a key such as access_tokens_per_user.
  • A list or object with content, for example credentialWarnings with warnings in it, or credentialInjection. Opening those safely needs a per-field decision, so this PR leaves them.
  • token_type and credential_type, and the sources entry for a *_tokens setting (a word such as "default"). They are short strings that no general rule can tell from a password.

Files

  • src/pkg/adminmcp/adminmcp.go: readMaskExempt and helpers, used only by the read scrub; sensitiveKey uses authorizationKey.
  • src/pkg/adminmcp/scrub_read_test.go: new.
  • src/docs/admin-mcp.md: new section "What a read masks".
  • changelog.d/fixed-admin-mcp-read-scrub-false-positives.md

Tests

  • TestScrubShowsValuesThatCannotBeASecret: 13 cases.
  • TestScrubStillMasksWhatCouldBeASecret: 23 cases that must stay masked, environment variable names among them.
  • TestScrubStillScrubsKeptValuesByShape
  • TestPendingScrubIsAsStrictAsBefore: the write-preview scrub still masks all of these.
  • TestKeyWords
  • Mutants of the new rules (for example "a credential qualifier before tokens is ignored", "a list with content is shown", "authorization is never sensitive") each fail a test.
  • go test ./pkg/adminmcp/ ./cmd/hive-admin-mcp/ passes, and so do the AdminMCP, SettingsRead and Diag tests in ./pkg/dashboard/, which include the settings secret-leak test.

🤖 Generated with Claude Code

A read masked every value under a key containing token, secret,
password, credential or authorization, booleans and *tokens counts
excepted. settings_read therefore hid the name of the environment variable
that supplies a secret (token_env, gitlabTokenEnv, webhookSecretEnv), a
numeric rate (tokens_per_coin), the whole per-repo self-authorization hold
policy, and showed [masked:token] for a secret that is not set.
contributors_list hid token_expires_at and its sibling timestamps.

readMaskExempt keeps, in read results only: null and empty values, a
timestamp, a token count or rate with the unit after the word, an
upper-case environment variable name under a key ending in env, and the
self-authorization hold settings. Kept strings are still scrubbed by
shape. maskExempt, which the pending-confirmation scrub shares, is
unchanged, so what a write preview may store is as strict as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 6, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nicholasjackson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16884 ✨ feat(adminmcp): read and act on the Activity monitor; writes run as the verified caller same files src/docs/admin-mcp.md
src/pkg/adminmcp/adminmcp.go

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 6, 2026

@hivecommons-hive hivecommons-hive Bot 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.

Read the scrub paths in the tree before the body. The widening is confined to the read scrub: maskSensitive (src/pkg/adminmcp/adminmcp.go:831) is the only caller of the new readMaskExempt, while the write-preview scrub (scrubPendingValue, adminmcp.go:603-640) still uses credentialBearingKey + the old maskExempt, so the "pending scrub is as strict as before" claim holds. Each new exemption is one a credential cannot satisfy: nil/""/empty list/empty object, an RFC3339 parse, a tokens count/rate guarded by credentialTokenQualifiers and the other sensitive words (tokenRateKey, adminmcp.go:942-962), and an upper-case [A-Z0-9_] value only under a key whose last word is env (envNameKey/envNameShaped). Kept strings still pass through scrubOutboundString in the walk. authorizationKey only carves out the *selfauthorizationhold suffix. Looks correct to me.

Two small notes, neither a defect:

  • src/docs/admin-mcp.md new section says "a list or object with content under such a key is masked whole", but readMaskExempt returns tokenRateKey(k) for a non-empty map[string]any (adminmcp.go:896), so an object under e.g. tokens_per_model is shown and walked. That matches the pre-existing maskExempt behaviour for *tokens maps; the doc sentence could say "except token-count/rate blocks".
  • The PR carries conflicts-with-open-pr; #16885 / #16890 also edit adminmcp.go, so whichever lands second will need a rebase. Not a reason to hold this one.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

Review note on hivecommons#16889: the new "What a read masks" section said every
list or object with content under a sensitive key is masked whole. An
object under a token count key (tokens, tokens_by_model) is walked, as it
was before this PR; the section now says so.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The first note is right: an object under a token count key (tokens, tokens_by_model) is walked and its inner keys judged one by one, as it was before this PR, so "masked whole" was too broad. The section in src/docs/admin-mcp.md now says so (ed3dcf0). No code change.

On the second note: the overlap with the other open PRs is in different parts of adminmcp.go (this one adds helpers next to sensitiveKey), so a plain merge of v6 should be enough when they land.

@hivecommons-hive hivecommons-hive Bot 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.

Decision needed: @clubanderson should decide whether the admin MCP read scrub may show an upper-case [A-Z0-9_] value under a key ending in env unmasked, accepting that an AWS-style access key id pasted into such a field by mistake would then be visible to MCP readers.

The code is correct and I would not change it; I am routing this only because it loosens what the read path shows under credential-named keys, which is a policy call, not a code call.

What I verified from the tree:

  • Kept values are not un-scrubbed: maskSensitive still calls walk(val) on an exempt entry (src/pkg/adminmcp/adminmcp.go:833-837), so nested api_token keys are masked and strings still go through scrubOutboundString. TestScrubStillScrubsKeptValuesByShape covers exactly that.
  • The pending-confirmation scrub is untouched: scrubPendingValue still uses the strict maskExempt (adminmcp.go:613), and TestPendingScrubIsAsStrictAsBefore pins it.
  • authorizationKey only carves out keys whose squashed suffix is selfauthorizationhold; self_authorization_hold_token stays masked (tested).
  • tokenRateKey refuses the credentialTokenQualifiers stems and any key containing secret/password/credential/authorization.

The one residual worth a human's explicit OK: envNameShaped accepts any [A-Z0-9_]{1,128} string (no leading digit) under a key whose last word is env / env var / env name. Env-var names look like that, but so does an AWS access key id (AKIA + 16 upper-case alphanumerics). If someone had pasted such a value into a *_env field, it would now be shown on reads unless crux/logscrub catches it by shape. The author flags this in the comment on envNameShaped; I just want the acceptance to be deliberate. Low severity — the field is documented as holding a variable name, and GitHub/OpenAI-style tokens do not match the shape.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @ed3dcf0
  • the review found: the reviewer marked this change high-risk
  • reviewer question: @clubanderson should decide whether the admin MCP read scrub may show an upper-case [A-Z0-9_] value under a key ending in env unmasked, accepting that an AWS-style access key id pasted into such a field by mistake would then be visible to MCP readers.
  • the automerge lane will not merge this unattended

Head: verdict requires_human @ed3dcf0, 43/53 checks green, 10 pending, DCO yes, soak 0s of 10m0s.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed. An ordinary contributor cannot release their own PR.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@github-actions github-actions Bot removed the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 6, 2026
The review asked for the owner's decision on one of the rules: showing an
upper-case value under a key ending in env. That is a policy call, so the
rule is taken out of this change and will be proposed on its own. A value
under token_env and the like stays masked, as it was.

What remains shown under a sensitive-looking key: nothing (null, empty
string, list or object), a timestamp, a token count or rate, and the
self-authorization hold settings.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Taking the policy question out of this PR rather than leaving the whole change waiting on it.

The rule the review routed for a decision, showing an upper-case value under a key ending in env, is removed in the latest commit. A value under token_env, webhookSecretEnv and the like stays masked, exactly as on v6, and TestScrubStillMasksWhatCouldBeASecret now pins that. I will propose that rule on its own, so the decision can be made there without holding the rest.

What this PR still shows under a sensitive-looking key is only what cannot hold a credential: null and empty values, a timestamp, a token count or rate, and the self-authorization hold settings. The description is updated to match.

One fact for whoever takes up the separate question: the example in the review, an AWS-style access key id pasted into such a field, would not have been shown. A kept string still goes through the shape scrub, and that has an aws-access-key pattern for AKIA/ASIA ids. The open case is an upper-case secret with no known shape, such as a base32 seed.

@hivecommons-hive hivecommons-hive Bot 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.

Read the scrub paths at 723fe7f. Looks correct to me, and the relaxation is bounded to shapes that cannot carry a credential.

What I verified in the tree:

  • Only maskSensitive (src/pkg/adminmcp/adminmcp.go:831) switches to readMaskExempt; the pending-confirmation scrub at adminmcp.go:613 still uses credentialBearingKey + maskExempt, so the write-preview rule is unchanged as the body claims.
  • readMaskExempt (adminmcp.go:887-905) exempts exactly: nil, "", empty []/{}, an RFC3339Nano-parsable string, and a float64/map under a tokenRateKey. A non-empty map that is kept is still passed through walk(val) (adminmcp.go:833), so inner keys like api_token are masked on their own — the test at scrub_read_test.go:78-91 exercises that.
  • authorizationKey (adminmcp.go:869-875) only carves out keys whose squashed form ends in selfauthorizationhold; Authorization, proxy_authorization, authorizationHold and self_authorization_hold_token stay sensitive (scrub_read_test.go:50-53).
  • tokenRateKey (adminmcp.go:939-958) refuses any key also containing secret/password/credential/authorization and any stem ending in a credentialTokenQualifiers entry, so access_tokens_per_user stays masked.
  • go build ./pkg/adminmcp/ ./cmd/hive-admin-mcp/ clean; CI build-go green.

Two notes, neither a defect:

  1. Scrub is called from EncodeResult (result_cap.go:19) and on error strings in cmd/hive-admin-mcp/main.go:232,238,408, so the new exemptions apply to every tool result, not strictly "reads". That's fine given what is exempted, but the body's "used only by the read scrub" is slightly narrower than the code.
  2. The tokenRateKey doc comment says tokens must have "more after it", but the loop at adminmcp.go:947-956 returns true for a trailing tokens word too (max_tokens). No behaviour change results — tokenCountKey already exempts that case for the same value types — but the comment overstates the check.

The one new disclosure is set-vs-unset: [masked:…] now implies a value exists. The body states that as the goal; flagging it so a maintainer confirms that's acceptable on the admin surface.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

hivecommons-hive Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from reviewer (folded here because this head already carries its hive review):

Read the change against the tree at 723fe7f, including the existing maskExempt/tokenCountKey/credentialTokenQualifiers it builds on (src/pkg/adminmcp/adminmcp.go:970-1003). The code does what it says and I found no path that exposes a real credential, but this is a deliberate loosening of a secret scrub, so I am routing the yes/no to a maintainer rather than calling it myself.

What I verified.

  • The pending-confirmation scrub keeps using the strict maskExempt; only the read path at adminmcp.go:831 switches to readMaskExempt, which is maskExempt plus: null/""/{}/[], RFC3339 strings, and numbers or objects under a tokens… rate key.
  • tokenRateKey (:947-968) refuses any key that also contains secret/password/credential/authorization, and refuses a qualifier stem before tokens — keyWords splits accessTokensRevoked → access → masked; APITokens never splits so it is still masked; validTokens is masked by the id suffix, exactly as the existing tokenCountKey already behaves. The new tests at scrub_read_test.go cover refresh_tokens_by_user (map, still masked), access_tokens_per_user, token_env/webhookSecretEnv names (still masked).
  • authorizationKey (:866-872) only un-masks keys whose squashed form ends in selfauthorizationhold; self_authorization_hold_token stays masked (tested).
  • Strings kept by these exemptions still pass through the shape scrubber like every other string.

One open point, not a defect in this diff. An object under an unqualified tokens… key (e.g. tokens_by_model) is now walked rather than masked whole, so inner values are protected only by their own key names and the shape scrub. The same is already true on v6 for plain *tokens maps via maskExempt → tokenCountKey (:995-1003), so this PR extends an existing class rather than creating one. If a maintainer knows of a GET /api/config shape that nests raw secrets under non-sensitive inner keys inside such a block, that is the thing to check before merging.

docs/admin-mcp.md gains a "What a read masks" section that matches the implemented rules.

Evidence bundle `#16889723fe7f` sha256:5ba652840948c8d728f03a2da4497ab3eec17fe018a10a92127b107b70893ed7 — download from the dashboard or `hivectl review evidence #16889`.

@hivecommons-hive
hivecommons-hive Bot merged commit 035efee into hivecommons:v6 Nov 6, 2026
67 of 70 checks passed
Danathar added a commit to Danathar/hive that referenced this pull request Nov 6, 2026
…cker

src/docs/admin-mcp.md: kept the reorganized guide and carried over v6's changes to it: ping and notification answers (hivecommons#16893), version_read hash/short (hivecommons#16890), settings_read takes no limit and the triggers section (hivecommons#16892), What a read masks (hivecommons#16889), and write tools always listed with metadata.preview.enabled (hivecommons#16890); the troubleshooting row follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant