Correct option:
{
"Statement": [
{
"Sid": "AllowEveryoneReadOnlyAccess",
"Effect": "Allow",
"Principal": "*",
"Action": [ "s3:GetObject", "s3:ListBucket" ],
"Resource": ["urn:aws:s3:::mybucket","urn:aws:s3:::mybucket/*"]
}
]
}
This policy is the right fit for providing read-only access to all users.
Resource: Buckets, objects, access points, and jobs are the Amazon S3 resources for which you can allow or deny permissions. In a policy, you use the Amazon Resource Name (ARN) to identify the resource. urn:aws:s3:::mybucket","urn:aws:s3:::mybucket/* are the resources for which the policy is defined.
Effect: Effect is the effect will be when the user requests the specific action—this can be either allow or deny. If you do not explicitly grant access to (allow) a resource, access is implicitly denied. You can also explicitly deny access to a resource.
Action: For each resource, Amazon S3 supports a set of operations called actions. GetObject and ListBucket actions help list the objects in the bucket and access the objects.
Principal: The account or user who is allowed access to the actions and resources in the statement. In a bucket policy, the principal is the user, account, service, or other entity that is the recipient of this permission. * signifies that any principal can access this S3 bucket.
Incorrect options:
{
"Statement": [
{
"Sid": "AllowEveryoneReadOnlyAccess",
"Effect": "Allow",
"Principal": "*",
"Action": [ "s3:ReadObject", "s3:ListBucket" ],
"Resource": ["urn:aws:s3:::mybucket"]
}
]
}
There is no action like s3:ReadObject. Hence, this policy is incorrect.
{
"Statement": [
{
"Sid": "ReadOnlyAccess",
"Effect": "read-only",
"Principal": "*.*",
"Action": [ "s3:GetObject", "s3:ListBucket" ],
"Resource": ["urn:aws:s3:::mybucket*"]
}
]
}
Effect can be either allow or deny. read-only is not a valid effect and hence this policy is incorrect.
{
"Statement": [
{
"Sid": "AllowEveryoneReadOnlyAccess",
"Effect": "deny",
"Principal": ".",
"Action": [ "s3:GetObject", "s3:GetBucket" ],
"Resource": ["urn:aws:s3:::mybucket"]
}
]
}
There is no GetBucket action. Moreover, deny will not provide the necessary permissions, as is the need for the use case.
Reference:
https://docs.amazonaws.cn/en_us/AmazonS3/latest/userguide/access-policy-language-overview.html