Question

Setting DO Spaces files to Public for Django CKEditor

I’m using the Django plugin, django-ckeditor, which unfortunately does not work with S3 unless the following is set: AWS_QUERYSTRING_AUTH = False.

https://django-ckeditor.readthedocs.io/en/latest/#using-s3

The problem is that all files must be set to public to work with that setting. That plugin, in particular, has hundreds of directories with hundreds of files. So my question is two-fold.

Is there any security risk in making all of my css, js, images, and ckeditor files public?

Secondly, is my only option to manually go through each of these directories and change them to public? Is there a faster option?

Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I figured out a way to do this by setting up the following.

backends.py (site/cdn/backends.py):

from storages.backends.s3boto3 import S3Boto3Storage


class CustomS3Boto3Storage(S3Boto3Storage):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.default_acl = "private"  # Set the default ACL to 'private'
        self.querystring_auth = True

    def _save(self, name, content):
        if name.startswith("static/ckeditor/"):
            # Make ckeditor/ folder inside static/ public
            self.default_acl = "public-read"
            self.querystring_auth = False
        else:
            self.default_acl = "private"  # Set all other files/folders to private
            self.querystring_auth = True

        return super()._save(name, content)


class MediaRootS3Boto3Storage(S3Boto3Storage):
    location = "media"

Then in site/cdn/conf.py

DEFAULT_FILE_STORAGE = "inkwise.cdn.backends.MediaRootS3Boto3Storage"
STATICFILES_STORAGE = "inkwise.cdn.backends.CustomS3Boto3Storage"

Then in settings.py

if os.environ.get("server_type") == "production":
    from .cdn.conf import *

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.