Restricting S3 permission

,

I have two buckets on S3 that I use with an app; one for test environment, and one for production.
I’ve been wrestling with permissions on IAM panel to try to get the developers to only have access to the test environment bucket, especially since they had accidentally deleted files from production bucket in the past.

I have no specific policy set up to grant them S3 access aside from list objects, and a policy that allows s3:* in the resource that is relevant to them (arn:aws:s3:::testbucket).

For some reason, when I log in as the test user, I am still able to get into the production bucket, upload files, and delete files no problem. What am I doing wrong here? I checked bucket permissions as well - s3 buckets don’t have any specific bucket permissions set aside from root user having max permissions.


Related discussions:

I believe you’ll want to setup a policy on the bucket itself to only allow certain people access to the production bucket or you may have to deny a group or individual users.

https://docs.aws.amazon.com/AmazonS3/latest/dev/example-walkthroughs-managing-access-example1.html

Also - I would recommend enable versioning for your buckets.

You might get more/better help if you post a redacted/obfuscated copy of the IAM policy in question.

I concur, I’d go as far as saying that we need to see all the policies affecting that user/bucket.

My guess is either a policy is granting too much on testbucket* or the bucket itself is wide open.

Here is a policy I use to restrict users to a specific bucket..

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: “s3:",
“Resource”: "arn:aws:s3:::awesomebucket/
”
}
]
}

The key bit is to specify the bucket arn as a resource…

So create the policy, and apply the policy either to a role, user, or group ..

You should probably create a new, separate account for the test bucket, and other test AWS resources. AWS can roll the billing up for both accounts into one for you.

Are there any bucket policies or ACLs on the production bucket? Post them if so.

Which takes precedence over the other in the event that there are overlapping permissions between IAM group policies and bucket-specific policies set on S3?

Allows all overlap, you can’t, for example, allow writes for everyone on a bucket policy then only allow writes to a sub folder on an IAM policy.

Explicit denies are higher priority than allows always.

Please post redacted policies so we can help.

I did exactly this :confused:
and when I log in as the dev user account, while I am not able to create buckets at root (I get the message "You do not have permission to read this.. or something like that), I can still get into the production bucket and create new directories, upload, and delete.

As for the bucket itself… no other permissions set other than me (root user) having full control.

I have a couple of other policies which I think are unrelated, that have to do with Beanstalk use. Actions relating to autoscaling, elastic beanstalk, and of course a redundant “read only” s3 policy is also present.

Other than that, I can’t think of any reason why they are able to read/write as they do.

Here are all the policies I have:

Policy 1

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“elasticbeanstalk:Check*”,
“elasticbeanstalk:Describe*”,
“elasticbeanstalk:List*”,
“elasticbeanstalk:RequestEnvironmentInfo”,
“elasticbeanstalk:RetrieveEnvironmentInfo”,
“ec2:Describe*”,
“elasticloadbalancing:Describe*”,
“autoscaling:Describe*”,
“cloudwatch:Describe*”,
“cloudwatch:List*”,
“cloudwatch:Get*”,
“s3:Get*”,
“s3:List*”,
“sns:Get*”,
“sns:List*”,
“cloudformation:Describe*”,
“cloudformation:Get*”,
“cloudformation:List*”,
“cloudformation:Validate*”,
“cloudformation:Estimate*”,
“rds:Describe*”,
“sqs:Get*”,
“sqs:List*”
],
“Resource”: “*”
}
]
}

Policy 2

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "elasticbeanstalk:DescribeApplicationVersions",
            "elasticbeanstalk:DescribeApplications",
            "elasticbeanstalk:UpdateApplication",
            "elasticbeanstalk:UpdateApplicationVersion",
            "elasticbeanstalk:CreateStorageLocation",
            "elasticbeanstalk:UpdateEnvironment"
        ],
        "Resource": [
            "My beanstalk environment"
        ]
    }
]
}

Policy 3

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "elasticbeanstalk:CreateApplicationVersion"
        ],
        "Resource": [
            "*"
        ]
    }
]
}

Policy 4

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "autoscaling:*"
        ],
        "Resource": [
            "*"
        ]
    }
]
}

Policy 5

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "elasticloadbalancing:RegisterInstancesWithLoadBalancer"
        ],
        "Resource": [
            "My load balancer"
        ]
    }
]
}

Policy 6

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
        
            "elasticbeanstalk:CreateStorageLocation"
        ],
        "Resource": "*"
    }
]
}

Policy 7

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "s3:*"
        ],
        "Resource": [
            "My s3 bucket",
            "My s3 bucket/*"
        ]
    }
]
}

You can do permissions on the bucket side. If you can narrow down who has access to the production bucket, you can do an explicit deny on anything other than the IAM account(s) mentioned in the bucket policy.

Maybe this will help. I’ve used this template to restrict access.

“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“s3:ListAllMyBuckets”,
“s3:GetBucketLocation”
],
“Resource”: “arn:aws:s3:::"
},
{
“Effect”: “Allow”,
“Action”: “s3:ListBucket”,
“Resource”: “arn:aws:s3:::BUCKET”,
“Condition”: {“StringLike”: {“s3:prefix”: [“”,“FOLDER/”]}}
},
{
“Effect”: “Allow”,
“Action”: "s3:
”,
“Resource”: [
“arn:aws:s3:::BUCKET/FOLDER”,
“arn:aws:s3:::BUCKET/FOLDER/*”
]
}
]

I posted my policies up here
I don’t really have any bucket-specific policies other than the default root user access.

Policy 7 Allows all actions on the bucket on every folder.

I defined the S3 test bucket under Resource though? How would I frame it so they are permitted all actions just to that particular bucket? The way I have it set up with policy 7, I can still log in as the dev user and go into production use bucket and create, upload and delete.

Whoops, sorry, I thought My s3 bucket was the production bucket.

Are you sure the test user doesn’t have any groups or other policies attached? Maybe managed policies or other stuff, the new IAM interface sometimes hides those tables so make sure you expand every section and get into the nitty gritty of the user.

As a test I would start removing all policies from the testuser and logging in and testing the bucket access.

They’re all group policies - the user has no policies attached. Unfortunately those 7 are the only policies I have active anywhere.
Bah! I think i might just create another AWS account for them. Had enough headache with this heh