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
fix perms mismatch
Justin D'Souzaa2ad6cdd3416
diff --git a/cli/beacon-hooks/internal/logging/endpoint_event_test.go b/cli/beacon-hooks/internal/logging/endpoint_event_test.goindex c169fc37..d44f128f 100644--- a/cli/beacon-hooks/internal/logging/endpoint_event_test.go+++ b/cli/beacon-hooks/internal/logging/endpoint_event_test.go@@ -5,6 +5,7 @@ import ("os""path/filepath""strings"+ "syscall""testing")@@ -41,6 +42,31 @@ func TestEndpointEventStillWritesStructuredTelemetry(t *testing.T) {}}+func TestEndpointEventCreatesSharedRuntimeFilesDespiteUmask(t *testing.T) {+ oldUmask := syscall.Umask(0022)+ t.Cleanup(func() {+ syscall.Umask(oldUmask)+ })++ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)++ logger := NewLoggerForPlatform("agent-thought", "cursor")+ if err := logger.EndpointEvent("agent.reasoning", "session", "info", "Agent reasoning captured", nil); err != nil {+ t.Fatalf("EndpointEvent returned error: %v", err)+ }++ for _, target := range []string{logPath, logPath + ".lock"} {+ info, err := os.Stat(target)+ if err != nil {+ t.Fatalf("stat %s: %v", target, err)+ }+ if got := info.Mode().Perm(); got != endpointRuntimeFileMode {+ t.Fatalf("%s mode = %o, want %o", target, got, endpointRuntimeFileMode)+ }+ }+}+func TestEndpointEventAddsCloudRunMetadataFromEnvironment(t *testing.T) {logPath := filepath.Join(t.TempDir(), "runtime.jsonl")t.Setenv("BEACON_ENDPOINT_LOG", logPath)diff --git a/cli/beacon-hooks/internal/logging/logging.go b/cli/beacon-hooks/internal/logging/logging.goindex f712f462..6bc5cbac 100644--- a/cli/beacon-hooks/internal/logging/logging.go+++ b/cli/beacon-hooks/internal/logging/logging.go@@ -18,6 +18,7 @@ import (const (defaultEndpointRotateBytes = 10 * 1024 * 1024defaultEndpointRotateArchives = 5+ endpointRuntimeFileMode = 0666)// Logger provides structured JSON logging for hook events@@ -273,7 +274,7 @@ func appendEndpointJSONL(path string, line []byte, rotateBytes int64, rotateArchif err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {return err}- lock, err := os.OpenFile(path+".lock", os.O_CREATE|os.O_RDWR, 0644)+ lock, err := openEndpointRuntimeFile(path+".lock", os.O_CREATE|os.O_RDWR)if err != nil {return err}@@ -289,7 +290,7 @@ func appendEndpointJSONL(path string, line []byte, rotateBytes int64, rotateArchif err := rotateEndpointLogIfNeeded(path, rotateBytes, rotateArchives, int64(len(line))); err != nil {return err}- f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)+ f, err := openEndpointRuntimeFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY)if err != nil {return err}@@ -298,6 +299,25 @@ func appendEndpointJSONL(path string, line []byte, rotateBytes int64, rotateArchreturn err}+func openEndpointRuntimeFile(path string, flag int) (*os.File, error) {+ existed := true+ if _, err := os.Stat(path); err != nil {+ if !os.IsNotExist(err) {+ return nil, err+ }+ existed = false+ }+ f, err := os.OpenFile(path, flag, endpointRuntimeFileMode)+ if err != nil {+ return nil, err+ }+ if err := os.Chmod(path, endpointRuntimeFileMode); err != nil && !existed {+ _ = f.Close()+ return nil, err+ }+ return f, nil+}+func rotateEndpointLogIfNeeded(path string, maxSize int64, archives int, nextWriteBytes int64) error {if maxSize <= 0 {return nildiff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.goindex fef7cbcb..b7f09b38 100644--- a/cli/beacon/cmd/endpoint_diagnostics.go+++ b/cli/beacon/cmd/endpoint_diagnostics.go@@ -974,7 +974,7 @@ func actionForCheck(check diagnostics.Check, runtimeLog lifecycle.RuntimeLogSourif check.Evidence == "runtime_log_missing" || check.Evidence == "missing_optional_file" {return "beacon endpoint doctor --fix"}- return "chmod 644 " + check.Target+ return "chmod 666 " + check.Targetcase "runtime_log_source":if runtimeLog.RequestedUserMode && !runtimeLog.EffectiveUserMode {return "stop the system collector or run beacon endpoint install --user"diff --git a/cli/beacon/internal/endpoint/diagnostics/diagnostics.go b/cli/beacon/internal/endpoint/diagnostics/diagnostics.goindex 0d2a585e..feb97bf3 100644--- a/cli/beacon/internal/endpoint/diagnostics/diagnostics.go+++ b/cli/beacon/internal/endpoint/diagnostics/diagnostics.go@@ -87,8 +87,8 @@ func checkLogPermissions(path string) Check {return Check{Name: "runtime_log_permissions", Target: path, Status: StatusWarn, Severity: SeverityLow, Message: "runtime log not created yet", Evidence: "runtime_log_missing"}}mode := info.Mode().Perm()- if mode&0022 != 0 {- return Check{Name: "runtime_log_permissions", Target: path, Status: StatusFail, Severity: SeverityHigh, Message: fmt.Sprintf("runtime log is group/world writable: %o", mode), Evidence: "group_or_world_writable"}+ if mode&0222 == 0 {+ return Check{Name: "runtime_log_permissions", Target: path, Status: StatusFail, Severity: SeverityHigh, Message: fmt.Sprintf("runtime log is not writable: %o", mode), Evidence: "not_writable"}}if mode&0044 == 0 {return Check{Name: "runtime_log_permissions", Target: path, Status: StatusWarn, Severity: SeverityLow, Message: fmt.Sprintf("runtime log may not be readable by Wazuh: %o", mode), Evidence: "not_group_or_world_readable"}diff --git a/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go b/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.goindex 57deb664..68b754dd 100644--- a/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go+++ b/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go@@ -51,7 +51,7 @@ func TestCheckLogPermissions(t *testing.T) {if err := os.Chmod(logPath, 0666); err != nil {t.Fatalf("chmod writable log: %v", err)}- if check := checkLogPermissions(logPath); check.Status != "fail" || check.Severity != "high" {+ if check := checkLogPermissions(logPath); check.Status != "ok" {t.Fatalf("0666 log permissions check = %#v", check)}@@ -61,6 +61,13 @@ func TestCheckLogPermissions(t *testing.T) {if check := checkLogPermissions(logPath); check.Status != "warn" || check.Severity != "low" {t.Fatalf("0200 log permissions check = %#v", check)}++ if err := os.Chmod(logPath, 0444); err != nil {+ t.Fatalf("chmod non-writable log: %v", err)+ }+ if check := checkLogPermissions(logPath); check.Status != "fail" || check.Severity != "high" || check.Evidence != "not_writable" {+ t.Fatalf("0444 log permissions check = %#v", check)+ }}func TestRunAndHasFailures(t *testing.T) {diff --git a/cli/beacon/internal/endpoint/writer/writer.go b/cli/beacon/internal/endpoint/writer/writer.goindex e28f1fed..8d1ed4bb 100644--- a/cli/beacon/internal/endpoint/writer/writer.go+++ b/cli/beacon/internal/endpoint/writer/writer.go@@ -21,6 +21,7 @@ const (DefaultRotateBytes = 10 * 1024 * 1024DefaultRotateArchives = 5RotateBytes = DefaultRotateBytes+ runtimeFileMode = 0666)type Options struct {@@ -107,7 +108,7 @@ func appendJSONL(path string, line []byte, rotateBytes int64, rotateArchives intif err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {return err}- lock, err := os.OpenFile(path+".lock", os.O_CREATE|os.O_RDWR, 0644)+ lock, err := openRuntimeFile(path+".lock", os.O_CREATE|os.O_RDWR)if err != nil {return err}@@ -123,7 +124,7 @@ func appendJSONL(path string, line []byte, rotateBytes int64, rotateArchives intif err := rotateIfNeeded(path, rotateBytes, rotateArchives, int64(len(line))); err != nil {return err}- f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)+ f, err := openRuntimeFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY)if err != nil {return err}@@ -132,6 +133,25 @@ func appendJSONL(path string, line []byte, rotateBytes int64, rotateArchives intreturn err}+func openRuntimeFile(path string, flag int) (*os.File, error) {+ existed := true+ if _, err := os.Stat(path); err != nil {+ if !os.IsNotExist(err) {+ return nil, err+ }+ existed = false+ }+ f, err := os.OpenFile(path, flag, runtimeFileMode)+ if err != nil {+ return nil, err+ }+ if err := os.Chmod(path, runtimeFileMode); err != nil && !existed {+ _ = f.Close()+ return nil, err+ }+ return f, nil+}+func rotateIfNeeded(path string, maxSize int64, archives int, nextWriteBytes int64) error {if maxSize <= 0 {return nildiff --git a/cli/beacon/internal/endpoint/writer/writer_test.go b/cli/beacon/internal/endpoint/writer/writer_test.goindex b3674672..5b1eb94b 100644--- a/cli/beacon/internal/endpoint/writer/writer_test.go+++ b/cli/beacon/internal/endpoint/writer/writer_test.go@@ -7,6 +7,7 @@ import ("strconv""strings""sync"+ "syscall""testing""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"@@ -43,6 +44,33 @@ func TestAppendEventWritesSingleJSONLine(t *testing.T) {}}+func TestAppendEventCreatesSharedRuntimeFilesDespiteUmask(t *testing.T) {+ oldUmask := syscall.Umask(0022)+ t.Cleanup(func() {+ syscall.Umask(oldUmask)+ })++ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ event := schema.NewEvent(schema.NewEventOptions{+ Action: "agent.detected",+ Harness: schema.HarnessInfo{Name: "test"},+ Message: "test event",+ })+ if _, err := AppendEvent(event, Options{Path: path}); err != nil {+ t.Fatalf("AppendEvent returned error: %v", err)+ }++ for _, target := range []string{path, path + ".lock"} {+ info, err := os.Stat(target)+ if err != nil {+ t.Fatalf("stat %s: %v", target, err)+ }+ if got := info.Mode().Perm(); got != runtimeFileMode {+ t.Fatalf("%s mode = %o, want %o", target, got, runtimeFileMode)+ }+ }+}+func TestAppendEventRedactsSecrets(t *testing.T) {path := filepath.Join(t.TempDir(), "runtime.jsonl")event := schema.NewEvent(schema.NewEventOptions{