C-Bizz
C-Bizz

Reputation: 654

Digitalocean space access denied

I created a digital ocean storage space. The url of the space is as https://storagespace.nyc3.digitaloceanspaces.com However, when I click on the url to open on the browser I get the following error:

<Error>
<Code>AccessDenied</Code>
<BucketName>storagespace</BucketName>
<RequestId>tx000000000000001618a5e-0081246af3-1805687a-nyc3c</RequestId>
<HostId>1805987a-nyc3c-nyc3-zg03</HostId>
</Error>

I have no idea what this error means or why I'm having it. I connected the s3 bucket with my django website and the static files are not being served to the browser as well, instead I get 403 forbidden error. Please how do I remove this access denied error?

Upvotes: 1

Views: 5732

Answers (3)

Steve Austin
Steve Austin

Reputation: 131

To be brief, items added to Digital Ocean Spaces are set to private by default. To counter this, you would ideally require to specify them as publicly accessible to view them from your browser without 403s.

As some items may already be uploaded, a provisioning alongside the file indicated as "Manage Permissions" will allow you to toggle such items to public.toggle uploaded items to public This can otherwise be done as so: (I will give a rails implementation now and a python one when I can)

A rails implementation to set uploads as public on write

Take note of the "public-read" decree.

An honorable mention also: The endpoint is https://<data-center-region>.digitaloceanspaces.com, for your case, this should be: https://nyc3.digitaloceanspaces.com while the bucket is storagespace.

Upvotes: 1

EarlyCoder
EarlyCoder

Reputation: 1313

The problem is that you were missing AWS_DEFAULT_ACL = 'public-read' in your settings.py at the time you ran python manage.py collectstatic. Now, you need to go back and set the permission on all the files throwing 403 Forbidden error manually to public-read. I'd suggest to also add AWS_DEFAULT_ACL = 'public-read' to your settings for future collectstatic commands.

Upvotes: 1

acw
acw

Reputation: 948

tl;dr follow their official tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-django-app-with-digitalocean-managed-databases-and-spaces

Unfortunately, we don't really know what packages you're using (like are you using Django-storages to to get those static files to S3?). I have no experience with digital ocean, but here are some things to try:

As you can see in the tutorial, they have these settings which I presume digital ocean has provided you:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

# Moving static assets to DigitalOcean Spaces as per:
# https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django
AWS_ACCESS_KEY_ID = 'your_spaces_access_key'
AWS_SECRET_ACCESS_KEY = 'your_spaces_secret_key'

AWS_STORAGE_BUCKET_NAME = 'your_space_name'
AWS_S3_ENDPOINT_URL = 'spaces_endpoint_URL'
AWS_S3_CUSTOM_DOMAIN = 'spaces_edge_endpoint_URL'
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
AWS_DEFAULT_ACL = 'public-read'

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATIC_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATIC_ROOT = 'static/'

Upvotes: 2

Related Questions