Active Storage: encourage `Rails.env` in bucket names

https://github.com/rails/rails/issues/42186 outlined a problem I've seen in the wild before (with AS, but also with other gems like papertrail) where developers interact with production data locally and inadvertently destroy it.

A simple way to prevent this in the Active Storage case is to make the `bucket` name for services be based on `Rails.env`. This way, if you pull a production database copy and call `purge` on a blob for it, AS will try and destroy the file from the `your_own_bucket-development` bucket. But the file doesn't live there - it lives in the `your_own_bucket-production` bucket.

This is just a suggestion and people who know what they are doing can name their buckets whatever they want. But for first time Active Storage users I think this removes an unnecessarily sharp knife.
This commit is contained in:
Alex Ghiculescu 2021-05-09 20:37:51 -05:00 committed by GitHub
parent be8d8edf50
commit 01d90fb372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -12,21 +12,21 @@ local:
# access_key_id: <%%= Rails.application.credentials.dig(:aws, :access_key_id) %> # access_key_id: <%%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%%= Rails.application.credentials.dig(:aws, :secret_access_key) %> # secret_access_key: <%%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1 # region: us-east-1
# bucket: your_own_bucket # bucket: your_own_bucket-<%%= Rails.env %>
# Remember not to checkin your GCS keyfile to a repository # Remember not to checkin your GCS keyfile to a repository
# google: # google:
# service: GCS # service: GCS
# project: your_project # project: your_project
# credentials: <%%= Rails.root.join("path/to/gcs.keyfile") %> # credentials: <%%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket # bucket: your_own_bucket-<%%= Rails.env %>
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft: # microsoft:
# service: AzureStorage # service: AzureStorage
# storage_account_name: your_account_name # storage_account_name: your_account_name
# storage_access_key: <%%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> # storage_access_key: <%%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name # container: your_container_name-<%%= Rails.env %>
# mirror: # mirror:
# service: Mirror # service: Mirror