Description
Passing --audit-log /dev/null is a standard unix idiom for discarding output, and a natural way for users to disable audit logging entirely. Currently it fails with:
level=warning msg="Failed to open audit log file /dev/null: chmod /dev/null: operation not permitted"
The failure is caused by NewFileHook calling f.Chmod(0600) unconditionally after opening the file. The chmod syscall fails on device files like /dev/null.
Proposed Solution
Only call Chmod on newly-created regular files, not on pre-existing files. Better yet, create the file with the correct permissions (0600) from the start to avoid needing Chmod in most cases.
Implementation:
- Check if the file existed before opening it
- Open the file with mode 0600 (instead of 0644)
- Call
Chmod(0600) only if the file was just created (to ensure pre-existing files also get the correct permissions updated)
This way:
- New files get 0600 directly at creation time
- Pre-existing regular files get updated to 0600 (security fix)
- Device files like
/dev/null skip the Chmod call entirely
Changes Required
- File:
internal/audit/audit_logger.go — NewFileHook()
- Check file existence before opening
- Change initial mode from 0644 to 0600
- Conditional
Chmod based on whether file was newly created
Testing
- Unit test:
NewFileHook("/dev/null", ...) succeeds and writes entries without error
- E2E test (tier1):
--audit-log /dev/null allows the command to execute normally (audit data is discarded)
Documentation
- Add to docs: "To disable audit logging on unix-like systems, pass
--audit-log /dev/null"
Description
Passing
--audit-log /dev/nullis a standard unix idiom for discarding output, and a natural way for users to disable audit logging entirely. Currently it fails with:level=warning msg="Failed to open audit log file /dev/null: chmod /dev/null: operation not permitted"
The failure is caused by
NewFileHookcallingf.Chmod(0600)unconditionally after opening the file. Thechmodsyscall fails on device files like/dev/null.Proposed Solution
Only call
Chmodon newly-created regular files, not on pre-existing files. Better yet, create the file with the correct permissions (0600) from the start to avoid needingChmodin most cases.Implementation:
Chmod(0600)only if the file was just created (to ensure pre-existing files also get the correct permissions updated)This way:
/dev/nullskip theChmodcall entirelyChanges Required
internal/audit/audit_logger.go—NewFileHook()Chmodbased on whether file was newly createdTesting
NewFileHook("/dev/null", ...)succeeds and writes entries without error--audit-log /dev/nullallows the command to execute normally (audit data is discarded)Documentation
--audit-log /dev/null"