Skip to content

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

Write a system install's user runtime config as that user, not root

Claudec7b0b3e3a802
diff --git a/cli/beacon/cmd/endpoint.go b/cli/beacon/cmd/endpoint.go
index b21fd120..39054ade 100644
--- a/cli/beacon/cmd/endpoint.go
+++ b/cli/beacon/cmd/endpoint.go
@@ -395,6 +395,7 @@ func init() {
endpointHooksCmd.AddCommand(endpointHooksStatusCmd)
endpointHooksCmd.AddCommand(endpointHooksRepairInstalledCmd)
endpointUserConfigCmd.AddCommand(endpointUserConfigRepairInstalledCmd)
+ endpointUserConfigCmd.AddCommand(endpointUserConfigApplyNativeCmd)
endpointTracesCmd.AddCommand(endpointTracesStatusCmd)
endpointTracesCmd.AddCommand(endpointTracesReindexCmd)
endpointTracesCmd.AddCommand(endpointTracesListCmd)
@@ -585,6 +586,9 @@ func init() {
endpointUserConfigRepairInstalledCmd.Flags().StringVar(&endpointOpts.hookHarnesses, "harness", "claude,codex,cursor", "Comma-separated user runtime configs to repair")
endpointUserConfigRepairInstalledCmd.Flags().StringVar(&endpointOpts.hookLevel, "level", "user", "Hook install level: user or project")
endpointUserConfigRepairInstalledCmd.Flags().BoolVar(&endpointOpts.jsonOutput, "json", false, "Print repair result as JSON")
+ endpointUserConfigApplyNativeCmd.Flags().StringVar(&applyNativeOpts.harnesses, "harness", "claude,codex", "Comma-separated native runtime configs to write: claude, codex, gemini")
+ endpointUserConfigApplyNativeCmd.Flags().IntVar(&applyNativeOpts.grpcPort, "grpc-port", 4317, "Local collector OTLP gRPC port")
+ endpointUserConfigApplyNativeCmd.Flags().BoolVar(&applyNativeOpts.captureModelContext, "claude-capture-model-context", false, "Ask Claude Code for inline API bodies")
endpointHooksInstallCmd.Flags().BoolVar(&endpointOpts.allTargets, "all", false, "Target all supported hook harnesses")
endpointHooksInstallCmd.Flags().BoolVar(&endpointOpts.dryRun, "dry-run", false, "Print planned hook actions without changing files")
endpointHooksUninstallCmd.Flags().BoolVar(&endpointOpts.allTargets, "all", false, "Target all supported hook harnesses")
diff --git a/cli/beacon/cmd/endpoint_hooks_repair.go b/cli/beacon/cmd/endpoint_hooks_repair.go
index 8bfb35a0..95ebc423 100644
--- a/cli/beacon/cmd/endpoint_hooks_repair.go
+++ b/cli/beacon/cmd/endpoint_hooks_repair.go
@@ -383,10 +383,24 @@ func defaultRunHookRepairAsUser(info consoleUserInfo, args ...string) error {
if runtime.GOOS == "windows" {
return runHookRepairInProfile(ctx, bin, info, args...)
}
- // runuser is the root-side tool for this and ships with util-linux, so it is present on a
- // minimal Debian or RPM system where sudo may not be installed at all -- and a package
- // postinstall runs as root, which is exactly runuser's precondition. sudo remains the path
- // everywhere else, including macOS.
+ out, err := consoleUserCommand(ctx, info, bin, args...).CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("refresh hooks for %s: %s: %w", info.Username, strings.TrimSpace(string(out)), err)
+ }
+ if text := strings.TrimSpace(string(out)); text != "" {
+ fmt.Println(text)
+ }
+ return nil
+}
+
+// consoleUserCommand runs bin with args as the console user on POSIX, with that user's HOME.
+//
+// runuser is the root-side tool for this and ships with util-linux, so it is present on a minimal
+// Debian or RPM system where sudo may not be installed at all -- and a package postinstall runs as
+// root, which is exactly runuser's precondition. sudo remains the path everywhere else, including
+// macOS. Hook repair and native config repair share it so the two cannot disagree about who they
+// run as.
+func consoleUserCommand(ctx context.Context, info consoleUserInfo, bin string, args ...string) *exec.Cmd {
launcher, cmdArgs := "sudo", []string{"-u", info.Username}
if runtime.GOOS == "linux" && os.Geteuid() == 0 {
if path, err := exec.LookPath("runuser"); err == nil {
@@ -396,14 +410,7 @@ func defaultRunHookRepairAsUser(info consoleUserInfo, args ...string) error {
cmdArgs = append(cmdArgs, "env", "HOME="+info.HomeDir, "USER="+info.Username,
"LOGNAME="+info.Username, bin)
cmdArgs = append(cmdArgs, args...)
- out, err := exec.CommandContext(ctx, launcher, cmdArgs...).CombinedOutput()
- if err != nil {
- return fmt.Errorf("refresh hooks for %s: %s: %w", info.Username, strings.TrimSpace(string(out)), err)
- }
- if text := strings.TrimSpace(string(out)); text != "" {
- fmt.Println(text)
- }
- return nil
+ return exec.CommandContext(ctx, launcher, cmdArgs...)
}
// runHookRepairInProfile re-runs this binary against another user's profile on Windows.
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index 1045d052..c63f50ad 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -228,7 +228,17 @@ func TestPlannedInstallActionsSeparatesHookHarnesses(t *testing.T) {
}
}
+// writeNativeConfigInProcess runs native config repair in this process, the non-root path, so a
+// test that checks what the writers produce does not depend on whether the suite runs as root.
+func writeNativeConfigInProcess(t *testing.T) {
+ t.Helper()
+ old := writeAsConsoleUser
+ t.Cleanup(func() { writeAsConsoleUser = old })
+ writeAsConsoleUser = func() bool { return false }
+}
+
func TestRepairInstalledEndpointUserConfigConfiguresNativeAndHooks(t *testing.T) {
+ writeNativeConfigInProcess(t)
oldOpts := endpointOpts
oldActiveConsoleUser := activeConsoleUser
oldRunHookRepairAsUser := runHookRepairAsUser
@@ -342,6 +352,7 @@ func TestRepairInstalledEndpointUserConfigConfiguresNativeAndHooks(t *testing.T)
}
func TestRepairInstalledEndpointUserConfigAllowsNativeOnlyHarness(t *testing.T) {
+ writeNativeConfigInProcess(t)
oldOpts := endpointOpts
oldActiveConsoleUser := activeConsoleUser
oldRunHookRepairAsUser := runHookRepairAsUser
@@ -379,6 +390,7 @@ func TestRepairInstalledEndpointUserConfigAllowsNativeOnlyHarness(t *testing.T)
}
func TestRepairInstalledEndpointUserConfigHonorsHookOnlyAliases(t *testing.T) {
+ writeNativeConfigInProcess(t)
oldOpts := endpointOpts
oldActiveConsoleUser := activeConsoleUser
oldRunHookRepairAsUser := runHookRepairAsUser
diff --git a/cli/beacon/cmd/endpoint_user_config.go b/cli/beacon/cmd/endpoint_user_config.go
index 44257f3a..f887ac3a 100644
--- a/cli/beacon/cmd/endpoint_user_config.go
+++ b/cli/beacon/cmd/endpoint_user_config.go
@@ -1,12 +1,17 @@
package cmd
import (
+ "bytes"
+ "context"
"encoding/json"
"fmt"
"os"
"path/filepath"
+ "runtime"
"sort"
+ "strconv"
"strings"
+ "time"
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/harness"
@@ -131,70 +136,157 @@ func resolveUserConfigTargets(values []string) (userConfigTargets, error) {
return targets, nil
}
+// nativeConfigOptions is what the native runtime configs are rendered from. It is passed to the
+// child process on its command line, so it holds only plain values.
+type nativeConfigOptions struct {
+ GRPCPort int
+ CaptureModelContext bool
+}
+
+// nativeConfigResult is what apply-native reports back to the root-side repair.
+type nativeConfigResult struct {
+ Targets []string `json:"native_config_targets"`
+ Paths []string `json:"native_config_paths"`
+}
+
+var (
+ // writeAsConsoleUser reports whether native config must be written by a child process running
+ // as the console user rather than by this process. True for root on POSIX: see
+ // repairNativeRuntimeConfigForUser.
+ writeAsConsoleUser = defaultWriteAsConsoleUser
+ runNativeConfigAsUser = defaultRunNativeConfigAsUser
+)
+
+func defaultWriteAsConsoleUser() bool {
+ return runtime.GOOS != "windows" && os.Geteuid() == 0
+}
+
+// repairNativeRuntimeConfigForUser points the console user's Claude Code, Codex and Gemini configs
+// at the collector.
+//
+// A system install runs this as root, and root must not write into a home directory its owner
+// controls. The writers read and write paths such as ~/.claude/settings.json and their backups with
+// ordinary file calls, which follow symlinks: with ~/.claude linked to /etc, or settings.json to
+// /etc/shadow, a root writer edits or copies system files, and the chown that used to hand the
+// results back to the user then gave them ownership of the target. A package postinstall and the
+// scheduled updater both run this unattended, so any code running as that user -- a package script,
+// a prompt-injected agent -- could turn the next upgrade into root.
+//
+// So as root on POSIX the work runs in a child process that has dropped to the user, through the
+// same runuser/sudo launcher hook repair uses. Every file is then created by the user, with the
+// user's own permissions, and nothing needs chowning; a symlink the user planted can only lead to
+// files they could already write. Windows keeps the in-process path: an elevated process there
+// writes into a profile whose ACL already grants its owner full control (see
+// runHookRepairInProfile).
func repairNativeRuntimeConfigForUser(info consoleUserInfo, cfg endpointconfig.Config, targets []string) ([]string, []string, error) {
- grpcEndpoint := fmt.Sprintf("http://127.0.0.1:%d", cfg.Collector.GRPCPort)
+ if len(targets) == 0 {
+ return nil, nil, nil
+ }
+ opts := nativeConfigOptions{GRPCPort: cfg.Collector.GRPCPort, CaptureModelContext: cfg.ClaudeCaptureModelContext}
+ var result nativeConfigResult
+ var err error
+ if writeAsConsoleUser() {
+ result, err = runNativeConfigAsUser(info, targets, opts)
+ } else {
+ result, err = withUserHome(info.HomeDir, func() (nativeConfigResult, error) {
+ return applyNativeRuntimeConfig(targets, opts)
+ })
+ }
+ return result.Targets, result.Paths, err
+}
+
+// applyNativeRuntimeConfig writes the native runtime configs into the home directory of whoever
+// runs it.
+func applyNativeRuntimeConfig(targets []string, opts nativeConfigOptions) (nativeConfigResult, error) {
+ grpcEndpoint := fmt.Sprintf("http://127.0.0.1:%d", opts.GRPCPort)
seen := map[string]bool{}
- var configured []string
- var paths []string
- _, err := withUserHome(info.HomeDir, func() (struct{}, error) {
- for _, target := range targets {
- switch strings.TrimSpace(target) {
- case "claude":
- if seen["claude"] {
- continue
- }
- path, err := harness.ConfigureClaude(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true, CaptureModelContext: cfg.ClaudeCaptureModelContext})
- if err != nil {
- return struct{}{}, err
- }
- if err := collapseUserConfigBackups(path); err != nil {
- return struct{}{}, err
- }
- if err := chownUserConfigArtifacts(info, path); err != nil {
- return struct{}{}, err
- }
- configured = append(configured, "claude")
- paths = append(paths, path)
- seen["claude"] = true
- case "codex":
- if seen["codex"] {
- continue
- }
- path, err := harness.ConfigureCodex(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true})
- if err != nil {
- return struct{}{}, err
- }
- if err := collapseUserConfigBackups(path); err != nil {
- return struct{}{}, err
- }
- if err := chownUserConfigArtifacts(info, path); err != nil {
- return struct{}{}, err
- }
- configured = append(configured, "codex")
- paths = append(paths, path)
- seen["codex"] = true
- case "gemini":
- if seen["gemini"] {
- continue
- }
- path, err := harness.ConfigureGemini(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true})
- if err != nil {
- return struct{}{}, err
- }
- if err := collapseUserConfigBackups(path); err != nil {
- return struct{}{}, err
- }
- if err := chownUserConfigArtifacts(info, path); err != nil {
- return struct{}{}, err
- }
- configured = append(configured, "gemini")
- paths = append(paths, path)
- seen["gemini"] = true
- }
+ result := nativeConfigResult{Targets: []string{}, Paths: []string{}}
+ for _, target := range targets {
+ target = strings.TrimSpace(target)
+ if seen[target] {
+ continue
+ }
+ var path string
+ var err error
+ switch target {
+ case "claude":
+ path, err = harness.ConfigureClaude(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true, CaptureModelContext: opts.CaptureModelContext})
+ case "codex":
+ path, err = harness.ConfigureCodex(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true})
+ case "gemini":
+ path, err = harness.ConfigureGemini(harness.ConfigureOptions{Endpoint: grpcEndpoint, UserMode: true})
+ default:
+ continue
}
- return struct{}{}, nil
+ if err != nil {
+ return result, err
+ }
+ if err := collapseUserConfigBackups(path); err != nil {
+ return result, err
+ }
+ result.Targets = append(result.Targets, target)
+ result.Paths = append(result.Paths, path)
+ seen[target] = true
+ }
+ return result, nil
+}
+
+var endpointUserConfigApplyNativeCmd = &cobra.Command{
+ Use: "apply-native",
+ Short: "Point this user's native runtime configs at the local collector",
+ Hidden: true,
+ SilenceUsage: true,
+ Args: cobra.NoArgs,
+ RunE: runEndpointUserConfigApplyNative,
+}
+
+var applyNativeOpts struct {
+ harnesses string
+ grpcPort int
+ captureModelContext bool
+}
+
+// runEndpointUserConfigApplyNative is the child side of a root repair: it runs as the console user
+// and writes only into that user's own home.
+func runEndpointUserConfigApplyNative(cmd *cobra.Command, _ []string) error {
+ if applyNativeOpts.grpcPort <= 0 || applyNativeOpts.grpcPort > 65535 {
+ return fmt.Errorf("--grpc-port must be a TCP port, got %d", applyNativeOpts.grpcPort)
+ }
+ result, err := applyNativeRuntimeConfig(splitCSV(applyNativeOpts.harnesses), nativeConfigOptions{
+ GRPCPort: applyNativeOpts.grpcPort,
+ CaptureModelContext: applyNativeOpts.captureModelContext,
})
- return configured, paths, err
+ if err != nil {
+ return err
+ }
+ return json.NewEncoder(cmd.OutOrStdout()).Encode(result)
+}
+
+func defaultRunNativeConfigAsUser(info consoleUserInfo, targets []string, opts nativeConfigOptions) (nativeConfigResult, error) {
+ bin, err := os.Executable()
+ if err != nil {
+ return nativeConfigResult{}, err
+ }
+ args := []string{"endpoint", "user-config", "apply-native",
+ "--harness", strings.Join(targets, ","),
+ "--grpc-port", strconv.Itoa(opts.GRPCPort)}
+ if opts.CaptureModelContext {
+ args = append(args, "--claude-capture-model-context")
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+ cmd := consoleUserCommand(ctx, info, bin, args...)
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+ out, err := cmd.Output()
+ if err != nil {
+ return nativeConfigResult{}, fmt.Errorf("configure runtimes for %s: %s: %w", info.Username, strings.TrimSpace(stderr.String()), err)
+ }
+ var result nativeConfigResult
+ if err := json.Unmarshal(out, &result); err != nil {
+ return nativeConfigResult{}, fmt.Errorf("configure runtimes for %s: read result: %w", info.Username, err)
+ }
+ return result, nil
}
func collapseUserConfigBackups(path string) error {
@@ -218,12 +310,3 @@ func collapseUserConfigBackups(path string) error {
}
return nil
}
-
-func userConfigArtifacts(path string) []string {
- artifacts := []string{filepath.Dir(path), path}
- if matches, err := filepath.Glob(path + ".beacon.*.bak"); err == nil {
- artifacts = append(artifacts, matches...)
- }
- artifacts = append(artifacts, path+".beacon.bak")
- return artifacts
-}
diff --git a/cli/beacon/cmd/endpoint_user_config_test.go b/cli/beacon/cmd/endpoint_user_config_test.go
new file mode 100644
index 00000000..83f07a70
--- /dev/null
+++ b/cli/beacon/cmd/endpoint_user_config_test.go
@@ -0,0 +1,124 @@
+package cmd
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+
+ endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
+)
+
+// As root, native config repair must not write into the console user's home itself: a symlink the
+// user planted there (~/.claude -> /etc) would turn root's writes, backups and chown into theirs.
+// It hands the work to a child running as the user, and this process touches nothing.
+func TestRepairNativeRuntimeConfigRunsAsConsoleUserWhenRoot(t *testing.T) {
+ oldWrite, oldRun := writeAsConsoleUser, runNativeConfigAsUser
+ t.Cleanup(func() { writeAsConsoleUser, runNativeConfigAsUser = oldWrite, oldRun })
+
+ home := t.TempDir()
+ outside := t.TempDir()
+ target := filepath.Join(outside, "settings.json")
+ if err := os.WriteFile(target, []byte("not yours"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(outside, filepath.Join(home, ".claude")); err != nil {
+ t.Skipf("cannot create a symlink here: %v", err)
+ }
+
+ writeAsConsoleUser = func() bool { return true }
+ var gotInfo consoleUserInfo
+ var gotTargets []string
+ var gotOpts nativeConfigOptions
+ runNativeConfigAsUser = func(info consoleUserInfo, targets []string, opts nativeConfigOptions) (nativeConfigResult, error) {
+ gotInfo, gotTargets, gotOpts = info, append([]string(nil), targets...), opts
+ return nativeConfigResult{Targets: []string{"claude"}, Paths: []string{filepath.Join(home, ".claude", "settings.json")}}, nil
+ }
+
+ cfg := endpointconfig.Default(false, "")
+ cfg.Collector.GRPCPort = 4999
+ cfg.ClaudeCaptureModelContext = true
+ info := consoleUserInfo{Username: "alice", HomeDir: home}
+ configured, paths, err := repairNativeRuntimeConfigForUser(info, cfg, []string{"claude", "codex"})
+ if err != nil {
+ t.Fatalf("repairNativeRuntimeConfigForUser: %v", err)
+ }
+ if gotInfo != info || strings.Join(gotTargets, ",") != "claude,codex" || gotOpts != (nativeConfigOptions{GRPCPort: 4999, CaptureModelContext: true}) {
+ t.Fatalf("console-user run = %#v %v %#v, want alice's home, both targets and the config's port and capture setting", gotInfo, gotTargets, gotOpts)
+ }
+ if strings.Join(configured, ",") != "claude" || len(paths) != 1 {
+ t.Fatalf("result = %v %v, want what the console-user run reported", configured, paths)
+ }
+
+ // Nothing was written through the planted link or anywhere else in the home.
+ if data, err := os.ReadFile(target); err != nil || string(data) != "not yours" {
+ t.Fatalf("file behind the planted symlink = %q, %v; want it untouched", data, err)
+ }
+ if entries, _ := os.ReadDir(outside); len(entries) != 1 {
+ t.Fatalf("files behind the planted symlink = %d, want only the original", len(entries))
+ }
+ if entries, _ := os.ReadDir(home); len(entries) != 1 {
+ t.Fatalf("home entries = %d, want only the planted link", len(entries))
+ }
+}
+
+// apply-native is the child side: it writes the native configs into the home of whoever runs it and
+// reports what it wrote.
+func TestApplyNativeWritesTheCallersHomeAndReportsPaths(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ old := applyNativeOpts
+ t.Cleanup(func() { applyNativeOpts = old })
+ applyNativeOpts.harnesses = "claude,codex,gemini,claude"
+ applyNativeOpts.grpcPort = 4999
+
+ var out bytes.Buffer
+ cmd := endpointUserConfigApplyNativeCmd
+ cmd.SetOut(&out)
+ t.Cleanup(func() { cmd.SetOut(nil) })
+ if err := runEndpointUserConfigApplyNative(cmd, nil); err != nil {
+ t.Fatalf("apply-native: %v", err)
+ }
+ var result nativeConfigResult
+ if err := json.Unmarshal(out.Bytes(), &result); err != nil {
+ t.Fatalf("apply-native output %q is not a result: %v", out.String(), err)
+ }
+ if got := strings.Join(result.Targets, ","); got != "claude,codex,gemini" {
+ t.Fatalf("targets = %q, want each once", got)
+ }
+ for _, path := range result.Paths {
+ if !strings.HasPrefix(path, home) {
+ t.Fatalf("path %s is outside the caller's home %s", path, home)
+ }
+ data, err := os.ReadFile(path)
+ if err != nil || !strings.Contains(string(data), "127.0.0.1:4999") {
+ t.Fatalf("%s = %q, %v; want it pointed at the collector port", path, data, err)
+ }
+ }
+
+ applyNativeOpts.grpcPort = 0
+ if err := runEndpointUserConfigApplyNative(cmd, nil); err == nil {
+ t.Fatal("apply-native accepted port 0")
+ }
+}
+
+// The launcher drops to the console user and gives the child that user's HOME, so the child's
+// writes land in the right profile with the user's own permissions.
+func TestConsoleUserCommandRunsAsTheUserWithTheirHome(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("POSIX launcher")
+ }
+ cmd := consoleUserCommand(context.Background(), consoleUserInfo{Username: "alice", HomeDir: "/home/alice"}, "/opt/beacon/bin/beacon", "endpoint", "user-config", "apply-native")
+ args := strings.Join(cmd.Args[1:], " ")
+ if !strings.HasPrefix(args, "-u alice ") {
+ t.Fatalf("launcher args = %q, want it to run as alice", args)
+ }
+ if !strings.HasSuffix(args, "env HOME=/home/alice USER=alice LOGNAME=alice /opt/beacon/bin/beacon endpoint user-config apply-native") {
+ t.Fatalf("launcher args = %q, want alice's HOME and the child command", args)
+ }
+}
diff --git a/cli/beacon/cmd/endpoint_user_config_unix.go b/cli/beacon/cmd/endpoint_user_config_unix.go
deleted file mode 100644
index 17ecaac6..00000000
--- a/cli/beacon/cmd/endpoint_user_config_unix.go
+++ /dev/null
@@ -1,54 +0,0 @@
-//go:build !windows
-
-package cmd
-
-import (
- "fmt"
- "os"
- "syscall"
-
- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/osuser"
-)
-
-// chownUserConfigArtifacts gives the console user ownership of the settings files a system-mode
-// install just wrote on their behalf.
-//
-// Load-bearing rather than cosmetic. The install runs as root, so every file it creates is
-// root-owned; the person whose agent sessions matter then cannot edit their own settings, and their
-// agent may not be able to write alongside them. This is the step that hands them back.
-func chownUserConfigArtifacts(info consoleUserInfo, path string) error {
- uid, gid, err := userOwnership(info)
- if err != nil {
- return err
- }
- for _, candidate := range userConfigArtifacts(path) {
- if err := os.Chown(candidate, uid, gid); err != nil && !os.IsNotExist(err) {
- return err
- }
- }
- return nil
-}
-
-// userOwnership resolves the console user's numeric uid and gid.
-//
-// The account database first, since that is the authoritative answer, and osuser consults NSS so
-// a directory-backed account resolves rather than falling straight through. Falling back to the
-// home directory's owner still covers what NSS cannot answer -- a container with a bare passwd
-// file, or a host with no getent -- where the directory itself still records who they are.
-//
-// Both this and resolveConsoleUser go through osuser deliberately. They answer the same question
-// and disagreeing about it is how a settings file ends up owned by someone who cannot read it.
-func userOwnership(info consoleUserInfo) (int, int, error) {
- if u, err := osuser.Lookup(info.Username); err == nil {
- return u.UID, u.GID, nil
- }
- stat, err := os.Stat(info.HomeDir)
- if err != nil {
- return 0, 0, err
- }
- sys, ok := stat.Sys().(*syscall.Stat_t)
- if !ok {
- return 0, 0, fmt.Errorf("could not determine ownership for %s", info.HomeDir)
- }
- return int(sys.Uid), int(sys.Gid), nil
-}
diff --git a/cli/beacon/cmd/endpoint_user_config_windows.go b/cli/beacon/cmd/endpoint_user_config_windows.go
deleted file mode 100644
index d5da14f3..00000000
--- a/cli/beacon/cmd/endpoint_user_config_windows.go
+++ /dev/null
@@ -1,19 +0,0 @@
-//go:build windows
-
-package cmd
-
-// chownUserConfigArtifacts is a no-op on Windows, and the reason it can be is specific rather than
-// general.
-//
-// The POSIX version exists because a system-mode install runs as root and leaves root-owned files
-// in a user's home directory, which that user then cannot edit. Windows has no uid/gid to assign --
-// ownership is a SID and access is an ACL -- but it also does not create the problem in the same
-// way: a file written under %USERPROFILE% inherits that profile's ACL, which already grants the
-// profile's owner full control. So there is nothing to hand back.
-//
-// This is not the same question as whether a *system* log directory is writable by a non-admin
-// agent process. That one Windows does get wrong by default, and it is a real gap rather than a
-// non-issue -- but it belongs with the system paths, not here.
-func chownUserConfigArtifacts(_ consoleUserInfo, _ string) error {
- return nil
-}