Halaman ini menjelaskan cara menggunakan kebijakan otorisasi untuk menetapkan Identity-Aware Proxy (IAP) sebagai mesin otorisasi kustom dalam kebijakan otorisasi untuk Application Load Balancers.
Untuk mendelegasikan otorisasi ke IAP dan Identity and Access Management (IAM), Anda mengotorisasi traffic ke aturan penerusan berdasarkan identitas IAM atau pengguna akhir untuk load balancer terkelola. Hal ini memungkinkan Anda menerapkan kontrol akses berbasis IAP untuk layanan backend.
Sebelum memulai
- Memahami konsep kebijakan otorisasi.
- Pastikan layanan backend dari aturan penerusan tidak mengaktifkan IAP. Jika IAP diaktifkan, Anda akan menerima error saat mengirimkan konfigurasi.
- Mengaktifkan 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. Anda dapat memilih untuk menerapkan IAP hanya ke permintaan tertentu dengan menentukan kondisi di bagian httpRules file kebijakan. Jika bagian httpRules dihilangkan, IAP akan diterapkan pada semua permintaan.
gcloud
- Jalankan perintah berikut untuk menyiapkan file
policy.yaml. Kebijakan ini memungkinkan klien dengan rentang alamat IP10.0.0.0/24untuk mengaktifkan IAP pada aturan penerusan.
$ 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
- Jalankan perintah berikut untuk mengaktifkan IAP pada aturan penerusan.
gcloud network-security authz-policies import AUTHZ_POLICY_NAME \ --source=policy.yaml \ --location=LOCATION \ --project=PROJECT_ID
Ganti kode berikut:
- PROJECT_ID: Project ID Google Cloud
- LOCATION: Region tempat resource berada.
- FORWARDING_RULE_ID: ID resource aturan penerusan.
- AUTHZ_POLICY_NAME: Nama kebijakan otorisasi.
API
- Jalankan perintah berikut untuk menyiapkan file
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 Jalankan perintah berikut untuk mengaktifkan IAP pada aturan penerusan.
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"
Ganti kode berikut:
- PROJECT_ID: Project ID Google Cloud
- LOCATION: Region tempat resource berada.
- FORWARDING_RULE_ID: ID resource aturan penerusan.
- AUTHZ_POLICY_NAME: Nama kebijakan otorisasi.
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 tingkat project berlaku untuk semua Google Cloud resource dalam project.
Berikut adalah beberapa contoh perintah untuk mengonfigurasi izin. Untuk mengetahui informasi selengkapnya, lihat gcloud iap web set-iam-policy.
gcloud
Dalam perintah contoh, 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 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 iap web set-iam-policy POLICY_FILE --organization=ORGANIZATION
Mengonfigurasi izin di tingkat folder
gcloud iap web set-iam-policy POLICY_FILE --folder=FOLDER
Mengonfigurasi izin di tingkat project
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=iap_web
Mengonfigurasi izin untuk semua aturan penerusan global dalam project
gcloud iap web set-iam-policy POLICY_FILE --project=PROJECT_ID --resource-type=forwarding_rule
Mengonfigurasi izin untuk semua aturan penerusan dalam project di region
gcloud 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 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 region
gcloud 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: ID Google Cloud project.
- 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 tingkat project
projects/PROJECT_ID
Mengonfigurasi izin untuk semua aturan penerusan global dalam project
projects/PROJECT_ID/forwarding_rule
Mengonfigurasi izin untuk semua aturan penerusan dalam project di 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 region
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: ID Google Cloud project.
- REGION: Region tempat resource berada.
- SERVICE: ID atau nama aturan penerusan.