Repository navigation
Fix misleading error message and redact credential URLs from App/PackageRepository status - #1869
Conversation
…-schema type
- config/values-schema.yml: fix "trusted ca's" -> "trusted CAs" in the
caCerts field description, surfaced to users via kubectl explain and
Package/PackageInstall value schemas.
- cli/pkg/kctrl/cmd/package/available/values_schema.go: reword the
"unsupported type" error raised while parsing a valuesSchema
'properties' field. The previous message leaked Go type syntax
(map[string]interface{}, json.RawMessage) at a package author working
in YAML/OpenAPI, not Go; it now describes the expected shape in plain
terms and uses %T for the actual type.
No behavior or control-flow change, message text only.
Signed-off-by: Nikhil Sagotiya <nikhil.sagotiya@broadcom.com>
Subprocess (vendir/ytt/kbld/kapp) stdout, stderr and error text were copied verbatim into App and PackageRepository .status fields (Fetch, Template, Deploy, Inspect, Conditions[].Message, FriendlyDescription, UsefulErrorMessage). If any of those tools ever emit a credential embedded in a URL (e.g. a GOPROXY, git, or registry URL of the form https://user:token@host), it would land verbatim in a Kubernetes resource's status, visible via `kubectl get app -o yaml` and any tooling that reads it. - pkg/exec/cmd_run_result.go: add RedactSecrets, which masks the userinfo component of a URL (scheme://user:pass@host -> scheme://[REDACTED]@host). The match is greedy up to the last '@' before the host so a userinfo containing a literal '@' (e.g. in a password) is fully masked rather than partially. - pkg/app/app_reconcile.go, pkg/pkgrepository/app_reconcile.go: apply RedactSecrets at every point subprocess-derived text is written into .status (Fetch/Template/Deploy/Inspect Stdout/Stderr/Error, Condition.Message, FriendlyDescription, UsefulErrorMessage). No control flow, exit codes, or non-text fields changed. Signed-off-by: Nikhil Sagotiya <nikhil.sagotiya@broadcom.com>
aroradaman
left a comment
There was a problem hiding this comment.
Changes look good. Just wondering why this doesn't require a unit/integration test change.
Add comprehensive test coverage for the new RedactSecrets function, covering: - Basic URL credential redaction (https, http, ftp, custom schemes) - Edge case: passwords containing @ symbols (greedy match to last @) - Multiple URLs in a single string - Multiline output with embedded credentials - Special characters in passwords - Malformed URLs and non-URL text (unchanged) - Empty strings All 16 test cases pass and validate the regex pattern's correctness and the greedy-to-last-@ behavior for passwords with @ characters. Signed-off-by: Sameer Khan <sameer.khan@broadcom.com>
Added 16 unit tests for RedactSecrets covering all URL patterns and edge cases; the other changes are text-only. |
c6481d6 to
ff8cbd0
Compare
- Fix grammar inconsistency: "can not be empty" -> "cannot be empty" (validations.go:108) - Replace full TokenRequest object logging with specific safe field logging (token_manager.go:127) Signed-off-by: Sameer Khan <sameer.khan@broadcom.com>
ff8cbd0 to
ca80848
Compare
joaopapereira
left a comment
There was a problem hiding this comment.
The PR adds RedactSecrets to sanitize credential-bearing URLs from App/PackageRepository status fields (Fetch, Template, Deploy, Inspect, Conditions.Message, FriendlyDescription, UsefulErrorMessage). The redaction covers the primary credential leak vector (URL userinfo in GOPROXY/git/registry URLs) but does not attempt to redact arbitrary secret shapes (API keys, bare tokens). The satoken logging change also avoids logging full token request objects. These are security-sensitive paths where credential leakage could occur.
Issues
Minor (nice to have)
- Regex does not cover
ssh://scheme —pkg/exec/cmd_run_result.go:17pattern([a-zA-Z][a-zA-Z0-9+.-]*://)allowssshbut the test suite lacks anssh://user@hostcase. Git over SSH URLs (ssh://git@github.com/...) are common; adding a test would confirm coverage. - No test for
RedactSecretsidempotence — calling it twice on already-redacted output should be a no-op; not asserted. - Documentation gap —
config/values-schema.ymland CLI error message changes are user-visible but no docs/README update noted in checklist (items unchecked). Not blocking.
…ential redaction documentation Tests: - Add SSH URL test cases: ssh://user@host and ssh://git@github.com/repo.git - Add SSH URL with port test case - Add Test_RedactSecrets_Idempotence function verifying that calling RedactSecrets twice on the same input produces the same result (no-op on already-redacted content) Documentation: - Create docs/credential-redaction.md explaining the credential redaction feature, supported URL schemes, edge cases, security implications, and examples - Update docs/README.md to reference the new credential redaction documentation - Update main README.md to add Security features section highlighting credential redaction as a key security feature Addresses review comments: - SSH scheme coverage and test validation - Idempotence behavior documentation and testing - User-facing documentation for the credential redaction security feature Signed-off-by: Sameer Khan <sameer.khan@broadcom.com>
@joaopapereira Thanks for the review. All three points are addressed in 4905303:
|
What this PR does / why we need it:
Two independent, related fixes found while auditing user-facing error/status text in
kapp-controller:Error message clarity (
cli/pkg/kctrl/cmd/package/available/values_schema.go,config/values-schema.yml):values-schema.ymlcaCertsdescription had a grammar error ("trusted ca's" instead of "trusted CAs"), surfaced to users viakubectl explainand the Package/PackageInstall value schema.valuesSchemapropertiesfield leaked raw Go type syntax (map[string]interface{},json.RawMessage) at a package author working in YAML/OpenAPI, not Go. Reworded to describe the expected shape in plain terms.Redact credential-bearing URLs from
.status(pkg/exec/cmd_run_result.go,pkg/app/app_reconcile.go,pkg/pkgrepository/app_reconcile.go):AppandPackageRepositoryreconciliation copies subprocess (vendir/ytt/kbld/kapp) stdout, stderr, and error text verbatim into.statusfields (Fetch,Template,Deploy,Inspect,Conditions[].Message,FriendlyDescription,UsefulErrorMessage).GOPROXY, git, or registry URL of the formhttps://user:token@host), it lands verbatim in a Kubernetes resource's status — visible viakubectl get app -o yamland any tooling/logging that reads it.exec.RedactSecrets, which masks the userinfo component of a URL (scheme://user:pass@host→scheme://[REDACTED]@host), and applied it at every point subprocess-derived text is written intoApp/PackageRepositorystatus. The regex is greedy up to the last@before the host so a userinfo containing a literal@(e.g. in a password) is fully masked rather than partially.Both are pure message-text/output-sanitization changes; no behavior, API, or control-flow changes.
Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?
Additional Notes for your reviewer:
go build ./...,go vet ./..., andgolangci-lint run(pinnedv2.12.2, matching.github/workflows/golangci-lint.yml) are clean on all touched packages (0 issues).go test ./pkg/app/... ./pkg/pkgrepository/... ./pkg/exec/...was run locally; two pre-existing failures inpkg/app/pkg/pkgrepositoryreproduce identically on unmodifieddevelopin this sandbox (missingvendir/kbldbinaries in$PATH) and are unrelated to this change — confirmed by stashing the diff and re-running.RedactSecretsmasking pattern (URL userinfo) covers the credential-leak shape most relevant to this codebase (GOPROXY/git/registry URLs); it does not attempt to redact arbitrary secret shapes (API keys, tokens outside a URL) since none of the current subprocess integrations are known to emit those into status text.Review Checklist:
Additional documentation e.g., Proposal, usage docs, etc.: