Halaman ini menjelaskan cara menggunakan kebijakan otorisasi untuk menetapkan Identity-Aware Proxy (IAP) sebagai mesin otorisasi kustom dalam kebijakan otorisasi untuk Load Balancer Aplikasi.
Untuk mendelegasikan otorisasi ke IAP dan Identity and Access Management (IAM), Anda memberikan otorisasi traffic ke aturan penerusan berdasarkan IAM atau identitas pengguna akhir untuk load balancer terkelola. Hal ini memungkinkan Anda menerapkan kontrol akses berbasis IAP untuk layanan backend.
Sebelum memulai
- Pahami konsep kebijakan otorisasi.
- Pastikan layanan backend dari aturan penerusan tidak mengaktifkan IAP. Jika IAP diaktifkan, Anda akan menerima error saat mengirimkan konfigurasi.
- Aktifkan Network Services API.
Membuat kebijakan otorisasi dan mengaktifkan IAP
Untuk membuat kebijakan otorisasi, Anda membuat file kebijakan yang menentukan target dan aturan, lalu mengaktifkan IAP pada aturan penerusan.
gcloud
- Run the following command to prepare a
policy.yaml
file.
$ cat << EOF > policy.yaml
action: CUSTOM
description: authz policy with Cloud IAP
name: AUTHZ_POLICY_NAME
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 beta 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.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": [], "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/v1beta1/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.
Menerapkan izin ke resource
Anda dapat menggunakan IAP API untuk menerapkan izin IAM ke setiap resource dalam project yang diamankan IAP. Izin IAM yang diberikan pada tingkat tertentu berlaku untuk semua tingkat di bawahnya. Misalnya, izin yang diberikan di level project berlaku untuk semua resource Google Cloud dalam project.
Berikut adalah beberapa contoh perintah untuk mengonfigurasi izin. Untuk mengetahui
informasi selengkapnya, lihat gcloud alpha iap web set-iam-policy
.
gcloud
Dalam contoh perintah, ganti POLICY_FILE dengan jalur ke file berformat YAML yang berisi kebijakan yang valid. Berikut adalah contoh file YAML:
bindings:
members: user:example@example.com
role: roles/iap.httpsResourceAccessor
Memperbarui izin untuk siapa yang dapat mengakses resource aturan penerusan
gcloud alpha iap web set-iam-policy POLICY_FILE [--organization=ORGANIZATION \ --folder=FOLDER --project=/PROJECT_ID \ --resource-type=RESOURCE_TYPE --service=SERVICE]
Mengonfigurasi izin di tingkat organisasi
gcloud alpha iap web set-iam-policy POLICY_FILE --organization=ORGANIZATION
Mengonfigurasi izin di tingkat folder
gcloud alpha iap web set-iam-policy POLICY_FILE --folder=FOLDER
Mengonfigurasi izin di level project
gcloud alpha iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=iap_web
Mengonfigurasi izin untuk semua aturan penerusan global dalam project
gcloud alpha iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=forwarding_rule
Mengonfigurasi izin untuk semua aturan penerusan di project dalam region
gcloud alpha iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --region=REGION
Mengonfigurasi izin untuk aturan penerusan global tertentu dalam project
gcloud alpha iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --service=SERVICE
Mengonfigurasi izin untuk aturan penerusan tertentu dalam project di suatu wilayah
gcloud alpha iap web set-iam-policy POLICY_FILE --project=PROJECT_ID \ --resource-type=forwarding_rule --service=SERVICE --region=REGION
Ganti kode berikut:
- POLICY_FILE: Jalur ke file YAML yang berisi kebijakan yang valid.
- ORGANIZATION: ID organisasi Anda.
- FOLDER: Folder yang berisi aplikasi Anda.
- PROJECT_ID: Google Cloud Project ID.
- RESOURCE_TYPE: Jenis resource IAP. Jenis resource
harus berupa
app-engine
,iap_web
,compute
,organization
, ataufolder
. - SERVICE: ID atau nama aturan penerusan.
- REGION: Region tempat resource berada.
API
Mengonfigurasi izin di tingkat organisasi
organization/ORGANIZATION
Mengonfigurasi izin di tingkat folder
folders/FOLDER
Mengonfigurasi izin di level project
projects/PROJECT_ID
Mengonfigurasi izin untuk semua aturan penerusan global dalam project
projects/PROJECT_ID/forwarding_rule
Mengonfigurasi izin untuk semua aturan penerusan di project dalam region
projects/PROJECT_ID/iap_web/forwarding_rule-REGION
Mengonfigurasi izin untuk aturan penerusan global tertentu dalam project
projects/PROJECT_ID/iap_web/forwarding_rule/services/SERVICE
Mengonfigurasi izin untuk aturan penerusan tertentu dalam project di suatu wilayah
projects/PROJECT_ID/iap_web/forwarding_rule-REGION/services/SERVICE
Menetapkan kebijakan otorisasi
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"
Untuk policy.json
, Anda dapat membuat file JSON dengan menjalankan perintah berikut. Perbarui nilai sesuai kebutuhan.
cat << EOF > policy.json { "bindings": { "members": "user:example@example.com", "role": "roles/iap.httpsResourceAccessor", } } EOF
Ganti kode berikut:
- ORGANIZATION: ID organisasi Anda.
- FOLDER: Folder yang berisi aplikasi Anda.
- PROJECT_ID: Google Cloud Project ID.
- REGION: Region tempat resource berada.
- SERVICE: ID atau nama aturan penerusan.