AWS IAM のロールを作成します。

GKE on AWS は、AWS IAM ロールを使用してクラスタとノードプールを作成および管理します。このページでは、以下のデフォルト ロールを作成する方法について説明します。

Anthos Multi-Cloud API サービス エージェント ロール
GKE Multi-Cloud API では、この AWS IAM ロールを使用して、AWS API でリソースを管理します。このロールは、サービス エージェントと呼ばれる Google 管理のサービス アカウントで使用されます。
コントロール プレーンの AWS IAM ロール
クラスタ コントロール プレーンは、このロールを使用してノードプールを制御します。
ノードプールの AWS IAM ロール
コントロール プレーンは、このロールを使用してノードプール VM を作成します。

このページでは、次の状況でロールを作成する方法を説明します。

  • テストに便利なデフォルトの権限セット
  • 特定の AWS タグが付いたリソースで動作する権限

組織のセキュリティ ポリシーを満たすために、これらのオプションのいずれかを選択できます。タグの詳細については、AWS リソースのタグ付けをご覧ください。

必要に応じて、GKE on AWS が組織の要件を満たすために使用する AWS IAM ロールの権限の範囲を設定できます。詳細については、AWS IAM ロールをご覧ください。

始める前に

特定のタグが付いたリソースで動作する権限を作成する場合は、タグと値を選択する必要があります。これらの値を使用してクラスタ内のリソースにタグ付けし、リソースへのアクセスを制限します。

GKE Multi-Cloud API サービス エージェントのロールを作成する

GKE Multi-Cloud API サービス エージェントのロールを作成するには、次のコマンドを使用して Google Cloud プロジェクト番号を取得し、その番号を使用してロールを作成します。

PROJECT_ID="$(gcloud config get-value project)"
PROJECT_NUMBER=$(gcloud projects describe "$PROJECT_ID" \
    --format "value(projectNumber)")

aws iam create-role --role-name API_ROLE \
    --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [
        {
        "Sid": "",
        "Effect": "Allow",
        "Principal": {
            "Federated": "accounts.google.com"
        },
        "Action": "sts:AssumeRoleWithWebIdentity",
        "Condition": {
            "StringEquals": {
            "accounts.google.com:sub": "service-'$PROJECT_NUMBER'@gcp-sa-gkemulticloud.iam.gserviceaccount.com"
            }
      }
    }
  ]
}'

API_ROLE は、このロールの名前に置き換えます。

このコマンドで生成された Amazon リソース名(ARN)は、後で使用するために保存します。

スコープを設定された権限を作成する

GKE Multi-Cloud API サービス エージェントのロールにデフォルトの権限を持つポリシーを作成するか、特定のタグを持つリソースにスコープを設定する場合、以下を選択します。そのうえで、次のコマンドを実行します。

デフォルト

aws iam create-policy --policy-name API_POLICY \
  --policy-document '{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Action": [
        "ec2:AuthorizeSecurityGroupEgress",
        "ec2:AuthorizeSecurityGroupIngress",
        "ec2:CreateLaunchTemplate",
        "ec2:CreateNetworkInterface",
        "ec2:CreateSecurityGroup",
        "ec2:CreateTags",
        "ec2:CreateVolume",
        "ec2:DeleteLaunchTemplate",
        "ec2:DeleteNetworkInterface",
        "ec2:DeleteSecurityGroup",
        "ec2:DeleteTags",
        "ec2:DeleteVolume",
        "ec2:DescribeAccountAttributes",
        "ec2:DescribeInstances",
        "ec2:DescribeInternetGateways",
        "ec2:DescribeKeyPairs",
        "ec2:DescribeLaunchTemplates",
        "ec2:DescribeNetworkInterfaces",
        "ec2:DescribeSecurityGroupRules",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSubnets",
        "ec2:DescribeVpcs",
        "ec2:GetConsoleOutput",
        "ec2:ModifyInstanceAttribute",
        "ec2:ModifyNetworkInterfaceAttribute",
        "ec2:RevokeSecurityGroupEgress",
        "ec2:RevokeSecurityGroupIngress",
        "ec2:RunInstances",
        "iam:AWSServiceName",
        "iam:CreateServiceLinkedRole",
        "iam:GetInstanceProfile",
        "iam:PassRole",
        "autoscaling:CreateAutoScalingGroup",
        "autoscaling:CreateOrUpdateTags",
        "autoscaling:DeleteAutoScalingGroup",
        "autoscaling:DeleteTags",
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DisableMetricsCollection",
        "autoscaling:EnableMetricsCollection",
        "autoscaling:TerminateInstanceInAutoScalingGroup",
        "autoscaling:UpdateAutoScalingGroup",
        "elasticloadbalancing:AddTags",
        "elasticloadbalancing:CreateListener",
        "elasticloadbalancing:CreateLoadBalancer",
        "elasticloadbalancing:CreateTargetGroup",
        "elasticloadbalancing:DeleteListener",
        "elasticloadbalancing:DeleteLoadBalancer",
        "elasticloadbalancing:DeleteTargetGroup",
        "elasticloadbalancing:DescribeListeners",
        "elasticloadbalancing:DescribeLoadBalancers",
        "elasticloadbalancing:DescribeTargetGroups",
        "elasticloadbalancing:DescribeTargetHealth",
        "elasticloadbalancing:ModifyTargetGroupAttributes",
        "elasticloadbalancing:RemoveTags",
        "kms:DescribeKey",
        "kms:Encrypt",
        "kms:GenerateDataKeyWithoutPlaintext"
      ],
      "Resource": "*"
    }
  ]
}'

API_POLICY は、GKE Multi-Cloud API AWS IAM ポリシーの名前に置き換えます。

必要に応じて、Resource の値を arn:aws:iam::ACCOUNT_ID:* に設定し、ACCOUNT_ID を AWS アカウント ID に置き換えることで、このポリシーが特定のアカウントに適用されるリソースを制限できます。

タグのスコープ設定

aws iam create-policy --policy-name API_POLICY_ec2 \
  --policy-document '{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeAccountAttributes",
        "ec2:DescribeInstances",
        "ec2:DescribeInternetGateways",
        "ec2:DescribeKeyPairs",
        "ec2:DescribeLaunchTemplates",
        "ec2:DescribeNetworkInterfaces",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSecurityGroupRules",
        "ec2:DescribeSubnets",
        "ec2:DescribeVpcs",
        "ec2:GetConsoleOutput"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:CreateSecurityGroup"],
      "Resource": ["arn:aws:ec2:*:*:security-group/*"],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:CreateSecurityGroup"],
      "Resource": ["arn:aws:ec2:*:*:vpc/*"]
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:AuthorizeSecurityGroupEgress",
        "ec2:AuthorizeSecurityGroupIngress",
        "ec2:DeleteSecurityGroup",
        "ec2:RevokeSecurityGroupEgress",
        "ec2:RevokeSecurityGroupIngress"
      ],
      "Resource": ["arn:aws:ec2:*:*:security-group/*"],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:AuthorizeSecurityGroupEgress",
        "ec2:AuthorizeSecurityGroupIngress"
      ],
      "Resource": ["arn:aws:ec2:*:*:security-group-rule/*"],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:CreateLaunchTemplate"],
      "Resource": ["arn:aws:ec2:*:*:launch-template/*"],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DeleteLaunchTemplate"
      ],
      "Resource": ["arn:aws:ec2:*:*:launch-template/*"],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:RunInstances"],
      "Resource": ["arn:aws:ec2:*:*:image/ami-*"],
      "Condition": {
        "StringEquals": {
          "ec2:Owner": ["099720109477", "amazon"]
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:RunInstances"],
      "Resource": [
        "arn:aws:ec2:*:*:subnet/*"
      ],
      "Condition": {
        "ArnLike": {
          "ec2:LaunchTemplate": "arn:aws:ec2:*:*:launch-template/*"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:RunInstances"],
      "Resource": [
        "arn:aws:ec2:*:*:instance/*",
        "arn:aws:ec2:*:*:key-pair/*",
        "arn:aws:ec2:*:*:launch-template/*",
        "arn:aws:ec2:*:*:network-interface/*",
        "arn:aws:ec2:*:*:security-group/*",
        "arn:aws:ec2:*:*:volume/*"
      ],
      "Condition": {
        "Bool": {
          "ec2:IsLaunchTemplateResource": "true"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CreateVolume"
      ],
      "Resource": ["arn:aws:ec2:*:*:volume/*"],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DeleteVolume"
      ],
      "Resource": ["arn:aws:ec2:*:*:volume/*"],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CreateNetworkInterface"
      ],
      "Resource": ["arn:aws:ec2:*:*:network-interface/*"],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:CreateNetworkInterface"],
      "Resource": ["arn:aws:ec2:*:*:security-group/*"],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": ["ec2:CreateNetworkInterface"],
      "Resource": ["arn:aws:ec2:*:*:subnet/*"]
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DeleteNetworkInterface",
        "ec2:ModifyNetworkInterfaceAttribute"
      ],
      "Resource": [
        "arn:aws:ec2:*:*:network-interface/*",
        "arn:aws:ec2:*:*:security-group/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Action": [
        "ec2:CreateTags"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:ec2:*:*:launch-template/*",
        "arn:aws:ec2:*:*:network-interface/*",
        "arn:aws:ec2:*:*:security-group/*",
        "arn:aws:ec2:*:*:security-group-rule/*",
        "arn:aws:ec2:*:*:volume/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Action": [
        "ec2:CreateTags"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:ec2:*:*:instance/*"
      ],
      "Condition": {
         "StringEquals": {
          "ec2:CreateAction" : "RunInstances"
        }
      }
    },
    {
      "Action": [
        "ec2:CreateTags",
        "ec2:DeleteTags"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:ec2:*:*:instance/*",
        "arn:aws:ec2:*:*:launch-template/*",
        "arn:aws:ec2:*:*:network-interface/*",
        "arn:aws:ec2:*:*:security-group/*",
        "arn:aws:ec2:*:*:security-group-rule/*",
        "arn:aws:ec2:*:*:volume/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:ModifyInstanceAttribute"
      ],
      "Resource": [
        "arn:aws:ec2:*:*:instance/*",
        "arn:aws:ec2:*:*:security-group/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
        }
      }
    }
  ]
}'

次のように置き換えます。

  • API_POLICY: GKE Multi-Cloud API AWS IAM ポリシーの接頭辞。
  • ACCESS_CONTROL_TAG_KEY: このポリシーに適用するタグのキー
  • ACCESS_CONTROL_TAG_VALUE: このポリシーに適用するタグの値

必要に応じて、このポリシーをさらに制限し、AWS リージョンとアカウント ID にすることもできます。ポリシーをリージョンとアカウント ID に制限するには、arn:aws:ec2:*:*:security-group/* などのリソースの値を arn:aws:ec2:AWS_REGION:ACCOUNT_ID:security-group/* に置き換えます。

このポリシー用に作成された ARN をコピーし、次のコマンドで使用します。

タグの使用に関する追加のポリシーを作成する

タグを使用してアクセスを制限する場合は、以下の手順に沿って追加のポリシーを作成します。デフォルトのポリシーを使用している場合は、GKE Multi-Cloud API ロールにポリシーを接続するに進んでください。

  1. 次のコマンドを使用して、AWS IAM へのアクセスを制限するポリシーを作成します。

    aws iam create-policy --policy-name API_POLICY_iam \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["iam:CreateServiceLinkedRole"],
          "Resource": [
            "arn:aws:iam::*:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
          ],
          "Condition": {
            "StringEquals": {
              "iam:AWSServiceName": "autoscaling.amazonaws.com"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": ["iam:CreateServiceLinkedRole"],
          "Resource": [
            "arn:aws:iam::*:role/aws-service-role/elasticloadbalancing.amazonaws.com/AWSServiceRoleForElasticLoadBalancing"
          ],
          "Condition": {
            "StringEquals": {
              "iam:AWSServiceName": "elasticloadbalancing.amazonaws.com"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": ["iam:PassRole"],
          "Resource": ["arn:aws:iam::*:role/*"],
          "Condition": {
            "StringEquals": {
              "iam:PassedToService": "ec2.amazonaws.com"
            }
          }
        }
        ,
        {
          "Effect": "Allow",
          "Action": ["iam:GetInstanceProfile"],
          "Resource": ["arn:aws:iam::*:instance-profile/*"]
        }
      ]
    }'
    
  2. 次のコマンドを使用して、AWS EC2 自動スケーリング リソースへのアクセスを制限するポリシーを作成します。

    aws iam create-policy --policy-name API_POLICY_autoscaling \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["autoscaling:DescribeAutoScalingGroups"],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "autoscaling:CreateAutoScalingGroup",
            "autoscaling:CreateOrUpdateTags"
          ],
          "Resource": [
            "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*"
          ],
          "Condition": {
            "StringEquals": {
              "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": [
            "autoscaling:CreateOrUpdateTags",
            "autoscaling:DeleteAutoScalingGroup",
            "autoscaling:DeleteTags",
            "autoscaling:DisableMetricsCollection",
            "autoscaling:EnableMetricsCollection",
            "autoscaling:TerminateInstanceInAutoScalingGroup",
            "autoscaling:UpdateAutoScalingGroup"
          ],
          "Resource": [
            "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*"
          ],
          "Condition": {
            "StringEquals": {
              "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        }
      ]
    }'
    

    このコマンドで生成された ARN は、後で使用するために保存します。

  3. AWS Elastic Load Balancer リソースへのアクセスを制限するポリシーを作成します。

    aws iam create-policy --policy-name API_POLICY_elasticloadbalancing \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:DescribeListeners",
            "elasticloadbalancing:DescribeLoadBalancers",
            "elasticloadbalancing:DescribeTargetGroups",
            "elasticloadbalancing:DescribeTargetHealth"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:CreateTargetGroup",
            "elasticloadbalancing:AddTags"
          ],
          "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/gke-*"],
          "Condition": {
            "StringEquals": {
              "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:AddTags",
            "elasticloadbalancing:DeleteTargetGroup",
            "elasticloadbalancing:ModifyTargetGroupAttributes",
            "elasticloadbalancing:RemoveTags"
          ],
          "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/gke-*"],
          "Condition": {
            "StringEquals": {
              "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:CreateListener",
            "elasticloadbalancing:CreateLoadBalancer",
            "elasticloadbalancing:AddTags"
          ],
          "Resource": [
            "arn:aws:elasticloadbalancing:*:*:listener/net/gke-*",
            "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/gke-*"
          ],
          "Condition": {
            "StringEquals": {
              "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:AddTags",
            "elasticloadbalancing:DeleteListener",
            "elasticloadbalancing:DeleteLoadBalancer",
            "elasticloadbalancing:RemoveTags"
          ],
          "Resource": [
            "arn:aws:elasticloadbalancing:*:*:listener/net/gke-*",
            "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/gke-*"
          ],
          "Condition": {
            "StringEquals": {
              "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        }
      ]
    }'
    

    このコマンドで生成された ARN は、後で使用するために保存します。

  4. AWS Key Management Service リソースへのアクセスを制限するポリシーを作成します。

    各鍵の権限の詳細については、特定の権限を持つ KMS 鍵を作成するをご覧ください。

    aws iam create-policy --policy-name API_POLICY_kms \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["kms:DescribeKey"],
          "Resource": ["arn:aws:kms:*:*:key/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["kms:Encrypt"],
          "Resource": CONTROL_PLANE_CONFIG_KMS_KEY_ARN
        },
        {
          "Effect": "Allow",
          "Action": ["kms:Encrypt"],
          "Resource": NODE_POOL_CONFIG_KMS_KEY_ARN
        },
        {
          "Effect": "Allow",
          "Action": ["kms:GenerateDataKeyWithoutPlaintext"],
          "Resource": CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN
        }
      ]
    }'
    

    次のように置き換えます。

    このコマンドで生成された ARN は、後で使用するために保存します。

GKE Multi-Cloud API のロールにポリシーを接続する

前の手順で作成したポリシーごとに、次のコマンドを実行して、ポリシーを GKE Multi-Cloud API ロールに接続します。

aws iam attach-role-policy \
    --policy-arn API_POLICY_ARN \
    --role-name API_ROLE

置き換える

  • API_POLICY_ARN は、以前に作成した各ポリシーの API ポリシー ARN に置き換えます。
  • API_ROLE は、GKE Multi-Cloud API サービス エージェントのロール名に置き換えます

クラスタまたはノードプールを作成する

タグ付きリソースを範囲とするロールとポリシーを作成する場合は、クラスタやノードプールの作成時にタグを指定する必要があります。これは、クラスタとノードプールの作成コマンドの --tags パラメータを使用して行います。

クラスタの作成

クラスタを作成するには、クラスタを作成する手順に沿って、次のように --tags パラメータを含めます。

gcloud container aws clusters create CLUSTER_NAME \
...
    --tags="ACCESS_CONTROL_TAG_KEY=ACCESS_CONTROL_TAG_VALUE"

次のように置き換えます。

  • ACCESS_CONTROL_TAG_KEY: このポリシーに適用するタグのキー
  • ACCESS_CONTROL_TAG_VALUE: このポリシーに適用するタグの値

ノードプールの作成

ノードプールを作成するには、ノードプールを作成する手順に沿って、次のように --tags パラメータを含めます。

gcloud container aws node-pools create NODE_POOL_NAME \
...
    --tags "ACCESS_CONTROL_TAG_KEY=ACCESS_CONTROL_TAG_VALUE"

次のように置き換えます。

  • ACCESS_CONTROL_TAG_KEY: このポリシーに適用するタグのキー
  • ACCESS_CONTROL_TAG_VALUE: このポリシーに適用するタグの値

コントロール プレーン ロールの作成

デフォルトの権限を使用してコントロール プレーン ロールを作成するには、次の手順を行います。

  1. このロールを作成するには、次のコマンドを実行します。

    aws iam create-role --role-name CONTROL_PLANE_ROLE \
        --assume-role-policy-document '{
        "Version": "2012-10-17",
        "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                 "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
      ]
    }'
    

    CONTROL_PLANE_ROLE は、コントロール プレーン ロールの名前に置き換えます。

  2. このロールの IAM ポリシーを作成します。データベースと構成の暗号化に複数の KMS 鍵を作成した場合は、すべての ARN をカンマ区切りのリストとして含めます。

    コントロール プレーンに直接接続するか、コントロール プレーンに直接接続してタグを使用するかを選択します。

    直接接続

    aws iam create-policy --policy-name CONTROL_PLANE_POLICY \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "",
          "Effect": "Allow",
          "Action": [
            "ec2:AttachNetworkInterface",
            "ec2:AttachVolume",
            "ec2:AuthorizeSecurityGroupIngress",
            "ec2:CreateRoute",
            "ec2:CreateSecurityGroup",
            "ec2:CreateSnapshot",
            "ec2:CreateTags",
            "ec2:CreateVolume",
            "ec2:DeleteRoute",
            "ec2:DeleteSecurityGroup",
            "ec2:DeleteSnapshot",
            "ec2:DeleteTags",
            "ec2:DeleteVolume",
            "ec2:DescribeAccountAttributes",
            "ec2:DescribeAvailabilityZones",
            "ec2:DescribeDhcpOptions",
            "ec2:DescribeInstances",
            "ec2:DescribeInstanceTypes",
            "ec2:DescribeInternetGateways",
            "ec2:DescribeLaunchTemplateVersions",
            "ec2:DescribeRegions",
            "ec2:DescribeRouteTables",
            "ec2:DescribeSecurityGroups",
            "ec2:DescribeSnapshots",
            "ec2:DescribeSubnets",
            "ec2:DescribeTags",
            "ec2:DescribeVolumes",
            "ec2:DescribeVolumesModifications",
            "ec2:DescribeVpcs",
            "ec2:DetachVolume",
            "ec2:ModifyInstanceAttribute",
            "ec2:ModifyVolume",
            "ec2:RevokeSecurityGroupIngress",
            "autoscaling:DescribeAutoScalingGroups",
            "autoscaling:DescribeAutoScalingInstances",
            "autoscaling:DescribeLaunchConfigurations",
            "autoscaling:DescribeTags",
            "autoscaling:SetDesiredCapacity",
            "autoscaling:TerminateInstanceInAutoScalingGroup",
            "elasticloadbalancing:AddTags",
            "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer",
            "elasticloadbalancing:AttachLoadBalancerToSubnets",
            "elasticloadbalancing:ConfigureHealthCheck",
            "elasticloadbalancing:CreateListener",
            "elasticloadbalancing:CreateLoadBalancer",
            "elasticloadbalancing:CreateLoadBalancerListeners",
            "elasticloadbalancing:CreateLoadBalancerPolicy",
            "elasticloadbalancing:CreateTargetGroup",
            "elasticloadbalancing:DeleteListener",
            "elasticloadbalancing:DeleteLoadBalancer",
            "elasticloadbalancing:DeleteLoadBalancerListeners",
            "elasticloadbalancing:DeleteTargetGroup",
            "elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
            "elasticloadbalancing:DeregisterTargets",
            "elasticloadbalancing:DescribeListeners",
            "elasticloadbalancing:DescribeLoadBalancerAttributes",
            "elasticloadbalancing:DescribeLoadBalancerPolicies",
            "elasticloadbalancing:DescribeLoadBalancers",
            "elasticloadbalancing:DescribeTargetGroups",
            "elasticloadbalancing:DescribeTargetHealth",
            "elasticloadbalancing:DetachLoadBalancerFromSubnets",
            "elasticloadbalancing:ModifyListener",
            "elasticloadbalancing:ModifyLoadBalancerAttributes",
            "elasticloadbalancing:ModifyTargetGroup",
            "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
            "elasticloadbalancing:RegisterTargets",
            "elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer",
            "elasticloadbalancing:SetLoadBalancerPoliciesOfListener",
            "elasticfilesystem:CreateAccessPoint",
            "elasticfilesystem:DeleteAccessPoint",
            "elasticfilesystem:DescribeAccessPoints",
            "elasticfilesystem:DescribeFileSystems",
            "elasticfilesystem:DescribeMountTargets",
            "kms:CreateGrant",
            "kms:Decrypt",
            "kms:Encrypt",
            "kms:GrantIsForAWSResource"
          ],
          "Resource": "*"
        }
      ]
    }'
    

    次のように置き換えます。

    • CONTROL_PLANE_POLICY は、コントロール プレーン ポリシーの名前に置き換えます。

    タグで直接接続

    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_autoscaling \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "autoscaling:DescribeAutoScalingGroups",
            "autoscaling:DescribeAutoScalingInstances",
            "autoscaling:DescribeLaunchConfigurations",
            "autoscaling:DescribeTags"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "autoscaling:SetDesiredCapacity",
            "autoscaling:TerminateInstanceInAutoScalingGroup"
          ],
          "Resource": [
            "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*"
          ],
          "Condition": {
            "StringEquals": {
              "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
            }
          }
        }
      ]
    }'
    
    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_ec2 \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ec2:DescribeAccountAttributes",
            "ec2:DescribeAvailabilityZones",
            "ec2:DescribeDhcpOptions",
            "ec2:DescribeInstances",
            "ec2:DescribeInstanceTypes",
            "ec2:DescribeInternetGateways",
            "ec2:DescribeLaunchTemplateVersions",
            "ec2:DescribeRegions",
            "ec2:DescribeRouteTables",
            "ec2:DescribeSecurityGroups",
            "ec2:DescribeSnapshots",
            "ec2:DescribeSubnets",
            "ec2:DescribeTags",
            "ec2:DescribeVolumes",
            "ec2:DescribeVolumesModifications",
            "ec2:DescribeVpcs"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:AttachNetworkInterface"],
          "Resource": [
            "arn:aws:ec2:*:*:instance/*",
            "arn:aws:ec2:*:*:network-interface/*"
          ]
        },
        {
          "Effect": "Allow",
          "Action": [
            "ec2:CreateVolume",
            "ec2:CreateTags",
            "ec2:AttachVolume",
            "ec2:DeleteVolume",
            "ec2:DetachVolume",
            "ec2:ModifyVolume"
          ],
          "Resource": ["arn:aws:ec2:*:*:volume/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:AttachVolume", "ec2:DetachVolume"],
          "Resource": ["arn:aws:ec2:*:*:instance/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:CreateSecurityGroup", "ec2:CreateTags"],
          "Resource": ["arn:aws:ec2:*:*:security-group/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:CreateSecurityGroup"],
          "Resource": ["arn:aws:ec2:*:*:vpc/*"]
        },
        {
          "Effect": "Allow",
          "Action": [
            "ec2:AuthorizeSecurityGroupIngress",
            "ec2:DeleteSecurityGroup",
            "ec2:RevokeSecurityGroupIngress"
          ],
          "Resource": ["arn:aws:ec2:*:*:security-group/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:CreateSnapshot", "ec2:CreateTags", "ec2:DeleteSnapshot"],
          "Resource": ["arn:aws:ec2:*:*:snapshot/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:CreateSnapshot"],
          "Resource": ["arn:aws:ec2:*:*:volume/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:CreateRoute", "ec2:DeleteRoute"],
          "Resource": ["arn:aws:ec2:*:*:route-table/*"]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:ModifyInstanceAttribute"],
          "Resource": [
            "arn:aws:ec2:*:*:instance/*",
            "arn:aws:ec2:*:*:security-group/*",
            "arn:aws:ec2:*:*:volume/*"
          ]
        },
        {
          "Effect": "Allow",
          "Action": ["ec2:DeleteTags"],
          "Resource": [
            "arn:aws:ec2:*:*:security-group/*",
            "arn:aws:ec2:*:*:snapshot/*",
            "arn:aws:ec2:*:*:volume/*"
          ]
        }
      ]
    }'
    
    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_elasticloadbalancing \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:DescribeLoadBalancers",
            "elasticloadbalancing:DescribeLoadBalancerAttributes",
            "elasticloadbalancing:DescribeListeners",
            "elasticloadbalancing:DescribeLoadBalancerPolicies",
            "elasticloadbalancing:DescribeTargetGroups",
            "elasticloadbalancing:DescribeTargetHealth"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:AddTags",
            "elasticloadbalancing:AttachLoadBalancerToSubnets",
            "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer",
            "elasticloadbalancing:CreateListener",
            "elasticloadbalancing:CreateLoadBalancer",
            "elasticloadbalancing:CreateLoadBalancerPolicy",
            "elasticloadbalancing:CreateLoadBalancerListeners",
            "elasticloadbalancing:ConfigureHealthCheck",
            "elasticloadbalancing:DeleteLoadBalancer",
            "elasticloadbalancing:DeleteLoadBalancerListeners",
            "elasticloadbalancing:DetachLoadBalancerFromSubnets",
            "elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
            "elasticloadbalancing:ModifyLoadBalancerAttributes",
            "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
            "elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer",
            "elasticloadbalancing:SetLoadBalancerPoliciesOfListener"
          ],
          "Resource": ["arn:aws:elasticloadbalancing:*:*:loadbalancer/*"]
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:AddTags",
            "elasticloadbalancing:CreateTargetGroup",
            "elasticloadbalancing:DeleteTargetGroup",
            "elasticloadbalancing:DeregisterTargets",
            "elasticloadbalancing:ModifyTargetGroup",
            "elasticloadbalancing:RegisterTargets"
          ],
          "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/*"]
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticloadbalancing:DeleteListener",
            "elasticloadbalancing:ModifyListener"
          ],
          "Resource": ["arn:aws:elasticloadbalancing:*:*:listener/*"]
        }
      ]
    }'
    
    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_elasticfilesystem \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "elasticfilesystem:DescribeAccessPoints",
            "elasticfilesystem:DescribeFileSystems",
            "elasticfilesystem:DescribeMountTargets"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticfilesystem:CreateAccessPoint"
          ],
          "Resource": [
            "arn:aws:elasticfilesystem:*:*:file-system/*"
          ]
        },
        {
          "Effect": "Allow",
          "Action": [
            "elasticfilesystem:DeleteAccessPoint"
          ],
          "Resource": [
            "arn:aws:elasticfilesystem:*:*:access-point/*"
          ]
        }
      ]
    }'
    
    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_kms \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["kms:Decrypt", "kms:Encrypt"],
          "Resource": DATABASE_KMS_KEY_ARN
        },
        {
          "Effect": "Allow",
          "Action": ["kms:Decrypt"],
          "Resource": CONTROL_PLANE_CONFIG_KMS_KEY_ARN
        },
        {
          "Effect": "Allow",
          "Action": ["kms:CreateGrant"],
          "Resource": CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN,
          "Condition": {
            "Bool": {
              "kms:GrantIsForAWSResource": "true"
            }
          }
        }
      ]
    }'
    

    次のように置き換えます。

    Policy.Arn の値をコピーして、次のコマンドで使用します。

  3. HTTP プロキシを使用している場合は、AWS Secret Manager の追加ポリシーを作成します。

    aws iam create-policy --policy-name CONTROL_PLANE_POLICY_secretsmanager \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "secretsmanager:GetSecretValue"
          ],
          "Resource": PROXY_CONFIG_ARN
        }
      ]
    }'
    

    次のように置き換えます。

    • KMS_KEY_ARNKMS etcd 暗号鍵の ARN に置き換えます。
    • CONTROL_PLANE_POLICY は、コントロール プレーン ポリシーの名前に置き換えます。

    Policy.Arn の値をコピーして、次のコマンドで使用します。

  4. 新しいポリシーを、対応するロールに接続します。

    aws iam attach-role-policy \
        --policy-arn CONTROL_PLANE_POLICY_ARN \
        --role-name CONTROL_PLANE_ROLE
    

    以下を置き換えます。

    • CONTROL_PLANE_ROLE
    • CONTROL_PLANE_POLICY_ARN は、前のコマンドの Policy.Arn 値に置き換えます。
  5. IAM インスタンス プロファイルを作成するには、次のコマンドを実行します。

    aws iam create-instance-profile \
        --instance-profile-name CONTROL_PLANE_PROFILE
    

    CONTROL_PLANE_PROFILE は、GKE Multi-Cloud コントロール プレーン プロファイルの名前に置き換えます。

  6. 最後に、作成したインスタンス プロファイルに新しいロールを追加します。

    aws iam add-role-to-instance-profile \
        --instance-profile-name CONTROL_PLANE_PROFILE \
        --role-name CONTROL_PLANE_ROLE
    

    以下を置き換えます。

    • CONTROL_PLANE_PROFILE
    • CONTROL_PLANE_ROLE

    ここで選択したインスタンス プロファイル名は、後でクラスタの作成時に使用します。

ノードプール ロールの作成

デフォルトの権限を使用してノードプール ロールを作成するには、次の手順を行います。

  1. 使用するノードプール内の VM のロールを作成します。

    aws iam create-role --role-name NODE_POOL_ROLE \
        --assume-role-policy-document '{
        "Version": "2012-10-17",
        "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
            "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
      ]
    }'
    

    NODE_POOL_ROLE は、ノードプール ロールの名前に置き換えます。

  2. ノードプール VM で必要な権限を含むポリシーを作成します。コントロール プレーンに直接接続するか、HTTP プロキシを使用するかを選択します。

    直接

    aws iam create-policy --policy-name NODE_POOL_POLICY_kms \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["kms:Decrypt"],
          "Resource": NODE_POOL_CONFIG_KMS_KEY_ARN
        }
      ]
    }'
    

    次のように置き換えます。

    HTTP プロキシ

    aws iam create-policy --policy-name NODE_POOL_POLICY_kms \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["kms:Decrypt"],
          "Resource": NODE_POOL_CONFIG_KMS_KEY_ARN
        }
      ]
    }'
    
    aws iam create-policy --policy-name NODE_POOL_POLICY_secretsmanager \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "secretsmanager:GetSecretValue"
          ],
          "Resource": PROXY_CONFIG_ARN
        }
      ]
    }'
    

    次のように置き換えます。

    • KMS_KEY_ARN: ノードプールの KMS 鍵。
    • NODE_POOL_POLICY: ノードプール ポリシーの名前。
    • PROXY_CONFIG_ARN: プロキシ構成の ARN。詳細については、プロキシ構成を作成するをご覧ください。

    各 Policy.Arn の値をコピーして、次のコマンドで使用します。

  3. ポリシーにロールを接続します。

    aws iam attach-role-policy --role-name NODE_POOL_ROLE \
        --policy-arn "NODE_POOL_POLICY_ARN"
    

    次のように置き換えます。

    • NODE_POOL_ROLE: ノードプール ロールの名前。
    • NODE_POOL_POLICY_ARN: 前のコマンドの Policy.Arn 値。
  4. ワークロードが ECR コンテナ レジストリと連携する必要がある場合は、ECR アクセスに関する次のポリシーを接続します。

    一般公開レジストリ

    次の権限を持つポリシーを作成します。

      aws iam create-policy --policy-name NODE_POOL_POLICY_ecr \
      --policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ecr-public:GetAuthorizationToken",
            "sts:GetServiceBearerToken"
          ],
          "Resource": "*"
        }
      ]
    }'
    

    Policy.Arn の値を NODE_POOL_ECR_POLICY_ARN としてコピーします

    作成したノードプール ロールに接続します。

    aws iam attach-role-policy --role-name NODE_POOL_ROLE \
        --policy-arn "NODE_POOL_ECR_POLICY_ARN"
    

    次のように置き換えます。

    • NODE_POOL_ROLE: ノードプール ロールの名前。
    • NODE_POOL_ECR_POLICY_ARN: 前のコマンドの Policy.Arn 値。

    非公開レジストリ

    非公開レジストリへのアクセス用に AmazonEC2ContainerRegistryReadOnly をノードプール ロールに接続します。

    aws iam attach-role-policy --role-name NODE_POOL_ROLE \
        --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
    

    NODE_POOL_ROLE は、ノードプール ロールの名前に置き換えます。

  5. このロールのインスタンス プロファイルを作成します。

    aws iam create-instance-profile \
        --instance-profile-name NODE_POOL_PROFILE
    

    NODE_POOL_PROFILE は、ノードプール プロファイルの名前に置き換えます。

  6. インスタンス プロファイルに新しいロールを追加します。

    aws iam add-role-to-instance-profile \
        --instance-profile-name NODE_POOL_PROFILE \
        --role-name NODE_POOL_ROLE
    

    次のように置き換えます。

    • NODE_POOL_PROFILE: ノードプール プロファイルの名前。
    • NODE_POOL_ROLE: ノードプール ロールの名前。

次のステップ