1 Answer
- Newest
- Most votes
- Most comments
2
I answered the question below, but I'll post it here as well.
https://repost.aws/ja/questions/QU4FV_KOKYRS24qKSDRiNlRw/aws-s-3-%E3%81%AE-backup%E7%92%B0%E5%A2%83%E6%A7%8B%E7%AF%89
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::{bucket_name}",
"arn:aws:s3:::{bucket_name}/*"
],
"Condition": {
"StringNotEquals": {
"aws:PrincipalArn": [
"AWS Backup Service Role ARN",
"IAM User ARN"
]
}
}
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::{bucket_name}",
"arn:aws:s3:::{bucket_name}/*"
],
"Condition": {
"StringNotLike": {
"aws:userId": "AIDxxxxxxxxxxxxxxxxx"
},
"NotIpAddress": {
"aws:VpcSourceIp": [
"124.215.101.111/32",
"60.112.161.29/32"
]
}
}
}
]
}
You can check "aws:userId" with the following command.
When executing the command below, please execute it as the IAM user who will be setting up the backup plan.
aws sts get-caller-identity
Executing the command returns results like the following:
Please set "UserId" in this to your bucket policy.
{
"UserId": "AIDxxxxxxxxxxxxxxxxx",
"Account": "1111111111111",
"Arn": "arn:aws:iam::1111111111111:user/test"
}

To be clear, the second Deny statement will only match if both conditions are true: if the identity doesn't match the tested value and the IP doesn't match. If the intent is to block access from unexpected IPs, the IP check will have to be separated into its own statement. Also, AWS Backup won't be coming from those IPs, so this statement will block it too, unless the role AWS Backup is using is exempted in the condition clause.
The
aws:VpcSourceIprequest context condition key shouldn't be used alone. It should always be combined with theaws:SourceVpcoraws:SourceVpcekey. That's becauseaws:VpcSourceIpchecks for the client IP for requests received through a VPC endpoint, and within a VPC, anyone can use whichever IP addresses they like. If the intent is to permit access over the internet and not via a VPC endpoint, as I'm suspecting is the case based on the public-looking IPs, the correct key isaws:SourceIp, which is appropriate to use by itself. It won't match requests received over a VPC endpoint.In conclusion, it worked well. Thank you for your cooperation. I appreciate it.