The lab bucket uses the ObjectWriter object ownership setting, so ACLs are enabled and a client can upload an object with a canned ACL such as public-read. In this section you see why an Allow statement is not enough to stop that, and how a Deny statement fixes it.
private. Replace <your-account-id> and <region> with your values (you can copy the role ARN from the IAM console).{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPrivateAclOnly",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<your-account-id>:role/FCJ-S3Security-EC2-Role-<region>"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::<your-bucket-name>/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "private"
}
}
}
]
}

public-read:aws s3api put-object --key text01 --body textfile --bucket $bucket
aws s3api put-object --key text01 --body textfile --acl public-read --bucket $bucket
Both uploads succeed. The role’s IAM policy already allows s3:* on the bucket, so a bucket-policy Allow with a condition does not restrict anything: access is granted if any policy allows it and none denies it.

The object text01 is now readable by anyone who knows its URL. Re-upload it with the default ACL (the next step does this) and do not store real data in the lab bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyPublicAcls",
"Effect": "Deny",
"Principal": "*",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::<your-bucket-name>/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": [
"public-read",
"public-read-write",
"authenticated-read"
]
}
}
}
]
}

aws s3api put-object --key text01 --body textfile --acl public-read --bucket $bucket
aws s3api put-object --key text01 --body textfile --bucket $bucket
The public-read upload is now denied, while the normal upload (private ACL) still succeeds and resets the object to private.
