util: fix stripSecret re-appending the secret it redacted - #6444
Conversation
bb37fef to
1495664
Compare
nixpanic
left a comment
There was a problem hiding this comment.
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?
3dbcdd8 to
0f25fb0
Compare
Pull request has been modified.
iPraveenParihar
left a comment
There was a problem hiding this comment.
LGTM, @somanchi004-code can you squash your commits into one and we are good to merge?
0f25fb0 to
8df98d7
Compare
Squashed into one commit and rebased on devel, thanks. |
|
/queue |
|
/test ci/centos/k8s-e2e-external-storage/1.34 |
|
/test ci/centos/upgrade-tests-cephfs |
|
/test ci/centos/mini-e2e-helm/k8s-1.34 |
|
/test ci/centos/upgrade-tests-rbd |
|
/test ci/centos/mini-e2e/k8s-1.34 |
|
/test ci/centos/k8s-e2e-external-storage/1.35 |
|
/test ci/centos/mini-e2e-helm/k8s-1.35 |
|
/test ci/centos/mini-e2e/k8s-1.35 |
|
/test ci/centos/k8s-e2e-external-storage/1.36 |
|
/test ci/centos/mini-e2e-helm/k8s-1.36 |
|
/test ci/centos/mini-e2e/k8s-1.36 |
|
/retest ci/centos/mini-e2e/k8s-1.36 |
|
/retest ci/centos/mini-e2e/k8s-1.34 |
|
/retest ci/centos/mini-e2e-helm/k8s-1.34 |
|
Deprecation notice: This pull request comes from a fork and was queued with |
Merge Queue Status
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>
8df98d7 to
5ea7f27
Compare
|
/test ci/centos/k8s-e2e-external-storage/1.34 |
|
/test ci/centos/mini-e2e-helm/k8s-1.34 |
|
/test ci/centos/k8s-e2e-external-storage/1.36 |
|
/test ci/centos/mini-e2e/k8s-1.34 |
|
/test ci/centos/mini-e2e-helm/k8s-1.36 |
|
/test ci/centos/mini-e2e/k8s-1.36 |
|
/test ci/centos/k8s-e2e-external-storage/1.35 |
|
/test ci/centos/mini-e2e-helm/k8s-1.35 |
|
/test ci/centos/mini-e2e/k8s-1.35 |
|
/test ci/centos/upgrade-tests-cephfs |
|
/test ci/centos/upgrade-tests-rbd |
Describe what this PR does
stripSecretcuts the argument onsecret=and computes the end of the secret as an offset into the remainder, but then slices the original argument by that offset: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
stripSecretover three inputs:In the third case the literal text
secret=AQtinyappears inside the supposedly-redacted output. A realmon_addr=...prefix runs well over 60 characters while a Ceph key is around 40, so the offset overshoots and the entire key is reproduced.InArgsexists solely to redact secrets before logging, andExecCommandlogs 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 buildsmon_addr=...,secretfile=..., which contains nosecret=substring, but it then appends admin-suppliedkernelMountOptions(a documented StorageClass field), andsecret=is a validmount.cephoption.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:
and passes with it.
The line dates to the file's original commit in February 2019 and was carried through the
strings.Index→strings.Cutrefactor unchanged.I searched open and closed issues and PRs for
stripsecrets,stripSecret,strip secret,secret leak logandsanitize 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