Admission control with Open Policy Agent
Table of Contents
Expand all | Collapse all
-
- Getting started
- System Requirements
- Cluster Context
-
- Prisma Cloud Container Images
- Kubernetes
- Deploy the Prisma Cloud Console on Amazon ECS
- Console on Fargate
- Onebox
- Alibaba Cloud Container Service for Kubernetes (ACK)
- Azure Container Service (ACS) with Kubernetes
- Azure Kubernetes Service (AKS)
- Amazon Elastic Kubernetes Service (EKS)
- IBM Kubernetes Service (IKS)
- OpenShift v4
-
- Defender Types
- Manage your Defenders
- Redeploy Defenders
- Uninstall Defenders
-
- Deploy Orchestrator Defenders on Amazon ECS
- Automatically Install Container Defender in a Cluster
- Deploy Prisma Cloud Defender from the GCP Marketplace
- Deploy Defenders as DaemonSets
- VMware Tanzu Application Service (TAS) Defender
- Deploy Defender on Google Kubernetes Engine (GKE)
- Google Kubernetes Engine (GKE) Autopilot
- Deploy Defender on OpenShift v4
-
- Agentless Scanning Modes
-
- Onboard AWS Accounts for Agentless Scanning
- Onboard Azure Accounts for Agentless Scanning
- Configure Agentless Scanning for Azure
- Onboard GCP Accounts for Agentless Scanning
- Configure Agentless Scanning for GCP
- Onboard Oracle Cloud Infrastructure (OCI) Accounts for Agentless Scanning
- Configure Agentless Scanning for Oracle Cloud Infrastructure (OCI)
- Agentless Scanning Results
-
- Rule ordering and pattern matching
- Backup and Restore
- Custom feeds
- Configuring Prisma Cloud proxy settings
- Prisma Cloud Compute certificates
- Configure scanning
- User certificate validity period
- Enable HTTP access to Console
- Set different paths for Defender and Console (with DaemonSets)
- Authenticate to Console with Certificates
- Configure custom certs from a predefined directory
- Customize terminal output
- Collections
- Tags
- Logon settings
- Reconfigure Prisma Cloud
- Subject Alternative Names
- WildFire Settings
- Log Scrubbing
- Clustered-DB
- Permissions by feature
-
- Logging into Prisma Cloud
- Integrating with an IdP
- Integrate with Active Directory
- Integrate with OpenLDAP
- Integrate Prisma Cloud with Open ID Connect
- Integrate with Okta via SAML 2.0 federation
- Integrate Google G Suite via SAML 2.0 federation
- Integrate with Azure Active Directory via SAML 2.0 federation
- Integrate with PingFederate via SAML 2.0 federation
- Integrate with Windows Server 2016 & 2012r2 Active Directory Federation Services (ADFS) via SAML 2.0 federation
- Integrate Prisma Cloud with GitHub
- Integrate Prisma Cloud with OpenShift
- Non-default UPN suffixes
- Compute user roles
- Assign roles
-
- Prisma Cloud Vulnerability Feed
- Scanning Procedure
- Vulnerability Management Policies
- Vulnerability Scan Reports
- Scan Images for Custom Vulnerabilities
- Base images
- Vulnerability Explorer
- CVSS scoring
- CVE Viewer
-
- Configure Registry Scans
- Scan Images in Alibaba Cloud Container Registry
- Scan Images in Amazon Elastic Container Registry (ECR)
- Scan images in Azure Container Registry (ACR)
- Scan Images in Docker Registry v2 (including Docker Hub)
- Scan Images in GitLab Container Registry
- Scan images in Google Artifact Registry
- Scan Images in Google Container Registry (GCR)
- Scan Images in Harbor Registry
- Scan Images in IBM Cloud Container Registry
- Scan Images in JFrog Artifactory Docker Registry
- Scan Images in Sonatype Nexus Registry
- Scan images in OpenShift integrated Docker registry
- Scan Images in CoreOS Quay Registry
- Trigger Registry Scans with Webhooks
- Configure VM image scanning
- Configure code repository scanning
- Malware scanning
- Windows container image scanning
- Serverless Functions Scanning
- VMware Tanzu Blobstore Scanning
- Scan App-Embedded workloads
- Troubleshoot Vulnerability Detection
-
- Compliance Explorer
- Enforce compliance checks
- CIS Benchmarks
- Prisma Cloud Labs compliance checks
- Serverless functions compliance checks
- Windows compliance checks
- DISA STIG compliance checks
- Custom compliance checks
- Trusted images
- Host scanning
- VM image scanning
- App-Embedded scanning
- Detect secrets
- OSS license management
-
- Alert Mechanism
- AWS Security Hub
- Cortex XDR alerts
- Cortex XSOAR alerts
- Email alerts
- Google Cloud Pub/Sub
- Google Cloud Security Command Center
- IBM Cloud Security Advisor
- JIRA Alerts
- PagerDuty alerts
- ServiceNow alerts for Security Incident Response
- ServiceNow alerts for Vulnerability Response
- Slack Alerts
- Splunk Alerts
- Webhook alerts
- API
Admission control with Open Policy Agent
Prisma Cloud provides a dynamic admission controller for Kubernetes and OpenShift that is built on the Open Policy Agent (OPA).
In Console, you can manage and compose rules in Rego, which is OPA’s native query language.
Rules can allow or deny (alert or block) pods.
Console pushes your policies to Defender, which enforces them.
Decisions made by the system are logged.
There is currently no support for Windows.
Open Policy Agent
The Open Policy Agent is an open source, general-purpose policy engine that lets you consolidate policy enforcement in a single place.
OPA can enforce policies in microservices, Kubernetes clusters, CI/CD pipelines, API gateways, and so on.
OPA provides a high-level declarative language called Rego, which lets you specify policy as code.
The OPA APIs let you offload policy decision-making from your software.
OPA decouples policy decision-making from policy enforcement.
When your software needs to make policy decisions, it queries OPA and supplies structured data, such as JSON, as input.
The data can be inspected and transformed using OPA’s native query language Rego.
OPA generates policy decisions by evaluating the query input and against policies and data.
Prisma Cloud operationalizes OPA by:
- Extending Console to manage and compose policies in Rego.
- Integrating OPA’s decision-making library into Defender.
- Connecting Defender’s enforcement capabilities to OPA’s decisions.
Admission webhook
An admission controller is code that intercepts requests to the API server for creating objects.
There are two types of admission controllers: built-in and dynamic.
Prisma Cloud implements a dynamic admission controller.
Dynamic admission controllers are built as webhooks.
After registering to intercept admission requests, they assess requests against policy, and then accept or reject those requests.
In Kubernetes terms, these are known as validating admission webhooks.
The Prisma Cloud validating admission webhook handles the API server’s AdmissionReview requests, and returns decisions in an AdmissionReview object.
When configuring Prisma Cloud, you’ll create a ValidatingWebookConfiguration object, which sets up the Defender service to intercept all create, update, and connect calls to the API server.
The default ValidatingWebookConfiguration provided here sets failurePolicy to Ignore.
The failure policy specifies how your cluster handles unrecognized errors and timeout errors from the admission webhook.
When set to Ignore, the API request is allowed to continue.
Configuring the webhook
Configure the API server to route AdmissionReview requests to Prisma Cloud.
Prerequisites:
- You have a running instance of Prisma Cloud Compute Console.
- You have a Kubernetes cluster. Minimum supported version is v1.16.
- Defender has been deployed to your cluster as a DaemonSet. In Console, you can verify Defenders are running and connected underManage > Defenders > Manage.
- Go toDefend > Access > Admission
- Enable admission control.
- Click theAdmission controllerlink andCopy configurationand save it to a file. Nme this file webhook.yaml.If the Defender CA has been rotated and the old certificate still hasn’t expired, you may have Defenders using an old certificate. For daemonset which its Defenders are using an old certificate, you need to retrieve the old Defender CA certificate from the daemonset yaml file you deployed this daemonset with.Search for defender-ca.pem within the daemonset yaml, copy its content, then paste it to replace the content of the caBundle field of the webhook. If defender-ca.pem doesn’t exist in the daemonset yaml, use the content of the ca.pem field.If you don’t have the yaml file you used to deploy the daemonset, you can retrieve the old CA bundle from the Console certificates folder under old-defender-ca.pem.To identify whether your Defenders are using an old certificate, see Console-Defender communication certificates.
- Create the webhook configuration object.$ kubectl apply -f webhook.yamlAfter creating the object, the Kubernetes API server directs AdmissionReview requests to Defender.
Validating your setup
Validate that your webhook has been properly set up with one of the predefined admission rules.
The order in which the rules appear is the order in which they are evaluated.
Higher rules take precedence over lower rules.
Rules can be reordered.
Use the hamburger icon to drag and drop rules into the right place.
Notice that the processing of rules stops at the first match. To make sure the severe action will be taken in a case of more than one rule match, place the rules with action "Block" first.
- Navigate toDefend > Access > Admissionand verify there exist default admission rules and they are all enabled by default.
- Create the following YAML file to test theTwistlock Labs - CIS - Privileged pod createdrule.
- Create the following YAML file:priv-pod.yamlapiVersion: v1 kind: Pod metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 securityContext: privileged: true
- Create the privileged pod.$ kubectl apply -f priv-pod.yamlVerify an audit is created underMonitor > Events > Admission Audits.Clean up. Delete the pod.kubectl delete -f priv-pod.yaml
Creating custom admission rulesUse Rego syntax to create custom rules. To learn more about the syntax, review the predefined rules that ship with Prisma Cloud. Rules scripts are based on the admission review input JSON structure. For more information, see: https://github.com/kubernetes/api/blob/master/admission/v1beta1/types.go.ExamplesThe following examples should give you some ideas about how you can create your own policies by using the Rego language.Do not allow new namespaces to be created:match[{"msg": msg}] { input.request.operation == "CREATE" input.request.kind.kind == "Namespace" msg := "It's not allowed to create new namespace!" }Do not allow a specific image (for example nginx) in new pods:match[{"msg": msg}] { input.request.operation == "CREATE" input.request.kind.kind == "Pod" input.request.resource.resource == "pods" input.request.object.spec.containers[_].image == "nginx" msg := "It's not allowed to use the nginx Image!" }Do not allow new pods to expose TCP port 80:match[{"msg": msg}] { input.request.operation == "CREATE" input.request.kind.kind == "Pod" input.request.resource.resource == "pods" input.request.object.spec.containers[_].ports[_].containerPort == 80 msg := "It's not allowed to use port 80 (HTTP) with a Pod configuration!" }Control the scope of your the policy rules by checking the object’s metadata, such as namespace or labels.match[{"msg": msg}] { input.request.operation == "CREATE" input.request.kind.kind == "Pod" input.request.resource.resource == "pods" input.request.object.metadata.namespace == "sock-shop" not input.request.metadata.labels.owner msg := "Pod in namespace sock-shop is missing the owner label" }