שימוש במדיניות הרשאות כדי להעביר הרשאות ל-IAP ול-IAM

בדף הזה מוסבר איך להשתמש בכללי מדיניות הרשאה כדי להגדיר את Identity-Aware Proxy ‏(IAP) כמנוע ההרשאה המותאם אישית במדיניות הרשאה למאזני עומסים של אפליקציות.

כדי להעביר את הרשאת הגישה ל-IAP ולניהול הזהויות והרשאות הגישה (IAM), אתם מאשרים תנועה לכלל העברה שמבוסס על IAM או על זהויות של משתמשי קצה למאזני עומסים מנוהלים. כך תוכלו לאכוף בקרת גישה מבוססת-IAP לשירותי הקצה העורפי שלכם.

לפני שמתחילים

יצירת מדיניות ההרשאה והפעלת IAP

כדי ליצור מדיניות הרשאה, יוצרים קובץ מדיניות שמגדיר את היעד והכללים, ואז מפעילים את IAP בכלל ההעברה. אפשר להחיל את IAP רק על בקשות ספציפיות, על ידי הגדרת תנאים בקטע httpRules של קובץ המדיניות. אם משמיטים את הקטע httpRules,‏ IAP נאכף בכל הבקשות.

gcloud

  1. Run the following command to prepare a policy.yaml file. The policy allows clients with an IP address range of 10.0.0.0/24 to 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
    
  2. 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

  1. Run the following command to prepare a policy.json file.

    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
    
  2. 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: השם או המזהה של כלל ההעברה.