1 Answer
- Newest
- Most votes
- Most comments
0
i have added the following example please modify accordingly
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"eks:DescribeCluster",
"eks:ListFargateProfiles",
"eks:ListUpdates",
"eks:UpdateClusterVersion"
],
"Resource": "arn:aws:eks:us-west-2:123456789012:cluster/my-cluster",
"Condition": {
"StringEquals": {
"aws:userid": [
"user1",
"user2"
],
"sourceArn": [
"arn:aws:execute-api:us-west-2:123456789012:abcdefghij/*/GET/resource1",
"arn:aws:execute-api:us-west-2:123456789012:abcdefghij/*/GET/resource2"
]
}
}
},
{
"Effect": "Allow",
"Action": [
"ecr:BatchGetImage",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:ListTagsForResource",
"ecr:PutImage"
],
"Resource": "arn:aws:ecr:us-west-2:123456789012:repository/my-repo",
"Condition": {
"StringEquals": {
"aws:userid": [
"user1",
"user2"
],
"sourceArn": [
"arn:aws:execute-api:us-west-2:123456789012:abcdefghij/*/POST/resource3",
"arn:aws:execute-api:us-west-2:123456789012:abcdefghij/*/POST/resource4"
]
}
}
}
]
}
Relevant content
- asked 3 years ago
Before creating the policy, make sure that your EKS application support custom IAM action. IAM policy : { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "myCustomService:MyCustomAction", "myCustomService1:MyCustomAction1" ], "Resource": "*" } ] } Example in Kubernetes Aplication import boto3 from botocore.exceptions import ClientError
client = boto3.client('iam')
def check_custom_permission(action_name): try: response = client.simulate_principal_policy( PolicySourceArn='arn:aws:iam::ACCOUNT_ID:role/YOUR_ROLE_NAME', ActionNames=[action_name] ) return response['EvaluationResults'][0]['EvalDecision'] == 'allowed' except ClientError as e: print(e) return False