user2315104
user2315104

Reputation: 2730

how to combine two IAM policies together

Im new to IAM policies. Trying to combine below two policies and make single one. The role is AmazonEKSVPCCNIRole

below are two policies :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

and

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "<arn-value>"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "oidc.eks.us-east-1.amazonaws.com/id/<id>:sub": "system:serviceaccount:kube-system:aws-node",
                    "oidc.eks.us-east-1.amazonaws.com/id/<id>:aud": "sts.amazonaws.com"
                }
            }
        }
    ]
}

i just need single policy combining above two policies. Im getting JSON error when trying to combine. please help to create single policy

Upvotes: 1

Views: 1392

Answers (1)

Vikram S
Vikram S

Reputation: 842

Can add the element in the statement array separated by comma. This is trust policy and not a normal policy.

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "Federated": "<arn-value>"
        },
        "Action": "sts:AssumeRoleWithWebIdentity",
        "Condition": {
            "StringEquals": {
                "oidc.eks.us-east-1.amazonaws.com/id/<id>:sub": "system:serviceaccount:kube-system:aws-node",
                "oidc.eks.us-east-1.amazonaws.com/id/<id>:aud": "sts.amazonaws.com"
            }
        }
    },
 {
        "Effect": "Allow",
        "Principal": {
            "Service": "ec2.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }
]

}

Upvotes: 3

Related Questions