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
@@ -174,6 +174,43 @@ func TestValuesRedaction(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestValuesProgramSecrets: Spec.SecretKeys (on Effective) redacts a
|
||||
// program's own secret options and everything below one; other keys and
|
||||
// a key that only shares a prefix stay.
|
||||
func TestValuesProgramSecrets(t *testing.T) {
|
||||
merged, origins := coreconfig.Merge(coreconfig.Source{Name: "f", Data: map[string]any{
|
||||
"database": map[string]any{"url": "postgres://app:pw@db/x", "owner_url": "file:/run/o", "urls": "kept"},
|
||||
"smtp": map[string]any{"url": "smtps://u:pw@mail", "from": "a@b"},
|
||||
"vault": map[string]any{"inner": map[string]any{"key": "deep"}},
|
||||
}})
|
||||
e := &Effective{Name: "p", Merged: merged, Origins: origins, SecretKeys: []string{"database.url", "database.owner_url", "smtp.url", "vault"}}
|
||||
got := map[string]any{}
|
||||
for _, v := range e.Values(nil, false) {
|
||||
got[v.Key] = v.Value
|
||||
}
|
||||
want := map[string]any{
|
||||
"database.url": "<redacted>", "database.owner_url": "file:/run/o", "database.urls": "kept",
|
||||
"smtp.url": "<redacted>", "smtp.from": "a@b", "vault.inner.key": "<redacted>",
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Values = %v, want %v", got, want)
|
||||
}
|
||||
for _, v := range e.Values(nil, true) {
|
||||
if v.Key == "smtp.url" && v.Value != "smtps://u:pw@mail" {
|
||||
t.Errorf("show-secrets: %v", v.Value)
|
||||
}
|
||||
}
|
||||
|
||||
// Through "config show": the Spec's keys reach the output.
|
||||
root := t.TempDir()
|
||||
s := testSpec(root)
|
||||
s.SecretKeys = []string{"log-level"}
|
||||
writeFile(t, filepath.Join(root, "etc", "yamase", "yamase-test.yaml"), minimalTemplate+"log-level: debug\n")
|
||||
if code, out, errOut := run(t, s, "", "show"); code != ExitOK || strings.Contains(out, `"debug"`) || !strings.Contains(out, `log-level: "<redacted>"`) {
|
||||
t.Errorf("show: exit %d\n%s%s", code, out, errOut)
|
||||
}
|
||||
}
|
||||
|
||||
type inlineBase struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user