From 39af6ef94160816098aebd7bff7bf95a1943a3a1 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 4 Oct 2026 14:41:34 +0000 Subject: [PATCH] Verify inherited credential safety --- docs/roadmap/implementation.md | 2 +- internal/config/pipeline_configkit_test.go | 7 ++- .../config/scriptorium_credentials_test.go | 58 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index c983c1c..3a35ea3 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -226,7 +226,7 @@ ConfigKit. Parents must remain valid Narratio entries, not special templates. Complete when inherited explicit input and absent defaults have distinct, 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 existing secret boundary. diff --git a/internal/config/pipeline_configkit_test.go b/internal/config/pipeline_configkit_test.go index 01bfba5..b6da14f 100644 --- a/internal/config/pipeline_configkit_test.go +++ b/internal/config/pipeline_configkit_test.go @@ -432,7 +432,7 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) { for _, credential := range []string{testingKey, "null"} { t.Run(credential, func(t *testing.T) { 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 + "]" if credential == "null" { selected = credential @@ -447,8 +447,13 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) { if len(cfg.Audita.Credentials) != 0 { 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() { 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") } }) } diff --git a/internal/config/scriptorium_credentials_test.go b/internal/config/scriptorium_credentials_test.go index f84c0b4..6f96000 100644 --- a/internal/config/scriptorium_credentials_test.go +++ b/internal/config/scriptorium_credentials_test.go @@ -63,3 +63,61 @@ func TestScriptoriumCredentialsComposeAndSerializeSafely(t *testing.T) { 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") + } +}