🔟

[IAM Identity Center]許可セットでマネージドポリシーを上限以内に収める方法

に公開

マルチアカウント環境でユーザー管理を行う場合、「IAM Identity Center」を使用することも多いと思います。
今回は各AWSアカウントへのアクセス権限を定義する許可セットに付与するマネージドポリシーについてのお話です。

許可セットに付与できるマネージドポリシーの上限問題

許可セットに付与できるマネージドポリシーには10個まで(後述のクォータ増加申請を行えば20個まで)の上限があります。

最大 10 個のマネージドポリシー (AWS マネージドポリシーとカスタマーマネージドポリシー) を許可セットにアタッチできます。

クォータ増加申請

付与できるマネージドポリシーの数を増やすにはAWSにクォータの引き上げをリクエストします。

https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/reference_iam-quotas.html#reference_iam-quotas-entities

付与するポリシーの数を上限以内に収める

それでは上記のクォータ増加申請でクォータ増加を待てず迅速にポリシーを付与したい場合や、ポリシーの数が20個以上になりこれ以上ポリシーを増やせない場合はどうすればよいでしょうか?

結論から話すと、複数のマネージドポリシーをまとめたカスタマーポリシーを付与するです。

例えばEC2・RDS・S3のAWS マネージドポリシーが存在する場合を考えます。
このとき以下のようなEC2・RDS・S3のFullAccessポリシーをまとめて作成したカスタマーポリシーを作成します。
すると、全体としてはカスタマーポリシーの数を減らすことができます。

AWS カスタマー 全体
-3 +1 -2
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "ec2:*",
            "Effect": "Allow",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "elasticloadbalancing:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "cloudwatch:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "autoscaling:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:AWSServiceName": [
                        "autoscaling.amazonaws.com",
                        "ec2scheduled.amazonaws.com",
                        "elasticloadbalancing.amazonaws.com",
                        "spot.amazonaws.com",
                        "spotfleet.amazonaws.com",
                        "transitgateway.amazonaws.com"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "rds:*",
                "application-autoscaling:DeleteScalingPolicy",
                "application-autoscaling:DeregisterScalableTarget",
                "application-autoscaling:DescribeScalableTargets",
                "application-autoscaling:DescribeScalingActivities",
                "application-autoscaling:DescribeScalingPolicies",
                "application-autoscaling:PutScalingPolicy",
                "application-autoscaling:RegisterScalableTarget",
                "cloudwatch:DescribeAlarms",
                "cloudwatch:GetMetricStatistics",
                "cloudwatch:PutMetricAlarm",
                "cloudwatch:DeleteAlarms",
                "cloudwatch:ListMetrics",
                "cloudwatch:GetMetricData",
                "ec2:DescribeAccountAttributes",
                "ec2:DescribeAvailabilityZones",
                "ec2:DescribeCoipPools",
                "ec2:DescribeInternetGateways",
                "ec2:DescribeLocalGatewayRouteTablePermissions",
                "ec2:DescribeLocalGatewayRouteTables",
                "ec2:DescribeLocalGatewayRouteTableVpcAssociations",
                "ec2:DescribeLocalGateways",
                "ec2:DescribeSecurityGroups",
                "ec2:DescribeSubnets",
                "ec2:DescribeVpcAttribute",
                "ec2:DescribeVpcs",
                "ec2:GetCoipPoolUsage",
                "sns:ListSubscriptions",
                "sns:ListTopics",
                "sns:Publish",
                "logs:DescribeLogStreams",
                "logs:GetLogEvents",
                "outposts:GetOutpostInstanceTypes",
                "devops-guru:GetResourceCollection"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "pi:*",
            "Resource": [
                "arn:aws:pi:*:*:metrics/rds/*",
                "arn:aws:pi:*:*:perf-reports/rds/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "iam:AWSServiceName": [
                        "rds.amazonaws.com",
                        "rds.application-autoscaling.amazonaws.com"
                    ]
                }
            }
        },
        {
            "Action": [
                "devops-guru:SearchInsights",
                "devops-guru:ListAnomaliesForInsight"
            ],
            "Effect": "Allow",
            "Resource": "*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "devops-guru:ServiceNames": [
                        "RDS"
                    ]
                },
                "Null": {
                    "devops-guru:ServiceNames": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

この記事がどなたかのお役に立てれば幸いです。

Discussion