Skip to content

Commit 55bfa1c

Browse files
committed
fix: open log file with mode 0600 and remove permission widening fallback
The agent runs as root, so if it cannot open its own log file, chmod/chown workarounds won't help — just fail. Removed the fallback that ran chmod 666 which made the log world-writable. Now opens with 0600 and returns the error directly on failure.
1 parent 5f2fd86 commit 55bfa1c

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

pkg/logger/logger.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,9 @@ func setupLogFileWriter(logDir string) (io.Writer, error) {
158158
return nil, fmt.Errorf("failed to create log file '%s': %w", logFilePath, err)
159159
}
160160

161-
// Try to open log file for writing, handle permission issues
162-
file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND, 0666)
161+
// Try to open log file for writing
162+
file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND, 0600) //#nosec G304 - logFilePath is from trusted agent config
163163
if err != nil {
164-
// If it's a permission error and we're not running as root, try to fix permissions
165-
if os.IsPermission(err) {
166-
// Try to fix permissions using system command
167-
if fixErr := utils.RunSystemCommand("chmod", "666", logFilePath); fixErr == nil {
168-
// Retry opening the file after fixing permissions
169-
file, err = os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND, 0666)
170-
if err == nil {
171-
return file, nil
172-
}
173-
}
174-
}
175164
return nil, fmt.Errorf("failed to open log file '%s': %w", logFilePath, err)
176165
}
177166

0 commit comments

Comments
 (0)