OPA Gatekeeper Support

Details on OPA Gatekeeper Support in InsightCloudSec for Kubernetes Policy and Governance

Capability Summary

InsightCloudSec has implemented Open Policy Agent(OPA) Gatekeeper support to enable you to take advantage of the OPA Gatekeeper feature and ensure your clusters meet policies required to ensure the security and compliance of your Kubernetes infrastructure.

Per the Kubernetes Blog "Kubernetes allows decoupling policy decisions from the API server by means of admission controller webhooks to intercept admission requests before they are persisted as objects in Kubernetes. Gatekeeper was created to enable users to customize admission control via configuration, not code and to bring awareness of the cluster’s state, not just the single object under evaluation at admission time. Gatekeeper is a customizable admission webhook for Kubernetes that enforces policies executed by the Open Policy Agent (OPA), a policy engine for Cloud Native environments hosted by CNCF."

External References


Constraint - a declaration created by an author (you) for the system around a set of defined requirements. Constraints are written in Rego, a language used by OPA to enumerate instances of data that violate the expected state if the system.

  • For example, in a system with objects that can be labeled, you can create a Constraint to identify a specific label for each object (billable, point of contact, etc.)

Constraint Template - the format used by OPA to declare new Constraints. They can provide expected parameters and the underlying Rego to enforce their intent.

Use Cases

Example 1: Is a cluster compliant with Gatekeeper enforcement policy? Different sets of Constraints may be enforced on specific environments. And, as a user I’d like to easily understand which clusters (doesn’t) comply with a specific set of Constraints.

  • Result: Implement a Constraint to show you coverage by non-compliant clusters

Example 2: Show me specific Constraint configuration. As a security admin I would like to evaluate the configuration to better understand the Constraint adjustment as a followup for a high failure rate or unexpected high pass rate or to validate that the right namespaces are inspected.

  • *Result: InsightCloudSec harvests the individual Constraints (and templates) for easy visibility

Getting Started with Gatekeeper


  • InsightCloudSec version 23.3.28 or later
  • Kubernetes Local Scanner v. 4.0.1

What is Supported?

Assuming that you have both the latest version of InsightCloudSec and the Kubernetes Local Scanner InsightCloudSec can harvest two new resources.

  • Gatekeeper Constraint template: ConstraintTemplate describes both the Rego that enforces the constraint and the schema of the constraint

  • Gatekeeper Constraint: Constraints are used to inform Gatekeeper that the admin wants a ConstraintTemplate to be enforced, and how to enforce them

The combination of the Constraint template and Constraints creates enforcement policies on each k8s cluster. Check out the following article for additional details.

  • A policy (constraint + template) is specific to the cluster on which it is configured
  • InsightCloudSec will harvest and show inventory across all monitored clusters for the two new resource types

Using InsightCloudSec to Assess Gatekeeper

Gatekeeper Assessment Support

InsightCloudSec offers one Insight and two Query Filters to assist in assessing Gatekeeper status and OPA Constraints:

  • Query Filters
    • Kubernetes Security: Gatekeeper -- Identifies various Kubernetes resources that fail one or more Kubernetes Security checks for Gatekeeper.
    • Clusters Missing OPA Constraints -- Enables InsightCloudSec to check for compliance against any Constraints for resources within a Data Collection. If a cluster doesn’t have a full match to the Constraints associated with it (all specified constraints must be deployed on the cluster), the cluster will be marked as non-compliant. Note: This Query Filter currently keys off of the Cloud Accounts resource.


      Data Collection Tips

      The data collection should be set up with your list of required Gatekeeper constraints. The filter validates against the same list and will show all clusters that are not compliant, i.e., missing one or more of the constraints specified in the data collection.

  • Insight
    • Validating Gatekeeper Status -- The number of active Gatekeeper deployments does not equal the configured number. Uses the Kubernetes Security: Gatekeeper Query Filter.

Using Automation for Gatekeeper

Once InsightCloudSec has collected details and provided findings, you have the ability to build automation around notifications through our Bot (Automation) capability.

In the example below we've created a template for a Bot that detects new non-compliant clusters. When configuring this Bot, ensure you are scoping it based on the Cloud Account resource type and the Clusters Missing OPA Constraints Query Filter (and requisite associated Data Collection). The following actions are relevant to assessing OPA Gatekeeper compliance:

  • Email
  • Slack

Note: for any of the items above that require third-party integrations refer to our Integrations Overview documentation (which includes links to individual pages for each Integration offered). For the example below, you must have a configured Slack Integration.

 "resource_id": "divvybot:1:2921",
 "name": "OPA Gatekeeper Non-Compliant Cluster",
 "description": "",
 "notes": null,
 "insight_id": null,
 "source": null,
 "insight_name": null,
 "insight_severity": null,
 "owner": "divvyuser:1234:",
 "owner_name": "John Smith",
 "state": "RUNNING",
 "date_created": "2023-03-30 17:40:32",
 "date_modified": "2023-03-30 17:40:32",
 "category": "Security",
 "badge_scope_operator": null,
 "instructions": {
  "resource_types": [
  "filters": [
    "name": "divvy.query.k8s_cluster_missing_required_opa_constrains",
    "config": {
     "constraints": []
    "collections": {
     "constraints": 1
  "actions": [
    "name": "slack.action.send_slack_message",
    "config": {
     "webhook": "...",
     "channel": "my-channel",
     "username": "InsightCloudSec",
     "recipient_tag_keys": [],
     "recipient_badge_keys": [],
     "message": "A new OPA Gatekeeper non-compliant cluster has been found. Here are the finding details.",
     "skip_duplicates": false
    "run_when_result_is": true
  "groups": [
  "badges": [],
  "exclusion_badges": null,
  "hookpoints": [],
  "schedule": "{\"_type\": \"Daily\", \"time_of_day\": {\"_type\": \"TimeOfDay\", \"second\": 0, \"minute\": 0, \"hour\": 12}, \"exclude_days\": []}",
  "schedule_description": "{\"_type\": \"Daily\", \"time_of_day\": {\"_type\": \"TimeOfDay\", \"second\": 0, \"minute\": 0, \"hour\": 12}, \"exclude_days\": []}"
 "valid": true,
 "errors": [],
 "severity": "low",
 "detailed_logging": false,
 "scope": [

Creating a OPA Gatekeeper Bot From a Template

To use the template example above

1. From your InsightCloudSec platform installation, navigate to "Automation --> BotFactory".

2. On the BotFactory landing page, navigate to "Templates".


Importing a Bot template

3. From the "Templates" tab under BotFactory select the "Import Template" option and paste the example featured above into the JSON window.


Import JSON template

4. Click "Submit" to verify and store the template for future use. Review Creating Bots for more information on next steps.