I’m working on a SaaS application. Currently we’re only storing public uploads in a bucket. For a new feature I need to store private files only accessible for specific users.
What would you say is best practice, having a separate bucket for all private objects or just one bucket with only specific folders/objects that are public?
Regardless of the single- or multi-bucket approach that you decide to use, I wanted to make sure that you were aware of S3 Access Points. S3 APs are a way to manage access for different sets of users against data stored within a single bucket. With each AP, you get an additional custom hostname for your bucket, onto which you can apply a separate bucket policy.
I agree with the other comments. I just want to add, there is seldom a reason to make a bucket public instead of just making the objects public. An object being public should be intentional.
I’ve got one client who took it a step further. All of their public buckets are in a dedicated “public bucket account” that hosts absolutely nothing else.
Also, I would imagine the OP knew the moment they asked :). Honestly, you can do it either way safely. One way is just much easier to manage and tag and all the things if you keep them a separate as possible.
Technically, it is possible to host both public and private objects in a single bucket because S3 does allow that level of granular control at object level. However, as many others already said, it is best to use separate buckets and keep things simple. Is there something that is limiting you to one bucket only?
As many people have said, separate buckets. However, have you thought about how you will ensure that the access controls aren’t later changed? I’d suggest using tags on the buckets to clearly document intent (such as whether it should be public or private), and a tool like Cloud Custodian to ensure that the private bucket isn’t accidentally made public.