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

ActiveStorage + Azure : invalid options provided for SAS token generate #32225

Closed
fearcraftor opened this issue Mar 12, 2018 · 4 comments
Closed
Assignees
Milestone

Comments

@fearcraftor
Copy link

Hello

Steps to reproduce

I followed all the steps described in edgeguides to setup ActiveStorage in combination with an Azure Storage Account

Expected behavior

Attaching and uploading of a blob works fine. I can see the uploaded files in my Azure Storage container.
Then I use the url_for to display images stored on Azure.

Actual behavior

I got error 500 on requested images, and got this error when I try to open generated uri :

Azure::Storage::InvalidOptionsError in ActiveStorage::BlobsController#show

invalid options {:content_disposition=>"inline; filename="image.png"; filename*=UTF-8''image.png", :content_type=>"image/png"} provided for SAS token generate

azure-storage (0.15.0.preview) lib/azure/storage/core/auth/shared_access_signature_generator.rb:174:in 'generate_service_sas_token'
azure-storage (0.15.0.preview) lib/azure/storage/core/auth/shared_access_signature_generator.rb:340:in 'signed_uri'
activestorage (5.2.0.rc1) lib/active_storage/service/azure_storage_service.rb:81:in 'block in url'
activesupport (5.2.0.rc1) lib/active_support/notifications.rb:168:in 'block in instrument'
activesupport (5.2.0.rc1) lib/active_support/notifications/instrumenter.rb:23:in 'instrument'
activesupport (5.2.0.rc1) lib/active_support/notifications.rb:168:in 'instrument'
activestorage (5.2.0.rc1) lib/active_storage/service.rb:113:in 'instrument'
activestorage (5.2.0.rc1) lib/active_storage/service/azure_storage_service.rb:79:in 'url'
activestorage (5.2.0.rc1models) active_storage/blob.rb:113:in 'service_url'
activestorage (5.2.0.rc1controllers) active_storage/blobs_controller.rb:12:in 'show'

I asked Azure team, they tell me to setup a SAS token. As far I know there's no documentation from Rails about such a setup.

Are you aware of that problem ? Is there any further configuration I missed ?

Thank you in advance

System configuration

Rails version: 5.2.0.rc1

Ruby version: 2.5.0

using gem 'azure-storage', 0.15.0.preview

@pixeltrix
Copy link
Contributor

After much pain in setting up an Azure account I've managed to reproduce this - investigating now.

@fearcraftor that advice from the Azure team isn't much use - Active Storage is trying to create a signed url so is creating a SAS token for that. If you have to create a SAS token every time a user wanted to download a file it'd be a bit awkward 😄

@pixeltrix pixeltrix self-assigned this Mar 12, 2018
@pixeltrix pixeltrix added this to the 5.2.0 milestone Mar 12, 2018
@pixeltrix
Copy link
Contributor

@fearcraftor what did you set for the path option in your Azure config? If you set the primary endpoint of your storage account then it should work as the client uses the URI to determine which service to generate the SAS for, e.g:

azure:
  service: AzureStorage
  path: "https://<your-storage-account-name>.blob.core.windows.net"
  storage_account_name: "<your-storage-account-name>"
  storage_access_key: "<your-storage-account-key>"
  container: "<your-container>"

@georgeclaghorn the config for Azure doesn't seem very clear - we can drop the path option and pass the service via an option to signed_uri and let the client build the correct host.

@georgeclaghorn
Copy link
Contributor

I didn’t originally write the Azure service and don’t know much about it. Feel free to simplify.

pixeltrix added a commit that referenced this issue Mar 12, 2018
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.
@fearcraftor
Copy link
Author

Works fine ! Thank you

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