Skip to content

feat(doctor): require a read-only environment directory with a deployment dump - #45

Merged
brianvarskonst merged 4 commits into
mainfrom
fix/doctor-env-dir-readonly
Oct 23, 2026
Merged

brianvarskonst merged 4 commits into
mainfrom
fix/doctor-env-dir-readonly

Conversation

@brianvarskonst

@brianvarskonst brianvarskonst commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Finding

Review finding R-S1 (medium, operational): with the default cache-env: auto the PHP-FPM process writes .env.cached.php, executable PHP containing file-owned secrets, into env-dir at shutdown. That only works when the web identity can write the directory the generated configuration requires from, so any file-write primitive in the web process becomes a bootstrap code path. EnvCacheFormat::canReplace() only protects foreign files from being overwritten. Finding R-P4 (per-request stat() of every environment source file in cache mode) has the same remedy and is documented in the same PR.

Change

  • doctor --production adds production.env-dir-readonly once a deployment dump exists: pass when the environment directory is not writable by the checked identity, fail when it is, unknown for a different --php-user or when doctor runs as root (mode bits cannot prove the PHP-FPM identity's access; same rule as the readability checks).
  • docs/operations.md and docs/deployment.md explain why the directory must stay unwritable and that the request-time cache is a development convenience.

Verification

  • ProductionDoctorTest runs the strict profile against a read-only project directory (chmod 0555 during the doctor run) and adds a case for writable fail, read-only pass and foreign identity unknown.
  • Doctor, kernel bridge and operations suites pass; composer cs, composer static-analysis and tools/check-docs.py pass. testPhpIdentityChecksParentTraversal fails on main in the same container (missing POSIX user).

brianvarskonst and others added 4 commits October 24, 2026 00:03
…ment dump

The generated configuration executes .env.dump.php and .env.cached.php from the
environment directory. With cache-env auto the web process writes the cache there
itself, which needs write access on the bootstrap path. The strict production
profile now reports production.env-dir-readonly once a dump exists; another
identity remains unknown because mode bits cannot prove ACL behavior.
Root can write every directory, so is_writable() says nothing about the
PHP-FPM identity; mirror the readability checks' uid 0 handling.
@brianvarskonst
brianvarskonst merged commit a8c9fb7 into main Oct 23, 2026
16 checks passed
@brianvarskonst
brianvarskonst deleted the fix/doctor-env-dir-readonly branch October 23, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant