-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
[DigitalOcean] Private objects signing does not work with custom domain #944
Comments
I'm not sure anymore whether this is even supported by DigitalOcean. |
We are running into the same problem on OVH. It would be great if signatures would work for custom domains as well. Even though the token will change after 1,24 or whatever hours it would still save GB of bandwidth. |
According to some of the new replies on that issue raised for digital ocean, signing the object with the non-cdn url and then just replacing it by the cdn-url works. This would imply that we could "hotfix" this in this library. I don't have some free space to do this at the moment, so feel free to give it a try. |
Arriving here from google researching this on mixing public/private objects: throwing in an idea I'm about to test... Could this not be solved by changing the storage class without having to fork/change the code?
The above would accomplish the same thing: you have stripped the "custom_domain" from the storage object for a particular model, which will cause the signing method to fall back to Then you're just a template tag filter away from putting the url back in django templates. |
Anyone had any success with this? |
You'll have to verify all of this on Digital Ocean but based on my previous idea, I have implemented multi-storage on AWS S3/Cloudfront with a mixture of private and public buckets, like so: custom_storages.py (at the root of your django project):
And then settings.py:
With these you can import and use the individual storage class functions as storage backends. For instance, here's a custom media upload model for wagtail-media that uses the private storage bucket:
So what this accomplishes is I have two buckets, with media files in both. "location" points to the file structure within the bucket, not the bucket itself, so both my cdn-mydomain-com and priv-mydomain-com buckets have "media" folders that hold images or audio or video or whatever. In the above custom media model example, the media file itself will go to the priv bucket, and the thumbnail will go to the wagtail default public media location specified by 'media_thumbnails'. By setting "custom_domain = None" for the priv bucket, it is forced to generate signed url when calls to the URL method are made. For items in the cdn bucket, they inherit the cdn url from the settings.py file and do not generate signed urls, but rather cdn.mydomain.com/{{ media.location }} If you want to go a step further and implement signing of temp urls with the CDN url, as mentioned above just do it in a template tag.
usage in a template would be like:
|
FYI the above method is what is recommended in the Digital Ocean docs for generating signed urls on a custom-CDN domain object. https://docs.digitalocean.com/products/spaces/resources/s3-sdk-examples/#presigned-url
|
Hi @awhileback , Thank you so much for your detailed response ! The overriding However if I take the signed url like
And replace
The signature is no longer valid, which means the assumption of replacing the host is not valid :-(. I'm using Thanks a million! |
Woah! If I use Thanks a lot! |
Updated guide with your findings, you're welcome! |
A docs PR would be appreciated
…On Thursday, October 14, 2021, awhileback ***@***.***> wrote:
Updated with your findings, I can verify that "s3v4" works on AWS S3, so I
suppose people just have to experiment with this setting on a per-provider
basis.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#944 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAREDWFKN6BVKCISSP326DTUG5ASVANCNFSM4SLGIULA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Worth noting that the signature version 2 ( |
I can confirm that using digital ocean spaces & cusom domain & cdn & acl private & signedUrl is still impossible using up-to-date "regular" approach and contemporary library like @aws-sdk/client-s3 (I am from typescript nodejs world). The only way to make it work is using approach described above - s3 config s3ForcePathStyle: true, signatureVersion: s3 -> generate signed url -> replace / with <custom_endpoint>. Thank you for rising this issue and describing the solution! Also, they are deprecating library that makes such implementation possible https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-javascript-v2/ |
When using a custom domain on your DigitalOcean space, such as
cdn.peekalink.com
, enabled by settingAWS_S3_CUSTOM_DOMAIN=cdn.peekalink.com
, when having a storage with the propertydefault_acl='private'
, no signature is emitted on the object url and it cannot be accessed.This is because on the S3BotoStorage, the
url
method checks whether theres a custom domain, and if there is, it tries to sign the object url with the CloudFront Signer, thing which obviously does not work for DigitalOcean Spaces.I'm trying to figure out how to best do this but the most sensible thing probably to do is to create a
digitalocean_signer
that handles this edge case and can be set on an storagedigitalocean_signer
attribute.Opening this issue so that there's some evidence that this problem exists and serving private resources stored on DigitalOcean won't work until this is solved.
The text was updated successfully, but these errors were encountered: