logging: add DirMode options and propagate FileMode to rotations #7335
+371
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the
FileWriterlogging 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 #7314Changes
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)."0755") → directly specify directory permissions.0700(same as before, ensuring backward compatibility).Improved permission handling:
DirModeis set, directories are created using the requested mode.normalizeDirPerm()to ensure directories with read bits also gain execute bits (so they’re traversable).Propagated file mode to timberjack:
FileMode: os.FileMode(fw.Mode)to the embeddedtimberjack.Logger.Security-conscious defaults:
0700directories,0600files).r→xnormalization applies only to directories — not to files.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.dir_modefrom the Caddyfile.Assistance Disclosure
AI was used to generate this PR summery and also to expand some tests I wrote. Everything was reviewed by me.