GKE on AWS utilizza i ruoli IAM AWS per creare e gestire i cluster e i node pool. Questa pagina è rivolta agli amministratori di identità e account, agli operatori e agli sviluppatori che vogliono creare e gestire policy relative 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 Ruoli e attività comuni degli utenti GKE.
Questa pagina descrive come creare i seguenti ruoli predefiniti:
- Ruolo Agente di servizio API GKE Multi-Cloud
- L'API GKE Multi-Cloud utilizza questo ruolo IAM AWS 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 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 le policy di sicurezza della tua organizzazione. Per saperne di più sui tag, consulta Tagging delle risorse AWS.
Facoltativamente, puoi definire l'ambito delle autorizzazioni per i ruoli AWS IAM utilizzati da GKE on AWS per soddisfare i requisiti della tua organizzazione. Per saperne di più, consulta Ruoli IAM AWS.
Prima di iniziare
Se scegli di creare autorizzazioni che operano su risorse con determinati tag, devi scegliere un tag e un valore. Questi valori vengono poi utilizzati per taggare le risorse all'interno del cluster per limitarne l'accesso.
Crea il 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 del progetto Google Cloud e utilizzalo 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 l'Amazon Resource Name (ARN) generato da questo comando per utilizzarlo in un secondo momento.
Crea autorizzazioni con ambito
Scegli di seguito se vuoi creare una policy per il ruolo dell'agente di servizio dell'API GKE Multi-Cloud con autorizzazioni predefinite o con ambito limitato alle risorse con determinati tag. Quindi, esegui il comando seguente:
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 la policy IAM AWS dell'API GKE Multi-Cloud.
Facoltativamente, 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 il tuo 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 le policy IAM AWS dell'API GKE Multi-Cloud.ACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questa policyACCESS_CONTROL_TAG_VALUE: il valore del tag che si applica a questa policy
Se vuoi, puoi limitare ulteriormente questa policy a una regione e a un ID account AWS. Per limitare la policy a una regione e a un ID account, sostituisci i valori di Resource 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.
Crea policy aggiuntive per l'utilizzo dei tag
Se limiti l'accesso con i tag, segui questi passaggi per creare policy aggiuntive. Se utilizzi la policy predefinita, vai a Collega le policy al ruolo API GKE Multi-Cloud.
Crea una policy 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/*"] } ] }'Crea una policy per controllare l'accesso alle risorse di scalabilità automatica 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 un secondo momento.
Crea una policy 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.
Crea una policy per controllare l'accesso alle risorse di AWS Key Management Service.
Per ulteriori informazioni sulle autorizzazioni per ogni singola chiave, consulta 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:
CONTROL_PLANE_CONFIG_KMS_KEY_ARN: l'ARN della chiave di crittografia della configurazione del control plane KMS. Se utilizzi una sola chiave KMS per il cluster, utilizza l'ARN di quella chiave per tutti i valori qui.NODE_POOL_CONFIG_KMS_KEY_ARN: l'ARN della chiave di crittografia della configurazione del pool di nodi KMSCONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN: l'ARN della tua chiave di crittografia del volume principale del control plane KMS
Salva l'ARN generato da questo comando per utilizzarlo in un secondo momento.
Collega le policy al ruolo API GKE Multi-Cloud
Per ogni policy creata nei passaggi precedenti, esegui questo comando per collegarla al ruolo dell'API GKE Multi-Cloud:
aws iam attach-role-policy \
--policy-arn API_POLICY_ARN \
--role-name API_ROLE
Sostituisci
API_POLICY_ARNcon l'ARN della policy API di ogni policy creata in precedenzaAPI_ROLEcon il nome del ruolo dell'agente di servizio API GKE Multi-Cloud
Crea un cluster o pool di nodi
Se crei ruoli e policy con ambito limitato alle risorse con tag, devi specificare i tag quando crei un cluster o un pool di nodi. A questo scopo, utilizza il parametro --tags con i 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 policyACCESS_CONTROL_TAG_VALUE: il valore del 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 policyACCESS_CONTROL_TAG_VALUE: il valore del tag che si applica a questa policy
Crea il ruolo del control plane
Per creare il ruolo del control plane con le autorizzazioni predefinite, segui questi passaggi:
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_ROLEcon un nome per il ruolo del control plane.Crea una policy IAM per questo ruolo. Se hai creato più chiavi KMS per la crittografia del database e della configurazione, includi tutti i relativi ARN in un elenco separato da virgole.
Scegli se connetterti direttamente al control plane o se 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_POLICYcon un nome per la policy del control plane
Diretto 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:
CONTROL_PLANE_POLICY: un nome per la policy del control planeACCESS_CONTROL_TAG_KEY: la chiave tag che si applica a questa policyACCESS_CONTROL_TAG_VALUE: il valore del tag che si applica a questa policyDATABASE_KMS_KEY_ARN: l'ARN della chiave di crittografia etcd KMSCONTROL_PLANE_CONFIG_KMS_KEY_ARN: l'ARN della chiave di crittografia del control plane KMSCONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN: l'ARN della chiave di crittografia del volume principale del control plane KMS
Copia il valore di ogni
Policy.Arnda utilizzare in un comando successivo.Se utilizzi un proxy HTTP, crea una policy aggiuntiva 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:
KMS_KEY_ARNcon il tuo ARN della chiave di crittografia etcd KMSCONTROL_PLANE_POLICYcon un nome per la policy del control plane
Copia il valore di ogni
Policy.Arnda utilizzare nel comando successivo.Collega la nuova policy al ruolo corrispondente.
aws iam attach-role-policy \ --policy-arn CONTROL_PLANE_POLICY_ARN \ --role-name CONTROL_PLANE_ROLESostituisci quanto segue:
CONTROL_PLANE_ROLECONTROL_PLANE_POLICY_ARNcon il valorePolicy.Arndel comando precedente
Per creare un profilo dell'istanza IAM, esegui questo comando.
aws iam create-instance-profile \ --instance-profile-name CONTROL_PLANE_PROFILESostituisci
CONTROL_PLANE_PROFILEcon un nome per il profilo del control plane GKE Multi-Cloud.Infine, aggiungi il nuovo ruolo al profilo dell'istanza appena creato.
aws iam add-role-to-instance-profile \ --instance-profile-name CONTROL_PLANE_PROFILE \ --role-name CONTROL_PLANE_ROLESostituisci quanto segue:
CONTROL_PLANE_PROFILECONTROL_PLANE_ROLE
Utilizzerai il nome del profilo dell'istanza scelto qui in un secondo momento durante la creazione del cluster.
Crea il ruolo del pool di nodi
Per creare il ruolo pool di nodi con le autorizzazioni predefinite, segui questi passaggi:
Crea un ruolo che le VM nel pool di nodi possano utilizzare.
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_ROLEcon il nome del ruolo del node pool.Crea una policy con le autorizzazioni necessarie per le VM pool di nodi. Scegli se connetterti direttamente al control plane 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:
NODE_POOL_POLICY: il nome della policy del pool di nodi.NODE_POOL_CONFIG_KMS_KEY_ARN: l'ARN della chiave di crittografia della configurazione del pool di nodi KMS.
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 del proxy. Per saperne di più, consulta Crea una configurazione proxy.
Copia il valore di ogni Policy.Arn da utilizzare nel comando successivo.
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 valorePolicy.Arndel comando precedente.
Se i tuoi workload devono funzionare con il container registry ECR, collega la seguente policy 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.ArncomeNODE_POOL_ECR_POLICY_ARNCollegala al ruolo del node pool 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 valorePolicy.Arndel comando precedente.
Registry privato
Collega AmazonEC2ContainerRegistryReadOnly al ruolo del node pool per l'accesso al registry privato:
aws iam attach-role-policy --role-name NODE_POOL_ROLE \ --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnlySostituisci
NODE_POOL_ROLEcon il nome del ruolo del pool di nodi.Crea un profilo dell'istanza per questo ruolo.
aws iam create-instance-profile \ --instance-profile-name NODE_POOL_PROFILESostituisci
NODE_POOL_PROFILEcon il nome del profilo del pool di nodi.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_ROLESostituisci quanto segue:
NODE_POOL_PROFILE: il nome del profilo del pool di nodi.NODE_POOL_ROLE: il nome del ruolo del pool di nodi.