Creazione di ruoli IAM AWS

GKE su AWS utilizza i ruoli AWS IAM per creare e gestire i cluster e i pool di nodi. Questa pagina è rivolta agli amministratori di identità e account, agli operatori e agli sviluppatori che vogliono creare e gestire criteri relativi alle autorizzazioni utente. Per scoprire di più sui ruoli comuni e sulle attività di esempio a cui facciamo riferimento nei contenuti di Google Cloud , consulta la pagina Ruoli e attività utente GKE comuni.

Questa pagina descrive come creare i seguenti ruoli predefiniti:

Ruolo dell'agente di servizio API GKE Multi-cloud
L'API GKE Multi-Cloud utilizza questo ruolo AWS IAM per gestire le risorse utilizzando le API AWS. Questo ruolo viene utilizzato da un account di servizio gestito da Google noto come agente di servizio.
Ruolo AWS IAM del control plane
Il control plane del cluster utilizza questo ruolo per controllare i node pool.
Ruolo AWS IAM del node pool
Il control plane utilizza questo ruolo per creare le 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 sulle risorse con determinati tag AWS

Puoi scegliere una di queste opzioni per soddisfare i criteri di sicurezza della tua organizzazione. Per saperne di più sui tag, consulta Tagging AWS resources.

Se vuoi, puoi definire l'ambito delle autorizzazioni per i ruoli AWS IAM utilizzati da GKE su AWS per soddisfare i requisiti della tua 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. Quindi, utilizzi questi valori per taggare le risorse all'interno del cluster per limitarne l'accesso.

Crea il ruolo dell'agente di servizio dell'API GKE Multi-Cloud

Per creare il ruolo di service agent dell'API GKE Multi-Cloud, utilizza il seguente comando per recuperare il numero del tuo progetto e utilizzalo per creare il ruolo. 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"
            }
      }
    }
  ]
}'

Sostituisci API_ROLE con un nome per questo ruolo.

Salva l'Amazon Resource Name (ARN) generato da questo comando per utilizzarlo in un secondo momento.

Creare autorizzazioni con ambito

Scegli di seguito se vuoi creare un criterio per il ruolo di agente di servizio API GKE Multi-cloud con autorizzazioni predefinite o limitate 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 IAM AWS dell'API GKE Multi-Cloud.

Se vuoi, puoi limitare le risorse a cui si applica questa policy a un determinato account impostando il valore di Resource su arn:aws:iam::ACCOUNT_ID:* e sostituendo ACCOUNT_ID con l'ID account AWS.

Limitato ai 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 IAM dell'API GKE Multi-Cloud.
  • ACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questa policy
  • ACCESS_CONTROL_TAG_VALUE: il valore tag che si applica a questa policy

Se vuoi, puoi limitare ulteriormente questa policy a una regione AWS e a un ID account. 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 questa policy da utilizzare nel comando seguente.

Creare criteri aggiuntivi per l'utilizzo dei tag

Se limiti l'accesso con i tag, segui questi passaggi per creare criteri aggiuntivi. Se utilizzi la policy predefinita, vai a Collega le policy al ruolo 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 AWS EC2 Auto Scaling 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 un secondo momento.

  3. Crea un criterio per controllare l'accesso alle risorse 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 un secondo momento.

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

    Per ulteriori informazioni sulle autorizzazioni per ogni singola chiave, consulta la sezione Creazione di chiavi KMS con autorizzazioni specifiche.

    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 un secondo momento.

Allega criteri al ruolo API GKE Multi-cloud

Per ogni policy creata nei passaggi precedenti, esegui questo comando per collegare la policy al ruolo 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 della policy API di ogni policy che hai creato in precedenza
  • API_ROLE con il nome del ruolo dell'agente di servizio dell'API GKE Multi-Cloud

Crea un cluster o pool di nodi

Se crei ruoli e criteri con ambito limitato alle risorse taggate, devi specificare i tag quando crei un cluster o un pool di nodi. A questo scopo, utilizza 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 includi 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 questa policy
  • ACCESS_CONTROL_TAG_VALUE: il valore tag che si applica a questa policy

Crea un node pool

Per creare un pool di nodi, segui le istruzioni per creare un node pool e includi 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 questa policy
  • ACCESS_CONTROL_TAG_VALUE: il valore tag che si applica a questa policy

Crea il ruolo del control plane

Per creare il ruolo del control plane con le 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 di database e configurazione, includi tutti i relativi ARN come elenco separato da virgole.

    Scegli se connetterti direttamente al control plane o connetterti direttamente al control plane e utilizzare 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 la policy del piano di controllo

    Direct with tags

    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 da utilizzare in un comando successivo.

  3. Se utilizzi un proxy HTTP, crea un criterio aggiuntivo per AWS Secrets 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 da utilizzare nel comando successivo.

  4. Allega 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 dell'istanza IAM, esegui il comando seguente.

    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 GKE Multi-Cloud.

  6. Infine, aggiungi il nuovo ruolo al profilo dell'istanza che hai 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

    Il nome del profilo dell'istanza scelto qui verrà utilizzato in seguito durante la creazione del cluster.

Crea il ruolo del pool di nodi

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

  1. Crea un ruolo da utilizzare 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 ruolo del pool di nodi.

  2. Crea un criterio con le autorizzazioni necessarie per le VM del pool di nodi. Scegli se connetterti direttamente al piano di controllo o se utilizzare un proxy HTTP.

    Diretto

    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: il nome della policy del pool di nodi.
    • PROXY_CONFIG_ARN: l'ARN della configurazione proxy. Per saperne di più, consulta Creare una configurazione proxy.

    Copia il valore di ogni Policy.Arn da utilizzare nel comando successivo.

  3. Collega il ruolo alla relativa policy.

    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 tuoi workload devono funzionare con il registro dei container ECR, collega il seguente criterio per l'accesso a ECR:

    Registro pubblico

    Crea una policy 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

    Allegalo 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 ruolo del pool di nodi.

  5. Crea un profilo dell'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 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 pool di nodi.
    • NODE_POOL_ROLE: il nome del ruolo del pool di nodi.

Passaggi successivi