Commit Graph

66 Commits

Author SHA1 Message Date
Peter Zhu
ebedf0a6c0 Update azure-storage gem to latest version 2019-08-06 16:02:42 -04:00
Gannon McGibbon
388e011b08
Merge pull request #36792 from peterzhu2118/azure-content-disposition
Upload filename and disposition for Azure
2019-07-31 18:44:58 -04:00
Peter Zhu
24ae11daae Upload file with filename and disposition for Azure 2019-07-31 15:44:40 -04:00
Peter Zhu
e6d2e8bf9b Upload file with filename and disposition for S3 2019-07-31 09:54:51 -04:00
Eileen M. Uchitelle
dc7b650e15
Merge pull request #36715 from peterzhu2118/azure-content-type
Add content_type to upload method for Azure
2019-07-24 15:13:23 -04:00
Peter Zhu
094fa9277d Add content_type to upload in Azure 2019-07-24 14:56:20 -04:00
Peter Wagenet
b07ce56a38 Fix host for ActiveStorage DiskService
Previous behavior would only set host, which didn't work correctly
if the default_url_options contained the protocol or the port.
2019-07-09 12:54:35 -07:00
George Claghorn
d5a2f7ec14
Mirror direct uploads 2019-05-22 15:07:35 -04:00
George Claghorn
9c5135ce6a
S3: permit uploading files larger than 5 GB
Use multipart uploads for files larger than 100 MB. Dynamically calculate part size based on total object size and maximum part count.
2019-05-16 10:58:33 -04:00
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Abhay Nikam
d3f9226190 Delegated path_for to primary in the MirrorService 2019-02-14 23:06:42 +05:30
Simo Leone
c5b71c9bae
include the content type when uploading to S3 2019-01-24 17:05:49 +00:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Marcelo Perini Veloso
ce40e85194
add require 'database/setup' in activestorage/test/service/s3_service_test.rb 2018-12-01 15:47:54 -02:00
yuuji.yaginuma
6ca2f2acb2 metadata is not passed to service
Ref: 604fac6d71/activestorage/app/models/active_storage/blob.rb (L256-L264)

This fixes broken `GCSServiceTest`.
https://travis-ci.org/rails/rails/jobs/461868394#L6624-L6626

Follow up to  #34576.
2018-12-01 09:12:55 +09:00
Yannick Schutz
7bd21e8575
Add a test with extra keys to active_storage Service#upload 2018-11-30 15:54:38 +01:00
yuuji.yaginuma
ac721c8552 Fix "warning: ambiguous first argument; put parentheses or a space even after `/' operator" 2018-11-28 11:29:03 +09:00
yuuji.yaginuma
7e7a60bd3f Remove duplicated test
Since 06ab7b27ea1c1ab357085439abacdb464f6742bf,
`GCSServiceTest#test_signed_URL_response_headers` is broken.
https://travis-ci.org/rails/rails/jobs/460454477#L7084-L7087

This seems to be due to lack of `content_type` at upload.
This is solved by specifying `conten_type`.

However, since the same content is also tested with `test_upload_with_content_type`,
it will be duplicated content, so I think that can remove `test_signed_URL_response_headers`.
2018-11-28 10:01:03 +09:00
Rosa Gutierrez
06ab7b27ea Prevent content type and disposition bypass in storage service URLs
* Force content-type to binary on service urls for relevant content types

We have a list of content types that must be forcibly served as binary,
but in practice this only means to serve them as attachment always. We
should also set the Content-Type to the configured binary type.

As a bonus: add text/cache-manifest to the list of content types to be
served as binary by default.

* Store content-disposition and content-type in GCS

Forcing these in the service_url when serving the file works fine for S3
and Azure, since these services include params in the signature.
However, GCS specifically excludes response-content-disposition and
response-content-type from the signature, which means an attacker can
modify these and have files that should be served as text/plain attachments
served as inline HTML for example. This makes our attempt to force
specific files to be served as binary and as attachment can be easily
bypassed.

The only way this can be forced in GCS is by storing
content-disposition and content-type in the object metadata.

* Update GCS object metadata after identifying blob

In some cases we create the blob and upload the data before identifying
the content-type, which means we can't store that in GCS right when
uploading. In these, after creating the attachment, we enqueue a job to
identify the blob, and set the content-type.

In other cases, files are uploaded to the storage service via direct
upload link. We create the blob before the direct upload, which happens
independently from the blob creation itself. We then mark the blob as
identified, but we have already the content-type we need without having
put it in the service.

In these two cases, then, we need to update the metadata in the GCS
service.

* Include content-type and disposition in the verified key for disk service

This prevents an attacker from modifying these params in the service
signed URL, which is particularly important when we want to force them
to have specific values for security reasons.

* Allow only a list of specific content types to be served inline

This is different from the content types that must be served as binary
in the sense that any content type not in this list will be always
served as attachment but with its original content type. Only types in
this list are allowed to be served either inline or as attachment.

Apart from forcing this in the service URL, for GCS we need to store the
disposition in the metadata.

Fix CVE-2018-16477.
2018-11-27 15:36:27 -05:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
Marcelo Perini Veloso
0d4ba40688 Fix zero-byte files upload 2018-09-06 20:04:21 -03:00
Cameron Bothner
5cd2d07bdc Translate service-specific missing object exceptions into a generic one
`ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
`ActiveStorage::FileNotFoundError` when the corresponding file is missing
from the storage service. Services translate service-specific missing
object exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service
and `Errno::ENOENT` for the disk service) into
`ActiveStorage::FileNotFoundError`.
2018-08-21 15:31:14 -04:00
Joel Taylor
3082786be6 Improve ActiveStorage service adapter error handling 2018-08-06 18:17:49 -07:00
George Claghorn
bd680dd59a Fix uploading Tempfiles to Azure Storage
Closes #32530.
2018-08-03 22:41:19 -04:00
George Claghorn
56b9d0fd3a Generate a new key for each service test
Sidestep Google Cloud Storage's restrictive per-object rate limit.
2018-06-25 18:49:26 -04:00
yuuji.yaginuma
38dbc8e2b8 Fix "warning: Net::HTTPResponse#header is obsolete"
Ref: cc77a81129/lib/net/http/response.rb (L138-L155)
2018-06-17 21:35:07 +09:00
George Claghorn
bdd8b6843c
Merge pull request #32144 from kazu9su/master
Add ActiveStorage::Service::DiskService#url_for_direct_upload test
2018-05-22 17:34:19 -04:00
George Claghorn
bf5f41d948
Support streaming downloads from Google Cloud Storage 2018-05-01 23:20:56 -04:00
Andrew White
9436c22e2a
Use a current model to provide the host for service urls
Trying to pass the current request down to the service so that it can
create full urls instead of paths makes the API messy so use a model
based on ActiveSupport::CurrentAttributes to provide the current host
to services that need it (primarily the disk service).
2018-04-06 20:07:52 +01:00
Brian Knight
c1600009b2 Allow full use of the AWS S3 SDK authentication options (#32270)
If an explicit AWS key pair and/or region is not provided in
config/storage.yml, attempt to use environment variables, shared
credentials, or IAM role credentials. Order of precedence is
determined by the AWS SDK[1].

[1]: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html
2018-03-19 15:25:40 +00:00
George Claghorn
0443cb130c Update ASt test services config 2018-03-12 19:00:54 -04:00
Andrew White
309bb6c4d0 Remove path config option from Azure service
The Active Storage service for Azure Storage has an option called `path`
that is ambiguous in meaning. It needs to be set to the primary blob
storage endpoint but that can be determined from the blobs client anyway.

To simplify the configuration this commit removes the `path` option and
gets the endpoint from the blobs client instead.

Closes #32225.
2018-03-12 17:39:58 +00:00
George Claghorn
ccac681122 Generate root-relative paths in Active Storage disk service URL methods
Fixes #32129.
2018-03-05 11:54:43 -05:00
tommy
a21d11ce80 Add ActiveStorage::Service::DiskService#url_for_direct_upload test 2018-03-01 08:59:00 +09:00
George Claghorn
8a79d04e4d Avoid specifying content types for direct uploads to Google Cloud Storage
Fix customizing the download Content-Type for a directly-uploaded blob via a signed URL. See e8286ee.
2018-02-26 12:00:24 -05:00
Andrew White
7dce840dee Allow S3 tests against buckets in other regions
Only us-east-1 gives URLs like bucket.s3.amazonaws.com whereas other
regions have URLs like s3-eu-west-1.amazonaws.com/ubxd-rails
2018-02-21 12:06:25 +00:00
Shuhei Kitagawa
a5b3d5bf43 Eliminate ActiveStorage::Service::MirrorServiceTest#upload 2018-01-27 05:43:17 -05:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
George Claghorn
6fb3ac1536 Provide a sensible default host 2018-01-16 20:32:02 -05:00
George Claghorn
c2ba530c43
Extract content types from blob data 2018-01-15 13:06:17 -05:00
George Claghorn
e8286ee272 Fix customizing Content-Type via GCS service URLs 2017-12-07 15:16:24 -05:00
George Claghorn
8c5a7fbefd
Purge variants with their blobs 2017-12-02 22:43:28 -05:00
yuuji.yaginuma
9d65ac30fd Use credentials instead of keyfile in GCS sevice
The `keyfile` was renamed to `credentials` in `google-cloud-storage` 1.8.0.
https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/google-cloud-storage/CHANGELOG.md#180--2017-11-14

Although `keyfile` can still be used, but it looks like deprecate.
ddf7b2a856/google-cloud-storage/lib/google/cloud/storage.rb (L589...L590)

Therefore, I think that should use `credentials` in newly generated
applications.

Ref: https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/1802
2017-11-29 13:17:04 +09:00
George Claghorn
fbb12910bd Avoid connecting to GCS during app boot 2017-11-23 19:48:25 -05:00
George Claghorn
86938c495e
Fix streaming downloads from S3/Azure Storage
Closes #31073.
2017-11-06 21:29:37 -05:00
Ryuta Kamizono
325c06fbc4 Fix test "signed URL generation" failure
https://travis-ci.org/rails/rails/jobs/281044755#L5582-L5586
2017-09-30 05:48:23 +09:00
George Claghorn
d30586211b Preview PDFs and videos 2017-09-28 16:43:37 -04:00
George Claghorn
21e690cba8 Rename activestorage/test/service/configurations.yml to activestorage/test/service/configurations.example.yml 2017-09-11 18:06:08 -04:00
Koichi ITO
9e470b24c8 Fix order of Active Storage DiskService URL parameters
`content_type` parameter is before `disposition` parameter.
2017-08-26 23:16:07 +09:00