Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store protected assets outside of webroot #7710

Closed
chillu opened this issue Dec 15, 2017 · 5 comments
Closed

Store protected assets outside of webroot #7710

chillu opened this issue Dec 15, 2017 · 5 comments

Comments

@chillu
Copy link
Member

chillu commented Dec 15, 2017

Overview

Split out from 4.1-level change to public webroot in #7419

Acceptance Criteria

  • Protected assets can be placed outside of public/ webroot
  • Opt-in through an environment constant
  • Uploading and publishing assets moves them to the right folder
  • Works gracefully if there is no public/ folder ("legacy mode")
  • Migration can be documented as manual ("move public/assets/.protected to assets/)

Notes

  • Likely too impactful for the 4.x release line, because of the amount of hosting environment adjustments
  • Folder name to be determined (assets vs. public/assets might be too confusing?)
  • Will need adjustment in our hosting platforms (SSP and CWP) regarding snapshots from two folders
  • Will require users to consider which folders are webserver-writeable, and how to change their own backup/restore strategies
@sminnee
Copy link
Member

sminnee commented Sep 3, 2019

Ideally we could allow for this in the 4.x release line by introducing separate config settings for public-asset-path, and protected-asset-path. By default, protected-asset-path = $publicAsssetPath . '/.protected' but it can be overridden.

I would recommend allowing the use of environment variables to specify these, so that a hosting environment can specify its set-up.

@tractorcow
Copy link
Contributor

tractorcow commented Sep 4, 2019

We do have SS_PROTECTED_ASSETS_PATH, which lets you set the protected path. It's not safely normalised though (you might need to use ../assets to break out of the public dir).

You can also inject it this way.

SilverStripe\Core\Injector\Injector:
  SilverStripe\Assets\Flysystem\ProtectedAdapter:
    class: SilverStripe\Assets\Flysystem\ProtectedAssetAdapter
    constructor:
      root: './assets' # note: path relative to base path, not public or assets. Could be anything really.

Probably needs to have better docs, migration tools (i.e. for moving paths around), and could be set as the default at some point in the near future.

@sminnee
Copy link
Member

sminnee commented Sep 5, 2019

Cool, so this might simply be a matter of fully testing this use-case.

chillu added a commit to open-sausages/silverstripe-framework that referenced this issue Oct 15, 2020
Note that it's currently unclear whether Silverstripe Cloud or CWP support this,
but it shouldn't block us from recommend this in the open source project.
It's documented in the "server requirements", which should make it pretty
clear that this requires you to have control over server configuration (or check with those that have).

See silverstripe#7710
@chillu
Copy link
Member Author

chillu commented Oct 15, 2020

  1. Create project (4.6.1 in my case)
composer create-project silverstripe/installer
  1. Configure env (used Lando since it's easiest)

.env

SS_DATABASE_CLASS="MySQLPDODatabase"
SS_DATABASE_NAME="SS_mysite"
SS_DATABASE_SERVER="database"
SS_DATABASE_USERNAME="root"
SS_DATABASE_PASSWORD=""
SS_DEFAULT_ADMIN_PASSWORD="password"
SS_DEFAULT_ADMIN_USERNAME="admin"
SS_PROTECTED_ASSETS_PATH="../.protected/"

.lando.yml

name: my-project
recipe: lamp
config:
  webroot: public

proxy:
  appserver:
    - my-project.lndo.site
  1. Start up project, build
lando start
lando exec vendor/bin/sake dev/build
  1. Upload file in admin/assets

  2. Observe the file structure (abbreviated)

tree -L 3 -a
├── .protected
│   ├── .htaccess
│   └── 29195f23bb
│       ├── DSC01398.jpg
│       ├── DSC01398__FitMaxWzM1MiwyNjRd.jpg
│       └── DSC01398__FitMaxWzYwLDYwXQ.jpg
├── public
│   ├── .htaccess
│   ├── _resources
│   │   ├── .htaccess
│   │   ├── .method
│   │   ├── themes
│   │   └── vendor
│   ├── assets
│   │   ├── .gitignore
│   │   ├── .htaccess
│   │   ├── error-404.html
│   │   ├── error-500.html
│   │   └── web.config
│   ├── index.php
  1. Retrieve a protected file

There are no mechanisms for migrating from one configuration to another, although that should be pretty obvious to anyone who deals with files, right? It would only become our problem if we did this automatically for existing projects.

I've created a docs PR: #9736, and would say this closes this issue. While Lando is running nginx only, I can't see how this behaviour would be webserver dependant. Beyond requiring read access to that new folder location of course. Any further validation required?

@chillu
Copy link
Member Author

chillu commented Jan 13, 2021

Merged the docs PR, closing this issue.

@chillu chillu closed this as completed Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants