Skip to content

Conversation

@DeRuina
Copy link

@DeRuina DeRuina commented Nov 3, 2025

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 DirMode option to FileWriter:

    • "inherit" → copies the nearest existing parent directory’s permissions, normalizing rx for 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 DirMode is set, directories are created using the requested mode.
    • Added normalizeDirPerm() to ensure directories with read bits also gain execute bits (so they’re traversable).
  • Propagated file mode to timberjack:

    • Added FileMode: os.FileMode(fw.Mode) to the embedded timberjack.Logger.
    • Ensures rotated log files now use the same mode as the original log file.
  • Security-conscious defaults:

    • Maintains restrictive defaults (0700 directories, 0600 files).
    • Umask still applies.
    • r→x normalization 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:

    • DirMode values: inherit, from_file, explicit octal, and default.
    • Directory creation under different umasks.
    • Correct parsing of dir_mode from 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.

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2025

CLA assistant check
All committers have signed the CLA.

@francislavoie
Copy link
Member

Thanks! Please don't forget to sign the CLA

@DeRuina
Copy link
Author

DeRuina commented Nov 3, 2025

I just signed 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants