Skip to content

logging: add DirMode options and propagate FileMode to rotations#7335

Merged
francislavoie merged 2 commits intocaddyserver:masterfrom
DeRuina:test/dir-mode-and-parsing
Feb 23, 2026
Merged

logging: add DirMode options and propagate FileMode to rotations#7335
francislavoie merged 2 commits intocaddyserver:masterfrom
DeRuina:test/dir-mode-and-parsing

Conversation

@DeRuina
Copy link
Contributor

@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. Closes #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
Contributor Author

DeRuina commented Nov 3, 2025

I just signed 👍

@mholt mholt modified the milestones: v2.11.0, v2.11.1 Feb 18, 2026
@francislavoie francislavoie force-pushed the test/dir-mode-and-parsing branch from 8a069e3 to 5d73a30 Compare February 23, 2026 05:46
@francislavoie
Copy link
Member

Sorry for the delay! Looks great to me. I added another commit to fixup an issue with roll_at and roll_minutes config parsing I noticed while writing the docs for those options, so I'm sneaking that in here while I'm at it.

@francislavoie francislavoie enabled auto-merge (squash) February 23, 2026 07:24
@francislavoie francislavoie merged commit 294dfff into caddyserver:master Feb 23, 2026
27 checks passed
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.

log _subdirectory_ permissions

4 participants