-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Support passing user_project
argument to GCS bucket to support GCS buckets with “Requester pays” enabled
#51869
base: main
Are you sure you want to change the base?
Conversation
daf891b
to
9b99a6e
Compare
I'm a bit confused by testing here: it appears the service files are only ran when a configuration file is presented. The repo contains an encrypted Looking at the CI output, they're not set in CI though?
Are all these services actually being tested somewhere? |
Rails CI does not run these tests. There is a open issue #39015 |
Hmm, alright, thank you for the information! I'll draft this until I can come up with a manual test scenario then. |
9b99a6e
to
0454dac
Compare
Alright, testing this locally is pretty annoying. I've verified the behaviour following these steps, feel free to replicate them if you wish to do so:
|
…buckets with “Requester pays” enabled GCS has an option on buckets to make them a "Requester Pays" type of bucket: https://cloud.google.com/storage/docs/requester-pays. In short, this allows tracing of who/what is actually requesting an upload/download to be able to allocate the costs to the project used. To query a bucket where "requester pays" is enabled, the `userProject` needs to be added in the URL. The GCS Ruby library provides this as an optional `user_project` keyword argument to `Project#bucket`: https://github.com/googleapis/google-cloud-ruby/blob/google-cloud-storage/v1.11.0/google-cloud-storage/lib/google/cloud/storage/project.rb#L87-L99 (took v1.11 explicitly here as this is the current version requirement on Rails.) When this is not passed, an error is thrown when listing/uploading files in a requester-pays bucket: `Bucket is a requester pays bucket but no user project provided. (Google::Cloud::InvalidArgumentError)` This commit adds support for "requester pays"-buckets by accepting a `user_project` parameter (defaults to `nil`) on the GCS service bucket call (https://github.com/rails/rails/blob/cd31b164b1975abfe6adb9af8e0edc8bea7ce1b0/activestorage/lib/active_storage/service/gcs_service.rb#L192), set by a variable in the config `config.fetch(:user_project, nil)`.
0454dac
to
e9ad10b
Compare
Motivation / Background
GCS has an option on buckets to make them a "Requester Pays" type of bucket: https://cloud.google.com/storage/docs/requester-pays. In short, this allows tracing of who/what is actually requesting an upload/download to be able to allocate the costs to the project used.
To query a bucket where "requester pays" is enabled, the
userProject
needs to be added in the URL. The GCS Ruby library provides this as an optionaluser_project
keyword argument toProject#bucket
: https://github.com/googleapis/google-cloud-ruby/blob/google-cloud-storage/v1.11.0/google-cloud-storage/lib/google/cloud/storage/project.rb#L87-L99 (took v1.11 explicitly here as this is the current version requirement on Rails.)When this is not passed, an error is thrown when listing/uploading files in a requester-pays bucket:
Bucket is a requester pays bucket but no user project provided. (Google::Cloud::InvalidArgumentError)
Detail
This commit adds support for "requester pays"-buckets by accepting a
user_project
parameter (defaults tonil
) on the GCS service bucket call, set by a variable in the configconfig.fetch(:user_project, nil)
:rails/activestorage/lib/active_storage/service/gcs_service.rb
Line 192 in cd31b16
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]