feat(configcmd): Spec.SecretKeys redacts a program's own secret options
"config show" redacted only keys whose last segment is secrets, secret, token or password. A program's own secrets (database.url, oidc.client_secret, smtp.url, ...) were printed, so programs disabled show. Spec.SecretKeys names them as dotted keys (a key covers everything below it); Effective carries them to Values and Show. First consumer: yaemp and yaemp-mcp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31dbc347e8
commit
8513b6db4c
5 files changed
+67
-4
No files matched your search
+16
-2
@@ -28,7 +28,7 @@ const DefaultOrigin = "default"
|
||||
// Values returns every leaf of e, sorted by key, with its origin.
|
||||
// used reports whether the program reads a key (nil: every key); a
|
||||
// default it does not read is left out. Secret values (keys secrets,
|
||||
// secret, token, password) are replaced by "<redacted>" unless
|
||||
// secret, token, password, and e.SecretKeys) are replaced by "<redacted>" unless
|
||||
// showSecrets; a reference that only says where a secret is (env:,
|
||||
// file:, secret://) is shown.
|
||||
func (e *Effective) Values(used func(string) bool, showSecrets bool) []Value {
|
||||
@@ -42,7 +42,7 @@ func (e *Effective) Values(used func(string) bool, showSecrets bool) []Value {
|
||||
if !u && source == DefaultOrigin {
|
||||
return
|
||||
}
|
||||
if !showSecrets && isSecretKey(key) {
|
||||
if !showSecrets && e.isSecret(key) {
|
||||
v = redact(v)
|
||||
}
|
||||
out = append(out, Value{Key: key, Value: v, Source: source, Used: u})
|
||||
@@ -117,6 +117,20 @@ var secretKeys = map[string]bool{"secrets": true, "secret": true, "token": true,
|
||||
|
||||
func isSecretKey(key string) bool { return secretKeys[key[strings.LastIndex(key, ".")+1:]] }
|
||||
|
||||
// isSecret: a default secret name, or one of e.SecretKeys or a key below
|
||||
// one.
|
||||
func (e *Effective) isSecret(key string) bool {
|
||||
if isSecretKey(key) {
|
||||
return true
|
||||
}
|
||||
for _, k := range e.SecretKeys {
|
||||
if key == k || strings.HasPrefix(key, k+".") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// redact replaces secret values, keeping references that only say where
|
||||
// the secret is.
|
||||
func redact(v any) any {
|
||||
|
||||
Reference in new issue
Block a user