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 configured, Formal API key, with an AI provider configured; optionally an deployed and linked to the connector.
Overview
Formal’s Session 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.triggered_monitors and can trigger 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 adds an entry to the
input.triggered_monitorsarray - Policy enforcement takes action when scenarios are detected
name, as described in Using Scenarios in Policies.
Creating Monitors
Via Control Plane
Navigate to Session Monitors in the Control Plane 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.triggered_monitors array during policy evaluation. Each entry is an object:
Match on
name. SSH and Kubernetes sessions only set name, so id and reason are empty there.
Block Detected Threats
Quarantine the User
Quarantine ends every active session of the user and blocks the user. The
user can’t open SSH, Kubernetes, or RDP sessions until an admin clicks
Unblock User on the user’s page. See
Quarantine Action.
Require MFA for Risky Actions
Alert on Suspicious Activity
Policy Actions
Available actions when scenarios are detected: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.Reserve Quarantine for Serious Threats
Reserve Quarantine for Serious Threats
quarantine locks the user out of SSH, Kubernetes, and RDP until an admin
unblocks them. Use it when access should resume only after human review, such
as potential data exfiltration. Use suspend to end one session without
locking the user out.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
allowwith areasonto log borderline cases before enforcing
triggered_monitors array is empty
triggered_monitors 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