Skip to content

util: fix stripSecret re-appending the secret it redacted - #6444

Merged
mergify[bot] merged 1 commit into
ceph:develfrom
somanchi004-code:fix-stripsecret-tail-offset
Aug 6, 2026
Merged

util: fix stripSecret re-appending the secret it redacted#6444
mergify[bot] merged 1 commit into
ceph:develfrom
somanchi004-code:fix-stripsecret-tail-offset

Conversation

@somanchi004-code

Copy link
Copy Markdown
Contributor

Describe what this PR does

stripSecret cuts the argument on secret= and computes the end of the secret as an offset into the remainder, but then slices the original argument by that offset:

before, after, ok := strings.Cut(arg, secretArg)
end := strings.IndexByte(after, optionsArgSeparator)   // offset into `after`
out[i] = before + strippedSecret
if end != -1 {
    out[i] += arg[end+len(secretArg):]                 // ...but slices `arg`
}

The two coordinate systems only agree when secret= starts the argument. Any option before it shifts the tail and copies part of the secret back into the string that was just redacted.

Is there anything that requires special attention?

Yes — the longer the prefix, the more leaks, and a realistic mount option string leaks the whole key.

Running the current stripSecret over three inputs:

secret first            -> secret=***stripped***,mds_namespace=abc
secret after an option  -> name=admin,secret=***stripped***ersecretkey,mds_namespace=abc
long prefix             -> mon_addr=10.0.0.1:6789/10.0.0.2:6789,secret=***stripped***.0.1:6789/10.0.0.2:6789,secret=AQtiny,mds_namespace=abc

In the third case the literal text secret=AQtiny appears inside the supposedly-redacted output. A real mon_addr=... prefix runs well over 60 characters while a Ceph key is around 40, so the offset overshoots and the entire key is reproduced.

InArgs exists solely to redact secrets before logging, and ExecCommand logs the sanitized arguments on the success path too (internal/util/cephcmds.go), so this is every invocation rather than only failures.

After the change, all three redact correctly and no secret material survives.

The trigger is secret= not being first in its argv element. The kernel mounter builds mon_addr=...,secretfile=..., which contains no secret= substring, but it then appends admin-supplied kernelMountOptions (a documented StorageClass field), and secret= is a valid mount.ceph option.

This package had no test file. The new one covers a secret that is first, preceded by another option, preceded by a prefix longer than itself, last, and absent. It fails without the fix:

--- FAIL: TestInArgsStripsSecret/prefix_longer_than_the_secret
     got: ["-o" "mon_addr=...,secret=***stripped***.0.1:6789/10.0.0.2:6789,secret=AQtiny,mds_namespace=abc"]
    want: ["-o" "mon_addr=...,secret=***stripped***,mds_namespace=abc"]
    stripsecrets_test.go:65: secret material leaked into stripped output

and passes with it.

The line dates to the file's original commit in February 2019 and was carried through the strings.Indexstrings.Cut refactor unchanged.

I searched open and closed issues and PRs for stripsecrets, stripSecret, strip secret, secret leak log and sanitize args, and checked the open PR list for anything touching this file — I did not find a duplicate, but please close this if I missed one.

Checklist

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide
  • Reviewed the developer guide on Submitting a Pull Request
  • Pending release notes updated with breaking and/or notable changes for the next major release
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

@mergify mergify Bot added the bug Something isn't working label Aug 3, 2026
@somanchi004-code
somanchi004-code force-pushed the fix-stripsecret-tail-offset branch from bb37fef to 1495664 Compare August 3, 2026 22:55

@nixpanic nixpanic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @somanchi004-code! This looks good to me, just a small request.

Could you please correct the date in the new file? And maybe consider adding test-cases for stripKey() as well?

Comment thread internal/util/stripsecrets/stripsecrets_test.go Outdated
nixpanic
nixpanic previously approved these changes Aug 4, 2026
@nixpanic
nixpanic requested a review from a team August 4, 2026 11:53
Madhu-1
Madhu-1 previously approved these changes Aug 4, 2026
@somanchi004-code
somanchi004-code force-pushed the fix-stripsecret-tail-offset branch from 3dbcdd8 to 0f25fb0 Compare August 4, 2026 13:56
@mergify
mergify Bot dismissed stale reviews from Madhu-1 and nixpanic August 4, 2026 13:57

Pull request has been modified.

@iPraveenParihar iPraveenParihar 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.

LGTM, @somanchi004-code can you squash your commits into one and we are good to merge?

@somanchi004-code
somanchi004-code force-pushed the fix-stripsecret-tail-offset branch from 0f25fb0 to 8df98d7 Compare August 5, 2026 10:25
@somanchi004-code

Copy link
Copy Markdown
Contributor Author

LGTM, @somanchi004-code can you squash your commits into one and we are good to merge?

Squashed into one commit and rebased on devel, thanks.

@nixpanic

nixpanic commented Aug 5, 2026

Copy link
Copy Markdown
Member

/queue

@ceph-csi-bot ceph-csi-bot added the ok-to-test Label to trigger E2E tests label Aug 5, 2026
@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.36

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.36

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.36

@ceph-csi-bot ceph-csi-bot added ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. and removed ok-to-test Label to trigger E2E tests labels Aug 5, 2026
@mergify mergify Bot removed the ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. label Aug 5, 2026
@nixpanic

nixpanic commented Aug 5, 2026

Copy link
Copy Markdown
Member

/retest ci/centos/mini-e2e/k8s-1.36

@nixpanic

nixpanic commented Aug 5, 2026

Copy link
Copy Markdown
Member

/retest ci/centos/mini-e2e/k8s-1.34

@nixpanic

nixpanic commented Aug 5, 2026

Copy link
Copy Markdown
Member

/retest ci/centos/mini-e2e-helm/k8s-1.34

@nixpanic nixpanic mentioned this pull request Aug 5, 2026
1 task
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Deprecation notice: This pull request comes from a fork and was queued with update_method=rebase and update_bot_account impersonation. This capability will be removed on July 1, 2026. After this date, the merge queue will no longer be able to rebase fork pull requests with this configuration. To avoid disruption, switch to update_method=merge in your queue rule.

@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-08-05 18:41 UTC · Rule: default · triggered by merge protections
  • Checks passed · in-place
  • Merged2026-08-06 08:13 UTC · at 5ea7f2712b3beb4ea37d3cc875f97737716adda8 · rebase

This pull request spent 13 hours 31 minutes 52 seconds in the queue, including 13 hours 30 minutes 55 seconds running CI.

Required conditions to merge

stripSecret cut the argument on "secret=" and computed the end of the
secret as an offset into the remainder, but then sliced the original
argument by that offset. The two only agree when "secret=" starts the
argument, so any option preceding it shifted the tail and copied part of
the secret back into the redacted string.

The longer the prefix, the more leaks. With a realistic
"mon_addr=...,secret=..." the offset exceeds the length of the secret and
the whole key is reproduced verbatim, including its "secret=" label.

InArgs exists to redact secrets before logging, and ExecCommand logs the
sanitized arguments on the success path as well, so this affects every
invocation rather than only failures.

Slice the remainder instead of the original argument, and add tests
covering a secret that is first, preceded by another option, preceded by
a prefix longer than itself, last, and absent.

Also cover --key and --keyfile redaction in stripKey, the documented
behaviour that only one of key or secret is stripped per call, that
InArgs leaves its input slice unchanged, and correct the copyright year.

Assisted-by: Claude Code <noreply@anthropic.com>
Signed-off-by: Somanchi Poorna Sobhita <somanchi004@gmail.com>
@ceph-csi-bot
ceph-csi-bot force-pushed the fix-stripsecret-tail-offset branch from 8df98d7 to 5ea7f27 Compare August 5, 2026 18:42
@ceph-csi-bot
ceph-csi-bot requested a review from a team as a code owner August 5, 2026 18:42
@mergify mergify Bot added the ok-to-test Label to trigger E2E tests label Aug 5, 2026
@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.36

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.36

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.36

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot ceph-csi-bot added ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. and removed ok-to-test Label to trigger E2E tests labels Aug 5, 2026
@mergify mergify Bot added queued and removed ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. labels Aug 5, 2026
@mergify
mergify Bot merged commit 9848a8b into ceph:devel Aug 6, 2026
46 checks passed
@mergify mergify Bot removed the queued label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants