Open-Sourcing GCP Custom Constraints: Advanced Security Beyond Built-In Organization Policies
Standard GCP organization policies cover many common needs, but leave gaps. Custom constraints let you codify organization-specific preventative controls against the fields and resources defaults miss.
GCP custom organization policy constraints extend standard org policies to enforce organization-specific preventative controls on resources and fields not covered by defaults. We have open-sourced a GCP Custom Constraints Directory containing all supported resource types and fields, alongside ready-to-use custom constraints for BigQuery and our comprehensive Threat Model for BigQuery.
This post walks through five real implementation examples across Cloud SQL, Cloud Storage, GKE, BigQuery Data Transfer, and Compute Engine, so you can move from detective to preventative posture in GCP.
Introduction
Google Cloud Platform (GCP) custom organization policy constraints are a powerful extension of standard organization policies. While built-in organization policy constraints can cover many common security needs (e.g., disabling external IPs on VMs, restricting service accounts, enforcing resources be protected by a CMEK key), custom constraints go further by allowing you to define organization-specific preventative rules targeting specific resources and fields not supported by built-in organization policy constraints.
To help you get started with custom constraints, we have open-sourced our custom constraints for BigQuery, along with our Threat Model for BigQuery. Providing you with preventative control capabilities in one of the most widely used GCP services.
Additionally, in this blog, we will walk through several examples of implementing custom constraints with real examples for other widely used GCP services.
Benefits of Custom Constraints
- Granularity: Custom constraints can target specific resource fields (like enforcing authorized data sources on a BigQuery transfer config).
- Prevention-first: They block risky operations before they're deployed, reducing misconfiguration risks.
- Flexibility: You can encode organization-specific security requirements, rather than relying solely on Google's defaults.
- Safe testing with dry-run mode: Evaluate how a custom constraint would behave before enforcing it. Dry-run (audit-only) mode logs potential violations without blocking deployments, helping teams validate constraint logic and measure impact safely.
Challenges of Custom Constraints
- Maintenance overhead: Custom constraints must be kept up to date as services evolve. Without monitoring new GCP releases, constraints may miss new resource fields or features.
- Balance: Too-strict constraints can slow development or prevent authorized workloads, while too-lenient constraints leave gaps. Getting the scope right requires thoughtful design.
- Coverage gaps: Not all services or methods (CREATE/UPDATE) are currently supported, which means some risks can't be mitigated in this manner.
Why Custom Constraints Matter
Misconfigurations continue to be a leading cause of breaches. Standard org policies cover many scenarios but leave gaps. For example:
- No built-in way to require Cloud SQL backups.
- No built-in way to mandate GKE node auto-upgrades.
- No built-in way to enforce Compute Engine deletion protection.
Custom constraints enable you to codify these requirements directly in the organization's policy framework. This shifts your security posture from detective to preventative. As GCP expands its custom constraint-supported services, your governance options also grow.
Structure of Custom Constraints
A custom constraint is defined in a YAML file and consists of:
- Resource Types which GCP resources it applies to (e.g.,
compute.googleapis.com/Instance). - Conditions a CEL (Common Expression Language) expression inspecting resource fields.
- Method Types
CREATEand/orUPDATE. - Action
ALLOW(only allow if condition true) orDENY(deny if condition true).
Implementing Custom Constraints with Real Examples
Now that we understand the purpose, benefit, and structure of custom constraints, let's review five service-specific examples that illustrate how custom constraints can extend your defenses beyond predefined controls.
1. Cloud SQL: Automated Backups
Require Cloud SQL instances to contain a backup configuration enabled for data recovery.
This preventative control is related to CIS benchmark 6.7, ensuring automated backups are enabled for SQL instances. You can review our GCP mapping to CIS to see how each of our GCP controls aligns with their corresponding CIS benchmark.
name: organizations/ORG_ID/customConstraints/custom.cloudsqlRequireBackups
resourceTypes:
- sqladmin.googleapis.com/Instance
methodTypes:
- CREATE
- UPDATE
condition: "resource.settings.backupConfiguration.enabled != true"
actionType: DENY
displayName: "Require Cloud SQL Automated backups"
description: "Blocks the creation or modification of instances without backups enabled"
2. Cloud Storage: Object Versioning
Require object versioning on Cloud Storage buckets for disaster recovery.
name: organizations/ORG_ID/customConstraints/custom.storageRequireVersioning
resourceTypes:
- storage.googleapis.com/Bucket
methodTypes:
- CREATE
- UPDATE
condition: "resource.versioning.enabled != true"
actionType: DENY
displayName: "Require Cloud Storage Object Versioning"
description: "Block the creation or modification of buckets unless object versioning is enabled"
3. GKE: Node Auto-Upgrade
Require GKE node pools to have auto-upgrade enabled to fix security issues.
name: organizations/ORG_ID/customConstraints/custom.gkeRequireNodeAutoUpgrade
resourceTypes:
- container.googleapis.com/NodePool
methodTypes:
- CREATE
condition: "resource.management.autoUpgrade == true"
actionType: ALLOW
displayName: "Require GKE node auto-upgrade"
description: "Allow creation of Node Pools when auto-upgrade is enabled"
4. BigQuery: Data Transfer Data Sources
Deny BigQuery Data Transfers from unauthorized data sources.
name: organizations/ORG_ID/customConstraints/custom.bqDtsDenyDataSourceTransfers
resourceTypes:
- bigquerydatatransfer.googleapis.com/TransferConfig
methodTypes:
- CREATE
- UPDATE
condition: "!(resource.dataSourceId in ['authorizedSource1', 'authorizedSource2'])"
actionType: DENY
displayName: "Deny data transfers using unauthorized data sources"
description: "Deny creating or updating data transfers using unauthorized data sources"
5. Compute Engine: Instance Deletion Protection
Deny Compute VM instances without deletion protection enabled.
name: organizations/ORG_ID/customConstraints/custom.computeInstanceDeletionProtection
resourceTypes:
- compute.googleapis.com/Instance
methodTypes:
- CREATE
- UPDATE
condition: "resource.deletionProtection != true"
actionType: DENY
displayName: "Deny Compute VMs instances without deletion protection"
description: "Deny the creation or modification of Compute VM instances without deletion protection enabled"
Open Source Contributions for Custom Constraints
At TrustOnCloud, we believe security guardrails should be transparent and easy to adopt. That's why we have decided to open-source the GCP Custom Constraints Directory containing all custom constraint resource types and fields available in GCP and our ready-to-use custom constraints for BigQuery, alongside a comprehensive Threat Model of BigQuery. Additionally, I plan to create and open-source a user interface that enables security engineers to design their own curated, custom constraints more readily, based on the current supported resources and fields for GCP. If this is something you're interested in, please let me know at bryce@trustoncloud.com.
By sharing these resources as open source, we aim to accelerate adoption of best practices across the community and help organizations enforce preventative security at scale.
Conclusion
Custom org constraints allow you to codify your organization's preventative control capabilities in GCP. While standard organization policies exist and should remain a core aspect of your organization's security, you should also address service gaps or apply opinionated best practices with custom constraints, enforcing resource configurations such as CloudSQL automated backups, Cloud Storage object versioning, GKE node pools auto-upgrades, and Cloud SQL instance backups.
The challenge is that GCP is constantly adding new features and expanding custom constraint support across services. Without dedicated monitoring, it's easy to miss critical updates that could close security gaps.
This is where TrustOnCloud comes in. We continuously track updates (e.g., new custom constraints, additional features of a service) for GCP, AWS, and Azure services as part of our OverWatch offering, informing customers on a weekly basis of any new service features and the resulting threats and/or controls. Providing our customers with a process for staying up to date with all the available features of their CSP services and the information needed to secure their environments against the threats related to the applicable services.
To learn more about TrustOnCloud and our products, you can visit TrustOnCloud.com or contact us with any questions.
