intermediate25 min readcloud-providersUpdated: 2024-06-18

Google Cloud Organization Policies

Implement governance across GCP projects using Organization Policy Service and Security Command Center

๐Ÿ“‹ Prerequisites

  • Google Cloud account with organization-level access
  • Google Cloud CLI (gcloud) installed
  • Basic understanding of GCP resource hierarchy
  • Familiarity with YAML and command-line tools
  • Read: What is Policy-as-Code?

๐ŸŽฏ What You'll Learn

  • Understanding GCP resource hierarchy and policy inheritance
  • Creating and managing Organization Policy constraints
  • Implementing custom constraints with Cloud Build
  • Using Config Validator for Infrastructure-as-Code validation
  • Monitoring compliance with Security Command Center
  • Best practices for multi-project governance

๐Ÿท๏ธ Topics Covered

gcp organization policy examplesgoogle cloud governance best practicesgcp resource hierarchy policiescloud asset inventory policy validationgcp policy constraints examplesgoogle cloud security policies

GCP Organization Policy Examples: Complete Architecture Guide

Google Cloud's policy system is built around the resource hierarchy (Organization โ†’ Folders โ†’ Projects โ†’ Resources) with policies inherited down the hierarchy. This enables centralized governance while allowing flexibility at different organizational levels.

๐Ÿข Organization Policy Service

Central service for defining and enforcing organizational policies across the hierarchy

๐Ÿ” Config Validator

Pre-deployment validation tool for Infrastructure-as-Code using Constraint Framework

๐Ÿ›ก๏ธ Security Command Center

Centralized security and compliance monitoring dashboard

Google Cloud Governance Best Practices: Resource Hierarchy

Policy inheritance in GCP flows from Organization โ†’ Folders โ†’ Projects โ†’ Resources. Understanding this hierarchy is crucial for effective policy design.

View Resource Hierarchy

# Get organization ID
gcloud organizations list

# List folders in organization
gcloud resource-manager folders list --organization=ORGANIZATION_ID

# List projects in organization
gcloud projects list --filter="parent.id=ORGANIZATION_ID"

# View current project hierarchy
gcloud projects describe PROJECT_ID

# List all accessible projects
gcloud projects list --format="table(
  name,
  projectId,
  projectNumber,
  parent.id,
  parent.type
)"

GCP Resource Hierarchy Policies: Organization Service Tutorial

Organization policies provide centralized control over your organization's cloud resources. They can enforce security best practices, regulatory requirements, and operational standards.

Built-in Constraints

Common Built-in Constraints

# List all available constraints
gcloud resource-manager org-policies list --organization=ORGANIZATION_ID

# Common security constraints:
# compute.disableSerialPortAccess - Disable VM serial port access
# compute.vmExternalIpAccess - Restrict external IP assignment
# storage.publicAccessPrevention - Prevent public access to Cloud Storage
# iam.disableServiceAccountKeyCreation - Prevent service account key creation
# compute.restrictSharedVpcSubnetworks - Restrict shared VPC subnet usage

# View constraint details
gcloud resource-manager org-policies describe \
  constraints/compute.vmExternalIpAccess \
  --organization=ORGANIZATION_ID

Creating Organization Policies

disable-vm-serial-port.yaml

constraint: constraints/compute.disableSerialPortAccess
booleanPolicy:
  enforced: true

restrict-vm-external-ip.yaml

constraint: constraints/compute.vmExternalIpAccess
listPolicy:
  allowedValues:
    - projects/PROJECT_ID/zones/us-central1-a/instances/bastion-host
  deniedValues: []
  allValues: DENY

allowed-locations.yaml

constraint: constraints/gcp.resourceLocations
listPolicy:
  allowedValues:
    - in:us-locations
    - in:eu-locations
  deniedValues: []
  allValues: DENY

Applying Organization Policies

Apply Policies

# Apply policy at organization level
gcloud resource-manager org-policies set-policy \
  disable-vm-serial-port.yaml \
  --organization=ORGANIZATION_ID

# Apply policy at folder level
gcloud resource-manager org-policies set-policy \
  restrict-vm-external-ip.yaml \
  --folder=FOLDER_ID

# Apply policy at project level
gcloud resource-manager org-policies set-policy \
  allowed-locations.yaml \
  --project=PROJECT_ID

# View effective policy
gcloud resource-manager org-policies describe \
  constraints/compute.disableSerialPortAccess \
  --organization=ORGANIZATION_ID \
  --effective

# List all policies for an organization
gcloud resource-manager org-policies list \
  --organization=ORGANIZATION_ID \
  --show-unset

Advanced Policy Examples

๐Ÿ”ง 1. IAM Policy Constraints

iam-restrictions.yaml

# Restrict IAM policy bindings
constraint: constraints/iam.allowedPolicyMemberDomains
listPolicy:
  allowedValues:
    - C01abc234  # Google Workspace customer ID
    - C56def789  # Another trusted domain
  deniedValues: []
  allValues: DENY
---
# Disable service account key creation
constraint: constraints/iam.disableServiceAccountKeyCreation
booleanPolicy:
  enforced: true
---
# Restrict service account key uploads
constraint: constraints/iam.disableServiceAccountKeyUpload
booleanPolicy:
  enforced: true

๐Ÿ”ง 2. Compute Engine Restrictions

compute-restrictions.yaml

# Restrict VM instance types
constraint: constraints/compute.vmInstanceTypes
listPolicy:
  allowedValues:
    - e2-micro
    - e2-small
    - e2-medium
    - n1-standard-1
    - n1-standard-2
  allValues: DENY
---
# Require OS Login
constraint: constraints/compute.requireOsLogin
booleanPolicy:
  enforced: true
---
# Disable nested virtualization
constraint: constraints/compute.disableNestedVirtualization
booleanPolicy:
  enforced: true

๐Ÿ”ง 3. Storage Security Policies

storage-security.yaml

# Prevent public access to Cloud Storage buckets
constraint: constraints/storage.publicAccessPrevention
booleanPolicy:
  enforced: true
---
# Require uniform bucket-level access
constraint: constraints/storage.uniformBucketLevelAccess
booleanPolicy:
  enforced: true
---
# Restrict retention policy
constraint: constraints/storage.retentionPolicySeconds
listPolicy:
  allowedValues:
    - "2592000"    # 30 days
    - "7776000"    # 90 days
    - "31536000"   # 1 year
  allValues: DENY

GCP Policy Constraints Examples: Custom Implementation Guide

For policies not covered by built-in constraints, you can create custom constraints using Config Validator and the Constraint Framework.

Setting Up Config Validator

Install Config Validator

# Install using Go
go install github.com/GoogleCloudPlatform/config-validator/cmd/validator@latest

# Or download binary
curl -L https://github.com/GoogleCloudPlatform/config-validator/releases/latest/download/validator-linux-amd64 \
  -o validator
chmod +x validator
sudo mv validator /usr/local/bin/

# Verify installation
validator --version

Custom Constraint Template

gcp-storage-location-constraint.yaml

apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: gcpstoragelocationconstraint
spec:
  crd:
    spec:
      names:
        kind: GcpStorageLocationConstraint
      validation:
        properties:
          locations:
            type: array
            items:
              type: string
          exemptions:
            type: array
            items:
              type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package gcpstoragelocationconstraint

        required_locations := input.parameters.locations
        exemptions := input.parameters.exemptions

        violation[{"msg": msg}] {
          resource := input.review.object
          resource.kind == "StorageBucket"
          
          # Check if bucket is in exemptions
          not bucket_in_exemptions(resource.metadata.name)
          
          # Check if location is allowed
          not location_allowed(resource.spec.location)
          
          msg := sprintf("Storage bucket '%v' location '%v' is not in allowed locations: %v", 
            [resource.metadata.name, resource.spec.location, required_locations])
        }

        bucket_in_exemptions(bucket_name) {
          bucket_name == exemptions[_]
        }

        location_allowed(location) {
          location == required_locations[_]
        }

        location_allowed(location) {
          startswith(location, required_locations[_])
        }

Constraint Instance

storage-location-policy.yaml

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: GcpStorageLocationConstraint
metadata:
  name: storage-must-be-in-allowed-locations
spec:
  match:
    kinds:
      - apiGroups: ["storage.cnrm.cloud.google.com"]
        kinds: ["StorageBucket"]
  parameters:
    locations:
      - "us-central1"
      - "us-east1"
      - "europe-west1"
    exemptions:
      - "legacy-backup-bucket"
      - "temp-migration-bucket"

Testing Terraform Configurations

test-terraform-config.tf

# Compliant storage bucket
resource "google_storage_bucket" "compliant_bucket" {
  name          = "my-compliant-bucket"
  location      = "us-central1"
  force_destroy = true

  lifecycle_rule {
    condition {
      age = 365
    }
    action {
      type = "Delete"
    }
  }
}

# Non-compliant storage bucket (will fail validation)
resource "google_storage_bucket" "non_compliant_bucket" {
  name          = "my-non-compliant-bucket"
  location      = "asia-southeast1"  # Not in allowed locations
  force_destroy = true
}

Validate Configuration

# Generate Terraform plan
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json

# Convert to CAI (Cloud Asset Inventory) format
terraform-validator convert tfplan.json

# Validate against constraints
validator validate \
  --policy-path=constraints/ \
  --data=tfplan.json

# Alternative: Use Terraform Validator
terraform-validator validate tfplan.json \
  --policy-path=constraints/ \
  --project=PROJECT_ID

Google Cloud Security Policies: Advanced Constraint Patterns

Network Security Constraints

network-security-constraint.yaml

apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: gcpnetworksecurityconstraint
spec:
  crd:
    spec:
      names:
        kind: GcpNetworkSecurityConstraint
      validation:
        properties:
          blocked_ports:
            type: array
            items:
              type: string
          allowed_source_ranges:
            type: array
            items:
              type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package gcpnetworksecurityconstraint

        blocked_ports := input.parameters.blocked_ports
        allowed_source_ranges := input.parameters.allowed_source_ranges

        violation[{"msg": msg}] {
          resource := input.review.object
          resource.kind == "ComputeFirewall"
          
          # Check for blocked ports
          some i
          port := resource.spec.allow[i].ports[_]
          port == blocked_ports[_]
          
          # Check if source ranges are too permissive
          some j
          source_range := resource.spec.sourceRanges[j]
          not source_range_allowed(source_range)
          
          msg := sprintf("Firewall rule '%v' allows blocked port '%v' from unauthorized source range '%v'", 
            [resource.metadata.name, port, source_range])
        }

        source_range_allowed(source_range) {
          source_range == allowed_source_ranges[_]
        }

        # Allow private IP ranges by default
        source_range_allowed(source_range) {
          private_ranges := ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
          startswith(source_range, private_ranges[_])
        }

IAM Security Constraints

iam-security-constraint.yaml

apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: gcpiamsecurityconstraint
spec:
  crd:
    spec:
      names:
        kind: GcpIamSecurityConstraint
      validation:
        properties:
          prohibited_roles:
            type: array
            items:
              type: string
          required_conditions:
            type: array
            items:
              type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package gcpiamsecurityconstraint

        prohibited_roles := input.parameters.prohibited_roles
        required_conditions := input.parameters.required_conditions

        violation[{"msg": msg}] {
          resource := input.review.object
          resource.kind == "IAMPolicy"
          
          # Check for prohibited roles
          some i
          binding := resource.spec.bindings[i]
          binding.role == prohibited_roles[_]
          
          msg := sprintf("IAM policy '%v' contains prohibited role '%v'", 
            [resource.metadata.name, binding.role])
        }

        violation[{"msg": msg}] {
          resource := input.review.object
          resource.kind == "IAMPolicy"
          
          # Check for missing conditions on sensitive roles
          some i
          binding := resource.spec.bindings[i]
          is_sensitive_role(binding.role)
          not has_condition(binding)
          
          msg := sprintf("IAM policy '%v' grants sensitive role '%v' without conditions", 
            [resource.metadata.name, binding.role])
        }

        is_sensitive_role(role) {
          sensitive_roles := [
            "roles/owner",
            "roles/editor", 
            "roles/iam.securityAdmin",
            "roles/resourcemanager.organizationAdmin"
          ]
          role == sensitive_roles[_]
        }

        has_condition(binding) {
          binding.condition
        }

Cloud Asset Inventory Policy Validation: CI/CD Integration

Integrate policy validation into your deployment pipelines to catch violations before resources are created in GCP.

Cloud Build Pipeline

cloudbuild.yaml

steps:
# Install dependencies
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    # Install terraform-validator
    curl -L https://github.com/GoogleCloudPlatform/terraform-validator/releases/latest/download/terraform-validator-linux-amd64 \
      -o terraform-validator
    chmod +x terraform-validator
    
    # Install Config Validator
    curl -L https://github.com/GoogleCloudPlatform/config-validator/releases/latest/download/validator-linux-amd64 \
      -o validator
    chmod +x validator

# Terraform validation
- name: 'hashicorp/terraform:1.6'
  entrypoint: 'sh'
  args:
  - '-c'
  - |
    terraform init
    terraform validate
    terraform plan -out=tfplan
    terraform show -json tfplan > tfplan.json
  volumes:
  - name: 'tf-plan'
    path: '/workspace'

# Policy validation
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    # Validate using terraform-validator
    ./terraform-validator validate tfplan.json \
      --policy-path=constraints/ \
      --project=$PROJECT_ID \
      --format=json > validation-results.json
    
    # Check if there are violations
    violations=$(cat validation-results.json | jq length)
    if [ $violations -gt 0 ]; then
      echo "Policy violations found:"
      cat validation-results.json | jq '.'
      exit 1
    else
      echo "All policy validations passed!"
    fi
  volumes:
  - name: 'tf-plan'
    path: '/workspace'

# Deploy if validation passes
- name: 'hashicorp/terraform:1.6'
  entrypoint: 'sh'
  args:
  - '-c'
  - |
    if [ "$BRANCH_NAME" = "main" ]; then
      terraform apply tfplan
    else
      echo "Skipping deployment for branch: $BRANCH_NAME"
    fi
  volumes:
  - name: 'tf-plan'
    path: '/workspace'

# Generate compliance report
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    # Generate organization policy compliance report
    gcloud logging read \
      'resource.type="organization" AND protoPayload.methodName="SetOrgPolicy"' \
      --limit=50 \
      --format=json > policy-changes.json
    
    # Store results in Cloud Storage
    gsutil cp validation-results.json gs://${PROJECT_ID}-compliance-reports/
    gsutil cp policy-changes.json gs://${PROJECT_ID}-compliance-reports/

options:
  logging: CLOUD_LOGGING_ONLY

GitHub Actions Workflow

.github/workflows/gcp-policy-validation.yml

name: GCP Policy Validation

on:
  pull_request:
    paths:
      - '**.tf'
      - 'constraints/**'
      - 'policies/**'

env:
  GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
  GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}

jobs:
  policy-validation:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
    
    - name: Setup Terraform
      uses: hashicorp/setup-terraform@v3
      with:
        terraform_version: 1.6.0
    
    - name: Authenticate to Google Cloud
      uses: google-github-actions/auth@v2
      with:
        credentials_json: ${{ secrets.GCP_SA_KEY }}
    
    - name: Set up Cloud SDK
      uses: google-github-actions/setup-gcloud@v2
    
    - name: Install terraform-validator
      run: |
        curl -L https://github.com/GoogleCloudPlatform/terraform-validator/releases/latest/download/terraform-validator-linux-amd64 \
          -o terraform-validator
        chmod +x terraform-validator
        sudo mv terraform-validator /usr/local/bin/
    
    - name: Install Config Validator
      run: |
        curl -L https://github.com/GoogleCloudPlatform/config-validator/releases/latest/download/validator-linux-amd64 \
          -o validator
        chmod +x validator
        sudo mv validator /usr/local/bin/
    
    - name: Terraform Init and Plan
      run: |
        terraform init
        terraform plan -out=tfplan
        terraform show -json tfplan > tfplan.json
    
    - name: Validate with terraform-validator
      run: |
        echo "๐Ÿ” Running terraform-validator..."
        terraform-validator validate tfplan.json \
          --policy-path=constraints/ \
          --project=$GCP_PROJECT_ID \
          --format=json > tv-results.json
        
        # Check results
        violations=$(cat tv-results.json | jq length)
        if [ $violations -gt 0 ]; then
          echo "โŒ Policy violations found:"
          cat tv-results.json | jq '.'
          exit 1
        else
          echo "โœ… All terraform-validator checks passed!"
        fi
    
    - name: Validate with Config Validator
      run: |
        echo "๐Ÿ›ก๏ธ Running Config Validator..."
        if ! validator validate --policy-path=constraints/ --data=tfplan.json; then
          echo "โŒ Config Validator found policy violations"
          exit 1
        else
          echo "โœ… All Config Validator checks passed!"
        fi
    
    - name: Test Organization Policies
      run: |
        echo "๐Ÿ“‹ Testing Organization Policy changes..."
        
        # Dry run policy changes if they exist
        if [ -d "org-policies/" ]; then
          find org-policies/ -name "*.yaml" | while read policy; do
            echo "Testing policy: $policy"
            gcloud resource-manager org-policies set-policy \
              "$policy" \
              --organization=${{ secrets.GCP_ORG_ID }} \
              --dry-run
          done
        fi
    
    - name: Generate Policy Report
      if: always()
      run: |
        echo "## ๐Ÿ“Š GCP Policy Validation Report" >> $GITHUB_STEP_SUMMARY
        echo "" >> $GITHUB_STEP_SUMMARY
        
        # terraform-validator results
        if [ -f tv-results.json ]; then
          violations=$(cat tv-results.json | jq length)
          if [ $violations -eq 0 ]; then
            echo "โœ… **terraform-validator**: All checks passed" >> $GITHUB_STEP_SUMMARY
          else
            echo "โŒ **terraform-validator**: $violations violations found" >> $GITHUB_STEP_SUMMARY
            echo "```json" >> $GITHUB_STEP_SUMMARY
            cat tv-results.json | jq '.' >> $GITHUB_STEP_SUMMARY
            echo "```" >> $GITHUB_STEP_SUMMARY
          fi
        fi
        
        echo "" >> $GITHUB_STEP_SUMMARY
        echo "### Resources to be created:" >> $GITHUB_STEP_SUMMARY
        jq -r '.planned_values.root_module.resources[]? | "\(.type): \(.name)"' tfplan.json >> $GITHUB_STEP_SUMMARY

GCP Governance Best Practices: Compliance Monitoring Guide

Monitor ongoing compliance using Security Command Center, Cloud Asset Inventory, and custom monitoring solutions.

Security Command Center Integration

Enable SCC and Asset Inventory

# Enable Security Command Center API
gcloud services enable securitycenter.googleapis.com

# Enable Cloud Asset Inventory API
gcloud services enable cloudasset.googleapis.com

# Create custom security source for policy violations
gcloud scc sources create \
  --organization=ORGANIZATION_ID \
  --display-name="Policy Violations" \
  --description="Custom source for organization policy violations"

# Export asset inventory
gcloud asset export \
  --organization=ORGANIZATION_ID \
  --asset-types="cloudresourcemanager.googleapis.com/Project,compute.googleapis.com/Instance" \
  --output-path="gs://YOUR_BUCKET/asset-inventory.json" \
  --content-type=resource

Custom Compliance Monitoring Script

compliance-monitor.py

#!/usr/bin/env python3
import json
import sys
from google.cloud import asset_v1
from google.cloud import securitycenter
from google.cloud import resourcemanager_v3

def check_compute_instances_compliance(organization_id):
    """Check Compute Engine instances for policy compliance."""
    
    client = asset_v1.AssetServiceClient()
    parent = f"organizations/{organization_id}"
    
    # Get all compute instances
    response = client.search_all_resources(
        request={
            "scope": parent,
            "asset_types": ["compute.googleapis.com/Instance"],
        }
    )
    
    violations = []
    
    for resource in response:
        instance = resource
        
        # Check for external IP policy violation
        if has_external_ip(instance):
            violations.append({
                "resource": instance.name,
                "violation": "Instance has external IP",
                "policy": "compute.vmExternalIpAccess"
            })
        
        # Check for OS Login requirement
        if not has_os_login(instance):
            violations.append({
                "resource": instance.name,
                "violation": "Instance does not have OS Login enabled",
                "policy": "compute.requireOsLogin"
            })
    
    return violations

def has_external_ip(instance):
    """Check if instance has external IP."""
    try:
        additional_attributes = json.loads(instance.additional_attributes)
        network_interfaces = additional_attributes.get("networkInterfaces", [])
        
        for interface in network_interfaces:
            access_configs = interface.get("accessConfigs", [])
            if access_configs:
                return True
        return False
    except:
        return False

def has_os_login(instance):
    """Check if instance has OS Login enabled."""
    try:
        additional_attributes = json.loads(instance.additional_attributes)
        metadata = additional_attributes.get("metadata", {})
        items = metadata.get("items", [])
        
        for item in items:
            if item.get("key") == "enable-oslogin" and item.get("value") == "TRUE":
                return True
        return False
    except:
        return False

def check_organization_policies(organization_id):
    """Check organization policy compliance."""
    
    client = resourcemanager_v3.OrgPolicyClient()
    parent = f"organizations/{organization_id}"
    
    # List all policies
    policies = client.list_policies(parent=parent)
    
    policy_status = []
    for policy in policies:
        policy_status.append({
            "constraint": policy.name.split("/")[-1],
            "enforced": bool(policy.spec),
            "inheritance": policy.spec.inherit_from_parent if policy.spec else False
        })
    
    return policy_status

def create_scc_finding(organization_id, source_id, violation):
    """Create Security Command Center finding for policy violation."""
    
    client = securitycenter.SecurityCenterClient()
    source_name = f"organizations/{organization_id}/sources/{source_id}"
    
    finding_id = f"policy-violation-{hash(violation['resource'])}"
    finding = {
        "name": f"{source_name}/findings/{finding_id}",
        "resource_name": violation["resource"],
        "state": securitycenter.Finding.State.ACTIVE,
        "category": "POLICY_VIOLATION",
        "source_properties": {
            "policy": violation["policy"],
            "violation": violation["violation"]
        }
    }
    
    response = client.create_finding(
        parent=source_name,
        finding_id=finding_id,
        finding=finding
    )
    
    return response

def main():
    if len(sys.argv) != 2:
        print("Usage: python compliance-monitor.py ")
        sys.exit(1)
    
    organization_id = sys.argv[1]
    
    print(f"Checking compliance for organization: {organization_id}")
    
    # Check compute instances
    compute_violations = check_compute_instances_compliance(organization_id)
    
    # Check organization policies
    policy_status = check_organization_policies(organization_id)
    
    # Generate report
    report = {
        "organization_id": organization_id,
        "compute_violations": compute_violations,
        "policy_status": policy_status,
        "total_violations": len(compute_violations)
    }
    
    print(json.dumps(report, indent=2))
    
    # Create SCC findings for violations
    # source_id = "YOUR_CUSTOM_SOURCE_ID"
    # for violation in compute_violations:
    #     create_scc_finding(organization_id, source_id, violation)

if __name__ == "__main__":
    main()

GCP Policy Best Practices

๐Ÿ—๏ธ

Hierarchy Design

Use folders to group projects by environment, apply restrictive policies at org level, use project-level policies for specific needs, and plan for policy inheritance carefully.

๐Ÿ“Š

Policy Management

Start with monitoring mode before enforcement, use descriptive constraint names, document business rationale, and regular policy review and updates.

๐Ÿงช

Testing Strategy

Test policies in development projects first, use terraform-validator in CI/CD, validate custom constraints thoroughly, and monitor for unintended effects.

๐Ÿ”„

Deployment Strategy

Gradual rollout across environments, use exemptions sparingly and document, monitor compliance metrics, and plan for emergency policy changes.

๐Ÿ“š

Documentation

Maintain policy catalog, document exemption processes, provide remediation guidance, and create escalation procedures.

โšก

Monitoring

Set up compliance dashboards, use Cloud Asset Inventory, regular compliance reporting, and automated violation alerting.

Troubleshooting Common Issues

Organization Policy Issues

โŒ Policy not taking effect

Problem: Applied organization policy doesn't seem to enforce restrictions.

Solutions:

  • Check policy inheritance hierarchy
  • Verify resource is in policy scope
  • Wait for propagation (can take up to 10 minutes)
  • Check for conflicting policies at lower levels

โŒ Constraint template validation fails

Problem: Custom constraint templates fail validation.

Solutions:

  • Validate Rego syntax using OPA tools
  • Check constraint template CRD schema
  • Test with minimal example first
  • Review OPA builtins documentation

Validation Issues

โŒ terraform-validator errors

Problem: terraform-validator produces unexpected results.

Solutions:

  • Ensure Terraform plan is in JSON format
  • Check constraint path and file structure
  • Verify project ID and credentials
  • Update to latest validator version

๐ŸŽ‰ Congratulations!

Google Cloud Governance Mastery

You now have comprehensive knowledge of Google Cloud governance including:

โœ…

Organization Policy Service

Master GCP's native governance service for defining and enforcing organizational policies across the hierarchy.

โœ…

Custom Constraints

Create custom constraints with Config Validator and the Constraint Framework for advanced policy requirements.

โœ…

Infrastructure Validation

Implement Infrastructure-as-Code validation using terraform-validator and custom constraint patterns.

โœ…

CI/CD Integration

Integrate policy validation into deployment pipelines with Cloud Build and GitHub Actions workflows.

โœ…

Compliance Monitoring

Monitor ongoing compliance using Security Command Center, Cloud Asset Inventory, and custom monitoring solutions.

โœ…

Multi-Project Governance

Apply proven best practices for enterprise-scale GCP governance and multi-project policy management.

Next Steps