Create a new custom detection rule
Create a custom detection rule for cloud workload security risks.
Creating Custom Detection Rules gives you the flexibility to define and enforce security best practices tailored to your organization's objectives. Use them to detect the conditions, misconfigurations, and policy violations that matter to your organization but are not covered by the built-in rules that ship with Cortex Cloud.
Before you begin
Ensure you have a custom compliance control defined to associate the Custom Detection Rule to. For more information, see Use a built-in or custom standard.
How to create a custom detection rule
Go to Posture Management → Rules & Policies → Rules → Cloud Workload.
In the Cloud Workload Rules page, select Create Custom Rule.
Enter the following settings:
Rule name: A descriptive name for the custom rule.
Description: An optional field for adding additional details or context about the rule, such as its purpose or intended behavior.
Select a Scanner. A scanner determines the rule language, rule input, and assets that the rule can inspect.
Use the following table to select a scanner:
Agentless disk scan
Rego
File content and metadata for each file you declare
Inspect disk-image files, such as /etc/ssh/sshd_config or /etc/shadow
Kubernetes connector
Rego
The Kubernetes resource object being evaluated
Inspect Kubernetes resources, such as Deployments, Services, and RBAC roles
XDR agent
Python
Data that the script reads directly from the host
Run read-only Python scripts for custom host checks
Configure the scanner-specific settings:
Define Compliance Violation Severity of the compliance violation to ensure proper categorization and prioritization. Possible values are:
Critical
High
Medium
Low
Informational
Assign Compliance Controls to one or more existing compliance controls.
a. Click Add. b. Select a custom compliance control from the list. c. Click Assign.
For Remediation, you can optionally define the remediation steps to address any detected misconfiguration.
Select Create. The new rule appears in the Rules List. You can now use the rule as a check to either create an issue or monitor adherence to a specific requirement.
Create an issue
Under Posture Management → Policies → Cloud Workload, add the Custom Detection Rule to a Policy. This policy automatically runs the rule and creates an issue if the check fails.
Monitor compliance adherence
Under Posture Management → Compliance → Catalogs → Standards, create a custom standard that includes the custom control associated with the Custom Detection Rule, and then create an assessment profile that runs the custom standard. You can then monitor the compliance results in a report.
For detailed information, see Monitor and track compliance adherence.
Troubleshooting
The rule runs but does not produce a finding or report an error.
The rule accesses the scanner input using an incorrect structure.
Verify the input structure for the scanner. For Agentless Disk Scan, access files through input.files[id] and use fields such as f.path and f.content. For Kubernetes Connector, access the Kubernetes resource directly through fields such as input.kind, input.metadata, and input.spec.
A file permission comparison does not match the expected value.
The expected permission value is expressed in octal rather than decimal.
Convert the permission value to decimal. For example, 0600 is 384 and 0644 is 420.
The rule fails validation and cannot be saved.
The rule is missing one or more required elements.
Ensure that the rule declares package panw.compliance, imports rego.v1, and defines at least one match rule.
A directory check does not produce a finding.
The rule attempts to evaluate file content for a directory.
Check the file type before evaluating content. For example, use f.metadata.file_type == "file" to limit the logic to regular files.
A Python rule always passes.
The run function returns None or does not return a result value.
Return {"result": False, "cause": "<description>"} when a violation is detected. Return {"result": True} when the check passes.
A Python rule reports an error during execution.
The script does not define the required run function, or the script encounters an error during execution.
Define run(*args, **kwargs) as the entry point and verify that the script executes successfully using supported, read-only operations.
Last updated
Was this helpful?
