בדף הזה מוסבר איך משתמשים במדיניות הרשאות כדי להגדיר את Identity-Aware Proxy (IAP) כמנוע ההרשאות המותאם אישית במדיניות הרשאות למאזני עומסים של אפליקציות.
כדי להקצות הרשאה ל-IAP ולניהול הזהויות והרשאות הגישה (IAM), אתם מאשרים תנועה לכלל העברה על סמך IAM או זהויות של משתמשי קצה עבור מאזני עומסים מנוהלים. כך תוכלו לאכוף בקרת גישה מבוססת-IAP בשירותי ה-Backend שלכם.
לפני שמתחילים
- הסבר על מושגים שקשורים למדיניות הרשאות.
- מוודאים ש-IAP לא מופעל בשירותי הקצה העורפי של כללי ההעברה. אם הרכישות מתוך האפליקציה מופעלות, תופיע שגיאה כששולחים את ההגדרות.
- מפעילים את Network Services API.
יצירת מדיניות ההרשאות והפעלת IAP
כדי ליצור מדיניות הרשאות, יוצרים קובץ מדיניות שמגדיר את היעד והכללים, ואז מפעילים את IAP בכלל ההעברה. אפשר להגדיר תנאים בקטע httpRules של קובץ המדיניות כדי להחיל את IAP רק על בקשות ספציפיות. אם הקטע httpRules
לא מופיע, IAP נאכף על כל הבקשות.
gcloud
- Run the following command to prepare a
policy.yamlfile. The policy allows clients with an IP address range of10.0.0.0/24to enable IAP on a forwarding rule.
$ cat << EOF > policy.yaml
action: CUSTOM
description: authz policy with Cloud IAP
name: AUTHZ_POLICY_NAME
httpRules:
- from:
sources:
- ipBlocks:
- prefix: "10.0.0.0"
length: 24
customProvider:
cloudIap: {}
target:
loadBalancingScheme: EXTERNAL_MANAGED
resources:
- https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID
EOF
- Run the following command to enable IAP on a forwarding rule.
gcloud network-security authz-policies import AUTHZ_POLICY_NAME \ --source=policy.yaml \ --location=LOCATION \ --project=PROJECT_ID
Replace the following:
- PROJECT_ID: The Google Cloud project ID.
- LOCATION: The region that the resource is located in.
- FORWARDING_RULE_ID: The ID of the forwarding rule resource.
- AUTHZ_POLICY_NAME: The name of the authorization policy.
API
- Run the following command to prepare a
policy.jsonfile.cat << EOF > policy.json { "name": "AUTHZ_POLICY_NAME", "target": { "loadBalancingScheme": "INTERNAL_MANAGED", "resources": [ "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID" ], }, "action": "CUSTOM", "httpRules": [ { "from": { "sources": { "ipBlocks": [ { "prefix": "10.0.0.0", "length": 24 } ] } } } ], "customProvider": { "cloudIap": {} } } EOF Run the following command to enable IAP on a forwarding rule.
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @policy.json \ "https://networksecurity.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/authzPolicies"
Replace the following:
- PROJECT_ID: The Google Cloud project ID.
- LOCATION: The region that the resource is located in.
- FORWARDING_RULE_ID: The ID of the forwarding rule resource.
- AUTHZ_POLICY_NAME: The name of the authorization policy.
החלת הרשאות על משאבים
אתם יכולים להשתמש ב-IAP API כדי להחיל הרשאות IAM על משאבים ספציפיים בפרויקט שמוגן באמצעות IAP. הרשאות IAM שניתנות ברמה מסוימת חלות על כל הרמות שמתחתיה. לדוגמה, הרשאה שניתנת ברמת הפרויקט חלה על כל Google Cloud המשאבים בפרויקט.
בהמשך מופיעות כמה דוגמאות לפקודות להגדרת הרשאות. מידע נוסף זמין במאמר gcloud iap web set-iam-policy.
gcloud
בפקודות לדוגמה, מחליפים את POLICY_FILE בנתיב לקובץ בפורמט YAML שמכיל מדיניות תקינה. קובץ YAML לדוגמה:
bindings:
members: user:example@example.com
role: roles/iap.httpsResourceAccessor
עדכון ההרשאה לגישה למשאב של כלל העברת השיחות
gcloud iap web set-iam-policy POLICY_FILE [--organization=ORGANIZATION \ --folder=FOLDER --project=PROJECT_ID \ --resource-type=RESOURCE_TYPE --service=SERVICE]
הגדרת הרשאה ברמת הארגון
gcloud iap web set-iam-policy POLICY_FILE --organization=ORGANIZATION
הגדרת הרשאה ברמת התיקייה
gcloud iap web set-iam-policy POLICY_FILE --folder=FOLDER
הגדרת הרשאה ברמת הפרויקט
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=iap_web
הגדרת הרשאה לכל כללי ההעברה הגלובליים בפרויקט
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=forwarding_rule
הגדרת הרשאה לכל כללי ההעברה בפרויקט באזור מסוים
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --region=REGION
הגדרת הרשאה לכלל ספציפי להעברה גלובלית בפרויקט
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --service=SERVICE
הגדרת הרשאה לכלל העברה ספציפי בפרויקט באזור מסוים
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --service=SERVICE --region=REGION
מחליפים את מה שכתוב בשדות הבאים:
- POLICY_FILE: הנתיב לקובץ YAML שמכיל מדיניות תקינה.
- ORGANIZATION: מזהה הארגון.
- FOLDER: התיקייה שמכילה את האפליקציה.
- PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
- RESOURCE_TYPE: סוג משאב IAP. סוג המשאב צריך להיות
app-engine,iap_web,compute,organizationאוfolder. - SERVICE: המזהה או השם של כלל ההעברה.
- REGION: האזור שבו נמצא המשאב.
API
הגדרת הרשאה ברמת הארגון
organization/ORGANIZATION
הגדרת הרשאה ברמת התיקייה
folders/FOLDER
הגדרת הרשאה ברמת הפרויקט
projects/PROJECT_ID
הגדרת הרשאה לכל כללי ההעברה הגלובליים בפרויקט
projects/PROJECT_ID/forwarding_rule
הגדרת הרשאה לכל כללי ההעברה בפרויקט באזור מסוים
projects/PROJECT_ID/iap_web/forwarding_rule-REGION
הגדרת הרשאה לכלל ספציפי להעברה גלובלית בפרויקט
projects/PROJECT_ID/iap_web/forwarding_rule/services/SERVICE
הגדרת הרשאה לכלל העברה ספציפי בפרויקט באזור מסוים
projects/PROJECT_ID/iap_web/forwarding_rule-REGION/services/SERVICE
הגדרת מדיניות ההרשאות
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @policy.json \ "https://iap.googleapis.com/v1/RESOURCE_NAME:setIamPolicy"
כדי ליצור את קובץ ה-JSON עבור policy.json, מריצים את הפקודה הבאה. מעדכנים את הערכים לפי הצורך.
cat << EOF > policy.json
{
"bindings": {
"members": "user:example@example.com",
"role": "roles/iap.httpsResourceAccessor",
}
}
EOF
מחליפים את מה שכתוב בשדות הבאים:
- ORGANIZATION: מזהה הארגון.
- FOLDER: התיקייה שמכילה את האפליקציה.
- PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
- REGION: האזור שבו נמצא המשאב.
- SERVICE: המזהה או השם של כלל ההעברה.