Preserve secret tags in dynamic configuration values
This commit is contained in:
@@ -175,3 +175,54 @@ func TestSecretValuesStayOutOfLoadFailuresAndWarnings(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDynamicConcreteTagsRemainSecretThroughHistory(t *testing.T) {
|
||||
type sensitive struct {
|
||||
Token string `yaml:"token" configkit:"secret"`
|
||||
}
|
||||
type cfg struct {
|
||||
Payload any `yaml:"payload"`
|
||||
Derived string `yaml:"derived"`
|
||||
}
|
||||
for _, change := range []string{"retain", "replace", "delete", "introduce"} {
|
||||
t.Run(change, func(t *testing.T) {
|
||||
const canary = "DYNAMIC_TAG_CANARY"
|
||||
definition := Definition[cfg]{Defaults: func() cfg { return cfg{Payload: map[string]any{"nested": []any{sensitive{Token: canary}}}} }}
|
||||
path := Keys("payload", "nested").Index(0).Key("token")
|
||||
if change == "introduce" {
|
||||
definition.Defaults = nil
|
||||
}
|
||||
definition.Resolve = func(c *cfg, r *Resolution) error {
|
||||
if change == "introduce" {
|
||||
Normalize(r, Keys("payload"), &c.Payload, any(map[string]any{"nested": []any{sensitive{Token: canary}}}), "create")
|
||||
}
|
||||
if change == "replace" {
|
||||
Normalize(r, Keys("payload"), &c.Payload, any("public"), "replace")
|
||||
}
|
||||
if change == "delete" {
|
||||
Normalize(r, Keys("payload"), &c.Payload, any(nil), "remove")
|
||||
}
|
||||
Normalize(r, Keys("derived"), &c.Derived, canary, "derive", path)
|
||||
return nil
|
||||
}
|
||||
result, err := Load(NoSource(), Options[cfg]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, query := range []Path{Keys(), path, Keys("derived")} {
|
||||
explanation, _ := result.Explain(query)
|
||||
output.WriteString(fmt.Sprintf("%#v", explanation))
|
||||
}
|
||||
if strings.Contains(output.String(), canary) {
|
||||
t.Fatal("dynamic secret escaped inspection")
|
||||
}
|
||||
if !result.secrets[path.String()] || !result.secrets["/derived"] {
|
||||
t.Fatal("dynamic tag or dependency classification missing")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user