Mengelola resource Dataplex menggunakan batasan kustom

Halaman ini menunjukkan cara menggunakan batasan kustom Layanan Kebijakan Organisasi untuk membatasi operasi tertentu pada resource Google Cloud berikut:

  • dataplex.googleapis.com/AspectType
  • dataplex.googleapis.com/EntryType
  • dataplex.googleapis.com/EntryGroup
  • dataplex.googleapis.com/DataScan
  • dataplex.googleapis.com/MetadataJob

Untuk mempelajari Kebijakan Organisasi lebih lanjut, 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 resourceGoogle Cloud dan turunan dari resource tersebut dalam hierarki resourceGoogle Cloud . Anda dapat menerapkan kebijakan organisasi di tingkat organisasi, folder, atau project.

Kebijakan Organisasi memberikan batasan yang telah ditetapkan untuk berbagai layanan Google Cloud . Namun, jika ingin 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 dalam folder tersebut. Untuk mempelajari lebih lanjut perilaku ini dan cara mengubahnya, lihat Aturan evaluasi hierarki.

Batasan

Batasan kustom dan kebijakan organisasi tidak didukung di resource berikut:

  • dataplex.googleapis.com/Lake
  • dataplex.googleapis.com/Zone
  • dataplex.googleapis.com/Task
  • dataplex.googleapis.com/Asset
  • dataplex.googleapis.com/Environment

Sebelum memulai

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Install the Google Cloud CLI.
  5. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Make sure that billing is enabled for your Google Cloud project.

  9. Install the Google Cloud CLI.
  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. Pastikan Anda mengetahui ID organisasi Anda.

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:

  • ORGANIZATION_ID: ID organisasi Anda, seperti 123456789.

  • CONSTRAINT_NAME: nama yang Anda inginkan untuk batasan kustom baru. Batasan kustom harus diawali dengan custom., dan hanya dapat menyertakan huruf besar, huruf kecil, atau angka. Contohnya, custom.denyDataplexEntryGroup. Panjang maksimum kolom ini adalah 70 karakter.

  • RESOURCE_NAME: nama lengkap resourceGoogle Cloud yang berisi objek dan kolom yang ingin Anda batasi. Misalnya, dataplex.googleapis.com/dataplex.googleapis.com/EntryGroup.

  • 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.description.contains('invalid_name')"

  • ACTION: tindakan yang akan diambil jika condition terpenuhi. Kemungkinan nilainya adalah ALLOW dan DENY.

  • 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.

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 perintah gcloud org-policies set-custom-constraint:
gcloud org-policies set-custom-constraint CONSTRAINT_PATH
Ganti CONSTRAINT_PATH dengan jalur lengkap ke file batasan kustom Anda. Contohnya, /home/user/customconstraint.yaml Setelah selesai, batasan kustom Anda akan tersedia sebagai kebijakan organisasi dalam daftar Google Cloud kebijakan organisasi Anda. Untuk memverifikasi bahwa ada batasan kustom, gunakan perintah gcloud org-policies list-custom-constraints:
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
Ganti ORGANIZATION_ID dengan ID fasilitas organisasi Anda. Untuk mengetahui informasi selengkapnya, lihat Melihat kebijakan organisasi.

Menerapkan kebijakan organisasi kustom

Anda dapat menerapkan batasan boolean dengan membuat kebijakan organisasi yang mereferensikannya, lalu menerapkan kebijakan organisasi tersebut ke resource Google Cloud .

Konsol

  1. Di Google Cloud konsol, buka halaman Organization policies.

    Buka Organization policies

  2. Dari pemilih project, pilih project yang ingin Anda tetapkan kebijakan organisasinya.
  3. Dari daftar di halaman Organization policies, pilih batasan untuk melihat halaman Policy details untuk batasan tersebut.
  4. Untuk mengonfigurasi kebijakan organisasi untuk resource ini, klik Manage policy.
  5. Di halaman Edit policy, pilih Override parent's policy.
  6. Klik Add a rule.
  7. Di bagian Enforcement, pilih apakah penerapan kebijakan organisasi ini diaktifkan atau dinonaktifkan.
  8. Opsional: Untuk membuat kebijakan organisasi bersyarat pada tag, klik Add condition. 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.
  9. Jika ini adalah batasan kustom, Anda dapat mengklik Uji perubahan untuk menyimulasikan efek kebijakan organisasi ini. Untuk mengetahui informasi selengkapnya, lihat Menguji perubahan kebijakan organisasi dengan Policy Simulator.
  10. Untuk menyelesaikan dan menerapkan kebijakan organisasi, klik Set policy. Kebijakan ini memerlukan waktu hingga 15 menit untuk diterapkan.

gcloud

Untuk membuat kebijakan organisasi yang menerapkan batasan boolean, buat file YAML kebijakan yang merujuk batasan tersebut:

      name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
      spec:
        rules:
        - enforce: true
    

Ganti kode berikut:

  • PROJECT_ID: project tempat Anda ingin menerapkan batasan.
  • CONSTRAINT_NAME: nama yang Anda tentukan untuk batasan kustom. Contoh, custom.denyDataplexEntryGroup

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 khusus dan kebijakan yang membatasi pengguna membuat grup entri dalam project tertentu dengan deskripsi grup entri yang berisi teks invalid_name.

Sebelum memulai, Anda harus mengetahui hal-hal berikut:

  • ID organisasi Anda
  • Project ID

Membuat batasan

  1. Simpan file berikut sebagai constraint-valid-entry-groups.yaml:

    name: organizations/ORGANIZATION_ID/customConstraints/custom.denyDataplexEntryGroup
    resourceTypes:
    - dataplex.googleapis.com/EntryGroup
    methodTypes:
    - CREATE
    condition: "resource.description.contains('invalid_name')"
    actionType: DENY
    displayName: Validate entry group description
    description: All new entry groups have valid descriptions.
    

    Hal ini menentukan batasan untuk setiap grup entri baru, jika deskripsi berisi teks invalid_name, operasi akan ditolak.

  2. Terapkan batasan:

    gcloud org-policies set-custom-constraint ~/constraint-valid-entry-groups.yaml
    
  3. 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.denyDataplexEntryGroup               DENY         CREATE         dataplex.googleapis.com/EntryGroup   Validate Entry Group description
    ...
    

Membuat kebijakan

  1. Simpan file berikut sebagai policy-deny-entry-group.yaml:

    name: projects/PROJECT_ID/policies/custom.denyDataplexEntryGroup
    spec:
      rules:
      - enforce: true
    

    Ganti PROJECT_ID dengan project ID Anda.

  2. Terapkan kebijakan:

    gcloud org-policies set-policy ~/policy-deny-entry-group.yaml
    
  3. Pastikan kebijakan ada:

    gcloud org-policies list --project=PROJECT_ID
    

    Outputnya mirip dengan hal berikut ini:

    CONSTRAINT                      LIST_POLICY    BOOLEAN_POLICY    ETAG
    custom.denyDataplexEntryGroup   -              SET               COCsm5QGENiXi2E=
    

Setelah Anda menerapkan kebijakan, tunggu sekitar 15 menit hingga Google Cloud mulai menerapkan kebijakan tersebut.

Menguji kebijakan

Coba buat grup entri dalam project:

gcloud dataplex entry-groups create org-policy-test \
    --project=PROJECT_ID \
    --location=LOCATION \
    --display-name=DISPLAY_NAME \
    --description='invalid_name'

Operasi ditolak. Outputnya adalah sebagai berikut:

Operation denied by custom org policy on resource 'projects/PROJECT_ID/locations/LOCATION/entryGroups/org-policy-test': ["customConstraints/custom.denyDataplexEntryGroup"]

Contoh kebijakan organisasi kustom untuk kasus penggunaan umum

Tabel berikut memberikan sintaksis beberapa batasan kustom untuk kasus penggunaan umum:

Deskripsi Sintaksis batasan
Mewajibkan jenis aspek tertentu untuk jenis entri
    name: organizations/ORGANIZATION_ID/customConstraints/custom.requireAspectTypeForEntryType
    resourceTypes:
    - dataplex.googleapis.com/EntryType
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.requiredAspects.exists(value, value.type =="projects/PROJECT_ID/locations/LOCATION/aspectTypes/exampleAspectType")
    actionType: DENY
    displayName: All entry types require aspect type exampleAspectType
    description: All entry types require the aspect type exampleAspectType
    
Memerlukan frekuensi sampling minimum untuk pemindaian pembuatan profil data
    name: organizations/ORGANIZATION_ID/customConstraints/custom.minimumSamplingDataScans
    resourceTypes:
    - dataplex.googleapis.com/DataScan
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.dataProfileSpec.samplingPercent >= 20.0"
    actionType: ALLOW
    displayName: Require minimum sampling for data profiling scans
    description: All data profiling scans need at least 20% sampling rate
    

Resource yang didukung Dataplex

Tabel berikut mencantumkan resource Dataplex yang dapat Anda referensikan dalam batasan kustom.

Resource Kolom
dataplex.googleapis.com/AspectType resource.authorization.alternateUsePermission
resource.description
resource.displayName
resource.metadataTemplate.annotations.deprecated
resource.metadataTemplate.annotations.description
resource.metadataTemplate.annotations.displayName
resource.metadataTemplate.annotations.displayOrder
resource.metadataTemplate.annotations.stringType
resource.metadataTemplate.annotations.stringValues
resource.metadataTemplate.constraints.required
resource.metadataTemplate.enumValues.deprecated
resource.metadataTemplate.enumValues.index
resource.metadataTemplate.enumValues.name
resource.metadataTemplate.index
resource.metadataTemplate.name
resource.metadataTemplate.type
resource.metadataTemplate.typeId
resource.metadataTemplate.typeRef
dataplex.googleapis.com/DataScan resource.data.entity
resource.data.resource
resource.dataDiscoverySpec.bigqueryPublishingConfig.connection
resource.dataDiscoverySpec.bigqueryPublishingConfig.location
resource.dataDiscoverySpec.bigqueryPublishingConfig.tableType
resource.dataDiscoverySpec.storageConfig.csvOptions.delimiter
resource.dataDiscoverySpec.storageConfig.csvOptions.encoding
resource.dataDiscoverySpec.storageConfig.csvOptions.headerRows
resource.dataDiscoverySpec.storageConfig.csvOptions.quote
resource.dataDiscoverySpec.storageConfig.csvOptions.typeInferenceDisabled
resource.dataDiscoverySpec.storageConfig.excludePatterns
resource.dataDiscoverySpec.storageConfig.includePatterns
resource.dataDiscoverySpec.storageConfig.jsonOptions.encoding
resource.dataDiscoverySpec.storageConfig.jsonOptions.typeInferenceDisabled
resource.dataProfileSpec.excludeFields.fieldNames
resource.dataProfileSpec.includeFields.fieldNames
resource.dataProfileSpec.postScanActions.bigqueryExport.resultsTable
resource.dataProfileSpec.rowFilter
resource.dataProfileSpec.samplingPercent
resource.dataQualitySpec.postScanActions.bigqueryExport.resultsTable
resource.dataQualitySpec.postScanActions.notificationReport.recipients.emails
resource.dataQualitySpec.postScanActions.notificationReport.scoreThresholdTrigger.scoreThreshold
resource.dataQualitySpec.rowFilter
resource.dataQualitySpec.rules.column
resource.dataQualitySpec.rules.description
resource.dataQualitySpec.rules.dimension
resource.dataQualitySpec.rules.ignoreNull
resource.dataQualitySpec.rules.name
resource.dataQualitySpec.rules.rangeExpectation.maxValue
resource.dataQualitySpec.rules.rangeExpectation.minValue
resource.dataQualitySpec.rules.rangeExpectation.strictMaxEnabled
resource.dataQualitySpec.rules.rangeExpectation.strictMinEnabled
resource.dataQualitySpec.rules.regexExpectation.regex
resource.dataQualitySpec.rules.rowConditionExpectation.sqlExpression
resource.dataQualitySpec.rules.setExpectation.values
resource.dataQualitySpec.rules.sqlAssertion.sqlStatement
resource.dataQualitySpec.rules.statisticRangeExpectation.maxValue
resource.dataQualitySpec.rules.statisticRangeExpectation.minValue
resource.dataQualitySpec.rules.statisticRangeExpectation.statistic
resource.dataQualitySpec.rules.statisticRangeExpectation.strictMaxEnabled
resource.dataQualitySpec.rules.statisticRangeExpectation.strictMinEnabled
resource.dataQualitySpec.rules.suspended
resource.dataQualitySpec.rules.tableConditionExpectation.sqlExpression
resource.dataQualitySpec.rules.threshold
resource.dataQualitySpec.samplingPercent
resource.description
resource.displayName
resource.executionSpec.field
resource.executionSpec.trigger.schedule.cron
dataplex.googleapis.com/EntryGroup resource.description
resource.displayName
dataplex.googleapis.com/EntryType resource.authorization.alternateUsePermission
resource.description
resource.displayName
resource.platform
resource.requiredAspects.type
resource.system
resource.typeAliases
dataplex.googleapis.com/MetadataJob resource.exportSpec.outputPath
resource.exportSpec.scope.aspectTypes
resource.exportSpec.scope.entryGroups
resource.exportSpec.scope.entryTypes
resource.exportSpec.scope.organizationLevel
resource.exportSpec.scope.projects
resource.importSpec.aspectSyncMode
resource.importSpec.entrySyncMode
resource.importSpec.logLevel
resource.importSpec.scope.aspectTypes
resource.importSpec.scope.entryGroups
resource.importSpec.scope.entryTypes
resource.importSpec.sourceCreateTime
resource.importSpec.sourceStorageUri
resource.type

Langkah berikutnya