Skip to content

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

feat(windows): resolve the system log location from one place

shukieshah0e1c7c4484cb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0027f70f..a74fb613 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -203,12 +203,14 @@ jobs:
Copy-Item beacon-hooks.exe ..\beacon\internal\embedded\hooks.bin -Force
# Scoped to the packages this port actually gives Windows implementations, not `./...`.
#
- # The rest of the cli/beacon suite has never run on Windows and assumes a POSIX host in ways
- # unrelated to any of this: 47 tests redirect the home directory with t.Setenv("HOME"), which
- # does nothing there because os.UserHomeDir reads USERPROFILE; 15 assert Unix file modes that
- # Windows does not implement; others exec fixtures with no .exe extension. Running them here
- # would produce a permanently red gate that says nothing about the code under test, and a red
- # gate nobody can fix is one nobody reads.
+ # The scope grows as packages are made portable. config, collector, harness and hooks joined
+ # when the Windows filesystem work needed them gated -- which immediately paid for itself by
+ # surfacing a production bug: validateExecutable tested the POSIX executable bit, which is
+ # never set on Windows, so DiscoverBinary rejected every collector binary there.
+ #
+ # The remaining cli/beacon packages still assume a POSIX host and are not scoped in. Running
+ # them here would produce a permanently red gate that says nothing about the code under test,
+ # and a red gate nobody can fix is one nobody reads.
#
# Tracked as follow-up work rather than dropped -- see #318. The scope
# widens as those packages are made portable; it must not widen by adding `./...` back while
@@ -221,7 +223,11 @@ jobs:
./internal/endpoint/inventory/... `
./internal/ingest/endpoint/... `
./internal/endpoint/service/... `
- ./internal/endpoint/selfupdate/...
+ ./internal/endpoint/selfupdate/... `
+ ./internal/endpoint/config/... `
+ ./internal/endpoint/collector/... `
+ ./internal/endpoint/harness/... `
+ ./internal/endpoint/hooks/...
- name: Test the ported packages with the race detector
working-directory: cli/beacon
run: |
diff --git a/cli/beacon/internal/endpoint/cloudwatch/cloudwatch.go b/cli/beacon/internal/endpoint/cloudwatch/cloudwatch.go
index af68eab4..15b52602 100644
--- a/cli/beacon/internal/endpoint/cloudwatch/cloudwatch.go
+++ b/cli/beacon/internal/endpoint/cloudwatch/cloudwatch.go
@@ -2,6 +2,7 @@ package cloudwatch
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-cloudwatch-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const configAsset = "pack/vector.toml.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/collector/collector_test.go b/cli/beacon/internal/endpoint/collector/collector_test.go
index cfe44c67..2b6bd50c 100644
--- a/cli/beacon/internal/endpoint/collector/collector_test.go
+++ b/cli/beacon/internal/endpoint/collector/collector_test.go
@@ -2,11 +2,13 @@ package collector
import (
"errors"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"testing"
"time"
@@ -180,6 +182,7 @@ func TestWriteConfigCreatesConfigAndSpoolDirectory(t *testing.T) {
}
func TestWriteConfigUsesPrivatePermissionsWithSplunkToken(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
cfg := testConfig(t)
cfg.Destinations = &endpointconfig.Destinations{SplunkHEC: &endpointconfig.SplunkHEC{
Endpoint: "https://splunk.example:8088/services/collector",
@@ -199,6 +202,7 @@ func TestWriteConfigUsesPrivatePermissionsWithSplunkToken(t *testing.T) {
}
func TestWriteConfigUsesPrivatePermissionsWithFalconToken(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
cfg := testConfig(t)
cfg.Destinations = &endpointconfig.Destinations{FalconHEC: &endpointconfig.FalconHEC{
Endpoint: "https://cloud.us.humio.com/api/v1/ingest/hec",
@@ -259,8 +263,22 @@ func TestWaitForPortsAvailableReportsPersistentConflict(t *testing.T) {
}
}
+// stubCollectorName returns the fixture file name a collector binary must have to be discoverable
+// on this platform.
+//
+// exec.LookPath resolves a bare name through PATHEXT on Windows, so a fixture written without an
+// extension is invisible to it however its bits are set -- DiscoverBinary would report no collector
+// installed while the file sat right there on PATH. The production BinaryName stays extensionless
+// because LookPath is what applies the extension.
+func stubCollectorName() string {
+ if runtime.GOOS == "windows" {
+ return BinaryName + ".exe"
+ }
+ return BinaryName
+}
+
func TestDiscoverBinaryPrefersConfiguredExistingPath(t *testing.T) {
- bin := filepath.Join(t.TempDir(), BinaryName)
+ bin := filepath.Join(t.TempDir(), stubCollectorName())
if err := os.WriteFile(bin, []byte("#!/bin/sh\n"), 0755); err != nil {
t.Fatalf("write fake collector: %v", err)
}
@@ -281,7 +299,7 @@ func TestResolveBinaryRejectsMissingConfiguredPath(t *testing.T) {
func TestDiscoverBinaryFindsBeaconOtelcolOnPath(t *testing.T) {
dir := t.TempDir()
- bin := filepath.Join(dir, BinaryName)
+ bin := filepath.Join(dir, stubCollectorName())
if err := os.WriteFile(bin, []byte("#!/bin/sh\n"), 0755); err != nil {
t.Fatalf("write fake collector: %v", err)
}
@@ -348,7 +366,7 @@ func TestCheckStatusDoesNotTreatOpenOTLPPortsAsHealthy(t *testing.T) {
if healthReady() {
t.Skip("collector health check endpoint is already active")
}
- bin := filepath.Join(t.TempDir(), BinaryName)
+ bin := filepath.Join(t.TempDir(), stubCollectorName())
if err := os.WriteFile(bin, []byte("#!/bin/sh\n"), 0755); err != nil {
t.Fatalf("write fake collector: %v", err)
}
diff --git a/cli/beacon/internal/endpoint/config/config.go b/cli/beacon/internal/endpoint/config/config.go
index 240e6867..e08dffd0 100644
--- a/cli/beacon/internal/endpoint/config/config.go
+++ b/cli/beacon/internal/endpoint/config/config.go
@@ -39,6 +39,34 @@ func SystemConfigPath() string {
return filepath.Join(SystemBaseDir(), "config.json")
}
+// SystemLogDir is the single source of truth for where a system-mode endpoint writes its logs.
+//
+// The runtime log path was previously a literal repeated in fourteen places -- every destination
+// pack, the writer, the hook adapter's default, the inventory heartbeat and the self-updater --
+// which is exactly the shape SystemBaseDir was introduced to remove for the config directory. One
+// function is what makes a second platform possible at all: fourteen literals cannot disagree with
+// each other on Linux, but they cannot be given a Windows value either.
+//
+// The Linux and macOS value is unchanged, and deliberately so. /var/log/beacon-agent is where
+// installed endpoints already write, where the packaging scripts create directories, and what the
+// forwarder packs tail; moving it would be a migration, not a refactor.
+func SystemLogDir() string {
+ switch runtime.GOOS {
+ case "windows":
+ // Alongside the config rather than under a separate root. Windows has no /var/log
+ // equivalent, and %ProgramData% is the documented home for machine-wide application state
+ // that outlives any one user.
+ return filepath.Join(SystemBaseDir(), "logs")
+ default:
+ return "/var/log/beacon-agent"
+ }
+}
+
+// SystemLogPath is the system-mode runtime log.
+func SystemLogPath() string {
+ return filepath.Join(SystemLogDir(), "runtime.jsonl")
+}
+
const (
DefaultSplunkSource = "beacon-endpoint-agent"
DefaultSplunkSourcetype = "beacon:endpoint"
diff --git a/cli/beacon/internal/endpoint/config/config_test.go b/cli/beacon/internal/endpoint/config/config_test.go
index f4da6ba5..9b9c1169 100644
--- a/cli/beacon/internal/endpoint/config/config_test.go
+++ b/cli/beacon/internal/endpoint/config/config_test.go
@@ -104,6 +104,7 @@ func TestSaveLoadRoundTrip(t *testing.T) {
}
func TestSaveLoadSplunkHECRoundTripAndPrivatePermissions(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
home := t.TempDir()
testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "logs", "runtime.jsonl"))
@@ -153,6 +154,7 @@ func TestSaveRejectsIncompleteSplunkHEC(t *testing.T) {
}
func TestSaveLoadFalconHECRoundTripAndPrivatePermissions(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
home := t.TempDir()
testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "logs", "runtime.jsonl"))
diff --git a/cli/beacon/internal/endpoint/config/systemlog_test.go b/cli/beacon/internal/endpoint/config/systemlog_test.go
new file mode 100644
index 00000000..c0f42138
--- /dev/null
+++ b/cli/beacon/internal/endpoint/config/systemlog_test.go
@@ -0,0 +1,48 @@
+package config
+
+import (
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+)
+
+// The POSIX value must not move. /var/log/beacon-agent is where installed endpoints already write,
+// where the packaging scripts create directories, and what the forwarder packs tail -- changing it
+// would be a migration rather than a refactor, and this consolidation is meant to be neither.
+func TestSystemLogPathIsUnchangedOnPOSIX(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("the POSIX location does not apply")
+ }
+ if got, want := SystemLogDir(), "/var/log/beacon-agent"; got != want {
+ t.Errorf("SystemLogDir() = %q, want %q", got, want)
+ }
+ if got, want := SystemLogPath(), "/var/log/beacon-agent/runtime.jsonl"; got != want {
+ t.Errorf("SystemLogPath() = %q, want %q", got, want)
+ }
+}
+
+// On Windows the log lives under the same machine-wide root as the config, because there is no
+// /var/log equivalent and %ProgramData% is where state that outlives any one user belongs.
+func TestSystemLogPathIsUnderTheSystemBaseDirOnWindows(t *testing.T) {
+ if runtime.GOOS != "windows" {
+ t.Skip("the Windows location does not apply")
+ }
+ if !strings.HasPrefix(SystemLogDir(), SystemBaseDir()) {
+ t.Errorf("SystemLogDir() = %q, want it under SystemBaseDir() %q", SystemLogDir(), SystemBaseDir())
+ }
+ if got, want := SystemLogPath(), filepath.Join(SystemLogDir(), "runtime.jsonl"); got != want {
+ t.Errorf("SystemLogPath() = %q, want %q", got, want)
+ }
+}
+
+// The log path must derive from the same root as the config, or a Windows install would scatter
+// its state across two locations and only one of them would be documented.
+func TestSystemLogPathDerivesFromOneRoot(t *testing.T) {
+ if got := SystemLogPath(); !strings.HasSuffix(filepath.ToSlash(got), "/runtime.jsonl") {
+ t.Errorf("SystemLogPath() = %q, want it to name runtime.jsonl", got)
+ }
+ if SystemLogDir() == "" || SystemBaseDir() == "" {
+ t.Fatal("neither root may be empty; an empty prefix silently writes to the process's cwd")
+ }
+}
diff --git a/cli/beacon/internal/endpoint/datadog/datadog.go b/cli/beacon/internal/endpoint/datadog/datadog.go
index 8aca7fbb..48165919 100644
--- a/cli/beacon/internal/endpoint/datadog/datadog.go
+++ b/cli/beacon/internal/endpoint/datadog/datadog.go
@@ -1,6 +1,7 @@
package datadog
import (
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"embed"
@@ -12,10 +13,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-datadog-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const configAsset = "pack/conf.yaml.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/elastic/elastic.go b/cli/beacon/internal/endpoint/elastic/elastic.go
index 6d0606be..9ead0000 100644
--- a/cli/beacon/internal/endpoint/elastic/elastic.go
+++ b/cli/beacon/internal/endpoint/elastic/elastic.go
@@ -3,6 +3,7 @@ package elastic
import (
"embed"
"fmt"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"os"
"path/filepath"
@@ -15,10 +16,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-elastic-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
type File struct {
Name string
Content string
diff --git a/cli/beacon/internal/endpoint/falcon/falcon.go b/cli/beacon/internal/endpoint/falcon/falcon.go
index 93bac613..3e70721b 100644
--- a/cli/beacon/internal/endpoint/falcon/falcon.go
+++ b/cli/beacon/internal/endpoint/falcon/falcon.go
@@ -2,6 +2,7 @@ package falcon
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-falcon-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const (
configAsset = "pack/vector.toml.tmpl"
smokeTestAsset = "pack/falcon-hec-smoke-test.sh.tmpl"
diff --git a/cli/beacon/internal/endpoint/gcs/gcs.go b/cli/beacon/internal/endpoint/gcs/gcs.go
index 1095b18b..919828f2 100644
--- a/cli/beacon/internal/endpoint/gcs/gcs.go
+++ b/cli/beacon/internal/endpoint/gcs/gcs.go
@@ -2,6 +2,7 @@ package gcs
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-gcs-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const smokeTestAsset = "pack/gcs-upload-smoke-test.sh.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/hooks/runtime.go b/cli/beacon/internal/endpoint/hooks/runtime.go
index 557c92f4..caad5822 100644
--- a/cli/beacon/internal/endpoint/hooks/runtime.go
+++ b/cli/beacon/internal/endpoint/hooks/runtime.go
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "runtime"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/embedded"
@@ -169,16 +170,51 @@ func defaultLogPath(userMode bool) string {
return filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")
}
}
- return "/var/log/beacon-agent/runtime.jsonl"
+ return endpointconfig.SystemLogPath()
}
+// endpointConfigPathForHook picks which config a hook should read, from where its log lives.
+//
+// A log under a machine-wide location means the hook is feeding a system-mode endpoint, whatever
+// scope the caller asked for, so it must read the system config. That was decided by matching the
+// POSIX prefixes "/var/log/" and "/Library/" -- which named two of the three platforms' locations
+// and no Windows one, so a Windows system install would have sent its hooks to the *user* config
+// and pointed them at a log the collector never reads.
+//
+// Comparing against the resolved directories instead makes the question platform-independent, and
+// keeps working if either location ever moves.
func endpointConfigPathForHook(logPath string, userMode bool) string {
- if strings.HasPrefix(logPath, "/var/log/") || strings.HasPrefix(logPath, "/Library/") {
+ if underSystemLocation(logPath) {
return endpointconfig.ConfigPath(false)
}
return endpointconfig.ConfigPath(userMode)
}
+// underSystemLocation reports whether a path sits beneath a machine-wide Beacon directory.
+//
+// Case-insensitive on Windows, where paths are, and separator-normalized so a value built with
+// either separator compares the same. A false negative here is the dangerous direction: it routes
+// a system-mode hook to the user config, which fails silently rather than loudly.
+func underSystemLocation(path string) bool {
+ norm := func(p string) string {
+ p = filepath.ToSlash(filepath.Clean(p))
+ if runtime.GOOS == "windows" {
+ p = strings.ToLower(p)
+ }
+ return strings.TrimSuffix(p, "/") + "/"
+ }
+ target := norm(path)
+ for _, root := range []string{endpointconfig.SystemLogDir(), endpointconfig.SystemBaseDir()} {
+ if root == "" {
+ continue
+ }
+ if strings.HasPrefix(target, norm(root)) {
+ return true
+ }
+ }
+ return false
+}
+
func shellQuote(value string) string {
return "'" + strings.ReplaceAll(value, "'", "'\\''") + "'"
}
diff --git a/cli/beacon/internal/endpoint/hooks/scope_test.go b/cli/beacon/internal/endpoint/hooks/scope_test.go
new file mode 100644
index 00000000..2619c3f9
--- /dev/null
+++ b/cli/beacon/internal/endpoint/hooks/scope_test.go
@@ -0,0 +1,61 @@
+package hooks
+
+import (
+ "path/filepath"
+ "runtime"
+ "testing"
+
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
+)
+
+// A hook writing to a machine-wide log is feeding a system-mode endpoint and must read the system
+// config, whatever scope the caller asked for. The previous test matched the POSIX prefixes
+// "/var/log/" and "/Library/", which named two platforms' locations and no Windows one -- so a
+// Windows system install would have routed its hooks to the *user* config and pointed them at a
+// log the collector never reads. That fails silently, which is the worst way for it to fail.
+func TestSystemLogRoutesHooksToTheSystemConfig(t *testing.T) {
+ system := endpointconfig.ConfigPath(false)
+
+ for _, logPath := range []string{
+ endpointconfig.SystemLogPath(),
+ filepath.Join(endpointconfig.SystemLogDir(), "inventory_state.jsonl"),
+ filepath.Join(endpointconfig.SystemBaseDir(), "logs", "runtime.jsonl"),
+ } {
+ if got := endpointConfigPathForHook(logPath, true); got != system {
+ t.Errorf("a hook logging to %q asked for user mode and got %q, want the system config %q",
+ logPath, got, system)
+ }
+ }
+}
+
+// A log in the user's own tree must keep the caller's scope, or a user-mode install would write
+// its hook configuration into a system path it may not even be able to open.
+func TestUserLogKeepsTheRequestedScope(t *testing.T) {
+ userLog := filepath.Join(t.TempDir(), ".beacon", "endpoint", "logs", "runtime.jsonl")
+
+ if got, want := endpointConfigPathForHook(userLog, true), endpointconfig.ConfigPath(true); got != want {
+ t.Errorf("user-mode log routed to %q, want %q", got, want)
+ }
+ if got, want := endpointConfigPathForHook(userLog, false), endpointconfig.ConfigPath(false); got != want {
+ t.Errorf("system-mode caller with a user log routed to %q, want %q", got, want)
+ }
+}
+
+// Windows paths compare case-insensitively and may arrive with either separator. A false negative
+// is the dangerous direction, so both spellings must still be recognized.
+func TestSystemLocationMatchIsPlatformAppropriate(t *testing.T) {
+ dir := endpointconfig.SystemLogDir()
+ if !underSystemLocation(filepath.Join(dir, "runtime.jsonl")) {
+ t.Fatalf("the system log dir %q must be recognized", dir)
+ }
+ if runtime.GOOS == "windows" {
+ mixed := filepath.Join(dir, "RUNTIME.JSONL")
+ if !underSystemLocation(mixed) {
+ t.Errorf("windows path comparison must be case-insensitive, %q was not matched", mixed)
+ }
+ }
+ // A sibling directory whose name merely starts with the same characters is not underneath it.
+ if underSystemLocation(dir + "-other/runtime.jsonl") {
+ t.Errorf("%q-other must not be treated as being under %q", dir, dir)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/inventory/heartbeat.go b/cli/beacon/internal/endpoint/inventory/heartbeat.go
index 3b063b27..a458c7e3 100644
--- a/cli/beacon/internal/endpoint/inventory/heartbeat.go
+++ b/cli/beacon/internal/endpoint/inventory/heartbeat.go
@@ -53,7 +53,7 @@ func LogPath(runtimeLogPath string, userMode bool) string {
}
return filepath.Join(home, ".beacon", "endpoint", "logs", LogFileName)
}
- return filepath.Join("/var/log", "beacon-agent", LogFileName)
+ return filepath.Join(endpointconfig.SystemLogDir(), LogFileName)
}
func LockState(path string) (*LockedState, State, error) {
diff --git a/cli/beacon/internal/endpoint/rapid7/rapid7.go b/cli/beacon/internal/endpoint/rapid7/rapid7.go
index 7ab9bca9..2c18505e 100644
--- a/cli/beacon/internal/endpoint/rapid7/rapid7.go
+++ b/cli/beacon/internal/endpoint/rapid7/rapid7.go
@@ -2,6 +2,7 @@ package rapid7
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-rapid7-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const smokeTestAsset = "pack/rapid7-upload-smoke-test.sh.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/s3/s3.go b/cli/beacon/internal/endpoint/s3/s3.go
index 8e544160..28773bc8 100644
--- a/cli/beacon/internal/endpoint/s3/s3.go
+++ b/cli/beacon/internal/endpoint/s3/s3.go
@@ -2,6 +2,7 @@ package s3
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-s3-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const smokeTestAsset = "pack/s3-upload-smoke-test.sh.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/selfupdate/systemlog.go b/cli/beacon/internal/endpoint/selfupdate/systemlog.go
index 9d4705a4..f3770330 100644
--- a/cli/beacon/internal/endpoint/selfupdate/systemlog.go
+++ b/cli/beacon/internal/endpoint/selfupdate/systemlog.go
@@ -1,6 +1,7 @@
package selfupdate
import (
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"path/filepath"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
@@ -27,7 +28,7 @@ func SystemLogPath(runtimeLogPath string, userMode bool) string {
if userMode {
return filepath.Join(filepath.Dir(writer.DefaultPath(true)), SystemLogFileName)
}
- return filepath.Join("/var/log", "beacon-agent", SystemLogFileName)
+ return filepath.Join(endpointconfig.SystemLogDir(), SystemLogFileName)
}
type CheckEventOptions struct {
diff --git a/cli/beacon/internal/endpoint/sentinel/sentinel.go b/cli/beacon/internal/endpoint/sentinel/sentinel.go
index 073b46b1..437d74f2 100644
--- a/cli/beacon/internal/endpoint/sentinel/sentinel.go
+++ b/cli/beacon/internal/endpoint/sentinel/sentinel.go
@@ -3,6 +3,7 @@ package sentinel
import (
"embed"
"fmt"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -12,10 +13,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-sentinel-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
func Files() []siempack.File {
return []siempack.File{
{Name: "README.md", Content: mustRead("pack/README.md")},
diff --git a/cli/beacon/internal/endpoint/sumo/sumo.go b/cli/beacon/internal/endpoint/sumo/sumo.go
index e0347d8c..cb04e182 100644
--- a/cli/beacon/internal/endpoint/sumo/sumo.go
+++ b/cli/beacon/internal/endpoint/sumo/sumo.go
@@ -2,6 +2,7 @@ package sumo
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"io/fs"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/siempack"
@@ -11,10 +12,13 @@ import (
var packFS embed.FS
const (
- DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
DefaultOutputDir = "beacon-sumo-pack"
)
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
+
const smokeTestAsset = "pack/sumo-upload-smoke-test.sh.tmpl"
// File is the installable pack-file type, shared with siempack.
diff --git a/cli/beacon/internal/endpoint/wazuh/wazuh.go b/cli/beacon/internal/endpoint/wazuh/wazuh.go
index 43456609..c72593f9 100644
--- a/cli/beacon/internal/endpoint/wazuh/wazuh.go
+++ b/cli/beacon/internal/endpoint/wazuh/wazuh.go
@@ -2,6 +2,7 @@ package wazuh
import (
"embed"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"os"
"path/filepath"
"strings"
@@ -10,7 +11,9 @@ import (
//go:embed pack/*
var packFS embed.FS
-const DefaultLogPath = "/var/log/beacon-agent/runtime.jsonl"
+// DefaultLogPath is a var rather than a const because the system log location is now
+// resolved per platform by one function instead of repeated as a literal in every pack.
+var DefaultLogPath = endpointconfig.SystemLogPath()
type File struct {
Name string
diff --git a/cli/beacon/internal/endpoint/writer/writer.go b/cli/beacon/internal/endpoint/writer/writer.go
index 3122e677..7fd0ad04 100644
--- a/cli/beacon/internal/endpoint/writer/writer.go
+++ b/cli/beacon/internal/endpoint/writer/writer.go
@@ -9,13 +9,13 @@ import (
"strconv"
"strings"
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/filelock"
)
const (
- SystemLogPath = "/var/log/beacon-agent/runtime.jsonl"
UserLogPath = ".beacon/endpoint/logs/runtime.jsonl"
MaxEventBytes = 64 * 1024
DefaultRotateBytes = 10 * 1024 * 1024
@@ -32,6 +32,12 @@ type Options struct {
RotateArchives int
}
+// SystemLogPath is the system-mode runtime log, resolved per platform.
+//
+// Delegated rather than duplicated: this was one of fourteen copies of the same literal, and the
+// copies could not be given a Windows value independently without disagreeing.
+func SystemLogPath() string { return endpointconfig.SystemLogPath() }
+
func DefaultPath(userMode bool) string {
if userMode {
home, err := os.UserHomeDir()
@@ -40,7 +46,7 @@ func DefaultPath(userMode bool) string {
}
return filepath.Join(home, UserLogPath)
}
- return SystemLogPath
+ return SystemLogPath()
}
func AppendEvent(event schema.Event, opts Options) (string, error) {
diff --git a/cli/beacon/internal/testenv/testenv.go b/cli/beacon/internal/testenv/testenv.go
index f29f9998..97d0e8eb 100644
--- a/cli/beacon/internal/testenv/testenv.go
+++ b/cli/beacon/internal/testenv/testenv.go
@@ -11,7 +11,10 @@
// that needs it -- is what produced the inconsistency in the first place.
package testenv
-import "testing"
+import (
+ "runtime"
+ "testing"
+)
// SetHome redirects the user's home directory for the duration of a test, on every platform.
//
@@ -23,3 +26,20 @@ func SetHome(t *testing.T, dir string) {
t.Setenv("HOME", dir)
t.Setenv("USERPROFILE", dir)
}
+
+// RequirePOSIXFileModes skips a test whose assertion is about Unix permission bits.
+//
+// Windows does not implement them: os.Chmod only toggles a read-only attribute, and Go reports
+// 0666 for any ordinary file. A mode assertion there is not merely unsupported, it is misleading --
+// it would either fail for a reason unrelated to the property or pass vacuously.
+//
+// The property these tests protect is real on both platforms: a config file holding a credential
+// must not be readable by other users. Windows expresses that as an ACL rather than a mode, so
+// this is the seam where a Windows equivalent belongs once the endpoint sets ACLs on the files it
+// writes. Skipping is honest in the meantime; asserting 0666 == 0600 would not be.
+func RequirePOSIXFileModes(t *testing.T) {
+ t.Helper()
+ if runtime.GOOS == "windows" {
+ t.Skip("Unix permission bits do not exist on Windows; the equivalent is an ACL check")
+ }
+}