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
Make user-mode runtime logs private (0600 / 0700) (#798)
Justin D'Souzad7eefd2b9004
diff --cc cli/beacon/internal/endpoint/writer/writer.goindex 59a33b86,6a201b3a..4faf3b58--- a/cli/beacon/internal/endpoint/writer/writer.go+++ b/cli/beacon/internal/endpoint/writer/writer.go@@@ -155,32 -151,21 +157,34 @@@ func EnsureSystemLogWritable(path strinif err := os.Chmod(dir, 0755); err != nil {return fmt.Errorf("make the log directory %s traversable: %w", dir, err)}- return grantInteractiveUsersWrite(dir)+ if err := secureSystemLog(path); err != nil {+ return fmt.Errorf("secure the log directory %s: %w", dir, err)+ }+ return nil+}++// LogACLState is what doctor reports about a system log's access control.+type LogACLState struct {+ // HooksCanAppend is true when a hook running as the interactive user can open the log for+ // append and its lock for read-write.+ HooksCanAppend bool+ // Problems lists grants or owners that would let an ordinary user delete, rename or redirect+ // the files a SYSTEM process writes. Empty when the ACL is the one install applies.+ Problems []string}-// SystemLogWritableByUsers reports whether that grant is in place, for doctor.-func SystemLogWritableByUsers(dir string) (bool, error) {- return interactiveUsersCanWrite(dir)+// CheckSystemLogACL reports the state EnsureSystemLogWritable establishes, for doctor.+func CheckSystemLogACL(path string) (LogACLState, error) {+ return inspectSystemLog(path)}- // EnsureRuntimeFile creates the shared runtime log with the shared writable- // mode without appending an event, for doctor --fix and setup flows that- // pre-create the log so user-run hooks can append to it later.+ // EnsureRuntimeFile creates the runtime log without appending an event, for doctor --fix and setup+ // flows that pre-create the log so hooks can append to it later. The shared system log gets the+ // shared writable mode; a log in the current user's home is private (see+ // asymptoteobserve.RuntimeLogModes).func EnsureRuntimeFile(path string) error {- if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ _, dirMode, _ := asymptoteobserve.RuntimeLogModes(path)+ if err := os.MkdirAll(filepath.Dir(path), dirMode); err != nil {return err}f, err := openRuntimeFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY)@@@ -319,21 -314,13 +333,25 @@@ func rotateIfNeeded(path string, maxSiz}}rotated := path + ".1"- return os.Rename(path, rotated)+ if err := os.Rename(path, rotated); err != nil {+ return err+ }+ asymptoteobserve.TightenPrivateRuntimeLogArchives(path, archives)+ return nil}+// rotationRefused reports whether a rotation failed because this process may not rename or delete+// in the log directory, which is the expected outcome for an unprivileged writer of a system log.+//+// Rotation belongs to the privileged writers there: on POSIX the directory is root-owned 0755, and+// on Windows its ACL gives ordinary users no right to add, rename or delete entries -- which is the+// point, since those are the rights that let a user redirect a SYSTEM write. The first step of a+// rotation is therefore the one refused, nothing has moved, and the event is better appended past+// the size limit than lost; the collector rotates the log at its next write.+func rotationRefused(err error) bool {+ return errors.Is(err, fs.ErrPermission)+}+// needsRotation reports whether appending nextWriteBytes to path would take it past maxSize, which// is when rotateIfNeeded rotates. An empty or missing file never rotates, so one oversized line// still lands somewhere.