Prepare and test your skills
Prepare and test your skills
Authoring and enforcing custom organization policy constraints is the preventive way to block misconfigured Google Cloud resources before they are created. Google Cloud Organization Policy Service (opens in a new tab) is the centralized control plane that evaluates constraints when resources are created or updated. Custom constraints extend built-in controls with field-level rules so teams prevent drift instead of detecting it afterward.
Custom constraints are user-defined rules that govern specific fields of supported Google Cloud resources, while managed constraints are predefined rules supplied by Google. A managed constraint such as constraints/storage.publicAccessPrevention, constraints/iam.allowedPolicyMemberDomains, or constraints/compute.skipDefaultNetworkCreation enforces one fixed behavior across the hierarchy. A custom constraint targets a service-specific resource type, such as compute.googleapis.com/BackendService, certificatemanager.googleapis.com/Certificate, or clouddeploy.googleapis.com/DeliveryPipeline, and uses a Common Expression Language (CEL) expression to allow or deny the request based on values in the creation payload.
The request flows from the user or automation to the service API and then to the policy engine for an allow or deny decision. Choose a managed constraint when a predefined control covers the requirement, and choose a custom constraint when governance needs field-level precision such as approved VM machine families, disk size limits, allowed health-check protocols, or required firewall tag configurations. The following comparison summarizes when to use each option:
| Option | Defined by | Scope of control | Choose when |
|---|---|---|---|
| Managed constraint | Google Cloud | Fixed service-wide behavior | A predefined control such as blocking public buckets or default networks applies |
| Custom constraint | Organization policy administrator | Specific resource field governed by CEL | Fine-grained configuration such as machine type, protocol, tier, or tag must be enforced |
Custom constraints depend on the supporting service exposing its resource fields to Organization Policy, so not every field is governable. Legacy global HTTP and HTTPS health checks, for example, are not supported for custom constraints.
Hierarchical inheritance is the rule that determines where an organization policy applies in the Google Cloud resource hierarchy. The hierarchy flows from organization to folder to project to service resource, and the effective policy at a project is the combination of policies inherited from its ancestors plus any policy attached directly to the project. By default, descendants inherit the parent policy, and evaluation rules can alter that behavior for an exception subtree.
The organization policy administrator owns constraints and policies at the level where they are attached, while project owners inherit those guardrails without the ability to weaken a higher-level deny. Place broad preventive baselines high in the hierarchy for consistent posture, and place narrower custom constraints lower when only one folder or project needs the restriction.
Exam tip: Inheritance flows downward from organization to folder to project; a folder-level policy automatically governs all child projects unless inheritance is explicitly disabled.
Conditional tag-based enforcement is the mechanism for scoping an organization policy to a subset of resources using tags and conditions rather than moving resources in the hierarchy. The policy still attaches at the organization, folder, or project level, but its rule includes a condition that checks tags bound to the target resource or its ancestry. Creation traffic flows to the policy engine, the engine resolves the tags on the resource, and only requests matching the tag condition are subject to the deny or allow logic.
This model separates placement from intent, so one folder can host both restricted and exempt workloads distinguished by tags such as environment:prod or data-classification:restricted. Use tag conditions when a single control must apply selectively without creating extra folders, and use separate hierarchy attachments when the boundary should follow team or billing ownership. Because the policy depends on correct tag bindings, tag administration and tag inheritance must be governed as tightly as the constraint itself.
The author-to-enforcement workflow is the ordered lifecycle for rolling out a custom constraint safely at scale. The constraint definition, the policy attachment, and the enforcement mode are separate objects, which allows simulation before blocking production changes. The ordered rollout operates as follows:
Dry-run simulation depends on representative traffic and existing inventory, so run it long enough to observe automation, CI/CD pipelines, and manual workflows. Only after dry-run shows no unintended denials should enforcement be enabled on production folders.
Common preventive patterns use custom and managed constraints together to maintain baseline posture and stop drift across many projects. The Organization Policy Service evaluates these controls at request time, which prevents the misconfigured resource from existing rather than flagging it after creation. Representative patterns drawn from supported services include:
constraints/iam.disableServiceAccountKeyCreation and constraints/iam.automaticIamGrantsForDefaultServiceAccounts to block long-lived keys and automatic Editor grants to default service accounts.constraints/compute.skipDefaultNetworkCreation and constraints/compute.trustedImageProjects so new projects do not receive a default network and VMs launch only from trusted image projects.Automated drift detection and posture remediation is the continuous comparison of live Google Cloud configuration against an Infrastructure-as-Code baseline, with programmatic correction when they diverge. Security Command Center (SCC) (opens in a new tab) posture service defines the baseline as a posture, detects drift as findings, and exports those findings for action. Cloud Asset Inventory feeds, Pub/Sub, and event-driven compute such as Cloud Functions or Cloud Run close the loop by carrying change events to custom logic that creates findings and executes remediation.
A security posture in Security Command Center is one or more policy sets that enforce the preventive and detective controls required to meet a security standard. A policy set groups the policies for one standard or regulation, a policy is a single constraint or detector, and a posture deployment applies the posture to an organization, folder, or project. Supported policies in a posture are Organization Policy Service constraints, including custom constraints, for prevention and Security Health Analytics detectors, including custom modules, for detection.
The posture service is automatically enabled when Security Command Center is activated at the organization level on the Premium tier. This activation creates the management plane where baselines are defined once and then deployed to many hierarchy nodes for consistent enforcement.
Preventive controls in Organization Policy Service set centralized restrictions on how resources can be configured across the resource hierarchy. Declarative Infrastructure-as-Code provides the known good state, so the same Terraform and Cloud Build configuration can be redeployed, rolled back, audited, and checked automatically before deployment. Policy as code extends that check into the CI/CD pipeline, where Policy Controller and Open Policy Agent validate IaC for acceptable configuration before it is applied.
The preventive toolkit divides responsibility across four peer capabilities:
Traffic from developers flows first through OPA and Policy Controller checks, then through Organization Policy Service enforcement at deploy time, then through IAM and VPC Service Controls enforcement at access time.
Detective controls in Security Health Analytics continuously scan running Google Cloud assets for vulnerabilities, misconfigurations, and leaked secrets without requiring OS agents. Security Command Center aggregates signals from multiple security sources, runs attack path simulations that show how minor issues chain from the internet to high-value compute or billing permissions, and monitors active workloads with Container Threat Detection and Cloud Run Threat Detection. Compliance Manager frameworks map those findings to obligations and alert on posture drift from the defined benchmark.
The baseline controls library is designed to be extended as requirements mature:
Exam tip: Only one posture can be deployed to each organization, folder, or project, and when an organization-level posture and a project-level posture define the same policy differently, the lower-level posture controls that project.
Real-time drift remediation connects Cloud Asset Inventory, Security Command Center, Pub/Sub, and Cloud Run functions into an event-driven loop that compares live state to the IaC baseline. After a posture is deployed, Security Command Center reports drift as findings that can be reviewed, filtered, resolved, and exported like any other finding. A custom asset-change solution creates Security Command Center findings from inventory changes and can trigger automated remediation, while log-based alerts notify on errors from the Security Command Center service agent.
The ordered remediation loop operates as follows:
The automation depends on least-privilege service identities, so the remediation function depends on IAM permissions that allow it to read findings and inventory while limiting its power to modify only the intended resource types.
Posture deployment at scale relies on hierarchy inheritance where postures deployed at higher levels flow down to child folders and projects. If postures exist at both the organization level and the project level, all policies in both postures apply to resources in that project, and only direct conflicts are resolved in favor of the lower-level posture. The recommended pattern deploys a broad posture at the organization level for business-wide controls, then deploys more stringent postures to folders or projects that need them.
A common example enforces constraints/gcp.restrictCmekCryptoKeyProjects on common and environment folders so projects use keys only from designated key projects. Scale is bounded by explicit service limits that shape how postures are partitioned: the security posture service allows a maximum of 100 postures in an organization, a maximum of 400 policies in a posture, and a maximum of 1000 posture deployments in an organization. Predefined templates for secure defaults, BigQuery, Cloud Storage, VPC, CIS Benchmark v2.0.0, NIST SP 800-53, ISO 27001, PCI DSS, and secure AI reduce design work because essentials templates deploy without changes while extended templates must be customized to the environment.
Building and deploying custom modules for Security Health Analytics extends detection beyond built-in detectors to organization-specific misconfigurations. Security Health Analytics (SHA) (opens in a new tab) custom modules are custom detectors that continuously evaluate Cloud Asset Inventory metadata to generate findings at scale. Custom modules run in Security Command Center Premium and Enterprise tiers and let teams encode internal baselines that standard benchmarks miss.
Custom modules expand SHA posture management to business-specific drift that standard benchmarks miss. A custom module applies only to Google Cloud resources and is not supported for other cloud platforms such as Amazon Web Services or Microsoft Azure. Built-in detectors cover Google Cloud plus, in Enterprise, AWS and Azure after onboarding, but custom logic evaluates only Google Cloud asset data.
This boundary makes custom modules the tool for enforcing internal baselines across an organization, folder, or project hierarchy in Google Cloud. Built-in findings are grouped into high-level resource categories that illustrate the breadth of SHA coverage:
Custom modules complement these categories rather than replace them, pinpointing misconfigurations on supported Google Cloud resources where no built-in detector exists.
Detection logic with CEL and Cloud Asset Inventory is a Common Expression Language expression that tests normalized asset metadata for a violation. Cloud Asset Inventory supplies a normalized snapshot of each supported resource and its configuration, and SHA loads that asset data as input to the expression. The CEL expression tests fields such as network settings, encryption state, labels, or IAM bindings and returns true only when the resource violates the intended state.
This design creates a continuous drift-detection loop where data flows from the Google Cloud resource to Cloud Asset Inventory and then to the SHA evaluation engine. When the expression matches, SHA creates a finding bound to that specific asset; when it does not match, no finding is produced. Because evaluation depends on Cloud Asset Inventory coverage, a custom module can only pinpoint misconfigurations on resource types that Cloud Asset Inventory supports.
Finding definition is the set of properties that determines how a custom module finding is triaged and scoped. The definition names a finding category, such as DEFAULT_NETWORK or DEFAULT_ENCRYPTION_NOT_VERIFIED, assigns a severity level such as MEDIUM, and carries a revision number that tracks logic changes over time. The definition also declares an enforcement mode, such as Detective or Audit, and lists supported target resources, which include organization, folder, and project.
The finding inherits the severity and category from its parent module, so all assets that violate the same CEL rule share the same triage priority. Severity controls operational response, while category determines how the finding groups with related posture issues in Security Command Center. Defining these properties up front ensures that continuous evaluation produces findings that are actionable, scoped to the correct hierarchy level, and comparable across environments.
Exam tip: Custom modules require SCC Premium or Enterprise and apply only to Google Cloud; they do not evaluate AWS or Azure assets.
The build and deployment workflow creates a module definition owned at an organization, folder, or project that SHA then schedules for continuous scanning. A custom module can be built through the guided workflow in the Google Cloud console or as code for automation at scale. The console path suits one-off rules, while the as-code path supports version control, review, and rollout across many folders and projects.
Deployment as code follows an ordered workflow:
Once enabled, the module depends on Cloud Asset Inventory freshness and SHA scheduling to detect drift. Changes to infrastructure that alter asset metadata re-trigger evaluation, and remediation that makes the CEL expression evaluate to false allows the finding to move to inactive.
Managed constraints are predefined rules supplied by Google that enforce one fixed service-wide behavior, while custom constraints are user-defined rules that govern specific fields of supported resources using a Common Expression Language (CEL) expression. Choose a managed constraint when a predefined control covers the requirement, and choose a custom constraint when governance needs field-level precision such as approved machine families, disk size limits, allowed protocols, or required tag configurations. Custom constraints depend on the supporting service exposing its resource fields to Organization Policy, so not every field is governable.
The safe workflow is to define the custom constraint in the organization resource with the target resource, governed fields, and Common Expression Language (CEL) condition, then attach the organization policy to an organization, folder, or project node with inheritance and tag-based conditions. Deploy the policy in dry-run mode first so the policy engine logs what would have been denied without blocking requests, then review logs to identify workloads that would drift. Only after dry-run shows no unintended denials, switch the policy to enforced mode and validate that compliant requests succeed while violating requests are denied.
A Security Command Center (SCC) posture is one or more policy sets that combine Organization Policy Service constraints for prevention with Security Health Analytics detectors for detection, and postures deployed at higher levels flow down to child folders and projects. Only one posture can be deployed to each organization, folder, or project, and when policies conflict the lower-level posture controls that project while all non-conflicting policies from both postures still apply. Scale is bounded by a maximum of 100 postures in an organization, a maximum of 400 policies in a posture, and a maximum of 1000 posture deployments in an organization.
Security Health Analytics (SHA) custom modules are custom detectors that continuously evaluate Cloud Asset Inventory metadata with a Common Expression Language (CEL) expression and generate a finding bound to the specific asset when the expression matches a violation. Custom modules require Security Command Center Premium or Enterprise tiers, apply only to Google Cloud resources, and are not supported for other clouds such as Amazon Web Services or Microsoft Azure. Once remediated so the expression evaluates to false, the finding moves to inactive.
An enterprise enforces strict Infrastructure-as-Code (IaC) baselines across its entire Google Cloud organization. To minimize the window of exposure caused by out-of-band modifications, the security engineering team must design a continuous drift detection and automated remediation pipeline.
The solution must satisfy the following architectural requirements:
Which architecture should the security team deploy?
Configure Security Command Center (SCC) continuous exports and Cloud Asset Inventory real-time feeds to stream findings and resource state changes to Pub/Sub topics, and trigger Cloud Functions via Pub/Sub subscriptions to execute programmatic remediations.
Enable Compliance Manager in Security Command Center to automatically mute duplicate Security Health Analytics detectors and directly execute automated infrastructure rollbacks natively within the SCC dashboard.
Deploy a Cloud Composer environment that schedules hourly DAGs to execute Terraform plan across all projects, writes drift records to BigQuery, and triggers Cloud Workflows to re-apply Terraform states.
Configure Cloud Audit Logs aggregated log sinks at the organization root routed directly to Cloud Functions HTTP endpoints using Webhooks to parse IAM mutations and rollback drift.
Last updated