Skip to content

Create local storage directories as 0755 so web servers can read them - #4

Merged
mtarld merged 5 commits into
bakslashHQ:mainfrom
feymo:fix/3-public-directory-permissions
Oct 21, 2026
Merged

mtarld merged 5 commits into
bakslashHQ:mainfrom
feymo:fix/3-public-directory-permissions

Conversation

@feymo

@feymo feymo commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #3

When storage is a local path, the bundle builds a LocalFilesystemAdapter without a visibility converter, so Flysystem falls back to PortableVisibilityConverter's default of Visibility::PRIVATE for directories. The output root and every directory created under it (e.g. <path>/ with clean_urls) end up as 0700, which a web server running as a different user (shared hosting, php-fpm vs. Apache, ...) cannot traverse, so the generated pages are not served.

A generated static site is public by definition, so this passes a PortableVisibilityConverter with defaultForDirectories: Visibility::PUBLIC (0755). All other Flysystem defaults are kept. A storage given as a @service reference is left untouched; its permissions remain the user's responsibility.

Changes:

  • BakslashStaticSiteBundle::configureStorage(): pass a public-by-default visibility converter to the local adapter.
  • New functional test generating nested clean-URL pages with a pinned umask (0022) and asserting the root and subdirectories are 0755; it fails without the fix (0700).
  • README: note the 0755 directory mode and how to use other modes through a custom Flysystem operator.
  • CHANGELOG: entry under 0.2.0.

Possible follow-up: I kept this minimal, so other modes still require declaring a custom Flysystem operator and referencing it with storage: '@service_id'. If you'd rather make this configurable from the bundle itself, a permissions option could map to PortableVisibilityConverter::fromArray(), e.g.:

bakslash_static_site:
    permissions:
        file: { public: 0o644, private: 0o600 }
        dir: { public: 0o755, private: 0o700 }

It would only apply to a local storage. Happy to add it to this PR or open a separate one, whichever you prefer.

Comment thread src/BakslashStaticSiteBundle.php Resolved
Comment thread README.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Comment thread tests/Functional/LocalStorageTest.php Resolved
feymo and others added 2 commits October 21, 2026 10:32
@feymo

feymo commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Your suggestion was anchored on LocalStorageTest.php, so applying it renamed the test class and broke CI. I moved the docblock to the LocalStorageKernel fixture where it was meant to go 🙂
Thanks for your reviews and suggestions @mtarld ❤️

@mtarld
mtarld merged commit 630e7d9 into bakslashHQ:main Oct 21, 2026
7 checks passed
@mtarld

mtarld commented Oct 21, 2026

Copy link
Copy Markdown
Member

Really nice one! Thank you @feymo 🙂

@feymo
feymo deleted the fix/3-public-directory-permissions branch October 21, 2026 08:47
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.

Generated directories are created with 0700 permissions, so the web server can't always read them

2 participants