GKE ב-AWS משתמש בתפקידי AWS IAM כדי ליצור ולנהל את האשכולות ומאגרי הצמתים. הדף הזה מיועד לאדמינים של זהויות וחשבונות, למפעילים ולמפתחים שרוצים ליצור ולנהל כללי מדיניות שקשורים להרשאות משתמשים. במאמר תפקידים ומשימות נפוצים של משתמשי GKE מפורטים תפקידים נפוצים ומשימות לדוגמה שמוזכרים בתוכן של Google Cloud .
בדף הזה מוסבר איך ליצור את תפקידי ברירת המחדל הבאים:
- תפקיד סוכן השירות של GKE Multi-Cloud API
- GKE Multi-Cloud API משתמש בתפקיד הזה ב-AWS IAM כדי לנהל משאבים באמצעות ממשקי API של AWS. התפקיד הזה משמש חשבון שירות בניהול Google שנקרא סוכן שירות.
- תפקיד AWS IAM במישור הבקרה
- מישור הבקרה של האשכול משתמש בתפקיד הזה כדי לשלוט במאגרי הצמתים.
- תפקיד AWS IAM של מאגר צמתים
- מישור הבקרה משתמש בתפקיד הזה כדי ליצור מכונות וירטואליות של מאגר צמתים.
בדף הזה מוסבר איך ליצור תפקידים למצבים הבאים:
- קבוצת הרשאות שמוגדרת כברירת מחדל, שימושית לבדיקות
- הרשאות לפעול במשאבים עם תגי AWS מסוימים
אתם יכולים לבחור אחת מהאפשרויות הבאות כדי לעמוד בדרישות של מדיניות האבטחה של הארגון. למידע נוסף על תגים, ראו תיוג משאבי AWS.
אם רוצים, אפשר להגדיר את היקף ההרשאות של תפקידי AWS IAM שבהם GKE on AWS משתמש כדי לעמוד בדרישות של הארגון. מידע נוסף מופיע במאמר תפקידי AWS IAM.
לפני שמתחילים
אם אתם בוחרים ליצור הרשאות שפועלות על משאבים עם תגים מסוימים, אתם צריכים לבחור תג וערך. לאחר מכן משתמשים בערכים האלה כדי לתייג את המשאבים באשכול, וכך להגביל את הגישה אליהם.
יצירת תפקיד של סוכן שירות ל-GKE Multi-Cloud API
כדי ליצור את תפקיד סוכן השירות של GKE Multi-Cloud API, משתמשים בפקודה הבאה כדי לאחזר את מספר הפרויקט ב- Google Cloud ומשתמשים בו כדי ליצור את התפקיד.
PROJECT_ID="$(gcloud config get-value project)"
PROJECT_NUMBER=$(gcloud projects describe "$PROJECT_ID" \
--format "value(projectNumber)")
aws iam create-role --role-name API_ROLE \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Federated": "accounts.google.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"accounts.google.com:sub": "service-'$PROJECT_NUMBER'@gcp-sa-gkemulticloud."
}
}
}
]
}'
מחליפים את API_ROLE בשם שרוצים לתת לתפקיד.
שומרים את שם המשאב של אמזון (ARN) שנוצר על ידי הפקודה הזו לשימוש מאוחר יותר.
יצירת הרשאות מוגבלות
צריך לבחור אם ליצור מדיניות לתפקיד של סוכן השירות של GKE Multi-Cloud API עם הרשאות ברירת מחדל, או עם הרשאות שמוגבלות למשאבים עם תגים מסוימים. לאחר מכן, מריצים את הפקודה הבאה:
ברירת מחדל
aws iam create-policy --policy-name API_POLICY \
--policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": [
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:CreateLaunchTemplate",
"ec2:CreateNetworkInterface",
"ec2:CreateSecurityGroup",
"ec2:CreateTags",
"ec2:CreateVolume",
"ec2:DeleteLaunchTemplate",
"ec2:DeleteNetworkInterface",
"ec2:DeleteSecurityGroup",
"ec2:DeleteTags",
"ec2:DeleteVolume",
"ec2:DescribeAccountAttributes",
"ec2:DescribeInstances",
"ec2:DescribeInternetGateways",
"ec2:DescribeKeyPairs",
"ec2:DescribeLaunchTemplates",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeSecurityGroupRules",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"ec2:GetConsoleOutput",
"ec2:ModifyInstanceAttribute",
"ec2:ModifyNetworkInterfaceAttribute",
"ec2:RevokeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress",
"ec2:RunInstances",
"iam:AWSServiceName",
"iam:CreateServiceLinkedRole",
"iam:GetInstanceProfile",
"iam:PassRole",
"autoscaling:CreateAutoScalingGroup",
"autoscaling:CreateOrUpdateTags",
"autoscaling:DeleteAutoScalingGroup",
"autoscaling:DeleteTags",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DisableMetricsCollection",
"autoscaling:EnableMetricsCollection",
"autoscaling:TerminateInstanceInAutoScalingGroup",
"autoscaling:UpdateAutoScalingGroup",
"elasticloadbalancing:AddTags",
"elasticloadbalancing:CreateListener",
"elasticloadbalancing:CreateLoadBalancer",
"elasticloadbalancing:CreateTargetGroup",
"elasticloadbalancing:DeleteListener",
"elasticloadbalancing:DeleteLoadBalancer",
"elasticloadbalancing:DeleteTargetGroup",
"elasticloadbalancing:DescribeListeners",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:DescribeTargetHealth",
"elasticloadbalancing:ModifyTargetGroupAttributes",
"elasticloadbalancing:RemoveTags",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKeyWithoutPlaintext"
],
"Resource": "*"
}
]
}'
מחליפים את API_POLICY בשם למדיניות ה-IAM של AWS ל-GKE Multi-Cloud API.
אם רוצים להגביל את המשאבים שהמדיניות הזו חלה עליהם לחשבון מסוים, מגדירים את הערך של Resource ל-arn:aws:iam::ACCOUNT_ID:* ומחליפים את ACCOUNT_ID במזהה החשבון ב-AWS.
מסונן לפי תגים
aws iam create-policy --policy-name API_POLICY_ec2 \
--policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeAccountAttributes",
"ec2:DescribeInstances",
"ec2:DescribeInternetGateways",
"ec2:DescribeKeyPairs",
"ec2:DescribeLaunchTemplates",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSecurityGroupRules",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"ec2:GetConsoleOutput"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": ["ec2:CreateSecurityGroup"],
"Resource": ["arn:aws:ec2:*:*:security-group/*"],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:CreateSecurityGroup"],
"Resource": ["arn:aws:ec2:*:*:vpc/*"]
},
{
"Effect": "Allow",
"Action": [
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:DeleteSecurityGroup",
"ec2:RevokeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress"
],
"Resource": ["arn:aws:ec2:*:*:security-group/*"],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress"
],
"Resource": ["arn:aws:ec2:*:*:security-group-rule/*"],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:CreateLaunchTemplate"],
"Resource": ["arn:aws:ec2:*:*:launch-template/*"],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteLaunchTemplate"
],
"Resource": ["arn:aws:ec2:*:*:launch-template/*"],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:RunInstances"],
"Resource": ["arn:aws:ec2:*:*:image/ami-*"],
"Condition": {
"StringEquals": {
"ec2:Owner": ["099720109477", "amazon"]
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:RunInstances"],
"Resource": [
"arn:aws:ec2:*:*:subnet/*"
],
"Condition": {
"ArnLike": {
"ec2:LaunchTemplate": "arn:aws:ec2:*:*:launch-template/*"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:RunInstances"],
"Resource": [
"arn:aws:ec2:*:*:instance/*",
"arn:aws:ec2:*:*:key-pair/*",
"arn:aws:ec2:*:*:launch-template/*",
"arn:aws:ec2:*:*:network-interface/*",
"arn:aws:ec2:*:*:security-group/*",
"arn:aws:ec2:*:*:volume/*"
],
"Condition": {
"Bool": {
"ec2:IsLaunchTemplateResource": "true"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateVolume"
],
"Resource": ["arn:aws:ec2:*:*:volume/*"],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteVolume"
],
"Resource": ["arn:aws:ec2:*:*:volume/*"],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface"
],
"Resource": ["arn:aws:ec2:*:*:network-interface/*"],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:CreateNetworkInterface"],
"Resource": ["arn:aws:ec2:*:*:security-group/*"],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": ["ec2:CreateNetworkInterface"],
"Resource": ["arn:aws:ec2:*:*:subnet/*"]
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteNetworkInterface",
"ec2:ModifyNetworkInterfaceAttribute"
],
"Resource": [
"arn:aws:ec2:*:*:network-interface/*",
"arn:aws:ec2:*:*:security-group/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Action": [
"ec2:CreateTags"
],
"Effect": "Allow",
"Resource": [
"arn:aws:ec2:*:*:launch-template/*",
"arn:aws:ec2:*:*:network-interface/*",
"arn:aws:ec2:*:*:security-group/*",
"arn:aws:ec2:*:*:security-group-rule/*",
"arn:aws:ec2:*:*:volume/*"
],
"Condition": {
"StringEquals": {
"aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Action": [
"ec2:CreateTags"
],
"Effect": "Allow",
"Resource": [
"arn:aws:ec2:*:*:instance/*"
],
"Condition": {
"StringEquals": {
"ec2:CreateAction" : "RunInstances"
}
}
},
{
"Action": [
"ec2:CreateTags",
"ec2:DeleteTags"
],
"Effect": "Allow",
"Resource": [
"arn:aws:ec2:*:*:instance/*",
"arn:aws:ec2:*:*:launch-template/*",
"arn:aws:ec2:*:*:network-interface/*",
"arn:aws:ec2:*:*:security-group/*",
"arn:aws:ec2:*:*:security-group-rule/*",
"arn:aws:ec2:*:*:volume/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:ModifyInstanceAttribute"
],
"Resource": [
"arn:aws:ec2:*:*:instance/*",
"arn:aws:ec2:*:*:security-group/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE"
}
}
}
]
}'
מחליפים את מה שכתוב בשדות הבאים:
-
API_POLICY: תחילית למדיניות IAM ב-AWS של GKE Multi-Cloud API. -
ACCESS_CONTROL_TAG_KEY: מפתח התג שחל על המדיניות הזו -
ACCESS_CONTROL_TAG_VALUE: ערך התג שחל על המדיניות הזו
אפשר גם להגביל את המדיניות הזו לאזור ולמזהה חשבון ב-AWS. כדי להגביל את המדיניות לאזור ולמזהה חשבון, מחליפים את הערכים של המשאב, כמו arn:aws:ec2:*:*:security-group/*, ב-arn:aws:ec2:AWS_REGION:ACCOUNT_ID:security-group/*.
מעתיקים את ה-ARN שנוצר למדיניות הזו כדי להשתמש בו בפקודה הבאה.
יצירת כללי מדיניות נוספים לשימוש בתגים
אם אתם מגבילים את הגישה באמצעות תגים, בצעו את השלבים הבאים כדי ליצור כללי מדיניות נוספים. אם אתם משתמשים במדיניות ברירת המחדל, דלגו אל צירוף כללי מדיניות לתפקיד של GKE Multi-Cloud API.
כדי ליצור מדיניות לשליטה בגישה ל-AWS IAM, מריצים את הפקודה הבאה:
aws iam create-policy --policy-name API_POLICY_iam \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["iam:CreateServiceLinkedRole"], "Resource": [ "arn:aws:iam::*:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" ], "Condition": { "StringEquals": { "iam:AWSServiceName": "autoscaling.amazonaws.com" } } }, { "Effect": "Allow", "Action": ["iam:CreateServiceLinkedRole"], "Resource": [ "arn:aws:iam::*:role/aws-service-role/elasticloadbalancing.amazonaws.com/AWSServiceRoleForElasticLoadBalancing" ], "Condition": { "StringEquals": { "iam:AWSServiceName": "elasticloadbalancing.amazonaws.com" } } }, { "Effect": "Allow", "Action": ["iam:PassRole"], "Resource": ["arn:aws:iam::*:role/*"], "Condition": { "StringEquals": { "iam:PassedToService": "ec2.amazonaws.com" } } } , { "Effect": "Allow", "Action": ["iam:GetInstanceProfile"], "Resource": ["arn:aws:iam::*:instance-profile/*"] } ] }'כדי ליצור מדיניות שתשלוט בגישה למשאבים של AWS EC2 Auto Scaling, מריצים את הפקודה הבאה:
aws iam create-policy --policy-name API_POLICY_autoscaling \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["autoscaling:DescribeAutoScalingGroups"], "Resource": "*" }, { "Effect": "Allow", "Action": [ "autoscaling:CreateAutoScalingGroup", "autoscaling:CreateOrUpdateTags" ], "Resource": [ "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*" ], "Condition": { "StringEquals": { "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } }, { "Effect": "Allow", "Action": [ "autoscaling:CreateOrUpdateTags", "autoscaling:DeleteAutoScalingGroup", "autoscaling:DeleteTags", "autoscaling:DisableMetricsCollection", "autoscaling:EnableMetricsCollection", "autoscaling:TerminateInstanceInAutoScalingGroup", "autoscaling:UpdateAutoScalingGroup" ], "Resource": [ "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*" ], "Condition": { "StringEquals": { "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } } ] }'שומרים את ה-ARN שנוצר על ידי הפקודה הזו לשימוש מאוחר יותר.
יוצרים מדיניות כדי לשלוט בגישה למשאבים של AWS Elastic Load Balancer.
aws iam create-policy --policy-name API_POLICY_elasticloadbalancing \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeListeners", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:CreateTargetGroup", "elasticloadbalancing:AddTags" ], "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/gke-*"], "Condition": { "StringEquals": { "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:AddTags", "elasticloadbalancing:DeleteTargetGroup", "elasticloadbalancing:ModifyTargetGroupAttributes", "elasticloadbalancing:RemoveTags" ], "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/gke-*"], "Condition": { "StringEquals": { "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:CreateListener", "elasticloadbalancing:CreateLoadBalancer", "elasticloadbalancing:AddTags" ], "Resource": [ "arn:aws:elasticloadbalancing:*:*:listener/net/gke-*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/gke-*" ], "Condition": { "StringEquals": { "aws:RequestTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:AddTags", "elasticloadbalancing:DeleteListener", "elasticloadbalancing:DeleteLoadBalancer", "elasticloadbalancing:RemoveTags" ], "Resource": [ "arn:aws:elasticloadbalancing:*:*:listener/net/gke-*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/net/gke-*" ], "Condition": { "StringEquals": { "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } } ] }'שומרים את ה-ARN שנוצר על ידי הפקודה הזו לשימוש מאוחר יותר.
יוצרים מדיניות כדי לשלוט בגישה למשאבים של שירות ניהול מפתחות (KMS) של AWS.
למידע נוסף על הרשאות לכל מפתח בנפרד, קראו את המאמר יצירת מפתחות KMS עם הרשאות ספציפיות.
aws iam create-policy --policy-name API_POLICY_kms \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["kms:DescribeKey"], "Resource": ["arn:aws:kms:*:*:key/*"] }, { "Effect": "Allow", "Action": ["kms:Encrypt"], "Resource": CONTROL_PLANE_CONFIG_KMS_KEY_ARN }, { "Effect": "Allow", "Action": ["kms:Encrypt"], "Resource": NODE_POOL_CONFIG_KMS_KEY_ARN }, { "Effect": "Allow", "Action": ["kms:GenerateDataKeyWithoutPlaintext"], "Resource": CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
CONTROL_PLANE_CONFIG_KMS_KEY_ARN: מפתח ההצפנה של הגדרות מישור הבקרה של KMS ARN. אם אתם משתמשים רק במפתח KMS אחד לאשכול, השתמשו ב-ARN של המפתח הזה לכל הערכים כאן. -
NODE_POOL_CONFIG_KMS_KEY_ARN: מפתח ההצפנה של הגדרת מאגר הצמתים ב-KMS -
CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN: ה-ARN של מפתח ההצפנה הראשי של מישור הבקרה של KMS
שומרים את ה-ARN שנוצר על ידי הפקודה הזו לשימוש מאוחר יותר.
-
צירוף כללי מדיניות לתפקיד של GKE Multi-Cloud API
לכל מדיניות שיצרתם בשלבים הקודמים, מריצים את הפקודה הבאה כדי לצרף את המדיניות לתפקיד של GKE Multi-Cloud API:
aws iam attach-role-policy \
--policy-arn API_POLICY_ARN \
--role-name API_ROLE
החלפה
API_POLICY_ARNעם ה-ARN של מדיניות ה-API של כל מדיניות שיצרתם קודם-
API_ROLEבשם התפקיד של סוכן השירות של GKE Multi-Cloud API
יצירת אשכול או מאגר צמתים
אם אתם יוצרים תפקידים וכללי מדיניות שמוגדרים למשאבים מתויגים, אתם צריכים לציין את התגים כשאתם יוצרים אשכול או מאגר צמתים. כדי לעשות זאת, משתמשים בפרמטר --tags בפקודות ליצירת אשכולות ומאגרי צמתים.
יצירת אשכול
כדי ליצור את האשכול, פועלים לפי ההוראות ליצירת אשכול וכוללים את הפרמטר --tags, כמו בדוגמה הבאה:
gcloud container aws clusters create CLUSTER_NAME \
...
--tags="ACCESS_CONTROL_TAG_KEY=ACCESS_CONTROL_TAG_VALUE"
מחליפים את מה שכתוב בשדות הבאים:
-
ACCESS_CONTROL_TAG_KEY: מפתח התג שחל על המדיניות הזו -
ACCESS_CONTROL_TAG_VALUE: ערך התג שחל על המדיניות הזו
יצירת מאגר צמתים
כדי ליצור מאגר צמתים, פועלים לפי ההוראות ליצירת מאגר צמתים וכוללים את הפרמטר --tags, כמו בדוגמה הבאה:
gcloud container aws node-pools create NODE_POOL_NAME \
...
--tags "ACCESS_CONTROL_TAG_KEY=ACCESS_CONTROL_TAG_VALUE"
מחליפים את מה שכתוב בשדות הבאים:
-
ACCESS_CONTROL_TAG_KEY: מפתח התג שחל על המדיניות הזו -
ACCESS_CONTROL_TAG_VALUE: ערך התג שחל על המדיניות הזו
יצירת התפקיד של מישור הבקרה
כדי ליצור את התפקיד של מישור הבקרה עם הרשאות ברירת המחדל:
כדי ליצור את התפקיד הזה, מריצים את הפקודה הבאה:
aws iam create-role --role-name CONTROL_PLANE_ROLE \ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }'מחליפים את
CONTROL_PLANE_ROLEבשם לתפקיד של מישור הבקרה.יוצרים מדיניות IAM לתפקיד הזה. אם יצרתם כמה מפתחות KMS להצפנה של מסד הנתונים וההגדרות, צריך לכלול את כל ה-ARN שלהם ברשימה מופרדת בפסיקים.
בוחרים אם להתחבר ישירות למישור הבקרה, או להתחבר ישירות למישור הבקרה ולהשתמש בתגים.
קישור ישיר
aws iam create-policy --policy-name CONTROL_PLANE_POLICY \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Action": [ "ec2:AttachNetworkInterface", "ec2:AttachVolume", "ec2:AuthorizeSecurityGroupIngress", "ec2:CreateRoute", "ec2:CreateSecurityGroup", "ec2:CreateSnapshot", "ec2:CreateTags", "ec2:CreateVolume", "ec2:DeleteRoute", "ec2:DeleteSecurityGroup", "ec2:DeleteSnapshot", "ec2:DeleteTags", "ec2:DeleteVolume", "ec2:DescribeAccountAttributes", "ec2:DescribeAvailabilityZones", "ec2:DescribeDhcpOptions", "ec2:DescribeInstances", "ec2:DescribeInstanceTypes", "ec2:DescribeInternetGateways", "ec2:DescribeLaunchTemplateVersions", "ec2:DescribeRegions", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroups", "ec2:DescribeSnapshots", "ec2:DescribeSubnets", "ec2:DescribeTags", "ec2:DescribeVolumes", "ec2:DescribeVolumesModifications", "ec2:DescribeVpcs", "ec2:DetachVolume", "ec2:ModifyInstanceAttribute", "ec2:ModifyVolume", "ec2:RevokeSecurityGroupIngress", "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeAutoScalingInstances", "autoscaling:DescribeLaunchConfigurations", "autoscaling:DescribeTags", "autoscaling:SetDesiredCapacity", "autoscaling:TerminateInstanceInAutoScalingGroup", "elasticloadbalancing:AddTags", "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer", "elasticloadbalancing:AttachLoadBalancerToSubnets", "elasticloadbalancing:ConfigureHealthCheck", "elasticloadbalancing:CreateListener", "elasticloadbalancing:CreateLoadBalancer", "elasticloadbalancing:CreateLoadBalancerListeners", "elasticloadbalancing:CreateLoadBalancerPolicy", "elasticloadbalancing:CreateTargetGroup", "elasticloadbalancing:DeleteListener", "elasticloadbalancing:DeleteLoadBalancer", "elasticloadbalancing:DeleteLoadBalancerListeners", "elasticloadbalancing:DeleteTargetGroup", "elasticloadbalancing:DeregisterInstancesFromLoadBalancer", "elasticloadbalancing:DeregisterTargets", "elasticloadbalancing:DescribeListeners", "elasticloadbalancing:DescribeLoadBalancerAttributes", "elasticloadbalancing:DescribeLoadBalancerPolicies", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth", "elasticloadbalancing:DetachLoadBalancerFromSubnets", "elasticloadbalancing:ModifyListener", "elasticloadbalancing:ModifyLoadBalancerAttributes", "elasticloadbalancing:ModifyTargetGroup", "elasticloadbalancing:RegisterInstancesWithLoadBalancer", "elasticloadbalancing:RegisterTargets", "elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer", "elasticloadbalancing:SetLoadBalancerPoliciesOfListener", "elasticfilesystem:CreateAccessPoint", "elasticfilesystem:DeleteAccessPoint", "elasticfilesystem:DescribeAccessPoints", "elasticfilesystem:DescribeFileSystems", "elasticfilesystem:DescribeMountTargets", "kms:CreateGrant", "kms:Decrypt", "kms:Encrypt", "kms:GrantIsForAWSResource" ], "Resource": "*" } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
CONTROL_PLANE_POLICYעם שם למדיניות של מישור הבקרה
ישיר עם תגים
aws iam create-policy --policy-name CONTROL_PLANE_POLICY_autoscaling \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeAutoScalingInstances", "autoscaling:DescribeLaunchConfigurations", "autoscaling:DescribeTags" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "autoscaling:SetDesiredCapacity", "autoscaling:TerminateInstanceInAutoScalingGroup" ], "Resource": [ "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/gke-*" ], "Condition": { "StringEquals": { "aws:ResourceTag/ACCESS_CONTROL_TAG_KEY": "ACCESS_CONTROL_TAG_VALUE" } } } ] }' aws iam create-policy --policy-name CONTROL_PLANE_POLICY_ec2 \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:DescribeAccountAttributes", "ec2:DescribeAvailabilityZones", "ec2:DescribeDhcpOptions", "ec2:DescribeInstances", "ec2:DescribeInstanceTypes", "ec2:DescribeInternetGateways", "ec2:DescribeLaunchTemplateVersions", "ec2:DescribeRegions", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroups", "ec2:DescribeSnapshots", "ec2:DescribeSubnets", "ec2:DescribeTags", "ec2:DescribeVolumes", "ec2:DescribeVolumesModifications", "ec2:DescribeVpcs" ], "Resource": "*" }, { "Effect": "Allow", "Action": ["ec2:AttachNetworkInterface"], "Resource": [ "arn:aws:ec2:*:*:instance/*", "arn:aws:ec2:*:*:network-interface/*" ] }, { "Effect": "Allow", "Action": [ "ec2:CreateVolume", "ec2:CreateTags", "ec2:AttachVolume", "ec2:DeleteVolume", "ec2:DetachVolume", "ec2:ModifyVolume" ], "Resource": ["arn:aws:ec2:*:*:volume/*"] }, { "Effect": "Allow", "Action": ["ec2:AttachVolume", "ec2:DetachVolume"], "Resource": ["arn:aws:ec2:*:*:instance/*"] }, { "Effect": "Allow", "Action": ["ec2:CreateSecurityGroup", "ec2:CreateTags"], "Resource": ["arn:aws:ec2:*:*:security-group/*"] }, { "Effect": "Allow", "Action": ["ec2:CreateSecurityGroup"], "Resource": ["arn:aws:ec2:*:*:vpc/*"] }, { "Effect": "Allow", "Action": [ "ec2:AuthorizeSecurityGroupIngress", "ec2:DeleteSecurityGroup", "ec2:RevokeSecurityGroupIngress" ], "Resource": ["arn:aws:ec2:*:*:security-group/*"] }, { "Effect": "Allow", "Action": ["ec2:CreateSnapshot", "ec2:CreateTags", "ec2:DeleteSnapshot"], "Resource": ["arn:aws:ec2:*:*:snapshot/*"] }, { "Effect": "Allow", "Action": ["ec2:CreateSnapshot"], "Resource": ["arn:aws:ec2:*:*:volume/*"] }, { "Effect": "Allow", "Action": ["ec2:CreateRoute", "ec2:DeleteRoute"], "Resource": ["arn:aws:ec2:*:*:route-table/*"] }, { "Effect": "Allow", "Action": ["ec2:ModifyInstanceAttribute"], "Resource": [ "arn:aws:ec2:*:*:instance/*", "arn:aws:ec2:*:*:security-group/*", "arn:aws:ec2:*:*:volume/*" ] }, { "Effect": "Allow", "Action": ["ec2:DeleteTags"], "Resource": [ "arn:aws:ec2:*:*:security-group/*", "arn:aws:ec2:*:*:snapshot/*", "arn:aws:ec2:*:*:volume/*" ] } ] }' aws iam create-policy --policy-name CONTROL_PLANE_POLICY_elasticloadbalancing \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeLoadBalancerAttributes", "elasticloadbalancing:DescribeListeners", "elasticloadbalancing:DescribeLoadBalancerPolicies", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:AddTags", "elasticloadbalancing:AttachLoadBalancerToSubnets", "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer", "elasticloadbalancing:CreateListener", "elasticloadbalancing:CreateLoadBalancer", "elasticloadbalancing:CreateLoadBalancerPolicy", "elasticloadbalancing:CreateLoadBalancerListeners", "elasticloadbalancing:ConfigureHealthCheck", "elasticloadbalancing:DeleteLoadBalancer", "elasticloadbalancing:DeleteLoadBalancerListeners", "elasticloadbalancing:DetachLoadBalancerFromSubnets", "elasticloadbalancing:DeregisterInstancesFromLoadBalancer", "elasticloadbalancing:ModifyLoadBalancerAttributes", "elasticloadbalancing:RegisterInstancesWithLoadBalancer", "elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer", "elasticloadbalancing:SetLoadBalancerPoliciesOfListener" ], "Resource": ["arn:aws:elasticloadbalancing:*:*:loadbalancer/*"] }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:AddTags", "elasticloadbalancing:CreateTargetGroup", "elasticloadbalancing:DeleteTargetGroup", "elasticloadbalancing:DeregisterTargets", "elasticloadbalancing:ModifyTargetGroup", "elasticloadbalancing:RegisterTargets" ], "Resource": ["arn:aws:elasticloadbalancing:*:*:targetgroup/*"] }, { "Effect": "Allow", "Action": [ "elasticloadbalancing:DeleteListener", "elasticloadbalancing:ModifyListener" ], "Resource": ["arn:aws:elasticloadbalancing:*:*:listener/*"] } ] }' aws iam create-policy --policy-name CONTROL_PLANE_POLICY_elasticfilesystem \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticfilesystem:DescribeAccessPoints", "elasticfilesystem:DescribeFileSystems", "elasticfilesystem:DescribeMountTargets" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "elasticfilesystem:CreateAccessPoint" ], "Resource": [ "arn:aws:elasticfilesystem:*:*:file-system/*" ] }, { "Effect": "Allow", "Action": [ "elasticfilesystem:DeleteAccessPoint" ], "Resource": [ "arn:aws:elasticfilesystem:*:*:access-point/*" ] } ] }' aws iam create-policy --policy-name CONTROL_PLANE_POLICY_kms \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["kms:Decrypt", "kms:Encrypt"], "Resource": DATABASE_KMS_KEY_ARN }, { "Effect": "Allow", "Action": ["kms:Decrypt"], "Resource": CONTROL_PLANE_CONFIG_KMS_KEY_ARN }, { "Effect": "Allow", "Action": ["kms:CreateGrant"], "Resource": CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN, "Condition": { "Bool": { "kms:GrantIsForAWSResource": "true" } } } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
CONTROL_PLANE_POLICY: שם למדיניות של מישור הבקרה -
ACCESS_CONTROL_TAG_KEY: מפתח התג שחל על המדיניות הזו -
ACCESS_CONTROL_TAG_VALUE: ערך התג שחל על המדיניות הזו -
DATABASE_KMS_KEY_ARN: מפתח ההצפנה ARN של KMS etcd -
CONTROL_PLANE_CONFIG_KMS_KEY_ARN: ה-ARN של מפתח ההצפנה של מישור הבקרה ב-KMS -
CONTROL_PLANE_MAIN_VOLUME_KMS_KEY_ARN: ה-ARN של מפתח ההצפנה של אמצעי האחסון הראשי במישור הבקרה של KMS
מעתיקים את הערך של כל
Policy.Arnכדי להשתמש בו בפקודה הבאה.-
אם אתם משתמשים בשרת proxy ל-HTTP, צרו מדיניות נוספת ל-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 } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
KMS_KEY_ARNעם ה-ARN של מפתח ההצפנה של KMS etcd -
CONTROL_PLANE_POLICYעם שם למדיניות של מישור הבקרה
מעתיקים את הערך של כל
Policy.Arnכדי להשתמש בו בפקודה הבאה.-
מצרפים את המדיניות החדשה לתפקיד המתאים.
aws iam attach-role-policy \ --policy-arn CONTROL_PLANE_POLICY_ARN \ --role-name CONTROL_PLANE_ROLEמחליפים את מה שכתוב בשדות הבאים:
CONTROL_PLANE_ROLE-
CONTROL_PLANE_POLICY_ARNעם הערך שלPolicy.Arnמהפקודה הקודמת
כדי ליצור פרופיל מכונה של IAM, מריצים את הפקודה הבאה.
aws iam create-instance-profile \ --instance-profile-name CONTROL_PLANE_PROFILEמחליפים את
CONTROL_PLANE_PROFILEבשם לפרופיל של מישור הבקרה של GKE Multi-Cloud.לבסוף, מוסיפים את התפקיד החדש לפרופיל המכונה שיצרתם.
aws iam add-role-to-instance-profile \ --instance-profile-name CONTROL_PLANE_PROFILE \ --role-name CONTROL_PLANE_ROLEמחליפים את מה שכתוב בשדות הבאים:
CONTROL_PLANE_PROFILECONTROL_PLANE_ROLE
תצטרכו להשתמש בשם פרופיל המכונה שתבחרו כאן בהמשך, במהלך יצירת האשכול.
יצירת התפקיד של מאגר הצמתים
כדי ליצור את התפקיד של מאגר הצמתים עם הרשאות ברירת המחדל:
יוצרים תפקיד למכונות הווירטואליות במאגר הצמתים.
aws iam create-role --role-name NODE_POOL_ROLE \ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }'מחליפים את
NODE_POOL_ROLEבשם התפקיד של מאגר הצמתים.יוצרים מדיניות עם ההרשאות שנדרשות למכונות הווירטואליות של מאגר הצמתים. בוחרים אם להתחבר ישירות למישור הבקרה או להשתמש בשרת 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 } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
NODE_POOL_POLICY: שם המדיניות של מאגר הצמתים. -
NODE_POOL_CONFIG_KMS_KEY_ARN: ה-ARN של מפתח ההצפנה של הגדרת מאגר הצמתים ב-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 } ] }'מחליפים את מה שכתוב בשדות הבאים:
-
KMS_KEY_ARN: מפתח ה-KMS של מאגר הצמתים. -
NODE_POOL_POLICY: שם המדיניות של מאגר הצמתים. -
PROXY_CONFIG_ARN: ה-ARN של הגדרות שרת ה-proxy. מידע נוסף זמין במאמר יצירת הגדרת שרת proxy.
מעתיקים את הערך של כל Policy.Arn לשימוש בפקודה הבאה.
-
מצרפים את התפקיד למדיניות שלו.
aws iam attach-role-policy --role-name NODE_POOL_ROLE \ --policy-arn "NODE_POOL_POLICY_ARN"מחליפים את מה שכתוב בשדות הבאים:
-
NODE_POOL_ROLE: שם התפקיד של מאגר הצמתים. -
NODE_POOL_POLICY_ARN: הערך שלPolicy.Arnמהפקודה הקודמת.
-
אם עומסי העבודה צריכים לעבוד עם Container Registry של ECR, צריך לצרף את המדיניות הבאה כדי לקבל גישה ל-ECR:
מרשם ציבורי
יוצרים מדיניות עם ההרשאות הבאות:
aws iam create-policy --policy-name NODE_POOL_POLICY_ecr \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr-public:GetAuthorizationToken", "sts:GetServiceBearerToken" ], "Resource": "*" } ] }'מעתיקים את הערך של
Policy.ArnבתורNODE_POOL_ECR_POLICY_ARNמצרפים אותו לתפקיד של מאגר הצמתים שיצרתם.
aws iam attach-role-policy --role-name NODE_POOL_ROLE \ --policy-arn "NODE_POOL_ECR_POLICY_ARN"מחליפים את מה שכתוב בשדות הבאים:
-
NODE_POOL_ROLE: שם התפקיד של מאגר הצמתים. -
NODE_POOL_ECR_POLICY_ARN: הערך שלPolicy.Arnמהפקודה הקודמת.
מרשם פרטי
מצרפים את AmazonEC2ContainerRegistryReadOnly לתפקיד של מאגר הצמתים כדי לקבל גישה למאגר הפרטי:
aws iam attach-role-policy --role-name NODE_POOL_ROLE \ --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnlyמחליפים את
NODE_POOL_ROLEבשם התפקיד של מאגר הצמתים.-
יוצרים פרופיל מכונה לתפקיד הזה.
aws iam create-instance-profile \ --instance-profile-name NODE_POOL_PROFILEמחליפים את
NODE_POOL_PROFILEבשם של פרופיל מאגר הצמתים.מוסיפים את התפקיד החדש לפרופיל המכונה.
aws iam add-role-to-instance-profile \ --instance-profile-name NODE_POOL_PROFILE \ --role-name NODE_POOL_ROLEמחליפים את מה שכתוב בשדות הבאים:
-
NODE_POOL_PROFILE: השם של פרופיל מאגר הצמתים. -
NODE_POOL_ROLE: שם התפקיד של מאגר הצמתים.
-