I'm not able to change IAM role policy in our corporate environment. So I want to be able to change role's permissions to S3 based on bucket policy. I want to setup AWS IAM instance role to have Allow on "s3:GetObject" based on this bucket policy.
I have this in my bucket policy:
{
"Sid": "tag-based",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::XY:role/testing"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::bucket1/path1/*",
"arn:aws:s3:::bucket1/path1"
]
},
And I want something like this in my IAM role inline policy -> To have allow only for resources which have TagKey equal to 'SG':
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:PutObjectAcl"
],
"Resource": "<HOW TO SETUP IT ONLY FOR RESORUCES WHICH HAVE TAG KEY 'SG?'>",
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": [
"SG"
]
}
}
}
Is this right way to achieve it?