Halaman ini menunjukkan cara menggunakan batasan kustom Layanan Kebijakan Organisasi untuk membatasi operasi tertentu pada resource berikut: Google Cloud
accesscontextmanager.googleapis.com/AccessPolicy
accesscontextmanager.googleapis.com/AccessLevel
accesscontextmanager.googleapis.com/AuthorizedOrgsDesc
accesscontextmanager.googleapis.com/ServicePerimeter
Untuk mempelajari lebih lanjut Kebijakan Organisasi, lihat Kebijakan organisasi kustom.
Tentang batasan dan kebijakan organisasi
Google Cloud Layanan Kebijakan Organisasi memberi Anda kontrol terpusat dan terprogram atas resource organisasi. Sebagai administrator kebijakan organisasi, Anda dapat menentukan kebijakan organisasi, yang merupakan serangkaian batasan yang disebut batasan yang berlaku untuk Google Cloud resource dan turunan dari resource tersebut dalam Google Cloud hierarki resource. Anda dapat menerapkan kebijakan organisasi di tingkat organisasi, folder, atau project.
Kebijakan Organisasi menyediakan batasan terkelola bawaan untuk berbagai layanan Google Cloud . Namun, jika menginginkan kontrol yang lebih terperinci dan dapat disesuaikan atas kolom tertentu yang dibatasi dalam kebijakan organisasi, Anda juga dapat membuat batasan khusus dan menggunakan batasan khusus tersebut dalam kebijakan organisasi.
Pewarisan kebijakan
Secara default, kebijakan organisasi diwarisi oleh turunan resource tempat Anda menerapkan kebijakan tersebut. Misalnya, jika Anda menerapkan kebijakan pada folder, Google Cloud akan menerapkan kebijakan tersebut pada semua project di folder tersebut. Untuk mempelajari lebih lanjut perilaku ini dan cara mengubahnya, lihat Aturan evaluasi hierarki.
Sebelum memulai
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- Pastikan Anda mengetahui ID organisasi Anda.
ORGANIZATION_ID
: ID organisasi Anda, seperti123456789
.CONSTRAINT_NAME
: nama yang Anda inginkan untuk batasan kustom baru. Batasan kustom harus diawali dengancustom.
, dan hanya boleh menyertakan huruf besar, huruf kecil, atau angka. Contohnya,custom.disableCustomAccessLevels
. Panjang maksimum kolom ini adalah 70 karakter.RESOURCE_NAME
: nama lengkap Google Cloud resource yang berisi objek dan kolom yang ingin Anda batasi. Misalnya,accesscontextmanager.googleapis.com/AccessLevel
.CONDITION
: kondisi CEL yang ditulis berdasarkan representasi resource layanan yang didukung. Kolom ini memiliki panjang maksimal 1.000 karakter. Lihat Resource yang didukung untuk mengetahui informasi selengkapnya tentang resource yang tersedia untuk menulis kondisi. Contoh,"resource.basic.conditions.exists(c, has(c.devicePolicy))"
ACTION
: tindakan yang akan diambil jikacondition
terpenuhi. Nilai yang mungkin adalahALLOW
danDENY
.DISPLAY_NAME
: nama yang mudah dibaca manusia untuk batasan. Kolom ini memiliki panjang maksimal 200 karakter.DESCRIPTION
: deskripsi batasan yang mudah dipahami untuk ditampilkan sebagai pesan error saat kebijakan dilanggar. Kolom ini memiliki panjang maksimal 2.000 karakter.- Di konsol Google Cloud , buka halaman Kebijakan organisasi.
- Dari pemilih project, pilih project yang ingin Anda tetapkan kebijakan organisasinya.
- Dari daftar di halaman Kebijakan organisasi, pilih batasan Anda untuk melihat halaman Detail kebijakan untuk batasan tersebut.
- Untuk mengonfigurasi kebijakan organisasi untuk resource ini, klik Manage policy.
- Di halaman Edit kebijakan, pilih Ganti kebijakan induk.
- Klik Add a rule.
- Di bagian Penerapan, pilih apakah penerapan kebijakan organisasi ini diaktifkan atau dinonaktifkan.
- Opsional: Untuk membuat kebijakan organisasi bersyarat pada tag, klik Tambahkan kondisi. Perhatikan bahwa jika menambahkan aturan kondisional ke kebijakan organisasi, Anda harus menambahkan setidaknya satu aturan tanpa syarat atau kebijakan tidak dapat disimpan. Untuk mengetahui informasi selengkapnya, lihat Menetapkan kebijakan organisasi dengan tag.
- Klik Uji perubahan untuk menyimulasikan efek kebijakan organisasi. Simulasi kebijakan tidak tersedia untuk batasan terkelola lama. Untuk mengetahui informasi selengkapnya, lihat Menguji perubahan kebijakan organisasi dengan Policy Simulator.
- Untuk menyelesaikan dan menerapkan kebijakan organisasi, klik Set policy. Kebijakan ini memerlukan waktu hingga 15 menit untuk diterapkan.
-
PROJECT_ID
: project tempat Anda ingin menerapkan batasan. -
CONSTRAINT_NAME
: nama yang Anda tentukan untuk batasan kustom. Contoh,custom.disableCustomAccessLevels
- ID organisasi Anda
- Project ID
Simpan file berikut sebagai
constraint-disable_custom_access_level.yaml
:name: organizations/ORGANIZATION_ID/customConstraints/custom.disableCustomAccessLevels resourceTypes: - accesscontextmanager.googleapis.com/AccessLevel methodTypes: - CREATE - UPDATE condition: "resource.basic.conditions.exists(c, has(c.devicePolicy))" actionType: DENY displayName: Deny basic access levels using `devicePolicy` description: Basic access levels must not use the `devicePolicy` attribute.
Ganti
ORGANIZATION_ID
dengan ID organisasi Anda.Hal ini menentukan batasan yang hanya mengizinkan pembuatan tingkat akses dasar dan menolak pembuatan tingkat akses kustom.
Terapkan batasan:
gcloud org-policies set-custom-constraint ~/constraint-disable_custom_access_level.yaml
Pastikan batasan ada:
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
Outputnya mirip dengan yang berikut ini:
CUSTOM_CONSTRAINT ACTION_TYPE METHOD_TYPES RESOURCE_TYPES DISPLAY_NAME custom.disableCustomAccessLevels DENY CREATE accesscontextmanager.googleapis.com/AccessLevel Deny basic access levels using `devicePolicy` ...
Simpan file berikut sebagai
policy-disable_custom_access_level.yaml
:name: organizations/ORGANIZATION_ID/policies/custom.disableCustomAccessLevels spec: rules: - enforce: true
Ganti
ORGANIZATION_ID
dengan ID organisasi Anda.Terapkan kebijakan:
gcloud org-policies set-policy ~/policy-disable_custom_access_level.yaml
Pastikan kebijakan ada:
gcloud org-policies list --organization=ORGANIZATION_ID
Outputnya mirip dengan hal berikut ini:
CONSTRAINT LIST_POLICY BOOLEAN_POLICY ETAG custom.disableCustomAccessLevels - SET COCsm5QGENiXi2E=
Simpan file spesifikasi tingkat akses berikut sebagai
example_access_level.yaml
:- devicePolicy: requireScreenlock: true
Buat tingkat akses:
gcloud access-context-manager levels create ACCESS_LEVEL_NAME --policy=ACCESS_POLICY_ID --title=ACCESS_LEVEL_TITLE --basic-level-spec=example_access_level.yaml
Ganti kode berikut:
ACCESS_LEVEL_NAME
: Nama unik untuk tingkat akses.ACCESS_POLICY_ID
: ID kebijakan akses organisasi Anda.ACCESS_LEVEL_TITLE
: Judul singkat untuk tingkat akses.
Untuk mengetahui informasi selengkapnya tentang cara membuat tingkat akses dasar, lihat Membuat tingkat akses dasar.
Outputnya mirip dengan hal berikut ini:
ERROR: (gcloud.access-context-manager.levels.create) [USER] does not have permission to access accessPolicies instance [ACCESS_POLICY_ID] (or it may not exist): The caller does not have permission. This command is authenticated as USER which is the active account specified by the [core/account] property '@type': type.googleapis.com/google.rpc.DebugInfo detail: '[ORIGINAL ERROR] generic::permission_denied: com.google.apps.framework.request.ForbiddenException: The user is not authorized!'
Contoh kebijakan organisasi kustom untuk kasus penggunaan umum
Tabel berikut memberikan sintaksis beberapa batasan khusus untuk kasus penggunaan umum:
Deskripsi Sintaksis batasan Menonaktifkan kebijakan terbatas name: organizations/ORGANIZATION_ID/customConstraints/custom.disableScopedPolicies resourceTypes: - accesscontextmanager.googleapis.com/AccessPolicy methodTypes: - CREATE - UPDATE condition: "size(resource.scopes) == 0" actionType: DENY displayName: Disable scoped policies description: Disables the creation of scoped policies.
Menonaktifkan tingkat akses kustom name: organizations/ORGANIZATION_ID/customConstraints/custom.denyBasicAccessLevels resourceTypes: - accesscontextmanager.googleapis.com/AccessLevel methodTypes: - CREATE - UPDATE condition: "has(resource.custom)" actionType: ALLOW displayName: Disable custom access levels description: Disables the creation of custom access levels. Allows only basic access levels.
Menonaktifkan region_code
di tingkat akses kustomname: organizations/ORGANIZATION_ID/customConstraints/custom.denyRegionCode resourceTypes: - accesscontextmanager.googleapis.com/AccessLevel methodTypes: - CREATE - UPDATE condition: "resource.custom.expr.expression.contains('region_code')" actionType: DENY displayName: Disable
region_code
in custom access levels description: Disables the use ofregion_code
attribute in custom access levels.Menerapkan deskripsi panjang untuk tingkat akses name: organizations/ORGANIZATION_ID/customConstraints/custom.enforseVerboseDescriptioninAccessLevels resourceTypes: - accesscontextmanager.googleapis.com/AccessLevel methodTypes: - CREATE - UPDATE condition: "size(resource.description) < 50" actionType: DENY displayName: Enforce access level descriptions to have at least 50 characters description: Denies access levels with a short description. The access level description must be at least 50 characters long.
Menonaktifkan perantara perimeter name: organizations/ORGANIZATION_ID/customConstraints/custom.denyBridgePerimeters resourceTypes: - accesscontextmanager.googleapis.com/ServicePerimeter methodTypes: - CREATE - UPDATE condition: "resource.perimeterType == 'PERIMETER_TYPE_BRIDGE'" actionType: DENY displayName: Disable perimeter bridges description: Disables the use of perimeter bridges. Instead, use ingress and egress rules.
Resource yang didukung Access Context Manager
Tabel berikut mencantumkan resource Access Context Manager yang dapat Anda rujuk dalam batasan kustom.Resource Kolom accesscontextmanager.googleapis.com/AccessLevel resource.basic.combiningFunction
resource.basic.conditions.devicePolicy.allowedDeviceManagementLevels
resource.basic.conditions.devicePolicy.allowedEncryptionStatuses
resource.basic.conditions.devicePolicy.osConstraints.minimumVersion
resource.basic.conditions.devicePolicy.osConstraints.osType
resource.basic.conditions.devicePolicy.osConstraints.requireVerifiedChromeOs
resource.basic.conditions.devicePolicy.requireAdminApproval
resource.basic.conditions.devicePolicy.requireCorpOwned
resource.basic.conditions.devicePolicy.requireScreenlock
resource.basic.conditions.ipSubnetworks
resource.basic.conditions.members
resource.basic.conditions.negate
resource.basic.conditions.regions
resource.basic.conditions.requiredAccessLevels
resource.custom.expr
resource.description
resource.title
accesscontextmanager.googleapis.com/AccessPolicy resource.parent
resource.scopes
resource.title
accesscontextmanager.googleapis.com/AuthorizedOrgsDesc resource.assetType
resource.authorizationDirection
resource.authorizationType
resource.orgs
accesscontextmanager.googleapis.com/ServicePerimeter resource.description
resource.perimeterType
resource.spec.accessLevels
resource.spec.egressPolicies.egressFrom.identities
resource.spec.egressPolicies.egressFrom.identityType
resource.spec.egressPolicies.egressFrom.sourceRestriction
resource.spec.egressPolicies.egressTo.externalResources
resource.spec.egressPolicies.egressTo.operations.methodSelectors.method
resource.spec.egressPolicies.egressTo.operations.methodSelectors.permission
resource.spec.egressPolicies.egressTo.operations.serviceName
resource.spec.egressPolicies.egressTo.resources
resource.spec.ingressPolicies.ingressFrom.identities
resource.spec.ingressPolicies.ingressFrom.identityType
resource.spec.ingressPolicies.ingressFrom.sources.accessLevel
resource.spec.ingressPolicies.ingressFrom.sources.resource
resource.spec.ingressPolicies.ingressTo.operations.methodSelectors.method
resource.spec.ingressPolicies.ingressTo.operations.methodSelectors.permission
resource.spec.ingressPolicies.ingressTo.operations.serviceName
resource.spec.ingressPolicies.ingressTo.resources
resource.spec.resources
resource.spec.restrictedServices
resource.spec.vpcAccessibleServices.allowedServices
resource.spec.vpcAccessibleServices.enableRestriction
resource.status.accessLevels
resource.status.egressPolicies.egressFrom.identities
resource.status.egressPolicies.egressFrom.identityType
resource.status.egressPolicies.egressFrom.sourceRestriction
resource.status.egressPolicies.egressTo.externalResources
resource.status.egressPolicies.egressTo.operations.methodSelectors.method
resource.status.egressPolicies.egressTo.operations.methodSelectors.permission
resource.status.egressPolicies.egressTo.operations.serviceName
resource.status.egressPolicies.egressTo.resources
resource.status.ingressPolicies.ingressFrom.identities
resource.status.ingressPolicies.ingressFrom.identityType
resource.status.ingressPolicies.ingressFrom.sources.accessLevel
resource.status.ingressPolicies.ingressFrom.sources.resource
resource.status.ingressPolicies.ingressTo.operations.methodSelectors.method
resource.status.ingressPolicies.ingressTo.operations.methodSelectors.permission
resource.status.ingressPolicies.ingressTo.operations.serviceName
resource.status.ingressPolicies.ingressTo.resources
resource.status.resources
resource.status.restrictedServices
resource.status.vpcAccessibleServices.allowedServices
resource.status.vpcAccessibleServices.enableRestriction
resource.title
resource.useExplicitDryRunSpec
Langkah berikutnya
- Pelajari lebih lanjut Layanan Kebijakan Organisasi.
- Pelajari lebih lanjut cara membuat dan mengelola kebijakan organisasi.
- Lihat daftar lengkap batasan kebijakan organisasi terkelola.
Peran yang diperlukan
Untuk mendapatkan izin yang diperlukan untuk mengelola kebijakan organisasi kustom, minta administrator untuk memberi Anda peran IAM Administrator Kebijakan Organisasi (roles/orgpolicy.policyAdmin
) di resource organisasi.
Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.
Membuat batasan khusus
Batasan kustom ditentukan dalam file YAML oleh resource, metode, kondisi, dan tindakan yang didukung oleh layanan tempat Anda menerapkan kebijakan organisasi. Kondisi untuk batasan kustom Anda ditentukan menggunakan Common Expression Language (CEL). Untuk mengetahui informasi selengkapnya tentang cara membangun kondisi dalam batasan khusus menggunakan CEL, lihat bagian CEL tentang Membuat dan mengelola batasan kustom.
Untuk membuat batasan khusus, buat file YAML menggunakan format berikut:
name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- RESOURCE_NAME
methodTypes:
- CREATE
- UPDATE
condition: "CONDITION"
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION
Ganti kode berikut:
Untuk mengetahui informasi selengkapnya tentang cara membuat batasan kustom, lihat Menentukan batasan kustom.
Menyiapkan batasan kustom
Setelah membuat file YAML untuk batasan khusus baru, Anda harus menyiapkannya agar tersedia untuk kebijakan organisasi di organisasi Anda. Untuk menyiapkan batasan kustom, gunakan perintahgcloud org-policies set-custom-constraint
:
gcloud org-policies set-custom-constraint CONSTRAINT_PATH
CONSTRAINT_PATH
dengan jalur lengkap ke file batasan kustom Anda. Contohnya, /home/user/customconstraint.yaml
Setelah selesai, batasan khusus Anda tersedia sebagai kebijakan organisasi dalam daftar kebijakan organisasi. Google Cloud
Untuk memverifikasi bahwa ada batasan kustom, gunakan perintah
gcloud org-policies list-custom-constraints
:
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
ORGANIZATION_ID
dengan ID resource organisasi Anda.
Untuk mengetahui informasi selengkapnya, lihat
Melihat kebijakan organisasi.
Menerapkan kebijakan organisasi kustom
Anda dapat menerapkan batasan dengan membuat kebijakan organisasi yang mereferensikannya, lalu menerapkan kebijakan organisasi tersebut ke resource Google Cloud .Konsol
gcloud
Untuk membuat kebijakan organisasi dengan aturan boolean, buat file YAML kebijakan yang merujuk batasan:
name: projects/PROJECT_ID/policies/CONSTRAINT_NAME spec: rules: - enforce: true
Ganti kode berikut:
Untuk menerapkan kebijakan organisasi yang berisi batasan, jalankan perintah berikut:
gcloud org-policies set-policy POLICY_PATH
Ganti POLICY_PATH
dengan jalur lengkap ke file YAML kebijakan organisasi Anda. Kebijakan ini memerlukan waktu hingga 15 menit untuk diterapkan.
Menguji kebijakan organisasi kustom
Contoh berikut membuat batasan dan kebijakan kustom yang menolak semua
tingkat akses dasar dalam organisasi tertentu yang menggunakan atribut devicePolicy
.
Sebelum memulai, Anda harus mengetahui hal-hal berikut:
Membuat batasan khusus
Membuat kebijakan
Setelah Anda menerapkan kebijakan, tunggu sekitar dua menit hingga Google Cloud mulai menerapkan kebijakan tersebut.