caddy
caddy copied to clipboard
logging: add DirMode options and propagate FileMode to rotations
Summary
This PR enhances the FileWriter logging module to give users explicit control over directory creation permissions and ensures that rotated log files inherit the correct file mode from configuration. This solves issue #7314
Changes
-
Added
DirModeoption toFileWriter:-
"inherit"→ copies the nearest existing parent directory’s permissions, normalizingr→xfor directories. -
"from_file"→ derives directory permissions from the file’s mode (e.g.,0644 → 0755,0600 → 0700). - Octal strings (e.g.,
"0755") → directly specify directory permissions. - Default remains
0700(same as before, ensuring backward compatibility).
-
-
Improved permission handling:
- When
DirModeis set, directories are created using the requested mode. - Added
normalizeDirPerm()to ensure directories with read bits also gain execute bits (so they’re traversable).
- When
-
Propagated file mode to timberjack:
- Added
FileMode: os.FileMode(fw.Mode)to the embeddedtimberjack.Logger. - Ensures rotated log files now use the same mode as the original log file.
- Added
-
Security-conscious defaults:
- Maintains restrictive defaults (
0700directories,0600files). - Umask still applies.
-
r→xnormalization applies only to directories — not to files.
- Maintains restrictive defaults (
Tests Added
-
Extended test coverage in:
-
filewriter_test.go(Unix) -
filewriter_test_window.go(Windows)
-
-
Added cases for:
-
DirModevalues:inherit,from_file, explicit octal, and default. - Directory creation under different umasks.
- Correct parsing of
dir_modefrom the Caddyfile. - Windows smoke test to ensure successful file creation across modes.
-
Assistance Disclosure
AI was used to generate this PR summery and also to expand some tests I wrote. Everything was reviewed by me.
Thanks! Please don't forget to sign the CLA
I just signed :+1: