Halaman ini menjelaskan cara membuat, menyiapkan, dan mengelola batasan kustom di instance Cloud SQL. Untuk ringkasan kebijakan organisasi kustom, lihat kebijakan organisasi kustom.
Resource yang didukung Cloud SQL
Halaman ini menunjukkan cara menggunakan batasan kustom Layanan Kebijakan Organisasi untuk membatasi operasi tertentu pada resource berikut: Google Cloud
sqladmin.googleapis.com/Instance
sqladmin.googleapis.com/BackupRun
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 gcloud 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 gcloud 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.region
. Panjang maksimum kolom ini adalah 70 karakter.RESOURCE_NAME
: nama lengkap Google Cloud resource yang berisi objek dan kolom yang ingin Anda batasi. Misalnya,sqladmin.googleapis.com/Instance
.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.region == "us-central1""
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.region
- 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.
Contoh kebijakan organisasi kustom untuk kasus penggunaan umum
Tabel berikut memberikan sintaksis beberapa batasan khusus untuk kasus penggunaan umum:
Deskripsi | Sintaksis batasan |
---|---|
Pastikan instance adalah Enterprise Plus |
name: organizations/ORGANIZATION_ID/customConstraints/custom.edition resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.edition == 'ENTERPRISE_PLUS'" actionType: ALLOW displayName: Instances must be Enterprise Plus. description: Cloud SQL instances must be Enterprise Plus. |
Memastikan instance selalu tersedia |
name: organizations/ORGANIZATION_ID/customConstraints/custom.availability resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.availabilityType == 'REGIONAL'" actionType: ALLOW displayName: Instances must be regional. description: Cloud SQL instances must be highly available. To do this, make them regional. |
Pastikan instance memiliki kebijakan sandi. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.enforcePassword resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.passwordValidationPolicy.enablePasswordPolicy == true" actionType: ALLOW displayName: The password policy must be enabled for Cloud SQL instances. description: Cloud SQL instances must have a password policy. |
Pastikan kebijakan sandi untuk instance memiliki panjang minimum |
name: organizations/ORGANIZATION_ID/customConstraints/custom.passwordMinLength resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.passwordValidationPolicy.minLength >= 6" actionType: ALLOW displayName: The password policy must have a minimum length of six characters. description: Cloud SQL instances must have a password policy that has a minimum length of six characters. |
Pastikan instance mengaktifkan kompleksitas kebijakan sandi. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.passwordComplexity resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.passwordValidationPolicy.complexity == 'COMPLEXITY_DEFAULT'" actionType: ALLOW displayName: The password policy complexity must be enabled. description: Cloud SQL instances must have a password policy with complex passwords. |
Mewajibkan Mode SSL diaktifkan dengan hanya koneksi terenkripsi. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.sslMode resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.ipConfiguration.sslMode == 'ENCRYPTED_ONLY'" actionType: ALLOW displayName: Only allow connections that are encrypted with SSL/TLS. description: Cloud SQL instances must only allow connections that are encrypted with SSL/TLS. |
Memblokir akses database dari mana saja di internet publik. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.authorizedNetworks resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.ipConfiguration.authorizedNetworks.exists(network, network.value == '0.0.0.0/0')" actionType: DENY displayName: The list of authorized networks can't contain 0.0.0.0/0 description: Authorized networks for Cloud SQL instances can't contain 0.0.0.0/0. This allows users to access the database from any IP address. |
Pastikan instance tidak dibuat dengan alamat IP eksternal. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.ipv4Enabled resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.ipConfiguration.ipv4Enabled == false" actionType: ALLOW displayName: ipv4Enabled must be set to false. description: Cloud SQL instances can't have an external IP address. |
Pastikan instance dienkripsi dengan kunci KMS. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.encrypted resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.diskEncryptionConfiguration.kmsKeyName.size() > 0" actionType: ALLOW displayName: Instances must be encrypted with a KMS key. description: Cloud SQL instances must be disk-encrypted with a KMS key. |
Pastikan Instance berada di us-central1 |
name: organizations/ORGANIZATION_ID/customConstraints/custom.region resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.region == 'us-central1'" actionType: ALLOW displayName: Instances must be in the us-central1 region. description: Cloud SQL instances must be in the us-central1 region. |
Pastikan instance telah mengaktifkan cache data. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.dataCache resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.dataCacheConfig.dataCacheEnabled == true" actionType: ALLOW displayName: Instances must have data cache enabled. description: Cloud SQL instances must have data cache enabled. |
Terapkan pencadangan otomatis. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.enableBackups resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.backupConfiguration.enabled == true" actionType: ALLOW displayName: Automated backups must be enabled. description: Cloud SQL instances must have automated backups enabled. |
Membatasi lokasi cadangan otomatis. |
name: organizations/ORGANIZATION_ID/customConstraints/custom.automatedBackupLocation resourceTypes: - sqladmin.googleapis.com/Instance methodTypes: - CREATE - UPDATE condition: "resource.settings.backupConfiguration.location == 'us-central1'" actionType: ALLOW displayName: The location of automated backups must be in the us-central1 region. description: The location of automated backups for Cloud SQL instances must be in the us-central1 region. |
Membatasi lokasi cadangan on-demand ke us-central1 |
name: organizations/ORGANIZATION_ID/customConstraints/custom.onDemandBackupLocation resourceTypes: - sqladmin.googleapis.com/BackupRun methodTypes: - CREATE - UPDATE condition: "condition: resource.location == 'us-central1'" actionType: ALLOW displayName: The location of on-demand backups must be in the us-central1 region. description: On-demand backups are restricted to the us-central1. |
Resource yang didukung Cloud SQL untuk PostgreSQL
Tabel berikut mencantumkan resource Cloud SQL untuk PostgreSQL yang dapat Anda rujuk dalam batasan kustom.Resource | Kolom |
---|---|
sqladmin.googleapis.com/BackupRun |
resource.description
|
resource.location
| |
sqladmin.googleapis.com/Instance |
resource.databaseVersion
|
resource.diskEncryptionConfiguration.kmsKeyName
| |
resource.diskEncryptionStatus.kmsKeyVersionName
| |
resource.failoverReplica.name
| |
resource.masterInstanceName
| |
resource.name
| |
resource.nodeCount
| |
resource.project
| |
resource.region
| |
resource.replicaConfiguration.cascadableReplica
| |
resource.replicaConfiguration.failoverTarget
| |
resource.settings.activationPolicy
| |
resource.settings.activeDirectoryConfig.domain
| |
resource.settings.advancedMachineFeatures.threadsPerCore
| |
resource.settings.availabilityType
| |
resource.settings.backupConfiguration.backupRetentionSettings.retainedBackups
| |
resource.settings.backupConfiguration.backupRetentionSettings.retentionUnit
| |
resource.settings.backupConfiguration.binaryLogEnabled
| |
resource.settings.backupConfiguration.enabled
| |
resource.settings.backupConfiguration.location
| |
resource.settings.backupConfiguration.pointInTimeRecoveryEnabled
| |
resource.settings.backupConfiguration.startTime
| |
resource.settings.backupConfiguration.transactionLogRetentionDays
| |
resource.settings.collation
| |
resource.settings.connectionPoolConfig.connectionPoolingEnabled
| |
resource.settings.connectionPoolConfig.flags.name
| |
resource.settings.connectionPoolConfig.flags.value
| |
resource.settings.connectorEnforcement
| |
resource.settings.databaseFlags.name
| |
resource.settings.databaseFlags.value
| |
resource.settings.dataCacheConfig.dataCacheEnabled
| |
resource.settings.dataDiskProvisionedIops
| |
resource.settings.dataDiskProvisionedThroughput
| |
resource.settings.dataDiskSizeGb
| |
resource.settings.dataDiskType
| |
resource.settings.deletionProtectionEnabled
| |
resource.settings.denyMaintenancePeriods.endDate
| |
resource.settings.denyMaintenancePeriods.startDate
| |
resource.settings.denyMaintenancePeriods.time
| |
resource.settings.edition
| |
resource.settings.enableDataplexIntegration
| |
resource.settings.enableGoogleMlIntegration
| |
resource.settings.insightsConfig.queryInsightsEnabled
| |
resource.settings.insightsConfig.queryPlansPerMinute
| |
resource.settings.insightsConfig.queryStringLength
| |
resource.settings.insightsConfig.recordApplicationTags
| |
resource.settings.insightsConfig.recordClientAddress
| |
resource.settings.ipConfiguration.authorizedNetworks.name
| |
resource.settings.ipConfiguration.authorizedNetworks.value
| |
resource.settings.ipConfiguration.customSubjectAlternativeNames
| |
resource.settings.ipConfiguration.enablePrivatePathForGoogleCloudServices
| |
resource.settings.ipConfiguration.ipv4Enabled
| |
resource.settings.ipConfiguration.privateNetwork
| |
resource.settings.ipConfiguration.pscConfig.allowedConsumerProjects
| |
resource.settings.ipConfiguration.pscConfig.pscAutoConnections.consumerNetwork
| |
resource.settings.ipConfiguration.pscConfig.pscAutoConnections.consumerProject
| |
resource.settings.ipConfiguration.pscConfig.pscEnabled
| |
resource.settings.ipConfiguration.serverCaMode
| |
resource.settings.ipConfiguration.serverCaPool
| |
resource.settings.ipConfiguration.sslMode
| |
resource.settings.locationPreference.secondaryZone
| |
resource.settings.locationPreference.zone
| |
resource.settings.maintenanceWindow.day
| |
resource.settings.maintenanceWindow.hour
| |
resource.settings.maintenanceWindow.updateTrack
| |
resource.settings.passwordValidationPolicy.complexity
| |
resource.settings.passwordValidationPolicy.disallowUsernameSubstring
| |
resource.settings.passwordValidationPolicy.enablePasswordPolicy
| |
resource.settings.passwordValidationPolicy.minLength
| |
resource.settings.passwordValidationPolicy.passwordChangeInterval
| |
resource.settings.passwordValidationPolicy.reuseInterval
| |
resource.settings.replicationLagMaxSeconds
| |
resource.settings.retainBackupsOnDelete
| |
resource.settings.sqlServerAuditConfig.bucket
| |
resource.settings.sqlServerAuditConfig.retentionInterval
| |
resource.settings.sqlServerAuditConfig.uploadInterval
| |
resource.settings.storageAutoResize
| |
resource.settings.tier
| |
resource.settings.timeZone
|