S3 Policy Limiting Access to only one foler - amazon-web-services

I have a bucket in S3 named home, and have multiple folders under it. I want to allow a specific user to be able to access to the folder1 under path: home/A/B/folder1. However I do not want him to see any other buckets and even other folders in this home bucket.
Can anyone help me with this policy?

Amazon S3 provides several User Policy Examples and the desired scenario is explored in Example: Allow each IAM user access to a folder in a bucket:
In this example, you want two IAM users, Alice and Bob, to have access to your bucket, examplebucket, so they can add, update, and delete objects. However, you want to restrict each user’s access to a single folder in the bucket.
As explained there, you can attach individual policies per user, however, it is meanwhile best addressed by using IAM Policy Variables:
Instead of attaching policies to individual users, though, you can
write a single policy that uses a policy variable and attach the
policy to a group. [...] The following example policy allows a set of
Amazon S3 permissions in the examplebucket/${aws:username} folder.
When the policy is evaluated, the policy variable ${aws:username} is
replaced by the requester's user name. [...]
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion"
],
"Resource":"arn:aws:s3:::examplebucket/${aws:username}/*"
}
]
}

Related

Possible if I grant another user in my AWS account is owner S3 object?

I have an administrator of AWS. I create a S3 bucket, and many sub folder in it. I want grant different permission for another user in my account in this bucket. Example:
My account ID is 1111-1111-1111, and I create 2 IAM users is alice and bob. I want the folder named is alice-folder has owner by alice. All of object which alice created in this folder has owner by her. Same with bob.
I read document in Controlling ownership but this said: The AWS account that uploads an object owns the object, has full control over it, and can grant other users access to it through ACLs., not as same as my case.
So, everyone who can talk to me how can I do, it is possible?
Thanks in advance.
Users do not "own" objects in Amazon S3. The objects are owned by the Account.
If you want to permit specific IAM Users to use a bucket, or a portion of a bucket, you can add policies to an IAM User or IAM Group to permit them to access the bucket or folder.
Here is an example policy from User policy examples - Amazon Simple Storage Service that permits Alice to access a folder in a bucket:
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion"
],
"Resource":"arn:aws:s3:::awsexamplebucket1/Alice/*"
}
]
}
This policy lets her Put, Get and Delete objects in the folder, which is probably what you want to allow them to do when you say that you want them to 'own' the folder.
If you are assigning such permissions to many users, you can instead create folders based on the name of IAM Users and then put this policy on an IAM Group. Anyone in the IAM Group will be able to use a subfolder with their IAM User name:
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion"
],
"Resource":"arn:aws:s3:::awsexamplebucket1/${aws:username}/*"
}
]
}

Grant S3 bucket access to all principals in organization

Scenario:
I have 3 AWS root accounts in the same organization.
admin#mydomain.com
user1#mydomain.com
user2#mydomain.com
user1 created an S3 bucket B1. I want user2 and admin to be able to see and browse B1 on their own S3 dashboard. Is this possible? What policy(policies) that I need to create? Where do I create these policies and how to create them?
**The original question has been edited. Some answers below might not be relevant any more
I believe all you need to do is add Principal: "*" to the policy. This opens access to anyone, but the condition will limit it to the org.
As far as I know, I cannot do the S3 bucket console sharing between root users. I've finally managed to share the bucket created by user1 with an IAM user.
Steps for Root User
Login into AWS console and go to IAM
Create group
Create IAM policy i.e. allowing S3 full access (see below)
Attach policy to group
Create IAM user
For Access type choose AWS Management Console access
Add user to the group you created in step 1
Follow through until you click on create user button
IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-xxxvvvwww8"
}
}
}
]
}
EDIT:
After rigorous trial & error testing, it seems that we don't even need bucket policy for this to work. I've removed the bucket policy and it all still works!
Steps for IAM User
Log into AWS console as IAM user
Go to S3 console. You should be able to see and browse all buckets and objects created by all organization members
Note
Your IAM user would not be able to see the bucket listed on its S3 console dashboard. That shared bucket can only be accessed through direct link. So your root user must provide the URL i.e. https://s3.console.aws.amazon.com/s3/buckets/bucket1/ to your IAM user

AWS S3 make bucket public

I am logged in AWS with admin privilege. I am trying to make a bucket public read, write. I have deselected these options. I also followed this one Duplicate and tried to update bucket policy, but getting access denied error. All those answers are from 2018.
The link that you referred is still working fine!
Along with "Bucket Public Access" option, you should paste the following bucket policy in "Bucket Policy":
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal":"*",
"Action":[
"s3:GetObject",
"s3:PutObject"
],
"Resource":[
"arn:aws:s3:::your-bucket-arn-here/*"
]
}]
}
This grants both read and write operations into your bucket.
Please, remember to change your bucket's Amazon Resource Name (arn) where key in bucket policy points to "Resource".
You can find your bucket's arn above bucket policy paste field.
Also, you may make use of AWS policies generator for further access grants.
I hope I might help.
If your bucket policy is using the following then at least this is setup to allow public read and write. Be aware this is anonymous so anyone can perform a read or write to the bucket, you will still be responsible for this.
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal":"*",
"Action":[
"s3:GetObject",
"s3:PutObject"
],
"Resource":[
"arn:aws:s3:::bucketname/*"
]
}]
}
Be aware that if ACLs are involved you would also need to apply the permissions of s3:PutObjectAcl. In addition the ACL would need to grant the public read/write which would be counterintuitive as you're using a bucket policy to do this.
If you're getting access denied when updating the bucket policy your user is prohibited from performing the action.
There are a few reasons why this could occur:
Your IAM user does not have the IAM policy permissions.
Your account is part of an AWS organisation that is using an SCP (Service Control Policy) to prohibit applying a bucket policy.
Your IAM user has been configured with an IAM boundary that it prohibiting this access.
If you do not have the ability to modify your permissions or your account was given to you via a service you would need to communicate with them.

Grant access to a single folder in the bucket by AWS STS token

I need to allow an anonymous user to access a single folder in the Amazon S3 bucket by providing an STS Token.
I found a guide on how to provide an access to a user-specific folders in one bucket based on policies and policy variables. There you use long-term user keys. Would that be possible to implemented something similar but using the STS tokens and only one user vs. multiple users each having their own folders?
When you call AssumeRole through the STS service you include a policy document that specifies what permissions the temporary credentials will have. In that policy document you would specify the exact S3 permissions you want this user to have. You wouldn't need to use policy variables because you are generating a policy document for a single user at that point (no user variable needed because you know who the exact user is in this scenario).
Your policy document would look something like this (replacing my-bucket and my-folder with the actual bucket name and folder name you want to grant the specific user access to):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*"
],
"Resource": "arn:aws:s3:::my-bucket/my-folder/*"
}
]
}

How to restrict the user to download data from amazon S3 usin IAM?

I have many buckets and none of them should allow anonymous access
The user I have added must have access to one bucket only and should
be able to enter any other bucket
The user must NOT be able to add/modify/delete buckets
The user should be able to list files in his bucket
The user must NOT be able to download files from the buckets The user
should be able to add files in the bucket
please suggest
It sounds like your requirements are:
You have multiple IAM Users
Each user will have their own bucket
Users can list the contents of their bucket and upload files to their bucket
Users cannot do anything else to the objects in their bucket, nor to the bucket itself
To do this, you will want to create a policy for each IAM User.
The policy would look something like:
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:PutObject",
"s3:ListBucket"
],
"Resource":"arn:aws:s3:::Ahito-Bucket"
}
]
}
See: User Policy Examples - Amazon Simple Storage Service
An alternative method is to have all users share one bucket, but create a policy that limits users to their own directory.
See: IAM Policy Elements: Variables - AWS Identity and Access Management