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
endpoint: keep a restricted log restricted across reinstall and Jamf repair
Claude4a5c27ed61a1
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.goindex 1825407c..9772c465 100644--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go@@ -1107,6 +1107,11 @@ func buildConfig(opts InstallOptions) endpointconfig.Config {// The log access mode is an operator's security choice; a repair or upgrade that dropped// it would silently make a restricted log world-writable again.cfg.LogAccess = existing.LogAccess+ } else if !opts.UserMode && logIsRestricted(cfg.LogPath) {+ // No config to carry the mode over from -- an uninstall with --keep-logs removed it, or it+ // does not load -- but the root-owned marker beside the kept log still records restricted.+ // Defaulting to shared here would make every kept event world-readable.+ cfg.LogAccess = asymptoteobserve.LogAccessRestricted}if opts.LogAccess != "" {cfg.LogAccess = opts.LogAccessdiff --git a/cli/beacon/internal/endpoint/lifecycle/logaccess_test.go b/cli/beacon/internal/endpoint/lifecycle/logaccess_test.goindex 28852f56..0b17bd0d 100644--- a/cli/beacon/internal/endpoint/lifecycle/logaccess_test.go+++ b/cli/beacon/internal/endpoint/lifecycle/logaccess_test.go@@ -2,6 +2,8 @@ package lifecycleimport ("errors"+ "os"+ "path/filepath""runtime""strings""testing"@@ -10,6 +12,7 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/loggroup""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/service""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// A repair or package upgrade re-runs install, which rebuilds config.json. A restricted log that@@ -32,6 +35,28 @@ func TestBuildConfigWithoutAnExistingConfigIsShared(t *testing.T) {}}+// uninstall --keep-logs removes config.json but keeps the log, its archives and the marker. A+// reinstall without --log-access must keep them restricted rather than share them.+func TestBuildConfigWithoutAConfigKeepsTheModeTheMarkerRecords(t *testing.T) {+ testenv.SetHome(t, t.TempDir())+ if _, err := endpointconfig.Load(false); err == nil {+ t.Skip("this machine has a system endpoint config")+ }+ logPath := filepath.Join(t.TempDir(), "beacon-agent", "runtime.jsonl")+ if err := os.MkdirAll(filepath.Dir(logPath), 0o755); err != nil {+ t.Fatal(err)+ }+ if err := asymptoteobserve.SetRuntimeLogAccess(logPath, asymptoteobserve.LogAccessRestricted); err != nil {+ t.Fatal(err)+ }+ if cfg := buildConfig(InstallOptions{LogPath: logPath}); cfg.LogAccess != asymptoteobserve.LogAccessRestricted {+ t.Fatalf("LogAccess = %q, want the marker's restricted mode kept", cfg.LogAccess)+ }+ if cfg := buildConfig(InstallOptions{LogPath: logPath, LogAccess: "shared"}); cfg.LogAccess != "shared" {+ t.Fatalf("LogAccess = %q, want an explicit shared to win", cfg.LogAccess)+ }+}+func TestValidateLogAccess(t *testing.T) {system := func(mode string) endpointconfig.Config {return endpointconfig.Config{UserMode: false, LogAccess: mode}diff --git a/packaging/macos/jamf/claude/common/repair-hooks.sh b/packaging/macos/jamf/claude/common/repair-hooks.shindex 373b8b35..c56bcdc6 100755--- a/packaging/macos/jamf/claude/common/repair-hooks.sh+++ b/packaging/macos/jamf/claude/common/repair-hooks.sh@@ -38,16 +38,30 @@ ARGS=(echo "Repairing Beacon system endpoint...""$BEACON_BIN" "${ARGS[@]}"-echo "Preparing runtime log path for user-run hooks..."-mkdir -p "$RUNTIME_DIR"-touch "$RUNTIME_LOG" "$RUNTIME_LOCK" "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"-chown root:wheel "$RUNTIME_DIR" "$RUNTIME_LOG" "$RUNTIME_LOCK" "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"-chmod 755 "$RUNTIME_DIR"-# Runtime log and lock stay 666 so user-run hooks can append even when a-# root-owned rotation or collector recreates them; Beacon's writers use the-# same shared mode.-chmod 666 "$RUNTIME_LOG" "$RUNTIME_LOCK"-chmod 644 "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"+# In the restricted log access mode (`--log-access restricted`) only the collector writes the+# runtime log: hooks hand their events to it over the ingest socket, and the directory and log+# belong to root:beacon-log with no access for anyone else. The repair above kept that mode, so+# none of the shared-mode preparation, grants or write checks below apply; running them would+# make the log world-writable again.+LOG_ACCESS=shared+if grep -qx restricted "$RUNTIME_DIR/.beacon-log-access" 2>/dev/null; then+ LOG_ACCESS=restricted+fi++if [ "$LOG_ACCESS" = shared ]; then+ echo "Preparing runtime log path for user-run hooks..."+ mkdir -p "$RUNTIME_DIR"+ touch "$RUNTIME_LOG" "$RUNTIME_LOCK" "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"+ chown root:wheel "$RUNTIME_DIR" "$RUNTIME_LOG" "$RUNTIME_LOCK" "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"+ chmod 755 "$RUNTIME_DIR"+ # Runtime log and lock stay 666 so user-run hooks can append even when a+ # root-owned rotation or collector recreates them; Beacon's writers use the+ # same shared mode.+ chmod 666 "$RUNTIME_LOG" "$RUNTIME_LOCK"+ chmod 644 "$INVENTORY_LOG" "$INVENTORY_LOCK" "$INVENTORY_STATE" "$INVENTORY_STATE_LOCK"+else+ echo "Runtime log is in the restricted access mode; hooks deliver through the collector."+fiCONSOLE_USER="$(stat -f %Su /dev/console 2>/dev/null || true)"@@ -95,7 +109,6 @@ sudo -u "$CONSOLE_USER" mkdir -p "$HOOK_DIR"sudo -u "$CONSOLE_USER" chmod 755 "$HOME_DIR/.beacon" "$HOME_DIR/.beacon/endpoint" "$HOOK_DIR"sudo -u "$CONSOLE_USER" rm -f "$HOOK_BIN"-echo "Granting $CONSOLE_USER append access to Beacon runtime and inventory logs..."# The directory stays root-owned 0755 with no grant to add or remove entries: hooks only append# to the files below. Such a grant would let a user swap a log for a link that the root collector# and inventory job then open. Earlier versions of this script, and the Jamf guide's snippet,@@ -110,13 +123,33 @@ revoke_entry_grants() {chmod -a# "$index" "$1"done}-revoke_entry_grants "$RUNTIME_DIR"-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$RUNTIME_LOG" || true-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$RUNTIME_LOCK" || true-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_LOG" || true-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_LOCK" || true-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_STATE" || true-chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_STATE_LOCK" || true+# A restricted log keeps no per-user grant at all: one an earlier shared-mode run of this script+# left would still let that user read and rewrite every account's events.+revoke_file_grants() {+ [ -e "$1" ] || return 0+ ls -led "$1" |+ awk '$1 ~ /^[0-9]+:$/ && / allow / && /read|write|append/ { sub(":", "", $1); print $1 }' |+ sort -rn |+ while read -r index; do+ chmod -a# "$index" "$1"+ done+}+if [ -d "$RUNTIME_DIR" ]; then+ revoke_entry_grants "$RUNTIME_DIR"+fi+if [ "$LOG_ACCESS" = shared ]; then+ echo "Granting $CONSOLE_USER append access to Beacon runtime and inventory logs..."+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$RUNTIME_LOG" || true+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$RUNTIME_LOCK" || true+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_LOG" || true+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_LOCK" || true+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_STATE" || true+ chmod +a "$CONSOLE_USER allow read,write,append,readattr,writeattr,readextattr,writeextattr" "$INVENTORY_STATE_LOCK" || true+else+ echo "Revoking per-user grants on the restricted runtime log..."+ revoke_file_grants "$RUNTIME_LOG"+ revoke_file_grants "$RUNTIME_LOCK"+fiecho "Installing Claude Code hooks as $CONSOLE_USER..."sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" "$BEACON_BIN" endpoint hooks install \@@ -131,13 +164,15 @@ if [ ! -x "$HOOK_BIN" ]; thenexit 1fi-echo "Validating hook write permissions..."-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$RUNTIME_LOG"-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$RUNTIME_LOCK'"-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$INVENTORY_LOG"-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$INVENTORY_LOCK'"-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$INVENTORY_STATE"-sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$INVENTORY_STATE_LOCK'"+if [ "$LOG_ACCESS" = shared ]; then+ echo "Validating hook write permissions..."+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$RUNTIME_LOG"+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$RUNTIME_LOCK'"+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$INVENTORY_LOG"+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$INVENTORY_LOCK'"+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" test -w "$INVENTORY_STATE"+ sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" sh -c ": >> '$INVENTORY_STATE_LOCK'"+fiecho "Running manual Claude hook smoke test..."sudo -u "$CONSOLE_USER" HOME="$HOME_DIR" BEACON_SMOKE_RUNTIME_LOG="$RUNTIME_LOG" sh -lc 'diff --git a/packaging/macos/test-endpoint-scripts.sh b/packaging/macos/test-endpoint-scripts.shindex d1647b6c..8b08626e 100644--- a/packaging/macos/test-endpoint-scripts.sh+++ b/packaging/macos/test-endpoint-scripts.sh@@ -1168,6 +1168,12 @@ STUB# The log directory carries grants an earlier version of the script (and the Jamf guide) left.cat >"$REPAIR_HOOKS_BIN/ls" <<'STUB'#!/bin/sh+if [ "$1" = "-led" ] && [ -f "$2" ]; then+ # A log an earlier shared-mode run granted the console user.+ printf -- '-rw-r-----+ 1 root beacon-log 0 Jan 1 00:00 %s\n' "$2"+ printf ' 0: user:hookuser allow read,write,append,readattr\n'+ exit 0+fiif [ "$1" = "-led" ]; thenprintf 'drwxr-xr-x+ 2 root wheel 64 Jan 1 00:00 %s\n' "$2"printf ' 0: user:olduser allow add_file,add_subdirectory\n'@@ -1231,6 +1237,44 @@ if ! grep -qx "sudo -u hookuser mkdir -p $REPAIR_HOOKS_HOME/.beacon/endpoint/hooecho "repair-hooks should create the hook directory as the console user and install hooks there" >&2exit 1fi+# On a restricted endpoint (the marker beside the log) the script must leave the log's+# root:beacon-log ownership and 0640 mode alone, grant nobody anything, and revoke the per-user+# grants an earlier shared-mode run left on the log and its lock.+REPAIR_HOOKS_RESTRICTED="$TMP_DIR/repair-hooks-restricted"+mkdir -p "$REPAIR_HOOKS_RESTRICTED"+printf 'restricted\n' >"$REPAIR_HOOKS_RESTRICTED/.beacon-log-access"+: >"$REPAIR_HOOKS_RESTRICTED/runtime.jsonl"+: >"$REPAIR_HOOKS_RESTRICTED/runtime.jsonl.lock"+/bin/chmod 640 "$REPAIR_HOOKS_RESTRICTED/runtime.jsonl" "$REPAIR_HOOKS_RESTRICTED/runtime.jsonl.lock"+: >"$REPAIR_HOOKS_CALLS"+REPAIR_HOOKS_LOGS_SHARED="$REPAIR_HOOKS_LOGS"+REPAIR_HOOKS_LOGS="$REPAIR_HOOKS_RESTRICTED"+run_repair_hooks || {+ echo "repair-hooks should succeed on a restricted endpoint" >&2+ exit 1+}+REPAIR_HOOKS_LOGS="$REPAIR_HOOKS_LOGS_SHARED"+for file in runtime.jsonl runtime.jsonl.lock; do+ if [ "$(stat -f %Lp "$REPAIR_HOOKS_RESTRICTED/$file" 2>/dev/null || stat -c %a "$REPAIR_HOOKS_RESTRICTED/$file")" != 640 ]; then+ echo "repair-hooks changed the mode of the restricted $file" >&2+ exit 1+ fi+done+if grep -q -e "^chown .*$REPAIR_HOOKS_RESTRICTED" -e '^acl +a' "$REPAIR_HOOKS_CALLS"; then+ echo "repair-hooks must not chown or grant anything on a restricted log" >&2+ exit 1+fi+if [ -e "$REPAIR_HOOKS_RESTRICTED/inventory_state.jsonl" ]; then+ echo "repair-hooks must not create files in a restricted log directory" >&2+ exit 1+fi+for file in runtime.jsonl runtime.jsonl.lock; do+ if ! grep -qx "acl -a# 0 $REPAIR_HOOKS_RESTRICTED/$file" "$REPAIR_HOOKS_CALLS"; then+ echo "repair-hooks should revoke the per-user grant on the restricted $file" >&2+ exit 1+ fi+done+# A ~/.beacon the user turned into a symlink is refused, not followed as root.REPAIR_HOOKS_VICTIM="$TMP_DIR/repair-hooks-victim"mkdir -p "$REPAIR_HOOKS_VICTIM"