Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

sentinel: dollars in a credential, a stuck service, a moved log

shukieshah7ce2ca415d9b
diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder.go b/cli/beacon/internal/endpoint/sentinel/forwarder.go
index c799495e..ae5bef2e 100644
--- a/cli/beacon/internal/endpoint/sentinel/forwarder.go
+++ b/cli/beacon/internal/endpoint/sentinel/forwarder.go
@@ -449,7 +449,10 @@ func Install(o InstallOptions) (InstallResult, error) {
// created in dir (readable only by root, or SYSTEM and Administrators) and removed straight after.
func validateConfig(vectorBin, dir, rendered string, secrets map[string]string) error {
for key, value := range secrets {
- rendered = strings.ReplaceAll(rendered, fmt.Sprintf("SECRET[%s.%s]", secretBackend, key), siempack.TOMLEscape(value))
+ // Doubled dollars, because Vector expands $NAME in the config text before it reads the
+ // TOML, and the secret backend hands it the value untouched at runtime.
+ literal := strings.ReplaceAll(siempack.TOMLEscape(value), "$", "$$")
+ rendered = strings.ReplaceAll(rendered, fmt.Sprintf("SECRET[%s.%s]", secretBackend, key), literal)
}
f, err := os.CreateTemp(dir, ".validate-*.toml")
if err != nil {
@@ -543,15 +546,15 @@ func Remove(keepState bool) error {
settings = Settings{}
}
manager := newForwarderService(ForwarderSpec(settings.AuthorityHost))
- unloadErr := manager.Unload()
+ if err := manager.Unload(); err != nil {
+ // The settings stay while the service might still be registered, so a retry can find it.
+ return err
+ }
manager.RemoveUnits()
if keepState {
- return unloadErr
- }
- if err := os.RemoveAll(ForwarderDir()); err != nil {
- return errors.Join(unloadErr, err)
+ return nil
}
- return unloadErr
+ return os.RemoveAll(ForwarderDir())
}
// ReconcileResult reports what Reconcile did.
@@ -621,10 +624,11 @@ func Reconcile(opts ReconcileOptions) (ReconcileResult, error) {
return ReconcileResult{Warning: err.Error()}, err
}
pruneVectorLogs(filepath.Join(dir, logDirName))
- if logPath != "" {
+ logPathChanged := logPath != "" && logPath != settings.LogPath
+ if logPathChanged {
settings.LogPath = logPath
}
- _, secretsPath, certificatePath, configPath, dataDir, logDir := paths(dir)
+ settingsPath, secretsPath, certificatePath, configPath, dataDir, logDir := paths(dir)
hasPassword := false
if settings.Credential == CredentialCertificate {
if _, err := os.Stat(secretsPath); err == nil {
@@ -663,6 +667,11 @@ func Reconcile(opts ReconcileOptions) (ReconcileResult, error) {
configChanged = false
} else if err := atomicfile.Write(configPath, []byte(rendered), 0o600); err != nil {
return ReconcileResult{Warning: err.Error()}, err
+ } else if logPathChanged {
+ // What status reports follows what Vector now reads.
+ if data, err := json.MarshalIndent(settings, "", " "); err == nil {
+ _ = atomicfile.Write(settingsPath, append(data, '\n'), 0o600)
+ }
}
}
unitCurrent, _ := manager.UnitCurrent(vector.Path, configPath)
diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go b/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
index 2110f51a..45c08b7e 100644
--- a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
+++ b/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
@@ -19,6 +19,7 @@ type fakeService struct {
spec service.ForwarderSpec
unsupported string
loadErr error
+ unloadErr error
units []string
loads int
unloads int
@@ -43,7 +44,14 @@ func (f *fakeService) Load() error {
f.running = true
return nil
}
-func (f *fakeService) Unload() error { f.unloads++; f.running = false; return nil }
+func (f *fakeService) Unload() error {
+ f.unloads++
+ if f.unloadErr != nil {
+ return f.unloadErr
+ }
+ f.running = false
+ return nil
+}
func (f *fakeService) RemoveUnits() { f.removed++ }
func (f *fakeService) Status() service.Status {
return service.Status{Label: f.spec.Label, Loaded: f.running, Running: f.running}
@@ -441,15 +449,15 @@ func TestForwarderValidatesWithTheCredentialAndRunsWithTheReference(t *testing.T
t.Fatal(err)
}
o := validInstall()
- o.ClientSecret, o.CertificatePath, o.CertificatePassword = "", pfx, `pfx "pass"`
+ o.ClientSecret, o.CertificatePath, o.CertificatePassword = "", pfx, `pfx "pa$s"`
if _, err := Install(o); err != nil {
t.Fatal(err)
}
- if len(checked) != 1 || !strings.Contains(checked[0], `certificate_password = "pfx \"pass\""`) {
+ if len(checked) != 1 || !strings.Contains(checked[0], `certificate_password = "pfx \"pa$$s\""`) {
t.Fatalf("the checked copy must carry the password itself:\n%v", checked)
}
config := readFile(t, filepath.Join(f.dir, configFileName))
- if strings.Contains(config, "pfx") && strings.Contains(config, `\"pass\"`) || !strings.Contains(config, "SECRET[beacon_sentinel.certificate_password]") {
+ if strings.Contains(config, "pa$s") || !strings.Contains(config, "SECRET[beacon_sentinel.certificate_password]") {
t.Fatalf("the installed config must hold only the reference:\n%s", config)
}
matches, _ := filepath.Glob(filepath.Join(f.dir, "*", ".validate-*"))
@@ -464,7 +472,7 @@ func TestForwarderValidatesWithTheCredentialAndRunsWithTheReference(t *testing.T
if _, err := Reconcile(ReconcileOptions{}); err != nil {
t.Fatal(err)
}
- if len(checked) != 2 || !strings.Contains(checked[1], `certificate_password = "pfx \"pass\""`) {
+ if len(checked) != 2 || !strings.Contains(checked[1], `certificate_password = "pfx \"pa$$s\""`) {
t.Fatalf("reconcile must check a copy with the password in it")
}
}
@@ -514,3 +522,33 @@ func TestForwarderRecordsAVectorChosenThroughTheEnvironment(t *testing.T) {
t.Fatalf("settings = %+v (%v)", settings, err)
}
}
+
+// A service that would not stop keeps its settings, so a later remove can still find it.
+func TestForwarderRemoveKeepsTheSettingsWhenTheServiceWouldNotStop(t *testing.T) {
+ f := newForwarderFixture(t)
+ if _, err := Install(validInstall()); err != nil {
+ t.Fatal(err)
+ }
+ f.svc.unloadErr = errors.New("the service did not stop")
+ if err := Remove(false); err == nil {
+ t.Fatal("Remove must report a service that would not stop")
+ }
+ if _, err := ReadSettings(); err != nil {
+ t.Fatalf("the settings must stay for a retry: %v", err)
+ }
+}
+
+// A repair that moves the log updates what status reports, along with what Vector reads.
+func TestForwarderReconcileRecordsAMovedLog(t *testing.T) {
+ newForwarderFixture(t)
+ if _, err := Install(validInstall()); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := Reconcile(ReconcileOptions{LogPath: "/srv/beacon/runtime.jsonl", Restart: true}); err != nil {
+ t.Fatal(err)
+ }
+ settings, err := ReadSettings()
+ if err != nil || settings.LogPath != "/srv/beacon/runtime.jsonl" {
+ t.Fatalf("settings = %+v (%v)", settings, err)
+ }
+}