signed urls do not work in Cloud Run with django-storages
See original GitHub issueUsing Cloud Run the default credentials do not allow signing of urls. The error is swallowed in most use cases and the file filed just returns a None in serializers or in django admin.
The error is confusing because everything works fine on the upload side. Even worse, if you use the same service account and run your container locally - it works fine. Since the credential is provided in the different manner.
To recreate:
- setup Django project in Cloud Run with Media objects in stored using GCS.
- Create file in Django admin (the file field comes back as None, but the file is in the GCS bucket)
- On editing a file in Django admin, the error is displayed:
Exception Type: | AttributeError
-- | --
you need a private key to sign credentials.the credentials you are currently using <class 'google.auth.compute_engine.credentials.Credentials'> just contains a token. see https://googleapis.dev/python/google-api-core/latest/auth.html#setting-up-a-service-account for more details.
/usr/local/lib/python3.8/site-packages/google/cloud/storage/_signing.py, line 51, in ensure_signed_credentials
I am still trying to figure out the best work around, but I wanted to add this in case anyone else runs into the error. This maybe a documentation update or a change to not swallow the error.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:9 (1 by maintainers)
Top Results From Across the Web
signed urls do not work in Cloud Run with django-storages
Using Cloud Run the default credentials do not allow signing of urls. The error is swallowed in most use cases and the file...
Read more >Google Cloud Storage — django-storages 1.13.1 documentation
Ensure the key is mounted/available to your running Django app. ... If set to False it forces the url not to be signed....
Read more >Signed URLs | Cloud Storage - Google Cloud
This page provides an overview of signed URLs, which give time-limited access to a specific Cloud Storage resource. Anyone in possession of the...
Read more >How to generate a Blob signed url in Google Cloud Run?
The answer @guillaume-blaquiere posted here does work, but it requires an additional step not mentioned, which is to add the Service Account ......
Read more >Django on Cloud Run - Google Codelabs
Django is a high-level Python web framework. In this tutorial, you will use these components to deploy a small Django project. What you'll...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Our workaround is as follows:
You should obviously then use this class as a replacement for the GoogleCloudStorage base class (we set up storages explicitly on a case-by-case basis, so this is fairly straightforard for us).
I know the OP wanted to use signed URLs, just a note we hit this issue accidentally because we were missing
GS_DEFAULT_ACLfrom our settings.py, so were accidentally enabling signed URLs.GS_DEFAULT_ACL = 'publicRead’