Repository navigation
[PRODENG-3922] Close credential redaction gaps in logging - #695
Conversation
Both plausible readings of rig's redaction API are implemented somewhere in this codebase, and both are wrong: go.mod replaces github.com/k0sproject/rig/v2 with a fork whose cmd.Redact matches literally (strings.ReplaceAll) and whose repeated Redact options compose rather than overwrite. Two classes of call site assumed the opposite of what the fork does. Regex patterns handed to the literal matcher never matched anything, so nothing was redacted: init_swarm.go's `--token \S+` left the swarm manager join token in the log of every cluster init, and mke.go's CA-dump pattern left the full certificate unredacted. Neither secret is known at the call site -- both are in the command's OUTPUT, not its arguments -- so no Redact pattern, literal or regex, can mask them; both now use cmd.HideOutput() instead. The swarm tokens are read back later with `swarm join-token` when needed and the CA PEM is returned to the caller, so nothing is lost. regexp.QuoteMeta applied to a value before handing it to the literal matcher escapes it into a spelling that never appears in the log. This is invisible in testing, because QuoteMeta is the identity function for alphanumeric input: only a credential containing a regex metacharacter exposed it. Seven sites in pkg/configurer's two AuthenticateDocker implementations and two more inside install_mke.go's adminCredentialRedactions helper, which doubly escaped one of its two values (regexp.QuoteMeta(shellescape.Quote(value))). All now pass literal values. pkg/configurer/redaction_semantics_test.go pins the fork's actual behaviour -- a metacharacter-bearing value is masked, the QuoteMeta'd form is not, and two Redact options both take effect -- so a future bump that flips the semantics back toward regex fails this test rather than silently disabling redaction. install_mke_test.go's own redact() harness compiled each value as a regex before this change: production assumed regex, the test assumed regex, they agreed with each other and neither agreed with rig. It now calls the real rig code path. upgrade_msr.go gains redaction for the MKE credentials BuildMKEFlags injects into the command line; nothing covered it before. msr.Destroy has the same gap and is deliberately left to PRODENG-3923, which removes that credential from argv entirely rather than redacting it in place; 3923 rewrites msr.Destroy today and a second hand in that file in the same afternoon is the more expensive mistake. This PR must not merge before PRODENG-3923 (#691). pkg/config/config.go's case-sensitive config-dump regex never matched the schema's camelCase adminUsername/adminPassword and missed keyData/certData entirely. It is replaced with pkg/util/redact.YAML, the key-based masking PRODENG-3921 introduced. A configuration that fails to parse is still dumped -- a debug dump of a broken configuration is exactly when the output is wanted -- using the old regex as a documented best-effort fallback: the log line announcing the fallback states explicitly that the masking is partial, so an operator deciding whether to share the output knows which guarantee they are relying on. install_mke.go's raw `installFlags.Join()` debug line is removed. It ran before rig's own redaction and printed --admin-password and --license with their values; rig already logs the rendered command with the redactions above applied. Trace and Debug records previously reached the persistent log file (~/.mirantis-launchpad/cluster/<name>/*.log) on every run regardless of flags, because the file hook was registered for log.AllLevels while the logger itself was set to TraceLevel unconditionally. That is what made every other gap in this PR persistent on disk rather than transient on a terminal. The file hook now receives Trace only with --trace and Debug only with --debug; the logger's level is unchanged, so command behaviour elsewhere is unaffected. .changes/PRODENG-3922.md documents the operator-visible change. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
There was a problem hiding this comment.
🟡 Changes recommended
Credential redaction can still expose secrets in debug and command logs when YAML parsing fails, quoted or split password flags are mishandled, or shorter credentials are redacted before overlapping passwords.
4 open issues
What changed in this PR
This PR strengthens credential redaction in Launchpad’s configuration and remote-command logging, and limits persistent debug output. It is intended to land after #691, which moves bootstrapper credentials out of command arguments.
Changes:
- Uses literal credential matches and hides sensitive command output.
- Adds structured YAML redaction and restricts file-log verbosity.
- Adds regression tests and documents the logging change.
| File | Description |
|---|---|
pkg/product/mke/phase/upgrade_msr.go |
Adds credential redaction to MSR upgrades. |
pkg/product/mke/phase/msr_redactions.go |
Extracts MSR credential redaction values. |
pkg/product/mke/phase/install_mke.go |
Uses literal matches and removes sensitive flag logging. |
pkg/product/mke/phase/install_mke_test.go |
Tests redaction using rig’s implementation. |
pkg/product/mke/phase/init_swarm.go |
Hides output containing swarm join tokens. |
pkg/mke/mke.go |
Hides CA certificate command output. |
pkg/log/formatter_hook.go |
Gates file-log verbosity on debug and trace flags. |
pkg/log/file_hook_test.go |
Tests file logging under verbosity flags. |
pkg/configurer/windows.go |
Uses literal Docker credential matches. |
pkg/configurer/redaction_semantics_test.go |
Tests literal matching and composition. |
pkg/configurer/linux.go |
Uses literal Docker credential matches. |
pkg/config/redact_dump_test.go |
Tests structured redaction and malformed-input fallback. |
pkg/config/config.go |
Applies YAML redaction to configuration dumps. |
.changes/PRODENG-3922.md |
Documents file-log verbosity and support usage. |
Review effort: Balanced
Three measured defects from the review of #695, plus a strengthened fallback. Registration order decided whether a credential was masked. rig replaces each registered value in turn with strings.ReplaceAll, so a value that is a prefix of another destroys the longer match before it is tried. Measured with the real code path: username "admin" and password "admin!s3cr3t" registered in that order yield "login -u [REDACTED] -p [REDACTED]!s3cr3t", and the distinctive part of the password survives. redact.ByLengthDesc orders values longest first and drops empty ones; every site that registers more than one value now uses it -- both AuthenticateDocker implementations, adminCredentialRedactions, and the MSR helper. msrCredentialRedactions missed two spellings. A flag and its value in separate list elements ("--ucp-password", "split-secret") form a working command once Flags.Join concatenates them, but Flags.Get returns only the flag, so nothing was registered; the value is now read from the following element. And FlagValue uses strconv.Unquote, which does not decode the shell quoting BuildMKEFlags produces, so for a password containing a quote only the rendered spelling was registered and the password itself stayed visible wherever the bootstrapper echoed it back; the shell-decoded form is now registered alongside the rendered one. The unparseable-config fallback no longer uses the old two-word case-sensitive regex. redact.Text applies the same key set and the same environment-variable fragments as the structured path, line by line, so a configuration that fails to parse keeps camelCase and environment coverage instead of losing it. The real limit is now multi-line values rather than key names: a credential in a block scalar is not masked, which is what the log line means by best-effort. That limit is pinned by a test, and the test that pinned the previous weaker limit failed when this landed, which is what it was written to do. Four regression tests for the MSR helper, two for the fallback, one for ordering. The test helper in install_mke_test.go is renamed to applyRedactions to avoid shadowing the redact package. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
Brings in #691, which collides with this branch on two files. The resolution was validated against a simulated main before #691 merged, and is what that rehearsal found: install_mke.go take main's version wholesale install_mke_test.go stays deleted Nothing was hand-edited. #691 wins install_mke.go because it supersedes rather than contradicts. This branch fixed adminCredentialRedactions -- dropping regexp.QuoteMeta, since rig matches redactions literally (cmd/execoptions.go RedactString is strings.ReplaceAll) so a quoted spelling never appears in the log, and ordering values longest first so "admin" cannot eat the prefix of "admin!s3cr3t". #691 deletes that function entirely and passes the credentials through secretenv, so they never reach argv. A redaction fix for a string that is no longer rendered has nothing to redact. Neither finding is lost. #691's redact.go carries both: it sorts secrets by descending length and uses no QuoteMeta anywhere. redact.ByLengthDesc does not become dead code. The colliding call site was one of five; the others are pkg/configurer/linux.go:434, pkg/configurer/windows.go:422 and msr_redactions.go:45, all of which carry forward. install_mke_test.go stays deleted for the same reason: it tested the function #691 removed. What this branch still contributes against main is unchanged -- init_swarm.go, msr_redactions.go and its tests, upgrade_msr.go, pkg/util/redact, the file-log hook and the pkg/configurer redactions. Verified: install_mke.go is byte-identical to main's, go build ./... and go vet clean, make unit-test 0 failures, make lint 0 issues. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
TestRigRedactionIsLiteral's comment said go.mod replaces rig with a fork and that neither property could be assumed from upstream's source. The replace directive is gone (#707) and launchpad builds on upstream v2.2.1. Both properties still hold: the two tests pass unchanged against upstream. That is the point worth recording -- the behaviour the redaction sites depend on is not fork-specific. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
There was a problem hiding this comment.
🟡 Changes recommended
Credential redaction remains incomplete, allowing passwords to leak through forwarded bootstrap output, malformed-config debug dumps, and verbose logging of grouped upgrade flags.
3 open issues
4 resolved since last review
Review effort: Balanced
| if !isFlagWithValue(flag, name) { | ||
| continue |
| execOpts = append(execOpts, cmd.Redact(value)) | ||
| } | ||
|
|
||
| if _, err := msr.Bootstrap("upgrade", *p.Config, msr.BootstrapOptions{OperationFlags: upgradeFlags, CleanupDisabled: p.CleanupDisabled(), ExecOptions: execOpts}); err != nil { |
| fragments = append(fragments, `[A-Za-z0-9_]*`+regexp.QuoteMeta(fragment)+`[A-Za-z0-9_]*`) | ||
| } | ||
|
|
||
| return regexp.MustCompile(`(?im)^(\s*-?\s*(?:` + strings.Join(keys, "|") + "|" + strings.Join(fragments, "|") + `)\s*[:=]\s*).+$`) |


What
Closes the redaction gaps the finding named: values handed to rig's literal
Redactmatcher wrapped inregexp.QuoteMeta, secrets that are a command's output rather than its arguments, an unredactedinstallFlags.Join()debug line, and a persistent log file that captured every Trace/Debug record regardless of flags.Why
PRODENG-3922, finding
secf_c896aee6323ffbcb4079164a.rig's
cmd.Redactmatches literally (cmd/execoptions.go'sRedactStringisstrings.ReplaceAll) and repeated options compose rather than overwrite. Both are the opposite of what the call sites assumed, in opposite directions — so some sites redacted nothing, and others redacted nothing for exactly the strongest credentials.QuoteMetais the identity function for alphanumerics, so the failure was invisible until a credential contained a regex metacharacter.How
init_swarm.go) and the MKE CA PEM (mke.go) are unknown at the call site, so noRedactpattern could ever have masked them. Both now usecmd.HideOutput(); the values remain available elsewhere (swarm join-token, the function's own return).regexp.QuoteMetaremoved from the redaction call sites inpkg/configurer's twoAuthenticateDockerimplementations. One site double-escaped:regexp.QuoteMeta(shellescape.Quote(value)).pkg/util/redact.ByLengthDescorders values longest-first, so a username that is a prefix of a password —adminagainstadmin!s3cr3t— cannot be substituted first and leave the remainder in the log.upgrade_msr.gogains redaction for credentialsBuildMKEFlagsputs in argv; nothing covered it.redact.YAML), with the old regex as a documented best-effort fallback on unparseable input — a debug dump of a broken config is exactly when output is wanted.--trace/--debug; previously every run persisted everything.Updated since the first revision
The #691 merge gate is satisfied. #691 merged, and this branch has been merged up to it. Its collision with this one is resolved: #691 deletes
adminCredentialRedactionsandinstall_mke_test.goentirely, passing MKE credentials throughsecretenvso they never reach argv, which supersedes the fix this branch made to the same function.install_mke.gohere is now byte-identical tomain. Neither of this branch's findings is lost — #691'sredact.gosorts by descending length and uses noQuoteMeta.msr.Destroy, deliberately left to #691, is covered by it.The rig fork is gone.
go.modno longer replaces rig; launchpad builds on upstreamv2.2.1(#707).redaction_semantics_test.gopinned the fork's behaviour and said so; both tests pass unchanged against upstream, and the comment is corrected to record that — the semantics the redaction sites depend on are not fork-specific.redact.ByLengthDesckeeps four consumers after #691 removed the colliding one:pkg/configurer/linux.go:434,pkg/configurer/windows.go:422,pkg/product/mke/phase/msr_redactions.go:45, and its own definition.Testing
redaction_semantics_test.go(2),file_hook_test.go(3 subtests),redact_dump_test.go(3),msr_redactions_test.gomake lint0 issues,make unit-test0 failures, on currentmainmake local, thendescribe configand a realapplyagainst a config carrying three fake credentials — 0 occurrences in the output or in the generatedapply.log, and nolevel=debug/level=tracelines reached the file on a flag-less runChecklist
Written by AI: claude-opus-5