Skip to content

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

Move launchd job logs out of world-writable /tmp

Claude9a9a07c9da2d
diff --git a/cli/beacon/internal/endpoint/service/collectorlog_test.go b/cli/beacon/internal/endpoint/service/collectorlog_test.go
index 0b827666..6d0f1164 100644
--- a/cli/beacon/internal/endpoint/service/collectorlog_test.go
+++ b/cli/beacon/internal/endpoint/service/collectorlog_test.go
@@ -16,14 +16,18 @@ func TestCollectorLogNamesWhereEachBackendSendsStderr(t *testing.T) {
testenv.SetHome(t, home)
launchd := Manager{UserMode: true, Kind: KindLaunchd}.CollectorLog()
- if launchd.Path != "/tmp/"+UserLabel+".err" {
- t.Errorf("launchd user log = %q, want /tmp/%s.err", launchd.Path, UserLabel)
+ if want := filepath.Join(home, "Library", "Logs", "Beacon", UserLabel+".err"); launchd.Path != want {
+ t.Errorf("launchd user log = %q, want %q", launchd.Path, want)
}
- if !strings.Contains(plist(UserLabel, "/bin/otelcol", "/tmp/otelcol.yaml"), "<string>"+launchd.Path+"</string>") {
+ stdout, stderr, err := launchdLogPaths(true, UserLabel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(plist(UserLabel, "/bin/otelcol", "/x/otelcol.yaml", stdout, stderr), "<string>"+launchd.Path+"</string>") {
t.Errorf("launchd log path %q is not the plist's StandardErrorPath", launchd.Path)
}
- if got := (Manager{UserMode: false, Kind: KindLaunchd}).CollectorLog().Path; got != "/tmp/"+SystemLabel+".err" {
- t.Errorf("launchd system log = %q, want /tmp/%s.err", got, SystemLabel)
+ if got := (Manager{UserMode: false, Kind: KindLaunchd}).CollectorLog().Path; got != "/Library/Logs/Beacon/"+SystemLabel+".err" {
+ t.Errorf("launchd system log = %q, want /Library/Logs/Beacon/%s.err", got, SystemLabel)
}
supervised := Manager{UserMode: true, Kind: KindSupervised}.CollectorLog()
diff --git a/cli/beacon/internal/endpoint/service/forwarder.go b/cli/beacon/internal/endpoint/service/forwarder.go
index dd346d67..b0d7e280 100644
--- a/cli/beacon/internal/endpoint/service/forwarder.go
+++ b/cli/beacon/internal/endpoint/service/forwarder.go
@@ -116,7 +116,14 @@ func (m ForwarderManager) WriteUnit(vectorBin, configPath string) (string, error
if m.resolvedKind() == KindSystemd {
content = forwarderUnitFile(vectorBin, configPath, m.UserMode)
} else {
- content = forwarderPlist(ForwarderLabel, vectorBin, configPath)
+ if err := ensureLaunchdLogDir(m.UserMode, ForwarderLabel); err != nil {
+ return "", err
+ }
+ stdout, stderr, err := launchdLogPaths(m.UserMode, ForwarderLabel)
+ if err != nil {
+ return "", err
+ }
+ content = forwarderPlist(ForwarderLabel, vectorBin, configPath, stdout, stderr)
}
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
return "", err
@@ -255,7 +262,7 @@ func forwarderUnitFile(vectorBin, configPath string, userMode bool) string {
}
// forwarderPlist renders the launchd job: resident, restarted by launchd, started at load.
-func forwarderPlist(label, vectorBin, configPath string) string {
+func forwarderPlist(label, vectorBin, configPath, stdoutPath, stderrPath string) string {
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -275,12 +282,12 @@ func forwarderPlist(label, vectorBin, configPath string) string {
<key>ThrottleInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
- <string>/tmp/%s.out</string>
+ <string>%s</string>
<key>StandardErrorPath</key>
- <string>/tmp/%s.err</string>
+ <string>%s</string>
</dict>
</plist>
-`, xmlEscape(label), xmlEscape(vectorBin), xmlEscape(configPath), xmlEscape(label), xmlEscape(label))
+`, xmlEscape(label), xmlEscape(vectorBin), xmlEscape(configPath), xmlEscape(stdoutPath), xmlEscape(stderrPath))
}
func xmlEscape(s string) string {
diff --git a/cli/beacon/internal/endpoint/service/forwarder_test.go b/cli/beacon/internal/endpoint/service/forwarder_test.go
index 78d92120..30de0443 100644
--- a/cli/beacon/internal/endpoint/service/forwarder_test.go
+++ b/cli/beacon/internal/endpoint/service/forwarder_test.go
@@ -13,7 +13,7 @@ import (
)
func TestForwarderPlistRunsVectorResidentWithKeepAlive(t *testing.T) {
- got := forwarderPlist(ForwarderLabel, "/opt/beacon/bin/vector", "/Users/me/.beacon/endpoint/asymptote/vector.toml")
+ got := forwarderPlist(ForwarderLabel, "/opt/beacon/bin/vector", "/Users/me/.beacon/endpoint/asymptote/vector.toml", "/Users/me/Library/Logs/Beacon/f.out", "/Users/me/Library/Logs/Beacon/f.err")
for _, want := range []string{
"<string>com.beacon.endpoint.asymptote-forwarder</string>",
"<string>/opt/beacon/bin/vector</string>",
@@ -30,8 +30,9 @@ func TestForwarderPlistRunsVectorResidentWithKeepAlive(t *testing.T) {
if strings.Contains(got, "StartCalendarInterval") {
t.Fatal("forwarder must be resident, not scheduled")
}
- escaped := forwarderPlist("l", "/tmp/a&b", "/tmp/<c>.toml")
- if !strings.Contains(escaped, "/tmp/a&amp;b") || !strings.Contains(escaped, "&lt;c&gt;") {
+ escaped := forwarderPlist("l", "/tmp/a&b", "/tmp/<c>.toml", `/x/"o".out`, "/x/e&.err")
+ if !strings.Contains(escaped, "/tmp/a&amp;b") || !strings.Contains(escaped, "&lt;c&gt;") ||
+ !strings.Contains(escaped, "/x/&quot;o&quot;.out") || !strings.Contains(escaped, "/x/e&amp;.err") {
t.Fatalf("plist must XML-escape paths:\n%s", escaped)
}
}
diff --git a/cli/beacon/internal/endpoint/service/inventory.go b/cli/beacon/internal/endpoint/service/inventory.go
index 4a621963..ec99694f 100644
--- a/cli/beacon/internal/endpoint/service/inventory.go
+++ b/cli/beacon/internal/endpoint/service/inventory.go
@@ -181,7 +181,14 @@ func (m InventoryManager) WriteUnit(program, logPath string) (string, error) {
}
return path, nil
}
- content := inventoryPlist(InventoryLabel, program, args, InventoryInterval(), inventoryJobLogPrefix(m.UserMode))
+ if err := ensureLaunchdLogDir(m.UserMode, InventoryLabel); err != nil {
+ return "", err
+ }
+ stdout, stderr, err := launchdLogPaths(m.UserMode, InventoryLabel)
+ if err != nil {
+ return "", err
+ }
+ content := inventoryPlist(InventoryLabel, program, args, InventoryInterval(), stdout, stderr)
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
return "", err
}
@@ -308,20 +315,9 @@ WantedBy=timers.target
`, int(interval.Seconds()), InventoryServiceUnit)
}
-// inventoryJobLogPrefix is where launchd sends the job's stdout and stderr. The user-mode path
-// carries the uid: a machine that also has (or once had) the system-mode job owns
-// /tmp/<label>.out as root, and a LaunchAgent that cannot open its own log files is refused by
-// launchd with EX_CONFIG before it ever runs.
-func inventoryJobLogPrefix(userMode bool) string {
- if userMode {
- return fmt.Sprintf("/tmp/%s.%d", InventoryLabel, os.Getuid())
- }
- return "/tmp/" + InventoryLabel
-}
-
// inventoryPlist renders the launchd job: one shot at load, then every interval. No KeepAlive,
// so launchd does not restart a job that exited normally.
-func inventoryPlist(label, program string, args []string, interval time.Duration, logPrefix string) string {
+func inventoryPlist(label, program string, args []string, interval time.Duration, stdoutPath, stderrPath string) string {
var argv strings.Builder
fmt.Fprintf(&argv, " <string>%s</string>\n", xmlEscape(program))
for _, arg := range args {
@@ -341,10 +337,10 @@ func inventoryPlist(label, program string, args []string, interval time.Duration
<key>StartInterval</key>
<integer>%d</integer>
<key>StandardOutPath</key>
- <string>%s.out</string>
+ <string>%s</string>
<key>StandardErrorPath</key>
- <string>%s.err</string>
+ <string>%s</string>
</dict>
</plist>
-`, xmlEscape(label), argv.String(), int(interval.Seconds()), xmlEscape(logPrefix), xmlEscape(logPrefix))
+`, xmlEscape(label), argv.String(), int(interval.Seconds()), xmlEscape(stdoutPath), xmlEscape(stderrPath))
}
diff --git a/cli/beacon/internal/endpoint/service/inventory_test.go b/cli/beacon/internal/endpoint/service/inventory_test.go
index 12c533cd..2718c048 100644
--- a/cli/beacon/internal/endpoint/service/inventory_test.go
+++ b/cli/beacon/internal/endpoint/service/inventory_test.go
@@ -15,38 +15,49 @@ import (
func TestInventoryPlistIsAOneShotIntervalJob(t *testing.T) {
args := inventoryJobArgs(false, "")
- got := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", args, 6*time.Hour, inventoryJobLogPrefix(false))
+ sysOut, sysErr, err := launchdLogPaths(false, InventoryLabel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ got := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", args, 6*time.Hour, sysOut, sysErr)
for _, want := range []string{
"<string>com.beacon.endpoint.inventory</string>",
"<string>/opt/beacon/bin/beacon</string>",
"<string>endpoint</string>\n <string>inventory</string>\n <string>heartbeat</string>\n <string>--scheduled</string>\n <string>--system</string>",
"<key>RunAtLoad</key>\n <true/>",
"<key>StartInterval</key>\n <integer>21600</integer>",
- "/tmp/com.beacon.endpoint.inventory.err",
+ "<string>/Library/Logs/Beacon/com.beacon.endpoint.inventory.out</string>",
+ "<string>/Library/Logs/Beacon/com.beacon.endpoint.inventory.err</string>",
} {
if !strings.Contains(got, want) {
t.Fatalf("plist missing %q:\n%s", want, got)
}
}
- for _, forbidden := range []string{"KeepAlive", "StartCalendarInterval", "--log-path"} {
+ for _, forbidden := range []string{"KeepAlive", "StartCalendarInterval", "--log-path", "/tmp/"} {
if strings.Contains(got, forbidden) {
t.Fatalf("plist must not contain %q:\n%s", forbidden, got)
}
}
- user := inventoryPlist(InventoryLabel, "/usr/local/bin/beacon", inventoryJobArgs(true, "/Users/me/.beacon/endpoint/logs/runtime.jsonl"), time.Hour, inventoryJobLogPrefix(true))
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ userOut, userErr, err := launchdLogPaths(true, InventoryLabel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ user := inventoryPlist(InventoryLabel, "/usr/local/bin/beacon", inventoryJobArgs(true, "/Users/me/.beacon/endpoint/logs/runtime.jsonl"), time.Hour, userOut, userErr)
if !strings.Contains(user, "<string>--user</string>") || strings.Contains(user, "<string>--system</string>") {
t.Fatalf("user-mode plist must carry --user:\n%s", user)
}
if !strings.Contains(user, "<string>--log-path</string>\n <string>/Users/me/.beacon/endpoint/logs/runtime.jsonl</string>") {
t.Fatalf("plist must pass the pinned log path:\n%s", user)
}
- // A user agent must not share the system daemon's root-owned /tmp log files, or launchd
- // refuses to spawn it (EX_CONFIG). Seen live on a Mac with both modes installed.
- uidSuffixed := fmt.Sprintf("/tmp/%s.%d.err", InventoryLabel, os.Getuid())
- if !strings.Contains(user, uidSuffixed) || strings.Contains(user, "/tmp/"+InventoryLabel+".err") {
- t.Fatalf("user-mode plist must log to a per-user path, got:\n%s", user)
+ // A user agent must not share the system daemon's root-owned log files, or launchd refuses to
+ // spawn it (EX_CONFIG). Seen live on a Mac with both modes installed. It logs under its own home.
+ userLogs := filepath.Join(home, "Library", "Logs", "Beacon", InventoryLabel)
+ if !strings.Contains(user, "<string>"+userLogs+".err</string>") || strings.Contains(user, "<string>/Library/Logs/Beacon/") {
+ t.Fatalf("user-mode plist must log under the user's home, got:\n%s", user)
}
- escaped := inventoryPlist("l", "/tmp/a&b", []string{"--log-path", "/tmp/<c>.jsonl"}, time.Hour, "/tmp/l")
+ escaped := inventoryPlist("l", "/tmp/a&b", []string{"--log-path", "/tmp/<c>.jsonl"}, time.Hour, "/x/l.out", "/x/l.err")
if !strings.Contains(escaped, "/tmp/a&amp;b") || !strings.Contains(escaped, "&lt;c&gt;") {
t.Fatalf("plist must XML-escape program and arguments:\n%s", escaped)
}
@@ -61,7 +72,7 @@ func TestInventoryIntervalEnvOverride(t *testing.T) {
if got := InventoryInterval(); got != time.Minute {
t.Fatalf("overridden interval = %s, want 1m", got)
}
- plist := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", inventoryJobArgs(false, ""), InventoryInterval(), inventoryJobLogPrefix(false))
+ plist := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", inventoryJobArgs(false, ""), InventoryInterval(), "/x/l.out", "/x/l.err")
if !strings.Contains(plist, "<key>StartInterval</key>\n <integer>60</integer>") {
t.Fatalf("plist should use the overridden interval:\n%s", plist)
}
diff --git a/cli/beacon/internal/endpoint/service/launchd.go b/cli/beacon/internal/endpoint/service/launchd.go
index 1fc26e56..3cc8fb41 100644
--- a/cli/beacon/internal/endpoint/service/launchd.go
+++ b/cli/beacon/internal/endpoint/service/launchd.go
@@ -103,7 +103,15 @@ func (b launchdBackend) writeUnit(userMode bool, program, configPath string) (st
if err := ensureDir(path); err != nil {
return "", err
}
- content := plist(b.label(userMode), program, configPath)
+ label := b.label(userMode)
+ if err := ensureLaunchdLogDir(userMode, label); err != nil {
+ return "", err
+ }
+ stdout, stderr, err := launchdLogPaths(userMode, label)
+ if err != nil {
+ return "", err
+ }
+ content := plist(label, program, configPath, stdout, stderr)
return path, os.WriteFile(path, []byte(content), 0o644)
}
@@ -261,13 +269,9 @@ func serviceDomain(userMode bool) string {
return "system"
}
-// launchdStderrPath is the collector job's StandardErrorPath, kept beside the plist template that
-// writes it so the two cannot drift.
-func launchdStderrPath(label string) string {
- return "/tmp/" + label + ".err"
-}
-
-func plist(label, program, configPath string) string {
+// plist renders the collector job. Every interpolated value is XML-escaped, as the forwarder,
+// updater and inventory plists are, so a path containing &, < or > cannot break the document.
+func plist(label, program, configPath, stdoutPath, stderrPath string) string {
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -285,10 +289,10 @@ func plist(label, program, configPath string) string {
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
- <string>/tmp/%s.out</string>
+ <string>%s</string>
<key>StandardErrorPath</key>
<string>%s</string>
</dict>
</plist>
-`, label, program, configPath, label, launchdStderrPath(label))
+`, xmlEscape(label), xmlEscape(program), xmlEscape(configPath), xmlEscape(stdoutPath), xmlEscape(stderrPath))
}
diff --git a/cli/beacon/internal/endpoint/service/launchd_logs.go b/cli/beacon/internal/endpoint/service/launchd_logs.go
new file mode 100644
index 00000000..174a346d
--- /dev/null
+++ b/cli/beacon/internal/endpoint/service/launchd_logs.go
@@ -0,0 +1,115 @@
+package service
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+// Where launchd sends the stdout and stderr of every job Beacon installs.
+//
+// These used to be fixed names in /tmp (/tmp/<label>.out|err). /tmp is world-writable, so any
+// local user could create one of those names before launchd did -- the updater does not run at
+// load, so its files did not exist until the first scheduled run -- and a root LaunchDaemon then
+// appended its output to a file that user owned, or, through a planted symlink, to any file on
+// the system. A user LaunchAgent's /tmp names were just as predictable to every other user.
+//
+// System daemons now log under /Library/Logs/Beacon, the macOS location for machine-wide
+// application logs, created root-owned 0755 before the plist is written so only root can create
+// or replace a file in it. It is deliberately not /var/log/beacon-agent: that directory holds the
+// runtime log hooks append to (0666 by design) and is what the forwarder packs tail, and daemon
+// stderr belongs in neither. User agents log under ~/Library/Logs/Beacon, which only that user
+// can write.
+var (
+ // launchdSystemLogDir is a variable so tests can point it at a temp dir.
+ launchdSystemLogDir = "/Library/Logs/Beacon"
+ // launchdIsRoot reports whether ownership can and must be forced to root.
+ launchdIsRoot = func() bool { return os.Geteuid() == 0 }
+)
+
+// LaunchdLogDir is the directory launchd writes Beacon job output to in this mode.
+func LaunchdLogDir(userMode bool) (string, error) {
+ if !userMode {
+ return launchdSystemLogDir, nil
+ }
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", err
+ }
+ return filepath.Join(home, "Library", "Logs", "Beacon"), nil
+}
+
+// launchdLogPaths returns a job's StandardOutPath and StandardErrorPath.
+func launchdLogPaths(userMode bool, label string) (stdout, stderr string, err error) {
+ dir, err := LaunchdLogDir(userMode)
+ if err != nil {
+ return "", "", err
+ }
+ return filepath.Join(dir, label+".out"), filepath.Join(dir, label+".err"), nil
+}
+
+// ensureLaunchdLogDir creates the log directory before any plist pointing into it is written, and
+// makes sure nothing in it can redirect a job's output.
+//
+// The system directory is forced to root-owned 0755 when running as root, replacing a symlink in
+// its place, so no other account can create or swap a file in it. The job's own two files are
+// removed when they are not plain files (a symlink would let launchd append through it) or, for a
+// daemon, not owned by root; launchd recreates them on the next start.
+func ensureLaunchdLogDir(userMode bool, label string) error {
+ dir, err := LaunchdLogDir(userMode)
+ if err != nil {
+ return err
+ }
+ mode := os.FileMode(0o755)
+ if userMode {
+ mode = 0o700
+ }
+ if fi, err := os.Lstat(dir); err == nil {
+ if fi.Mode()&os.ModeSymlink != 0 {
+ if err := os.Remove(dir); err != nil {
+ return fmt.Errorf("remove symlink at log directory %s: %w", dir, err)
+ }
+ } else if !fi.IsDir() {
+ return fmt.Errorf("log directory %s exists and is not a directory", dir)
+ }
+ } else if !os.IsNotExist(err) {
+ return err
+ }
+ if err := os.MkdirAll(dir, mode); err != nil {
+ return fmt.Errorf("create log directory %s: %w", dir, err)
+ }
+ if !userMode && launchdIsRoot() {
+ if err := os.Lchown(dir, 0, 0); err != nil {
+ return fmt.Errorf("make log directory %s root-owned: %w", dir, err)
+ }
+ }
+ // Chmod after MkdirAll: its mode is masked by umask, and an existing directory keeps its own.
+ if err := os.Chmod(dir, mode); err != nil {
+ return fmt.Errorf("set permissions on log directory %s: %w", dir, err)
+ }
+ stdout, stderr, err := launchdLogPaths(userMode, label)
+ if err != nil {
+ return err
+ }
+ for _, path := range []string{stdout, stderr} {
+ fi, err := os.Lstat(path)
+ if os.IsNotExist(err) {
+ continue
+ }
+ if err != nil {
+ return err
+ }
+ untrusted := !fi.Mode().IsRegular()
+ if !userMode && launchdIsRoot() {
+ if uid, ok := fileOwner(fi); ok && uid != 0 {
+ untrusted = true
+ }
+ }
+ if untrusted {
+ if err := os.Remove(path); err != nil {
+ return fmt.Errorf("remove untrusted log file %s: %w", path, err)
+ }
+ }
+ }
+ return nil
+}
diff --git a/cli/beacon/internal/endpoint/service/launchd_logs_test.go b/cli/beacon/internal/endpoint/service/launchd_logs_test.go
new file mode 100644
index 00000000..37aaf43d
--- /dev/null
+++ b/cli/beacon/internal/endpoint/service/launchd_logs_test.go
@@ -0,0 +1,182 @@
+package service
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
+)
+
+// pointSystemLogDir moves the system-mode launchd log directory into a temp dir and pretends the
+// test is not root, so nothing here touches /Library or tries to chown.
+func pointSystemLogDir(t *testing.T) string {
+ t.Helper()
+ dir := filepath.Join(t.TempDir(), "Logs", "Beacon")
+ oldDir, oldRoot := launchdSystemLogDir, launchdIsRoot
+ launchdSystemLogDir = dir
+ launchdIsRoot = func() bool { return false }
+ t.Cleanup(func() { launchdSystemLogDir, launchdIsRoot = oldDir, oldRoot })
+ return dir
+}
+
+// Every LaunchDaemon Beacon renders must log to the root-owned system directory and never to
+// /tmp, where any local user could pre-create the file or plant a symlink for root to append to.
+func TestSystemLaunchDaemonsNeverLogToTmp(t *testing.T) {
+ plists := map[string]string{}
+ paths := func(label string) (string, string) {
+ out, errPath, err := launchdLogPaths(false, label)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return out, errPath
+ }
+ out, errPath := paths(SystemLabel)
+ plists[SystemLabel] = plist(SystemLabel, "/opt/beacon/bin/beacon-otelcol", "/etc/beacon/endpoint/otelcol.yaml", out, errPath)
+ out, errPath = paths(ForwarderLabel)
+ plists[ForwarderLabel] = forwarderPlist(ForwarderLabel, "/opt/beacon/bin/vector", "/etc/beacon/endpoint/asymptote/vector.toml", out, errPath)
+ out, errPath = paths(UpdaterLabel)
+ plists[UpdaterLabel] = updaterPlist(UpdaterLabel, "/opt/beacon/bin/beacon", out, errPath)
+ out, errPath = paths(InventoryLabel)
+ plists[InventoryLabel] = inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", inventoryJobArgs(false, ""), InventoryInterval(), out, errPath)
+
+ for label, content := range plists {
+ if strings.Contains(content, "/tmp/") {
+ t.Errorf("%s LaunchDaemon logs to /tmp:\n%s", label, content)
+ }
+ for _, want := range []string{
+ "<key>StandardOutPath</key>\n <string>/Library/Logs/Beacon/" + label + ".out</string>",
+ "<key>StandardErrorPath</key>\n <string>/Library/Logs/Beacon/" + label + ".err</string>",
+ } {
+ if !strings.Contains(content, want) {
+ t.Errorf("%s LaunchDaemon missing %q:\n%s", label, want, content)
+ }
+ }
+ }
+}
+
+func TestUserLaunchAgentsLogUnderHome(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ want := filepath.Join(home, "Library", "Logs", "Beacon")
+ for _, label := range []string{UserLabel, ForwarderLabel, InventoryLabel} {
+ out, errPath, err := launchdLogPaths(true, label)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if out != filepath.Join(want, label+".out") || errPath != filepath.Join(want, label+".err") {
+ t.Errorf("%s user logs = %q, %q; want under %s", label, out, errPath, want)
+ }
+ }
+}
+
+func TestCollectorPlistEscapesEveryValue(t *testing.T) {
+ got := plist(`l&"x"`, "/opt/<b>/otelcol", "/etc/a&b.yaml", "/x/<o>.out", `/x/"e".err`)
+ for _, want := range []string{
+ "<string>l&amp;&quot;x&quot;</string>",
+ "<string>/opt/&lt;b&gt;/otelcol</string>",
+ "<string>/etc/a&amp;b.yaml</string>",
+ "<string>/x/&lt;o&gt;.out</string>",
+ "<string>/x/&quot;e&quot;.err</string>",
+ } {
+ if !strings.Contains(got, want) {
+ t.Errorf("collector plist missing escaped %q:\n%s", want, got)
+ }
+ }
+ for _, raw := range []string{"a&b", "<b>", `"e"`} {
+ if strings.Contains(got, raw) {
+ t.Errorf("collector plist carries unescaped %q:\n%s", raw, got)
+ }
+ }
+}
+
+func TestEnsureLaunchdLogDirCreatesTheSystemDir(t *testing.T) {
+ dir := pointSystemLogDir(t)
+ if err := ensureLaunchdLogDir(false, UpdaterLabel); err != nil {
+ t.Fatal(err)
+ }
+ fi, err := os.Lstat(dir)
+ if err != nil || !fi.IsDir() {
+ t.Fatalf("log dir not created: %v", err)
+ }
+ if testenv.HasPOSIXFileModes() && fi.Mode().Perm() != 0o755 {
+ t.Errorf("system log dir mode = %v, want 0755", fi.Mode().Perm())
+ }
+}
+
+func TestEnsureLaunchdLogDirTightensUserDir(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ dir := filepath.Join(home, "Library", "Logs", "Beacon")
+ if err := os.MkdirAll(dir, 0o777); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(dir, 0o777); err != nil {
+ t.Fatal(err)
+ }
+ if err := ensureLaunchdLogDir(true, UserLabel); err != nil {
+ t.Fatal(err)
+ }
+ fi, err := os.Stat(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if fi.Mode().Perm() != 0o700 {
+ t.Errorf("user log dir mode = %v, want 0700", fi.Mode().Perm())
+ }
+}
+
+// A symlink where the directory or a job's log file should be is removed, so launchd cannot be
+// steered into appending to its target.
+func TestEnsureLaunchdLogDirRemovesPlantedSymlinks(t *testing.T) {
+ dir := pointSystemLogDir(t)
+ target := filepath.Join(t.TempDir(), "victim")
+ if err := os.WriteFile(target, []byte("keep"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ elsewhere := t.TempDir()
+ if err := os.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(elsewhere, dir); err != nil {
+ t.Skipf("symlinks unavailable: %v", err)
+ }
+ if err := ensureLaunchdLogDir(false, UpdaterLabel); err != nil {
+ t.Fatal(err)
+ }
+ if fi, err := os.Lstat(dir); err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() {
+ t.Fatalf("symlinked log dir was not replaced by a real directory: %v", err)
+ }
+
+ _, errPath, err := launchdLogPaths(false, UpdaterLabel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(target, errPath); err != nil {
+ t.Fatal(err)
+ }
+ if err := ensureLaunchdLogDir(false, UpdaterLabel); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Lstat(errPath); !os.IsNotExist(err) {
+ t.Fatalf("planted log symlink survived: %v", err)
+ }
+ if b, err := os.ReadFile(target); err != nil || string(b) != "keep" {
+ t.Fatalf("symlink target was touched: %q, %v", b, err)
+ }
+}
+
+func TestEnsureLaunchdLogDirRefusesAFileInItsPlace(t *testing.T) {
+ dir := pointSystemLogDir(t)
+ if err := os.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(dir, nil, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := ensureLaunchdLogDir(false, UpdaterLabel); err == nil {
+ t.Fatal("a regular file at the log directory path must be refused")
+ }
+}
diff --git a/cli/beacon/internal/endpoint/service/launchd_volume_test.go b/cli/beacon/internal/endpoint/service/launchd_volume_test.go
index 5b84c590..d1853a15 100644
--- a/cli/beacon/internal/endpoint/service/launchd_volume_test.go
+++ b/cli/beacon/internal/endpoint/service/launchd_volume_test.go
@@ -59,7 +59,7 @@ func newVolumeFixture(t *testing.T) volumeFixture {
func (f volumeFixture) externalPlist(t *testing.T, label string) string {
t.Helper()
path := filepath.Join(f.external, "Library", "LaunchAgents", label+".plist")
- if err := os.WriteFile(path, []byte(plist(label, "/opt/homebrew/bin/beacon-otelcol", "/x/otelcol.yaml")), 0o644); err != nil {
+ if err := os.WriteFile(path, []byte(plist(label, "/opt/homebrew/bin/beacon-otelcol", "/x/otelcol.yaml", "/x/out", "/x/err")), 0o644); err != nil {
t.Fatal(err)
}
return path
@@ -68,7 +68,7 @@ func (f volumeFixture) externalPlist(t *testing.T, label string) string {
func (f volumeFixture) bootPlist(t *testing.T, label string) string {
t.Helper()
path := filepath.Join(f.boot, "Users", "test", "Library", "LaunchAgents", label+".plist")
- if err := os.WriteFile(path, []byte(plist(label, "/opt/homebrew/bin/beacon-otelcol", "/x/otelcol.yaml")), 0o644); err != nil {
+ if err := os.WriteFile(path, []byte(plist(label, "/opt/homebrew/bin/beacon-otelcol", "/x/otelcol.yaml", "/x/out", "/x/err")), 0o644); err != nil {
t.Fatal(err)
}
return path
diff --git a/cli/beacon/internal/endpoint/service/service.go b/cli/beacon/internal/endpoint/service/service.go
index 0aa7b8df..3d82ad85 100644
--- a/cli/beacon/internal/endpoint/service/service.go
+++ b/cli/beacon/internal/endpoint/service/service.go
@@ -328,7 +328,11 @@ type CollectorLog struct {
func (m Manager) CollectorLog() CollectorLog {
switch b := m.backend().(type) {
case launchdBackend:
- return CollectorLog{Path: launchdStderrPath(b.label(m.UserMode))}
+ _, stderr, err := launchdLogPaths(m.UserMode, b.label(m.UserMode))
+ if err != nil {
+ return CollectorLog{}
+ }
+ return CollectorLog{Path: stderr}
case supervisedBackend:
return CollectorLog{Path: supervisedLogPath(m.UserMode)}
case systemdBackend:
diff --git a/cli/beacon/internal/endpoint/service/service_test.go b/cli/beacon/internal/endpoint/service/service_test.go
index ed819667..e3cb6bb4 100644
--- a/cli/beacon/internal/endpoint/service/service_test.go
+++ b/cli/beacon/internal/endpoint/service/service_test.go
@@ -13,7 +13,7 @@ import (
)
func TestPlistContainsLaunchdContract(t *testing.T) {
- content := plist(UserLabel, "/tmp/otelcol", "/tmp/otelcol.yaml")
+ content := plist(UserLabel, "/tmp/otelcol", "/tmp/otelcol.yaml", "/Users/me/Library/Logs/Beacon/"+UserLabel+".out", "/Users/me/Library/Logs/Beacon/"+UserLabel+".err")
for _, want := range []string{
"<string>" + UserLabel + "</string>",
@@ -22,8 +22,8 @@ func TestPlistContainsLaunchdContract(t *testing.T) {
"<string>/tmp/otelcol.yaml</string>",
"<key>RunAtLoad</key>",
"<key>KeepAlive</key>",
- "<string>/tmp/" + UserLabel + ".out</string>",
- "<string>/tmp/" + UserLabel + ".err</string>",
+ "<key>StandardOutPath</key>\n <string>/Users/me/Library/Logs/Beacon/" + UserLabel + ".out</string>",
+ "<key>StandardErrorPath</key>\n <string>/Users/me/Library/Logs/Beacon/" + UserLabel + ".err</string>",
} {
if !strings.Contains(content, want) {
t.Fatalf("plist missing %q:\n%s", want, content)
diff --git a/cli/beacon/internal/endpoint/service/updater.go b/cli/beacon/internal/endpoint/service/updater.go
index b37f333f..cbd86f8c 100644
--- a/cli/beacon/internal/endpoint/service/updater.go
+++ b/cli/beacon/internal/endpoint/service/updater.go
@@ -127,7 +127,15 @@ func (m UpdaterManager) WriteUnit(program string) (string, error) {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return "", err
}
- return path, os.WriteFile(path, []byte(updaterPlist(UpdaterLabel, program)), 0o644)
+ // The updater is only ever a LaunchDaemon, so its output goes to the root-owned system dir.
+ if err := ensureLaunchdLogDir(false, UpdaterLabel); err != nil {
+ return "", err
+ }
+ stdout, stderr, err := launchdLogPaths(false, UpdaterLabel)
+ if err != nil {
+ return "", err
+ }
+ return path, os.WriteFile(path, []byte(updaterPlist(UpdaterLabel, program, stdout, stderr)), 0o644)
}
// writeSystemdUnits writes the oneshot service plus the timer that drives it.
@@ -270,7 +278,7 @@ WantedBy=timers.target
// updaterPlist renders the updater LaunchDaemon. It runs at business-hour intervals in local
// time and does not RunAtLoad or KeepAlive; each invocation resolves the configured mode.
-func updaterPlist(label, program string) string {
+func updaterPlist(label, program, stdoutPath, stderrPath string) string {
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -320,12 +328,12 @@ func updaterPlist(label, program string) string {
<key>RunAtLoad</key>
<false/>
<key>StandardOutPath</key>
- <string>/tmp/%s.out</string>
+ <string>%s</string>
<key>StandardErrorPath</key>
- <string>/tmp/%s.err</string>
+ <string>%s</string>
</dict>
</plist>
-`, label, program, label, label)
+`, xmlEscape(label), xmlEscape(program), xmlEscape(stdoutPath), xmlEscape(stderrPath))
}
func shellQuote(s string) string {
diff --git a/cli/beacon/internal/endpoint/service/updater_test.go b/cli/beacon/internal/endpoint/service/updater_test.go
index 5d99fee2..ec209290 100644
--- a/cli/beacon/internal/endpoint/service/updater_test.go
+++ b/cli/beacon/internal/endpoint/service/updater_test.go
@@ -8,7 +8,11 @@ import (
)
func TestUpdaterPlistContent(t *testing.T) {
- out := updaterPlist(UpdaterLabel, "/opt/beacon/bin/beacon")
+ stdout, stderr, err := launchdLogPaths(false, UpdaterLabel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ out := updaterPlist(UpdaterLabel, "/opt/beacon/bin/beacon", stdout, stderr)
for _, want := range []string{
"<string>com.beacon.endpoint.updater</string>",
"<string>/opt/beacon/bin/beacon</string>",
@@ -17,6 +21,8 @@ func TestUpdaterPlistContent(t *testing.T) {
"<array>",
"<key>Minute</key>",
"<integer>0</integer>",
+ "<key>StandardOutPath</key>\n <string>/Library/Logs/Beacon/com.beacon.endpoint.updater.out</string>",
+ "<key>StandardErrorPath</key>\n <string>/Library/Logs/Beacon/com.beacon.endpoint.updater.err</string>",
} {
if !strings.Contains(out, want) {
t.Errorf("plist missing %q", want)
@@ -37,6 +43,15 @@ func TestUpdaterPlistContent(t *testing.T) {
if !strings.Contains(out, "<key>RunAtLoad</key>\n <false/>") {
t.Errorf("updater plist should set RunAtLoad false")
}
+ if strings.Contains(out, "/tmp/") {
+ t.Errorf("updater LaunchDaemon must not log to world-writable /tmp:\n%s", out)
+ }
+ escaped := updaterPlist("l&", "/opt/<b>/beacon", `/x/"o".out`, "/x/e.err")
+ for _, want := range []string{"<string>l&amp;</string>", "/opt/&lt;b&gt;/beacon", "/x/&quot;o&quot;.out"} {
+ if !strings.Contains(escaped, want) {
+ t.Errorf("updater plist must XML-escape %q:\n%s", want, escaped)
+ }
+ }
}
func TestUpdaterPlistPath(t *testing.T) {
diff --git a/docs/guides/fleet-s3-mdm.mdx b/docs/guides/fleet-s3-mdm.mdx
index 5910095e..f10408f6 100644
--- a/docs/guides/fleet-s3-mdm.mdx
+++ b/docs/guides/fleet-s3-mdm.mdx
@@ -451,7 +451,7 @@ When you remove Beacon everywhere, also delete the IAM access key and the two Fl
```bash
sudo launchctl print system/com.beacon.endpoint.s3-forwarder | grep -E 'state =|last exit code'
- sudo tail -n 50 /tmp/com.beacon.endpoint.s3-forwarder.err
+ sudo tail -n 50 /Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err
```
If `launchctl` can't find the service, run `beacon-configure-s3-forwarding.sh` again. To confirm the credentials file exists without printing the keys:
@@ -464,7 +464,7 @@ When you remove Beacon everywhere, also delete the IAM access key and the two Fl
If uploads arrive anyway, the IAM user is missing `s3:ListBucket`, which only the startup check uses. Add it or ignore the error; see [step 2](#2-prepare-s3). If nothing arrives, check the key, the region, and any bucket policy that requires encryption headers.
</Accordion>
<Accordion title="An update failed with &quot;could not restore existing forwarder&quot;">
- The new package installed, but the S3 forwarder didn't stay running afterwards. Check `/tmp/com.beacon.endpoint.s3-forwarder.err` on the Mac, fix the cause, and run `beacon-configure-s3-forwarding.sh` again.
+ The new package installed, but the S3 forwarder didn't stay running afterwards. Check `/Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err` on the Mac, fix the cause, and run `beacon-configure-s3-forwarding.sh` again.
</Accordion>
<Accordion title="Self-updates aren't running">
```bash
diff --git a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
index 6c561a5a..54b4b56a 100644
--- a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
+++ b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
@@ -455,7 +455,7 @@ Check the forwarder:
```bash
sudo launchctl print system/com.beacon.endpoint.s3-forwarder
-sudo tail -n 100 /tmp/com.beacon.endpoint.s3-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err
```
If `launchctl` reports `Could not find service "com.beacon.endpoint.s3-forwarder"`,
diff --git a/docs/guides/jamf-falcon-mdm.mdx b/docs/guides/jamf-falcon-mdm.mdx
index ffef0cda..447401a8 100644
--- a/docs/guides/jamf-falcon-mdm.mdx
+++ b/docs/guides/jamf-falcon-mdm.mdx
@@ -212,7 +212,7 @@ Both services should report `state = running`.
### Check forwarder logs
```bash
-sudo tail -n 50 /tmp/com.beacon.endpoint.falcon-forwarder.err
+sudo tail -n 50 /Library/Logs/Beacon/com.beacon.endpoint.falcon-forwarder.err
```
Expected:
@@ -277,7 +277,7 @@ Check launchd and stderr:
```bash
sudo launchctl print system/com.beacon.endpoint.falcon-forwarder
-sudo tail -n 100 /tmp/com.beacon.endpoint.falcon-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.falcon-forwarder.err
```
Load it manually:
diff --git a/docs/guides/jamf-gcs-mdm.mdx b/docs/guides/jamf-gcs-mdm.mdx
index 73df8b7c..83f3df41 100644
--- a/docs/guides/jamf-gcs-mdm.mdx
+++ b/docs/guides/jamf-gcs-mdm.mdx
@@ -281,7 +281,7 @@ Check launchd and Vector stderr:
```bash
sudo launchctl print system/com.beacon.endpoint.gcs-forwarder
-sudo tail -n 100 /tmp/com.beacon.endpoint.gcs-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.gcs-forwarder.err
sudo /opt/beacon/jamf/claude/gcs/run-forwarder.sh
```
diff --git a/docs/guides/jamf-s3-mdm.mdx b/docs/guides/jamf-s3-mdm.mdx
index f83e02bd..f3bc92b4 100644
--- a/docs/guides/jamf-s3-mdm.mdx
+++ b/docs/guides/jamf-s3-mdm.mdx
@@ -449,7 +449,7 @@ Check the forwarder:
```bash
sudo launchctl print system/com.beacon.endpoint.s3-forwarder
-sudo tail -n 100 /tmp/com.beacon.endpoint.s3-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err
```
### Forwarder is not loaded
diff --git a/docs/guides/macos-object-storage-system.mdx b/docs/guides/macos-object-storage-system.mdx
index 5f7d60be..7ef9cd06 100644
--- a/docs/guides/macos-object-storage-system.mdx
+++ b/docs/guides/macos-object-storage-system.mdx
@@ -395,8 +395,8 @@ snapshot is not missed.
Check Vector errors:
```bash
-sudo tail -n 100 /tmp/com.beacon.endpoint.s3-forwarder.err
-sudo tail -n 100 /tmp/com.beacon.endpoint.gcs-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err
+sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.gcs-forwarder.err
```
Common causes of missing objects are:
diff --git a/docs/guides/rippling-gcs-mdm.mdx b/docs/guides/rippling-gcs-mdm.mdx
index 3678d4b4..575aaa08 100644
--- a/docs/guides/rippling-gcs-mdm.mdx
+++ b/docs/guides/rippling-gcs-mdm.mdx
@@ -538,7 +538,7 @@ runs Beacon's cleanup helper.
```bash
sudo launchctl print system/com.beacon.endpoint.gcs-forwarder
- sudo tail -n 100 /tmp/com.beacon.endpoint.gcs-forwarder.err
+ sudo tail -n 100 /Library/Logs/Beacon/com.beacon.endpoint.gcs-forwarder.err
sudo sh -c '
. "/Library/Application Support/Beacon/Forwarders/gcs-vector.env"
exec /opt/beacon/bin/vector validate --skip-healthchecks \
diff --git a/docs/log-forwarding/falcon.mdx b/docs/log-forwarding/falcon.mdx
index 28251fb7..e430c67f 100644
--- a/docs/log-forwarding/falcon.mdx
+++ b/docs/log-forwarding/falcon.mdx
@@ -251,7 +251,7 @@ Confirm Vector is running:
```bash title="Confirm Vector is running"
sudo launchctl print system/com.beacon.endpoint.falcon-forwarder
-tail -n 50 /tmp/com.beacon.endpoint.falcon-forwarder.err
+tail -n 50 /Library/Logs/Beacon/com.beacon.endpoint.falcon-forwarder.err
```
Generate a unique Claude prompt and confirm it appears locally:
diff --git a/examples/fleet/configure-beacon-macos-s3.sh b/examples/fleet/configure-beacon-macos-s3.sh
index 544ecb60..f8ed07ba 100755
--- a/examples/fleet/configure-beacon-macos-s3.sh
+++ b/examples/fleet/configure-beacon-macos-s3.sh
@@ -389,7 +389,7 @@ EOF
BEACON_POLICIES=(
"${INSTALLED_POLICY_NAME}|policies/beacon-installed|The Beacon package receipt and /opt/beacon/bin/beacon are present.|Install the Beacon Endpoint Agent software package on this host."
"Beacon: collector running|policies/collector-running|The Beacon collector (beacon-otelcol) is running as root.|Run /opt/beacon/fleet/scripts/repair.sh, or reinstall the Beacon package."
- "Beacon: S3 forwarder running|policies/s3-forwarder-running|The Vector S3 forwarder is running with the Beacon S3 config.|Run the ${CONFIGURE_S3_SCRIPT_NAME} script, then check /tmp/com.beacon.endpoint.s3-forwarder.err."
+ "Beacon: S3 forwarder running|policies/s3-forwarder-running|The Vector S3 forwarder is running with the Beacon S3 config.|Run the ${CONFIGURE_S3_SCRIPT_NAME} script, then check /Library/Logs/Beacon/com.beacon.endpoint.s3-forwarder.err."
"Beacon: S3 forwarding configured|policies/s3-forwarding-configured|The S3 forwarder env file, Vector config, and LaunchDaemon are present.|Run the ${CONFIGURE_S3_SCRIPT_NAME} script on this host."
"Beacon: inventory heartbeat within 4 days|policies/inventory-heartbeat-recent|The scheduled inventory job wrote a heartbeat in the last 96 hours. It runs every 6 hours while the Mac is awake.|Run sudo launchctl kickstart system/com.beacon.endpoint.inventory, then check sudo /opt/beacon/bin/beacon endpoint status --system."
)
diff --git a/packaging/macos/jamf/claude/falcon/install-forwarder.sh b/packaging/macos/jamf/claude/falcon/install-forwarder.sh
index 83700eac..5fff6963 100755
--- a/packaging/macos/jamf/claude/falcon/install-forwarder.sh
+++ b/packaging/macos/jamf/claude/falcon/install-forwarder.sh
@@ -6,6 +6,7 @@ VECTOR_BIN="${BEACON_VECTOR_BIN:-/opt/beacon/bin/vector}"
WRAPPER="${BEACON_FALCON_FORWARDER_WRAPPER:-/opt/beacon/jamf/claude/falcon/run-forwarder.sh}"
BASE_DIR="${BEACON_FORWARDER_BASE_DIR:-/Library/Application Support/Beacon/Forwarders}"
LAUNCHDAEMONS_DIR="${BEACON_LAUNCHDAEMONS_DIR:-/Library/LaunchDaemons}"
+LOG_DIR="${BEACON_FORWARDER_LOG_DIR:-/Library/Logs/Beacon}"
CONFIG_PATH="${BEACON_FALCON_VECTOR_CONFIG:-$BASE_DIR/falcon-vector.toml}"
ENV_PATH="${BEACON_FALCON_VECTOR_ENV:-$BASE_DIR/falcon-vector.env}"
DATA_DIR="${BEACON_FALCON_VECTOR_DATA_DIR:-$BASE_DIR/vector-data/falcon}"
@@ -85,6 +86,26 @@ include_array() {
}
mkdir -p "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR"
+
+# launchd opens StandardOutPath/StandardErrorPath as root for this daemon. They used to be fixed
+# names in world-writable /tmp, where any local user could pre-create them or plant a symlink for
+# root to append through. Keep them in a root-owned 0755 directory instead, and drop any job log
+# file that is not a plain file owned by root; launchd recreates it on the next start.
+if [ -L "$LOG_DIR" ]; then
+ rm -f "$LOG_DIR"
+fi
+mkdir -p "$LOG_DIR"
+if [ "$(id -u)" = "0" ]; then
+ chown 0:0 "$LOG_DIR"
+fi
+chmod 0755 "$LOG_DIR"
+for log_file in "$LOG_DIR/$LABEL.out" "$LOG_DIR/$LABEL.err"; do
+ if [ -L "$log_file" ] || { [ -e "$log_file" ] && [ ! -f "$log_file" ]; }; then
+ rm -rf "$log_file"
+ elif [ -e "$log_file" ] && [ "$(id -u)" = "0" ] && [ -n "$(find "$log_file" -prune ! -user 0 2>/dev/null)" ]; then
+ rm -f "$log_file"
+ fi
+done
chmod 0755 "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR" 2>/dev/null || true
INCLUDES="$(include_array)"
@@ -175,9 +196,9 @@ cat >"$PLIST_PATH" <<EOF
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
- <string>/tmp/$LABEL.out</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.out")</string>
<key>StandardErrorPath</key>
- <string>/tmp/$LABEL.err</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.err")</string>
</dict>
</plist>
EOF
@@ -204,7 +225,7 @@ else
echo "launchctl unavailable; wrote config but did not start $LABEL" >&2
fi
-if [ -f "/tmp/$LABEL.err" ]; then
+if [ -f "$LOG_DIR/$LABEL.err" ]; then
echo "Last Falcon Vector stderr lines:"
- tail -n 20 "/tmp/$LABEL.err" || true
+ tail -n 20 "$LOG_DIR/$LABEL.err" || true
fi
diff --git a/packaging/macos/jamf/claude/gcs/install-forwarder.sh b/packaging/macos/jamf/claude/gcs/install-forwarder.sh
index 549da027..69460c5f 100755
--- a/packaging/macos/jamf/claude/gcs/install-forwarder.sh
+++ b/packaging/macos/jamf/claude/gcs/install-forwarder.sh
@@ -6,6 +6,7 @@ VECTOR_BIN="${BEACON_VECTOR_BIN:-/opt/beacon/bin/vector}"
WRAPPER="${BEACON_GCS_FORWARDER_WRAPPER:-/opt/beacon/jamf/claude/gcs/run-forwarder.sh}"
BASE_DIR="${BEACON_FORWARDER_BASE_DIR:-/Library/Application Support/Beacon/Forwarders}"
LAUNCHDAEMONS_DIR="${BEACON_LAUNCHDAEMONS_DIR:-/Library/LaunchDaemons}"
+LOG_DIR="${BEACON_FORWARDER_LOG_DIR:-/Library/Logs/Beacon}"
CONFIG_PATH="${BEACON_GCS_VECTOR_CONFIG:-$BASE_DIR/gcs-vector.toml}"
ENV_PATH="${BEACON_GCS_VECTOR_ENV:-$BASE_DIR/gcs-vector.env}"
DATA_DIR="${BEACON_GCS_VECTOR_DATA_DIR:-$BASE_DIR/vector-data/gcs}"
@@ -159,6 +160,26 @@ trap cleanup_temp_files EXIT
trap 'exit 1' INT TERM
mkdir -p "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR"
+
+# launchd opens StandardOutPath/StandardErrorPath as root for this daemon. They used to be fixed
+# names in world-writable /tmp, where any local user could pre-create them or plant a symlink for
+# root to append through. Keep them in a root-owned 0755 directory instead, and drop any job log
+# file that is not a plain file owned by root; launchd recreates it on the next start.
+if [ -L "$LOG_DIR" ]; then
+ rm -f "$LOG_DIR"
+fi
+mkdir -p "$LOG_DIR"
+if [ "$(id -u)" = "0" ]; then
+ chown 0:0 "$LOG_DIR"
+fi
+chmod 0755 "$LOG_DIR"
+for log_file in "$LOG_DIR/$LABEL.out" "$LOG_DIR/$LABEL.err"; do
+ if [ -L "$log_file" ] || { [ -e "$log_file" ] && [ ! -f "$log_file" ]; }; then
+ rm -rf "$log_file"
+ elif [ -e "$log_file" ] && [ "$(id -u)" = "0" ] && [ -n "$(find "$log_file" -prune ! -user 0 2>/dev/null)" ]; then
+ rm -f "$log_file"
+ fi
+done
chmod 0755 "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR" 2>/dev/null || true
RUNTIME_INCLUDES="$(include_array "$RUNTIME_LOG_PATHS")"
@@ -289,9 +310,9 @@ cat >"$PLIST_TMP" <<EOF
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
- <string>/tmp/$LABEL.out</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.out")</string>
<key>StandardErrorPath</key>
- <string>/tmp/$LABEL.err</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.err")</string>
</dict>
</plist>
EOF
@@ -352,7 +373,7 @@ else
echo "launchctl unavailable; wrote config but did not start $LABEL" >&2
fi
-if [ -f "/tmp/$LABEL.err" ]; then
+if [ -f "$LOG_DIR/$LABEL.err" ]; then
echo "Last GCS Vector stderr lines:"
- tail -n 20 "/tmp/$LABEL.err" || true
+ tail -n 20 "$LOG_DIR/$LABEL.err" || true
fi
diff --git a/packaging/macos/jamf/claude/s3/install-forwarder.sh b/packaging/macos/jamf/claude/s3/install-forwarder.sh
index 49178fa7..f723dba3 100755
--- a/packaging/macos/jamf/claude/s3/install-forwarder.sh
+++ b/packaging/macos/jamf/claude/s3/install-forwarder.sh
@@ -6,6 +6,7 @@ VECTOR_BIN="${BEACON_VECTOR_BIN:-/opt/beacon/bin/vector}"
WRAPPER="${BEACON_S3_FORWARDER_WRAPPER:-/opt/beacon/jamf/claude/s3/run-forwarder.sh}"
BASE_DIR="${BEACON_FORWARDER_BASE_DIR:-/Library/Application Support/Beacon/Forwarders}"
LAUNCHDAEMONS_DIR="${BEACON_LAUNCHDAEMONS_DIR:-/Library/LaunchDaemons}"
+LOG_DIR="${BEACON_FORWARDER_LOG_DIR:-/Library/Logs/Beacon}"
CONFIG_PATH="${BEACON_S3_VECTOR_CONFIG:-$BASE_DIR/s3-vector.toml}"
ENV_PATH="${BEACON_S3_VECTOR_ENV:-$BASE_DIR/s3-vector.env}"
DATA_DIR="${BEACON_S3_VECTOR_DATA_DIR:-$BASE_DIR/vector-data/s3}"
@@ -126,6 +127,26 @@ inventory_paths() {
}
mkdir -p "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR"
+
+# launchd opens StandardOutPath/StandardErrorPath as root for this daemon. They used to be fixed
+# names in world-writable /tmp, where any local user could pre-create them or plant a symlink for
+# root to append through. Keep them in a root-owned 0755 directory instead, and drop any job log
+# file that is not a plain file owned by root; launchd recreates it on the next start.
+if [ -L "$LOG_DIR" ]; then
+ rm -f "$LOG_DIR"
+fi
+mkdir -p "$LOG_DIR"
+if [ "$(id -u)" = "0" ]; then
+ chown 0:0 "$LOG_DIR"
+fi
+chmod 0755 "$LOG_DIR"
+for log_file in "$LOG_DIR/$LABEL.out" "$LOG_DIR/$LABEL.err"; do
+ if [ -L "$log_file" ] || { [ -e "$log_file" ] && [ ! -f "$log_file" ]; }; then
+ rm -rf "$log_file"
+ elif [ -e "$log_file" ] && [ "$(id -u)" = "0" ] && [ -n "$(find "$log_file" -prune ! -user 0 2>/dev/null)" ]; then
+ rm -f "$log_file"
+ fi
+done
chmod 0755 "$BASE_DIR" "$DATA_DIR" "$LAUNCHDAEMONS_DIR" 2>/dev/null || true
RUNTIME_INCLUDES="$(include_array "$RUNTIME_LOG_PATHS")"
@@ -255,9 +276,9 @@ cat >"$PLIST_PATH" <<EOF
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
- <string>/tmp/$LABEL.out</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.out")</string>
<key>StandardErrorPath</key>
- <string>/tmp/$LABEL.err</string>
+ <string>$(xml_escape "$LOG_DIR/$LABEL.err")</string>
</dict>
</plist>
EOF
@@ -313,7 +334,7 @@ else
echo "launchctl unavailable; wrote config but did not start $LABEL" >&2
fi
-if [ -f "/tmp/$LABEL.err" ]; then
+if [ -f "$LOG_DIR/$LABEL.err" ]; then
echo "Last S3 Vector stderr lines:"
- tail -n 20 "/tmp/$LABEL.err" || true
+ tail -n 20 "$LOG_DIR/$LABEL.err" || true
fi
diff --git a/packaging/macos/test-endpoint-scripts.sh b/packaging/macos/test-endpoint-scripts.sh
index 5c719912..556062a2 100644
--- a/packaging/macos/test-endpoint-scripts.sh
+++ b/packaging/macos/test-endpoint-scripts.sh
@@ -11,6 +11,10 @@ FULL_CLEANUP_SCRIPT="$ROOT_DIR/packaging/macos/jamf/scripts/full-cleanup.sh"
FLEET_REPAIR_SCRIPT="$ROOT_DIR/packaging/macos/fleet/scripts/repair.sh"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
+# The forwarder installers write their LaunchDaemon logs under /Library/Logs/Beacon; keep every
+# invocation in this file inside the temp dir instead.
+BEACON_FORWARDER_LOG_DIR="$TMP_DIR/forwarder-logs"
+export BEACON_FORWARDER_LOG_DIR
sh -n "$INSTALL_SCRIPT"
sh -n "$UNINSTALL_SCRIPT"
@@ -63,6 +67,18 @@ if ! grep -q 'com.beacon.endpoint.gcs-forwarder' "$ROOT_DIR/packaging/macos/scri
echo "postinstall should restore the optional GCS forwarder" >&2
exit 1
fi
+for installer in "$ROOT_DIR"/packaging/macos/jamf/claude/*/install-forwarder.sh; do
+ # Root daemons must not log to fixed names in world-writable /tmp: a local user could pre-create
+ # the file or plant a symlink for root to append through.
+ if grep -q '/tmp/\$LABEL' "$installer"; then
+ echo "forwarder installer must not send LaunchDaemon output to /tmp: $installer" >&2
+ exit 1
+ fi
+ if ! grep -q '/Library/Logs/Beacon' "$installer"; then
+ echo "forwarder installer should log under /Library/Logs/Beacon: $installer" >&2
+ exit 1
+ fi
+done
for installer in \
"$ROOT_DIR/packaging/macos/jamf/claude/s3/install-forwarder.sh" \
"$ROOT_DIR/packaging/macos/jamf/claude/gcs/install-forwarder.sh"
@@ -644,6 +660,18 @@ if ! grep -q 'RunAtLoad' "$LAUNCHDAEMONS_DIR/com.beacon.endpoint.falcon-forwarde
echo "Falcon Vector plist missing RunAtLoad" >&2
exit 1
fi
+if ! grep -q "<string>$BEACON_FORWARDER_LOG_DIR/com.beacon.endpoint.falcon-forwarder.err</string>" "$LAUNCHDAEMONS_DIR/com.beacon.endpoint.falcon-forwarder.plist" \
+ || grep -q '/tmp/com.beacon' "$LAUNCHDAEMONS_DIR/com.beacon.endpoint.falcon-forwarder.plist"; then
+ echo "Falcon Vector plist should log under the forwarder log dir, not /tmp" >&2
+ exit 1
+fi
+case "$(ls -ld "$BEACON_FORWARDER_LOG_DIR" | awk '{print $1}')" in
+ drwxr-xr-x*) ;;
+ *)
+ echo "forwarder log dir should be 0755" >&2
+ exit 1
+ ;;
+esac
FALCON_VECTOR_STATE="$(BEACON_FORWARDER_BASE_DIR="$FORWARDER_BASE" BEACON_LAUNCHDAEMONS_DIR="$LAUNCHDAEMONS_DIR" "$ROOT_DIR/packaging/macos/jamf/extension-attributes/falcon-vector-forwarding-configured.sh")"
case "$FALCON_VECTOR_STATE" in
@@ -684,6 +712,11 @@ fi
S3_FORWARDER_BASE="$TMP_DIR/s3-forwarders"
S3_LAUNCHDAEMONS_DIR="$TMP_DIR/s3-launchdaemons"
mkdir -p "$S3_LAUNCHDAEMONS_DIR"
+# A symlink planted where the daemon's log goes must be removed, never followed.
+S3_LOG_VICTIM="$TMP_DIR/s3-log-victim"
+printf '%s\n' keep >"$S3_LOG_VICTIM"
+mkdir -p "$BEACON_FORWARDER_LOG_DIR"
+ln -sf "$S3_LOG_VICTIM" "$BEACON_FORWARDER_LOG_DIR/com.beacon.endpoint.s3-forwarder.err"
BEACON_VECTOR_BIN="$FAKE_VECTOR" \
BEACON_S3_FORWARDER_WRAPPER="$ROOT_DIR/packaging/macos/jamf/claude/s3/run-forwarder.sh" \
BEACON_FORWARDER_BASE_DIR="$S3_FORWARDER_BASE" \
@@ -712,6 +745,18 @@ if [ ! -f "$S3_LAUNCHDAEMONS_DIR/com.beacon.endpoint.s3-forwarder.plist" ]; then
echo "S3 Vector plist was not written" >&2
exit 1
fi
+if [ -L "$BEACON_FORWARDER_LOG_DIR/com.beacon.endpoint.s3-forwarder.err" ]; then
+ echo "S3 forwarder installer should remove a symlink planted at its log path" >&2
+ exit 1
+fi
+if [ "$(cat "$S3_LOG_VICTIM")" != "keep" ]; then
+ echo "S3 forwarder installer touched the planted symlink's target" >&2
+ exit 1
+fi
+if ! grep -q "<string>$BEACON_FORWARDER_LOG_DIR/com.beacon.endpoint.s3-forwarder.out</string>" "$S3_LAUNCHDAEMONS_DIR/com.beacon.endpoint.s3-forwarder.plist"; then
+ echo "S3 Vector plist should log under the forwarder log dir" >&2
+ exit 1
+fi
if ! grep -q 'sinks.beacon_runtime_s3' "$S3_FORWARDER_BASE/s3-vector.toml"; then
echo "S3 Vector config missing sink" >&2
exit 1