AWS IAM policy, user should see only s3 public buckets - amazon-web-services

i have tried several methods, couldn't succeed. I need to have policy that attach to users, so that they could see only public buckets not all the buckets in their aws console

The ability to view a list of buckets is granted via the s3:ListAllMyBuckets permission, which is defined as:
Grants permission to list all buckets owned by the authenticated sender of the request
Thus, the user either has permission to list the names of all buckets, or none of the buckets. It is not possible to filter which buckets are returned in the listing.

Related

Limiting S3 bucket access to users within one account

I have an IAM user that has full S3 access (i.e. can perform any S3 actions on any S3 resource within the AWS account). This user has created a bucket and put some files in it. The bucket has a policy which just contains an Allow rule that grants access to a different IAM user, in the same AWS account. Public access is turned off for the bucket.
Should the first user be able to access objects in this bucket? If so, is that because they created the bucket, or because they're in the account that owns the bucket? Is it possible to limit access to a bucket for users within the same AWS account?
S3 is one of the few services with resource policies, in this case they are called bucket policies.
A user in the same account has access to a (S3) resource if
nothing explicitly denies the access AND
either the bucket policy grants access OR the user / entity has a policy attached that grants access
If you wanted to restrict a bucket to a single user / entity you would
need to write a bucket policy that specifies that using a Deny statement for every user except the target one AND
either add a statement to the bucket policy or a policy attached to the user / entity granting access to the bucket.
The standard doc for understanding policy evaluation logic is this. There are other, more complicated ways to achieve your goal using e.g. permission boundaries and SCPs but they are probably overkill in your situation.

I am a AWS IAM user and I have created a bucket, and I want no other IAM users to access my bucket. How can I achieve it

I am a AWS IAM user having "S3FullPermissions". I have created a bucket, and I want no other IAM users to access my buckets. How can I achieve it. Please help me with bucket policy..
S3 buckets and their objects are by default private. No one has access to them unless given explicit permissions to do so. So if you are the only one with S3 buckets permissions, no other IAM user will be able to access your buckets and objects.

AWS S3 ACL for allowing access for all users or roles, etc. in a specific account

According to the Documentation: Granting permissions to multiple accounts with added conditions it is possible to create with the entry:
Principal": {"AWS": ["arn:aws:iam::111122223333:root","arn:aws:iam::444455556666:root"]}
just access for all the users inside this account. But unfortunately it is not working. When putting single users there the access for that User from that different account is working. But with all and the root option is does not work.
But with all and the root option is does not work.
This is because the admins of these accounts also have to add permissions to IAM users/roles to access the bucket. In other words, adding arn:aws:iam::111122223333:root to a bucket policy is not enough. The individual IAM users or roles from 111122223333 also need IAM permissions to access the bucket.

Iam permission vs resource permissions

In aws an IAm user can be given say read access to an s3 bucket using permissions. Similarly a policy (permission) can be attached to an s3 bucket to allow certain user access to that s3 bucket. My question is why there are two ways to do it. Should you define both? What if user 1 is allowed to access an s3 folder but IAM policy at resource level allows user 2 access to it. Who wins in this situation? What is the order of evaluation?
Typically:
To grant Amazon S3 access to a specific user, it is best to place the policy on the IAM User (or an IAM Group container IAM Users).
To grant public access, place a Bucket Policy on the bucket permitting anonymous access.
Yes, it is possible to grant individual access via a Bucket Policy, but this can become quite messy if multiple users are added this way.
The user will be permitted to access the bucket as long as either of these methods are used. However, any Deny policy will always override an Allow policy from either source.

How to identify which policy/role is granting access to S3 bucket

I have a Cognito pool / Federated identity setup with users receiving temporary IAM credentials via AWS Amplify. These users have access to getObject from a couple S3 buckets even though:
The buckets have all public access disabled
The buckets policy page is blank
The IAM role associated to the Cognito groups that these users are members of (Trust Relationship with cognito-identity.amazonaws.com) have no policies attached that grant any S3 permissions. Policies attached are only for AppSync, Cognito, and APIGateway
If I create a new bucket and point getObject at a contained object, the users get 403 Forbidden, an indication that some bucket-specific policy somewhere is granting access. Problem is we have so many policies and roles, many used in production, so I can't simply do on/off testing to narrow it down.
Is there a way somehow to trace what policy/role is providing access for a specific S3 getObject request?
EDIT I've run the IAM Policy Simulator for the role associated with the Cognito groups and it gives denied for the objects in question.
The objects I'm trying to have access correctly blocked for have no permissions set for them. The buckets have:
Block new public ACLs and uploading public objects (Recommended): True
Remove public access granted through public ACLs (Recommended): True
Block new public bucket policies (Recommended): True
Block public and cross-account access if bucket has public policies (Recommended): True
UPDATE I've added cloudtrail logging to my buckets. While an event with eventname = 'GetObject' is logged for any downloads I do from the bucket via console, no events are logged for s3.getObject downloads via the AWS javascript SDK. How can I get these events to log?
Use CloudTrail to log Amazon S3 API Calls.
An event logged in CloudTrail for S3 actions includes information about the requested action, the date and time of the action, request parameters, and the user identity, for example:
arn:aws:iam::123456789012:user/Alice
arn:aws:sts::123456789012:assumed-role/RoleToBeAssumed/MySessionName