Tighten bucket access by setting a bucket policy
My requirements:
- I want my backup script to ONLY have access to the backup bucket, and not to any other buckets in my Project. If somehow the credentials would get compromised (stolen, published, ...), I want the potential damage to be limited to only the contents of the backup bucket. NO other buckets should be accessible with those credentials.
- I ONLY want my backup script to be able to access the backup bucket. NO other principals with Object Storage access should have access to the backup bucket.
Here's where things got confusing for me the first time around. You may want to re-read the following explanation a few times :)
A this point my "Backup script" principal already implicitly has full Object Storage access to all the buckets under my Project, because of the IAM policy I created at the beginning.
The next thing I now need to do is create a bucket policy that explicitly grants my principal the required permissions to the backup bucket.
I know that seems like overkill, but stay with me.
- Go to Storage > Object Storage > Create bucket policy.
- Provide a useful name (e.g. "Backup script policy").
- Select your bucket.
- Add a statement using the Policy generator (default option).
- Leave Maintain access to bucket checked (!)
- Provide a statement to give your principal full access:
- Give the statement a useful name (e.g. "Grant access to backup script").
- Select which type(s) of principal to include (e.g. "application").
- Select which principal(s) to include (e.g. "Backup script").
- Select All Actions (you can this refine later if necessary).
- Click Create bucket policy.
(if the button is not clickable, you forgot to fill in a required field)
That's it. Your bucket policy is in place for the specific bucket you selected.
Why did I need to set a bucket policy in additon to an IAM policy?
Setting a bucket policy on a specific bucket targeting one or more specific principal(s) has the following effect:
- Because there now exists an explicit bucket policy, ONLY the mentioned principal(s) get access to the backup bucket. ALL other principals that may have had implicit access through the broad IAM policy before are now excluded. In other words, at this point ONLY the principal(s) mentioned in the bucket policy retain access. Part of my requirements is now satisfied.
The other part is that I want my principal to ONLY have access to the backup bucket and NOT to any other buckets in my Project.
To do this I have to also create a bucket policy for ALL of the other buckets in my Project and specify which principal(s) should have access.
Here's the reasoning:
Asuming people want to start out with basic requirements, granting all principals full Object Storage access (if they need it, of course) through an IAM policy means you don't need to start configuring things on bucket-by-bucket basis. Unless, of course, this is what you want, in which case, you can do so. But not everyone needs this, so Scaleway tries not to force everyone through bucket policies if it can be avoided.
If you're skeptical, try setting bucket policies without setting an IAM policy. Your principal won't have access to the overall Object Storage "space" to begin with, no matter which fine-grained permissions you grant on bucket level.
Remember, you don't have to grant full permissions on bucket level. You should learn about the available bucket-level permissions and strictly grant the smallest possible set of permissions for your principal to be able to do its job.
This is called The Principle of Least Access (no pun intended).
Final note:
Regardless of any bucket policies you may set up, the owner of the Organization will ALWAYS retain the right to create and delete bucket policies. In other words, the owner of an organization can NEVER be permanently locked of any bucket in the organisation because they will ALWAYS be ably to modify or delete all bucket policies.