הפעלת IAP ב-Compute Engine

בדף הזה מוסבר איך לאבטח מכונה של Compute Engine באמצעות שרת proxy לאימות זהויות (IAP).

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

כדי להפעיל את IAP ל-Compute Engine, צריך:

אם עדיין לא הגדרתם מכונה של Compute Engine, תוכלו לקרוא את המדריך המלא הגדרת IAP ל-Compute Engine.

כדי לאמת משתמשים, ב-IAP משתמשים בלקוח OAuth שמנוהל על ידי Google. רק משתמשים בתוך הארגון יכולים לגשת לאפליקציה שמופעל בה IAP. אם רוצים לאפשר גישה למשתמשים מחוץ לארגון, אפשר לעיין במאמר הפעלת IAP לאפליקציות חיצוניות.

אתם יכולים להפעיל את IAP בשירות לקצה העורפי או בכלל העברה של Compute Engine. כשמפעילים את IAP בשירות לקצה העורפי של Compute Engine, רק השירות הזה מוגן על ידי IAP. כשמפעילים את IAP בכלל העברה של Compute Engine, כל המכונות של Compute Engine שמאחורי כלל ההעברה מוגנות על ידי IAP.

הפעלת IAP בכלל העברה

אפשר להפעיל את IAP בכלל העברה באמצעות מסגרת כללי מדיניות ההרשאה של מאזן העומסים.

gcloud

  1. מריצים את הפקודה הבאה כדי להכין קובץ policy.yaml. המדיניות מאפשרת ללקוחות עם טווח כתובות IP של 10.0.0.0/24 להפעיל את IAP בכלל העברה.
$ 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
  1. מריצים את הפקודה הבאה כדי להפעיל את IAP בכלל העברה.
gcloud network-security authz-policies import AUTHZ_POLICY_NAME \
--source=policy.yaml \
--location=LOCATION \
--project=PROJECT_ID

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫LOCATION: האזור שבו נמצא המשאב.
  • ‫FORWARDING_RULE_ID: המזהה של משאב כלל ההעברה.
  • ‫AUTHZ_POLICY_NAME: השם של מדיניות ההרשאה.

API

  1. מריצים את הפקודה הבאה כדי להכין קובץ policy.json.
    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. מריצים את הפקודה הבאה כדי להפעיל את IAP בכלל העברה.

    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"
    

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • ‫LOCATION: האזור שבו נמצא המשאב.
    • ‫FORWARDING_RULE_ID: המזהה של משאב כלל ההעברה.
    • ‫AUTHZ_POLICY_NAME: השם של מדיניות ההרשאה.

אחרי שמפעילים את IAP בכלל העברה, אפשר להחיל הרשאות על משאבים.

הפעלת IAP בשירות לקצה העורפי של Compute Engine

אתם יכולים להפעיל את IAP בשירות לקצה העורפי של Compute Engine דרך השירות הזה.

console

לקוח OAuth בניהול Google לא זמין כשמפעילים את IAP באמצעות מסוףGoogle Cloud .

אם עדיין לא הגדרתם את מסך ההסכמה ל-OAuth בפרויקט, תתבקשו לעשות זאת. כדי להגדיר את מסך ההסכמה ל-OAuth, קראו את המאמר הגדרת מסך ההסכמה ל-OAuth.

אם אתם מריצים את GKE בגרסה 1.24 ואילך, אתם יכולים להגדיר את IAP ו-GKE באמצעות Kubernetes Gateway API. כדי לעשות זאת, מבצעים את השלבים הבאים ואז פועלים לפי ההוראות במאמר הגדרת IAP. לא להגדיר את BackendConfig.

הגדרת גישה ל-IAP

  1. נכנסים לדף Identity-Aware Proxy.
    כניסה לדף Identity-Aware Proxy
  2. בוחרים את הפרויקט שרוצים לאבטח באמצעות IAP.
  3. מסמנים את התיבה לצד המשאב שרוצים לתת גישה אליו.

    אם המשאב לא מופיע, צריך לוודא שהוא נוצר ושה-BackendConfig ובקר ה-Ingress של Compute Engine מסונכרנים.

    כדי לוודא ששירות הקצה העורפי זמין, מריצים את הפקודה הבאה של gcloud:

    gcloud compute backend-services list
  4. בחלונית שבצד שמאל, לוחצים על Add principal.
  5. בתיבת הדו-שיח Add principals שמופיעה, מזינים את כתובות האימייל של הקבוצות או המשתמשים שצריכים לקבל את התפקיד משתמש באפליקציית אינטרנט שמאובטחת באמצעות IAP בפרויקט.

    אפשר להקצות את התפקיד הזה לחשבונות המשתמשים הבאים:

    • חשבון Google: user@gmail.com
    • קבוצת Google: admins@googlegroups.com
    • חשבון שירות: server@example.
    • דומיין ב-Google Workspace: example.com

    חשוב להוסיף חשבון Google שיש לכם גישה אליו.

  6. ברשימה הנפתחת Roles, בוחרים באפשרות Cloud IAP > IAP-secured Web App User.
  7. לוחצים על Save.

הפעלת IAP

  1. בדף שרת proxy לאימות זהויות (IAP), בקטע APPLICATIONS, מאתרים את מאזן העומסים שמשרת את instance group שרוצים להגביל את הגישה אליו. כדי להפעיל את IAP למשאב,
    כדי להפעיל את IAP:
  2. בחלון Turn on IAP שמופיע, לוחצים על Turn On כדי לאשר שרוצים לאבטח את המשאב באמצעות IAP. אחרי שמפעילים את IAP, צריך להזין פרטי כניסה לכל החיבורים למאזן העומסים. רק חשבונות עם התפקיד משתמש באפליקציית אינטרנט מאובטחת באמצעות IAP בפרויקט יקבלו גישה.

gcloud

Before you set up your project and IAP, you need an up-to-date version of the gcloud CLI. For instructions on how to install the gcloud CLI, see Install the gcloud CLI.

  1. To authenticate, use the Google Cloud CLI and run the following command.
    gcloud auth login
  2. To sign in, follow the URL that appears.
  3. After you sign in, copy the verification code that appears and paste it in the command line.
  4. Run the following command to specify the project that contains the resource that you want to protect with IAP.
    gcloud config set project PROJECT_ID
  5. To enable IAP, run either the globally or regionally scoped command.

    Global scope
    gcloud compute backend-services update BACKEND_SERVICE_NAME --global --iap=enabled
    Regional scope
    gcloud compute backend-services update BACKEND_SERVICE_NAME --region REGION_NAME --iap=enabled

After you enable IAP, you can use the gcloud CLI to modify the IAP access policy using the IAM role roles/iap.httpsResourceAccessor. Learn more about managing roles and permissions.

API

  1. 运行以下命令以准备 settings.json 文件。

    cat << EOF > settings.json
    {
    "iap":
      {
        "enabled":true
      }
    }
    EOF
    

  2. 运行以下命令以启用 IAP。

    curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -d @settings.json \
    "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/REGION/backendServices/BACKEND_SERVICE_NAME"
    

启用 IAP 后,您可以使用 Google Cloud CLI 通过 IAM 角色 roles/iap.httpsResourceAccessor 修改 IAP 访问权限政策。详细了解如何管理角色和权限。