I need some help related to creating AWS policies.
I need a policy linked to an EC2 instance to be able to give only a get-parameters-by-path
to a specific parameter in AWS SSM parameter store, without being able to change anything like Delete
, Create
, etc and should only be able to get the values.
This policy specificity will be given through tags.
Here's my policy I'm trying to use:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ssm:*"],
"Resource": ["*"]
},
{
"Effect": "Deny",
"Action": [
"ssm:PutParameter",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:DeleteParameter",
"ssm:GetParameterHistory",
"ssm:DeleteParameters",
"ssm:GetParametersByPath"
],
"Resource": ["*"],
"Condition": {
"StringNotEquals": {
"ssm:resourceTag/env": "development-1"
}
}
}
]
}
Using the AWS Policy Simulator it informs you that when trying to View
, Create
, Modify
, Delete
Parameters with "ssm:resourceTag/env": "development-2"
a denial message is informed, while other projects with "ssm:resourceTag/env": "development-1"
it is possible to modify, view, etc.
However, when tying the same policy to an EC2 instance, the policy blocks any of the actions added in Deny.
EC2 Informed Messages:
/development-1/project-1
aws --region us-east-2 ssm get-parameters-by-path --path /development-1/project-1/ --recursive --with-decryption --output text --query "Parameters[].[Value]"
An error occurred (AccessDeniedException) when calling the GetParametersByPath operation: User: arn:aws:sts::111111111:assumed-role/rule-ec2/i-11111111111 is not authorized to perform: ssm:GetParametersByPath on resource: arn:aws:ssm:us-east-2:11111111111:parameter/development-1/project-1/ with an explicit deny
/development-2/project-2
aws --region us-east-2 ssm get-parameters-by-path --path /development-2/project-2/ --recursive --with-decryption --output text --query "Parameters[].[Value]"
An error occurred (AccessDeniedException) when calling the GetParametersByPath operation: User: arn:aws:sts::11111111111:assumed-role/rule-ec2/i-11111111111 is not authorized to perform: ssm:GetParametersByPath on resource: arn:aws:ssm:us-east-2:11111111111:parameter/development-2/project-2/ with an explicit deny
Tags used:
key=value
/development-1/project-1
:
env=development-1
/development-2/project-2
:
env=development-2
What am I doing wrong?