Creazione di ruoli IAM AWS

GKE su AWS utilizza i ruoli AWS IAM per creare e gestire i cluster e i pool di nodi. In questa pagina viene descritto come creare i seguenti ruoli predefiniti:

Ruolo agente di servizio API GKE Multi-Cloud
L'API GKE Multi-Cloud utilizza questo ruolo AWS IAM per gestire le risorse mediante le API AWS. Questo ruolo è utilizzato da un account di servizio gestito da Google noto come agente di servizio.
Ruolo AWS IAM del piano di controllo
Il piano di controllo del cluster utilizza questo ruolo per controllare i pool di nodi.
Ruolo AWS IAM del pool di nodi
Il piano di controllo utilizza questo ruolo per creare VM del pool di nodi.

Questa pagina mostra come creare ruoli per le seguenti situazioni:

  • Un insieme predefinito di autorizzazioni, utile per i test
  • Autorizzazioni per operare su risorse con determinati tag AWS

Puoi scegliere una di queste opzioni per soddisfare i criteri di sicurezza della tua organizzazione. Per maggiori informazioni sui tag, consulta la pagina relativa al tagging delle risorse AWS.

Facoltativamente, puoi definire l'ambito delle autorizzazioni per i ruoli AWS IAM utilizzati da GKE su AWS per soddisfare i requisiti dell'organizzazione. Per ulteriori informazioni, consulta Ruoli AWS IAM.

Prima di iniziare

Se scegli di creare autorizzazioni che operano su risorse con determinati tag, devi scegliere un tag e un valore. Potrai quindi usare questi valori per taggare le risorse all'interno del cluster e limitarne l'accesso.

Crea ruolo agente di servizio API GKE Multi-Cloud

Per creare il ruolo di agente di servizio dell'API GKE Multi-Cloud, utilizza il comando seguente per recuperare il numero di progetto Google Cloud e utilizzarlo per creare il ruolo.

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"
            }
      }
    }
  ]
}'

Sostituisci API_ROLE con un nome per questo ruolo.

Salva il nome della risorsa Amazon (ARN) generato da questo comando per utilizzarlo in seguito.

Crea autorizzazioni con ambito

Scegli di seguito se vuoi creare un criterio per il ruolo di agente di servizio dell'API GKE Multi-Cloud con autorizzazioni predefinite o limitato l'ambito alle risorse con determinati tag. Quindi, esegui questo comando:

Predefinito

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": "*"
    }
  ]
}'

Sostituisci API_POLICY con un nome per il criterio AWS IAM dell'API GKE Multi-Cloud.

Facoltativamente, puoi limitare le risorse applicate da questo criterio a un determinato account impostando il valore Resource su arn:aws:iam::ACCOUNT_ID:* e sostituendo ACCOUNT_ID con il tuo ID account AWS.

Ambito dei tag

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"
        }
      }
    }
  ]
}'

Sostituisci quanto segue:

  • API_POLICY: un prefisso per i criteri AWS dell'API GKE Multi-Cloud.
  • ACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questo criterio
  • ACCESS_CONTROL_TAG_VALUE: il valore tag applicabile a questo criterio

Facoltativamente, puoi limitare ulteriormente questo criterio a una regione e a un ID account AWS. Per limitare il criterio a una regione e a un ID account, sostituisci i valori di Risorsa come arn:aws:ec2:*:*:security-group/* con arn:aws:ec2:AWS_REGION:ACCOUNT_ID:security-group/*.

Copia l'ARN creato per questo criterio per utilizzarlo nel comando seguente.

Crea criteri aggiuntivi per l'utilizzo dei tag

Se limiti l'accesso con i tag, segui questi passaggi per creare criteri aggiuntivi. Se utilizzi il criterio predefinito, vai a Associa criteri al ruolo dell'API GKE Multi-Cloud.

  1. Crea un criterio per controllare l'accesso ad AWS IAM con il seguente comando:

    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. Crea un criterio per controllare l'accesso alle risorse di scalabilità automatica di AWS EC2 con il seguente comando:

    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"
            }
          }
        }
      ]
    }'
    

    Salva l'ARN generato da questo comando per utilizzarlo in seguito.

  3. Crea un criterio per controllare l'accesso alle risorse di 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"
            }
          }
        }
      ]
    }'
    

    Salva l'ARN generato da questo comando per utilizzarlo in seguito.

  4. Crea un criterio per controllare l'accesso alle risorse di AWS Key Management Service.

    Consulta Creazione di chiavi KMS con autorizzazioni specifiche per ulteriori informazioni sulle autorizzazioni per ogni singola chiave.

    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
        }
      ]
    }'
    

    Sostituisci quanto segue:

    Salva l'ARN generato da questo comando per utilizzarlo in seguito.

Collega criteri al ruolo dell'API GKE Multi-Cloud

Per ogni criterio creato nei passaggi precedenti, esegui questo comando per collegare il criterio al ruolo dell'API GKE Multi-Cloud:

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

Sostituisci

  • API_POLICY_ARN con l'ARN del criterio API di ogni criterio creato in precedenza
  • API_ROLE con il nome del ruolo di agente di servizio dell'API GKE Multi-Cloud

Crea un cluster o un pool di nodi

Se crei ruoli e criteri che hanno come ambito risorse con tag, devi specificare i tag quando crei un cluster o un pool di nodi. Puoi farlo utilizzando il parametro --tags nei comandi di creazione del cluster e del pool di nodi.

Crea un cluster

Per creare il cluster, segui le istruzioni per creare un cluster e includere il parametro --tags come segue:

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

Sostituisci quanto segue:

  • ACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questo criterio
  • ACCESS_CONTROL_TAG_VALUE: il valore tag applicabile a questo criterio

Crea un pool di nodi

Per creare un pool di nodi, segui le istruzioni per creare un pool di nodi e includere il parametro --tags come segue:

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

Sostituisci quanto segue:

  • ACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questo criterio
  • ACCESS_CONTROL_TAG_VALUE: il valore tag applicabile a questo criterio

Crea il ruolo del piano di controllo

Per creare il ruolo del piano di controllo con autorizzazioni predefinite:

  1. Per creare questo ruolo, esegui questo comando:

    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"
        }
      ]
    }'
    

    Sostituisci CONTROL_PLANE_ROLE con un nome per il ruolo del piano di controllo.

  2. Crea un criterio IAM per questo ruolo. Se hai creato più chiavi KMS per la crittografia del database e della configurazione, includi tutti i relativi ARN come elenco separato da virgole.

    Scegli se ti stai connettendo direttamente al tuo piano di controllo oppure direttamente al tuo piano di controllo e utilizza i tag.

    Connessione diretta

    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": "*"
        }
      ]
    }'
    

    Sostituisci quanto segue:

    • CONTROL_PLANE_POLICY con un nome per il criterio del piano di controllo

    Direttamente con tag

    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"
            }
          }
        }
      ]
    }'
    

    Sostituisci quanto segue:

    Copia il valore di ogni Policy.Arn per utilizzarlo in un comando seguente.

  3. Se utilizzi un proxy HTTP, crea un criterio aggiuntivo per 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
        }
      ]
    }'
    

    Sostituisci quanto segue:

    Copia il valore di ogni Policy.Arn per utilizzarlo nel comando successivo.

  4. Associa il nuovo criterio al ruolo corrispondente.

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

    Sostituisci quanto segue:

    • CONTROL_PLANE_ROLE
    • CONTROL_PLANE_POLICY_ARN con il valore Policy.Arn del comando precedente
  5. Per creare un profilo di istanza IAM, esegui questo comando.

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

    Sostituisci CONTROL_PLANE_PROFILE con un nome per il profilo del piano di controllo multi-cloud GKE.

  6. Infine, aggiungi il nuovo ruolo al profilo istanza appena creato.

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

    Sostituisci quanto segue:

    • CONTROL_PLANE_PROFILE
    • CONTROL_PLANE_ROLE

    Utilizzerai il nome del profilo istanza che scegli qui in seguito durante la creazione del cluster.

Crea il ruolo del pool di nodi

Per creare il ruolo del pool di nodi con autorizzazioni predefinite:

  1. Crea un ruolo per le VM nel pool di nodi.

    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"
        }
      ]
    }'
    

    Sostituisci NODE_POOL_ROLE con il nome del tuo ruolo del pool di nodi.

  2. Crea un criterio con le autorizzazioni necessarie per le VM del pool di nodi. Scegli se ti stai connettendo direttamente al tuo piano di controllo o se stai utilizzando un proxy HTTP.

    Diretta

    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
        }
      ]
    }'
    

    Sostituisci quanto segue:

    Proxy 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
        }
      ]
    }'
    

    Sostituisci quanto segue:

    • KMS_KEY_ARN: la chiave KMS del pool di nodi.
    • NODE_POOL_POLICY: nome del criterio del pool di nodi.
    • PROXY_CONFIG_ARN: l'ARN della configurazione del proxy. Per ulteriori informazioni, consulta la pagina Creare una configurazione proxy.

    Copia il valore di ogni Policy.Arn per utilizzarlo nel comando successivo.

  3. Collega il ruolo al relativo criterio.

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

    Sostituisci quanto segue:

    • NODE_POOL_ROLE: il nome del ruolo del pool di nodi.
    • NODE_POOL_POLICY_ARN: il valore Policy.Arn del comando precedente.
  4. Se i carichi di lavoro devono funzionare con il Container Registry ECR, collega il seguente criterio per l'accesso ECR:

    Registro pubblico

    Crea un criterio con le seguenti autorizzazioni:

      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": "*"
        }
      ]
    }'
    

    Copia il valore di Policy.Arn come NODE_POOL_ECR_POLICY_ARN

    Collegalo al ruolo del pool di nodi che hai creato.

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

    Sostituisci quanto segue:

    • NODE_POOL_ROLE: il nome del ruolo del pool di nodi.
    • NODE_POOL_ECR_POLICY_ARN: il valore Policy.Arn del comando precedente.

    Registro privato

    Collega AmazonEC2ContainerRegistryReadOnly al ruolo del pool di nodi per l'accesso al registro privato:

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

    Sostituisci NODE_POOL_ROLE con il nome del tuo ruolo del pool di nodi.

  5. Crea un profilo istanza per questo ruolo.

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

    Sostituisci NODE_POOL_PROFILE con il nome del profilo del tuo pool di nodi.

  6. Aggiungi il nuovo ruolo al profilo dell'istanza.

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

    Sostituisci quanto segue:

    • NODE_POOL_PROFILE: il nome del profilo del tuo pool di nodi.
    • NODE_POOL_ROLE: il nome del ruolo del pool di nodi.

Passaggi successivi