Repository navigation
fix(deploy): make hardening survive deploys - #1693
Open
faisalahammad wants to merge 3 commits into
Open
faisalahammad wants to merge 3 commits into
faisalahammad wants to merge 3 commits into
Conversation
- Make .env group-readable when hardened so the PHP runtime user can read it - Ensure per-release writable paths are group-writable on every deploy - Skip shared dir mode enforcement in hardened mode to avoid deploy failure Fixes roots#1691
Contributor
|
Does there also need to be additional nginx conf in |
- Add location_cache_php block to deny direct execution of .php files in cache directory - Explicitly set web_group on per-release writable paths and deployed .env - Add unit tests for location_cache_php in template tests Addresses PR feedback. Refs roots#1693
Contributor
Author
|
Added location_cache_php block in roles/wordpress-setup/templates/wordpress-site.conf.j2 to deny direct execution of .php files in cache directory, similar to uploads directory. Also added group permission to per-release writable paths and deployed .env. |
Contributor
|
@retlehs when could this make it into a release? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Submission Review Guidelines
Summary
With
wordpress_runtime_hardenedenabled, two things break after a deploy: the.envfile gets mode 0600 so the PHP runtime user can no longer read it (Dotenv throws InvalidPathException), and per-release writable paths likeweb/app/cachecome back unwritable because each new release is extracted with default permissions. Deploys also failed with EPERM when chmodding shared directories owned by the runtime user.This fixes all three. Deploys run as the
webuser without root, so the fix uses group permissions instead of chown:web's primary group iswww-data, which is the default runtime user's group.Fixes #1691
Changes
.env file mode
Before:
After:
Why: The file is owned by
webwith groupwww-data. In hardened mode PHP runs aswww-data, so it needs the group read bit. Same change applied to the provision-time.envinwordpress-installso both paths match.Per-release writable paths
New file:
roles/deploy/tasks/runtime-writable-paths.yml, included frombuild.ymlwhen hardened.Why: Paths with the
current/prefix (e.g.current/web/app/cache) only exist in the new release, and the provision-time chown does not survive the next deploy. Since deploys run aswebwithout sudo, the directories are made group-writable (0775) on every deploy instead.Shared directories in share.yml
Why: In hardened mode, shared paths are owned by the runtime user. The deploy task running as
web(a non-owner) failed with EPERM when chmodding them back to 0755, so the mode enforcement is skipped in hardened mode.Provision-time task split
roles/wordpress-setup/tasks/runtime-writable-paths.ymlnow only handlesshared/paths. Per-release paths have no target on a fresh server and are handled per deploy instead.Behavior is unchanged when
wordpress_runtime_hardenedis false (the default).Screenshots / Recordings
When
wordpress_runtime_hardened: true, deploys fail withEPERMon shared directory chmod,.envis written with mode0600(unreadable by runtime user), and new release directories reset to unwritable.Shared directory chmod skipped in hardened mode,
.envreceives mode0640withwww-datagroup read access, and per-release paths are set to0775via deploy task.Testing
Test 1: hardened provision and deploy
wordpress_runtime_hardened: trueand addcurrent/web/app/cachetowordpress_runtime_writable_paths.envis-rw-r----- web www-data, Acorn cache writes succeed after both deploysResult: works as expected. Tested manually: confirmed this resolves the reported issue.
Test 2: default mode
wordpress_runtime_hardenedat its default (false)Result: identical behavior to before.
Template render tests (pytest, 9 passing) and
ansible-playbook --syntax-checkon all five playbooks pass.One note for docs: a custom
wordpress_runtime_groupneeds the runtime user added toweb_group(www-data), since deploys cannot chgrp without root. The hardening comment block inwordpress-setupdefaults mentions this. Docs on roots.io may want to cover the shared vs per-release path split too.Milestone
Changelog Entry
.envmode to 0640 and release paths to group-writable.Release Communication