Verify inherited credential safety
This commit is contained in:
@@ -226,7 +226,7 @@ ConfigKit. Parents must remain valid Narratio entries, not special templates.
|
|||||||
Complete when inherited explicit input and absent defaults have distinct,
|
Complete when inherited explicit input and absent defaults have distinct,
|
||||||
correct domain outcomes and existing path bases are unchanged.
|
correct domain outcomes and existing path bases are unchanged.
|
||||||
|
|
||||||
## Stage 5: Verify safe effective projections and inherited credentials
|
## Stage 5: Verify safe effective projections and inherited credentials [x]
|
||||||
|
|
||||||
Purpose: ensure inheritance changes neither semantic comparison nor the
|
Purpose: ensure inheritance changes neither semantic comparison nor the
|
||||||
existing secret boundary.
|
existing secret boundary.
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
|
|||||||
for _, credential := range []string{testingKey, "null"} {
|
for _, credential := range []string{testingKey, "null"} {
|
||||||
t.Run(credential, func(t *testing.T) {
|
t.Run(credential, func(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\n")
|
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\nscriptorium:\n extends: audita\n")
|
||||||
selected := "[" + credential + "]"
|
selected := "[" + credential + "]"
|
||||||
if credential == "null" {
|
if credential == "null" {
|
||||||
selected = credential
|
selected = credential
|
||||||
@@ -447,8 +447,13 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
|
|||||||
if len(cfg.Audita.Credentials) != 0 {
|
if len(cfg.Audita.Credentials) != 0 {
|
||||||
t.Fatal("profile did not remove the base credential")
|
t.Fatal("profile did not remove the base credential")
|
||||||
}
|
}
|
||||||
|
if len(cfg.Scriptorium.Credentials) != 0 {
|
||||||
|
t.Fatal("inherited profile credential was not removed")
|
||||||
|
}
|
||||||
} else if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != testingKey || !cfg.Audita.Credentials[0].IsResolved() {
|
} else if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != testingKey || !cfg.Audita.Credentials[0].IsResolved() {
|
||||||
t.Fatal("profile credential was not resolved")
|
t.Fatal("profile credential was not resolved")
|
||||||
|
} else if len(cfg.Scriptorium.Credentials) != 1 || cfg.Scriptorium.Credentials[0].EnvName() != testingKey || cfg.Scriptorium.Credentials[0].Value() != "synthetic-test-key" {
|
||||||
|
t.Fatal("inherited profile credential was not resolved")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,3 +63,61 @@ func TestScriptoriumCredentialsComposeAndSerializeSafely(t *testing.T) {
|
|||||||
t.Fatal("empty selected credential accepted")
|
t.Fatal("empty selected credential accepted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScriptoriumInheritsResolvedTypedCredentialsSafely(t *testing.T) {
|
||||||
|
const envName = "NARRATIO_TEST_API_KEY"
|
||||||
|
const secret = "synthetic-inherited-secret"
|
||||||
|
t.Setenv(envName, secret)
|
||||||
|
dir := t.TempDir()
|
||||||
|
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://example.test/transcribe\naudita:\n credentials: [NARRATIO_TEST_API_KEY]\nscriptorium:\n extends: audita\n")
|
||||||
|
cfg, err := LoadPipeline(root)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != envName || !cfg.Audita.Credentials[0].IsResolved() || cfg.Audita.Credentials[0].Value() != secret {
|
||||||
|
t.Fatal("audita credential was not resolved")
|
||||||
|
}
|
||||||
|
if len(cfg.Scriptorium.Credentials) != 1 || cfg.Scriptorium.Credentials[0].EnvName() != envName || !cfg.Scriptorium.Credentials[0].IsResolved() || cfg.Scriptorium.Credentials[0].Value() != secret {
|
||||||
|
t.Fatal("scriptorium did not inherit the resolved typed credential")
|
||||||
|
}
|
||||||
|
for name, marshal := range map[string]func() ([]byte, error){
|
||||||
|
"config": func() ([]byte, error) { return yaml.Marshal(cfg) },
|
||||||
|
"effective": func() ([]byte, error) { return MarshalEffectivePipeline(cfg) },
|
||||||
|
} {
|
||||||
|
data, err := marshal()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(string(data), envName) || strings.Contains(string(data), secret) {
|
||||||
|
t.Fatalf("%s serialization did not safely expose credential identity", name)
|
||||||
|
}
|
||||||
|
var serialized struct {
|
||||||
|
Scriptorium struct {
|
||||||
|
Credentials []string `yaml:"credentials"`
|
||||||
|
} `yaml:"scriptorium"`
|
||||||
|
}
|
||||||
|
if err := yaml.Unmarshal(data, &serialized); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(serialized.Scriptorium.Credentials) != 1 || serialized.Scriptorium.Credentials[0] != envName {
|
||||||
|
t.Fatalf("%s serialization omitted the inherited Scriptorium credential", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
values, err := EffectivePipelineValues(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
inspection, err := yaml.Marshal(values)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
foundInheritedCredential := false
|
||||||
|
for _, value := range values {
|
||||||
|
if value.Path == "scriptorium.credentials" && strings.Contains(value.Value, envName) {
|
||||||
|
foundInheritedCredential = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundInheritedCredential || strings.Contains(string(inspection), secret) {
|
||||||
|
t.Fatal("effective inspection did not safely expose inherited credential identity")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user