OCI Cloud Guard Advanced: Custom Detectors, Responders, and Security Scoring

OCI Cloud Guard provides Cloud Security Posture Management: it continuously evaluates your tenancy against a set of security rules, surfaces findings when resources deviate from best practice, and can automatically remediate them using Responders. The default detector recipes cover common findings. Custom detector recipes let you define organization-specific rules. This post covers enabling Cloud Guard with Terraform, creating custom detectors, configuring automated responders, and integrating findings with your alerting pipeline.

Step 1: Enable Cloud Guard

resource "oci_cloud_guard_cloud_guard_configuration" "tenancy_config" {
  compartment_id   = var.tenancy_ocid
  reporting_region = var.region
  status           = "ENABLED"

  self_manage_resources_oracle_managed_list = false
}

resource "oci_cloud_guard_target" "production_target" {
  compartment_id       = var.compartment_id
  display_name         = "production-cloud-guard-target"
  target_resource_id   = var.compartment_id
  target_resource_type = "COMPARTMENT"

  # Attach Oracle-managed detector recipes
  target_detector_recipes {
    detector_recipe_id = data.oci_cloud_guard_detector_recipes.config_recipe.detector_recipe_collection[0].items[0].id
  }

  target_detector_recipes {
    detector_recipe_id = data.oci_cloud_guard_detector_recipes.activity_recipe.detector_recipe_collection[0].items[0].id
  }

  target_responder_recipes {
    responder_recipe_id = var.oracle_managed_responder_recipe_id
  }

  defined_tags = { "Operations.Environment" = "production", "Operations.ManagedBy" = "terraform" }
}

output "target_id" { value = oci_cloud_guard_target.production_target.id }

Step 2: Custom Detector Recipe

resource "oci_cloud_guard_detector_recipe" "custom_config_detector" {
  compartment_id           = var.compartment_id
  display_name             = "custom-configuration-detector"
  description              = "Organization-specific configuration security rules"
  source_detector_recipe_id = var.oracle_config_detector_recipe_id

  # Override specific detector rules to set severity and enable/disable
  detector_rules {
    detector_rule_id = "BUCKET_WITHOUT_LIFECYCLE"
    details {
      is_enabled   = true
      risk_level   = "MEDIUM"
      condition_groups {
        compartment_id = var.compartment_id
        condition      = jsonencode({
          "kind"       = "SIMPLE"
          "operator"   = "EQUALS"
          "parameter"  = "lifecycleConfigured"
          "value"      = "false"
          "valueType"  = "MANAGED"
        })
      }
    }
  }

  detector_rules {
    detector_rule_id = "BUCKET_WITHOUT_VERSIONING"
    details {
      is_enabled = false  # Disable - we allow versioning-disabled buckets for transient data
      risk_level = "LOW"
    }
  }

  detector_rules {
    detector_rule_id = "INSTANCE_PUBLIC_IP"
    details {
      is_enabled = true
      risk_level = "HIGH"  # Override to HIGH severity
    }
  }

  defined_tags = { "Operations.ManagedBy" = "terraform" }
}

Step 3: Automated Responder Recipe

resource "oci_cloud_guard_responder_recipe" "custom_responder" {
  compartment_id              = var.compartment_id
  display_name                = "custom-auto-responder"
  description                 = "Automated remediation for critical findings"
  source_responder_recipe_id  = var.oracle_managed_responder_recipe_id

  responder_rules {
    responder_rule_id = "MAKE_BUCKET_PRIVATE"
    details {
      is_enabled = true
      mode       = "AUTOACTION"  # Automatically remediate without waiting for approval
      configurations {
        config_key   = "targetBucketName"
        name         = "Target Bucket"
        value        = "DETECTED_RESOURCE"
      }
    }
  }

  responder_rules {
    responder_rule_id = "DISABLE_PUBLIC_IP"
    details {
      is_enabled = true
      mode       = "USERACTION"  # Require manual approval before executing
    }
  }

  defined_tags = { "Operations.ManagedBy" = "terraform" }
}

Step 4: High-Risk Finding Alarm

resource "oci_monitoring_alarm" "cloud_guard_critical_finding" {
  compartment_id        = var.compartment_id
  display_name          = "cloud-guard-critical-finding"
  is_enabled            = true
  metric_compartment_id = var.compartment_id
  namespace             = "oci_cloud_guard"
  query                 = "OpenCriticalProblems[1h]{targetId = 'CG_TARGET_OCID'}.sum() > 0"
  severity              = "CRITICAL"
  pending_duration      = "PT1H"
  destinations          = [var.security_notification_topic_id]
  body                  = "Cloud Guard has detected one or more critical security findings. Review the Cloud Guard problems list and remediate immediately."
}

Operational Notes

Use AUTOACTION mode only for responders that are safe to execute without human review. Automatically making a bucket private is safe: it restores a misconfiguration with no legitimate use case for a public bucket in production. Automatically disabling a public IP on an instance is risky: it may break connectivity to a load balancer or bastion that requires the public IP. Use USERACTION for any responder that could disrupt production traffic.

Cloud Guard findings are point-in-time evaluations, not continuous streams. If you remediate a finding manually, Cloud Guard marks it as resolved on its next evaluation cycle, which runs every few hours. Do not expect immediate resolution after a manual fix. The alarm on open critical problems may continue to fire until the next evaluation cycle confirms the problem is resolved.

Regards,
Osama

#OCI #OracleCloud #CloudGuard #CSPM #Terraform #IaC #TechBlog #Oracle #CloudSecurity #PlatformEngineering #DevSecOps #Compliance #OracleCloudInfrastructure #SecurityPosture #AutoRemediation #Responder #Detector #SecurityAutomation #CloudCompliance #ZeroTrust

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.