Outcome: After this guide, you can create AI-powered threat monitors that detect security scenarios in real-time using natural language descriptions.
Prerequisites: SSH or Kubernetes Resources configured, Formal API key.
Overview
Formal’s AI Monitors use large language models to detect security threats in SSH and Kubernetes sessions based on natural language descriptions. Instead of writing complex regex patterns or code, you describe the threat scenario in plain English, and Formal’s AI analyzes session activity in real-time. When a scenario is detected, it appears ininput.detected_scenarios and can trigger policy actions like blocking, alerting, or requiring MFA.
How It Works
- Create a scenario monitor with a natural language description of the threat
- AI analyzes sessions in real-time (SSH commands, Kubernetes operations)
- Scenario detection populates
input.detected_scenarios[]array - Policy enforcement takes action when scenarios are detected
Creating Monitors
Via Formal Console
Navigate to AI Monitors in the Formal console and click Create:- Name: Identifier for the scenario (e.g.,
ssh_curl_to_bash) - Description: Natural language description of the threat
- Status:
Activeto enable detection, orInactiveto disable
Example Scenarios
Prevent Secrets Exfiltration
Name:prevent_secrets_exfil
Description:
Jailbreak Detection
Name:jailbreak
Description:
Prevent PR Review Manipulation
Name:prevent_pr_review
Description:
SSH Curl to Bash
Name:ssh_curl_to_bash
Description:
Via API
Use theCreateScenarioMonitor endpoint to create scenarios programmatically:
- curl
- JavaScript
- Python
Using Scenarios in Policies
Once a scenario monitor is active, detected scenarios appear in theinput.detected_scenarios array during policy evaluation.
Block Detected Threats
Quarantine for Review
Quarantine pauses the session and requires admin approval to continue. Use
for scenarios requiring human review.
Require MFA for Risky Actions
Alert on Suspicious Activity
Policy Actions
Available actions when scenarios are detected:| Action | Description | Use Case |
|---|---|---|
allow | Permit with logging | Monitoring and alerting |
block | Deny immediately | Known threats |
quarantine | Pause for review | Suspicious activity requiring human judgment |
mfa | Require MFA challenge | Risky but potentially legitimate actions |
Best Practices
Be Specific
Be Specific
Provide clear context and specific examples in scenario descriptions. Instead of “detect suspicious commands,” write “detect commands that attempt to access /etc/shadow or other password files.”
Test Before Enforcing
Test Before Enforcing
Start with
allow action and logging to validate detection accuracy before
blocking or quarantining.Use Quarantine for Judgment Calls
Use Quarantine for Judgment Calls
For scenarios where you need human review (like detecting potential data
exfiltration), use
quarantine rather than immediate blocking.Combine with Traditional Policies
Combine with Traditional Policies
Use AI scenario monitoring alongside traditional Rego policies for defense in
depth. AI handles complex patterns; Rego handles precise rules.
Monitor Performance
Monitor Performance
Review detected scenarios regularly to tune descriptions and reduce false positives.
Troubleshooting
Scenario not detecting expected threats
Scenario not detecting expected threats
Possible causes:
- Scenario description is too vague or ambiguous
- Status is set to
inactive - Session type doesn’t match (e.g., database sessions vs. SSH)
- Make description more specific with concrete examples
- Verify status is
active - Ensure scenario is appropriate for the resource type (SSH/K8s only)
Too many false positives
Too many false positives
Possible causes:
- Description is too broad
- Lacks sufficient context
- Add specific exclusions to the description (e.g., “but not in login forms”)
- Provide more context about legitimate vs. malicious behavior
- Use
quarantineto review borderline cases before blocking
detected_scenarios array is empty
detected_scenarios array is empty
Possible causes:
- No active scenario monitors
- Policy evaluated before scenario analysis completed
- Resource type doesn’t support scenario monitoring
- Verify scenarios exist and are
active - Check that resource technology is SSH or Kubernetes
- Review session logs to confirm AI analysis ran