The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
sentinel: check a certificate's password the way Vector will use it
shukieshahf731b3cef6f3
diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder.go b/cli/beacon/internal/endpoint/sentinel/forwarder.goindex a3dd1c57..b274b679 100644--- a/cli/beacon/internal/endpoint/sentinel/forwarder.go+++ b/cli/beacon/internal/endpoint/sentinel/forwarder.go@@ -384,11 +384,7 @@ func Install(o InstallOptions) (InstallResult, error) {if err := writeFiles(preflight, secretsJSON, certificate); err != nil {return InstallResult{}, err}- preflightConfig := filepath.Join(scratch, configFileName)- if err := atomicfile.Write(preflightConfig, []byte(renderForwarderConfig(preflight)), 0o600); err != nil {- return InstallResult{}, err- }- if err := validateVector(vector.Path, preflightConfig); err != nil {+ if err := validateConfig(vector.Path, scratch, renderForwarderConfig(preflight), secrets); err != nil {return InstallResult{}, err}@@ -431,6 +427,30 @@ func Install(o InstallOptions) (InstallResult, error) {return InstallResult{Dir: dir, Config: configPath, Unit: unit, Vector: vector.Path, Service: manager.Status()}, nil}+// validateConfig has Vector check a rendered config. `vector validate` does not read secret+// backends: it takes a SECRET[...] reference as the literal value, which makes a certificate's+// password wrong and fails a config that runs. So it checks a copy with the credential written in,+// 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))+ }+ f, err := os.CreateTemp(dir, ".validate-*.toml")+ if err != nil {+ return err+ }+ path := f.Name()+ defer os.Remove(path)+ if _, err := f.WriteString(rendered); err != nil {+ f.Close()+ return err+ }+ if err := f.Close(); err != nil {+ return err+ }+ return validateVector(vectorBin, path)+}+// writeFiles writes the credential files and the directories the config points at.func writeFiles(o renderOptions, secretsJSON, certificate []byte) error {for _, dir := range []string{o.DataDir, o.LogDir} {@@ -600,12 +620,11 @@ func Reconcile(opts ReconcileOptions) (ReconcileResult, error) {configChanged := string(current) != renderedvar rejected stringif configChanged {- candidate := configPath + ".new"- if err := atomicfile.Write(candidate, []byte(rendered), 0o600); err != nil {- return ReconcileResult{Warning: err.Error()}, err+ secrets := map[string]string{}+ if data, err := os.ReadFile(secretsPath); err == nil {+ _ = json.Unmarshal(data, &secrets)}- if err := validateVector(vector.Path, candidate); err != nil {- _ = os.Remove(candidate)+ if err := validateConfig(vector.Path, dir, rendered, secrets); err != nil {if readErr != nil {// Nothing to fall back to.return ReconcileResult{Warning: "Vector rejected the config, and there is no previous one: " + err.Error()}, nil@@ -614,7 +633,7 @@ func Reconcile(opts ReconcileOptions) (ReconcileResult, error) {// upgrade removed it before this install, and an old config running beats none.rejected = "kept the previous config, which Vector still runs: " + err.Error()configChanged = false- } else if err := os.Rename(candidate, configPath); err != nil {+ } else if err := atomicfile.Write(configPath, []byte(rendered), 0o600); err != nil {return ReconcileResult{Warning: err.Error()}, err}}diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go b/cli/beacon/internal/endpoint/sentinel/forwarder_test.goindex 7df64e11..fbce8603 100644--- a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go+++ b/cli/beacon/internal/endpoint/sentinel/forwarder_test.go@@ -421,3 +421,49 @@ func TestForwarderReconcileKeepsTheVectorInstallWasGiven(t *testing.T) {t.Fatalf("findVector was asked for %q", asked)}}++// Vector's validate takes secret references literally, so the copy it checks has the credential+// written in, and is gone afterwards; the config Vector runs keeps only the reference.+func TestForwarderValidatesWithTheCredentialAndRunsWithTheReference(t *testing.T) {+ f := newForwarderFixture(t)+ var checked []string+ validateVector = func(_, config string) error {+ data, err := os.ReadFile(config)+ if err != nil {+ return err+ }+ checked = append(checked, string(data))+ return nil+ }+ pfx := filepath.Join(t.TempDir(), "app.pfx")+ if err := os.WriteFile(pfx, []byte("pfx bytes"), 0o600); err != nil {+ t.Fatal(err)+ }+ o := validInstall()+ o.ClientSecret, o.CertificatePath, o.CertificatePassword = "", pfx, `pfx "pass"`+ if _, err := Install(o); err != nil {+ t.Fatal(err)+ }+ if len(checked) != 1 || !strings.Contains(checked[0], `certificate_password = "pfx \"pass\""`) {+ 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]") {+ t.Fatalf("the installed config must hold only the reference:\n%s", config)+ }+ matches, _ := filepath.Glob(filepath.Join(f.dir, "*", ".validate-*"))+ more, _ := filepath.Glob(filepath.Join(f.dir, ".validate-*"))+ if len(matches)+len(more) != 0 {+ t.Fatalf("validation copies left behind: %v %v", matches, more)+ }+ // Reconcile checks a rewritten config the same way.+ if err := os.WriteFile(filepath.Join(f.dir, configFileName), []byte("# old\n"), 0o600); err != nil {+ t.Fatal(err)+ }+ if _, err := Reconcile(ReconcileOptions{}); err != nil {+ t.Fatal(err)+ }+ if len(checked) != 2 || !strings.Contains(checked[1], `certificate_password = "pfx \"pass\""`) {+ t.Fatalf("reconcile must check a copy with the password in it")+ }+}diff --git a/docs/log-forwarding/microsoft-sentinel.mdx b/docs/log-forwarding/microsoft-sentinel.mdxindex a0ad8200..0cc65262 100644--- a/docs/log-forwarding/microsoft-sentinel.mdx+++ b/docs/log-forwarding/microsoft-sentinel.mdx@@ -224,6 +224,8 @@ sudo /opt/beacon/bin/beacon endpoint sentinel forwarder status --systemVector saves its place in the log only after Azure has accepted a batch, and retries throttling, server errors and `401`/`403` answers without a limit. An outage or a role assignment that has not applied yet holds lines back rather than dropping them. After a crash some lines can be sent twice. Every row's `RawData` carries the event's `event.id`, so you can remove duplicates in a query.+One case is not retried. When Microsoft Entra ID refuses the credential itself, because the tenant or client ID is wrong or the certificate or secret has expired or been removed, Vector drops the batches it cannot get a token for, and `status` shows Entra's error. Lines written while the credential is refused are not sent. Renew the certificate or secret before it expires, and run `forwarder install` again with the new one.+### Run Vector yourself`vector.toml` in the pack is the same config for running Vector under your own service manager, with the values taken from its environment: `BEACON_SENTINEL_DCE_ENDPOINT` (the logs ingestion URL), `BEACON_SENTINEL_DCR_IMMUTABLE_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_ID` and `AZURE_CLIENT_SECRET`. If you already run it that way, stop that service before you install the managed forwarder, or every line is sent twice.diff --git a/packaging/windows/smoke-sentinel-forwarder.ps1 b/packaging/windows/smoke-sentinel-forwarder.ps1index 1fe9c78e..74547ccd 100644--- a/packaging/windows/smoke-sentinel-forwarder.ps1+++ b/packaging/windows/smoke-sentinel-forwarder.ps1@@ -167,17 +167,17 @@ switch ($Phase) {$probe = Join-Path $work 'pfx-probe.toml'@"data_dir = '$work'-[sources.probe]+[sources.probe_source]type = 'demo_logs'format = 'json'count = 1-[sinks.probe]+[sinks.probe_sink]type = 'azure_logs_ingestion'-inputs = ['probe']+inputs = ['probe_source']endpoint = 'https://127.0.0.1:9'dcr_immutable_id = '$dcr'stream_name = 'Custom-BeaconRuntimeRaw'-[sinks.probe.auth]+[sinks.probe_sink.auth]azure_credential_kind = 'client_certificate_credential'azure_tenant_id = '$tenant'azure_client_id = '$client'