This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Panther Analysis repository, containing security detection rules, policies, queries, and supporting infrastructure for the Panther SIEM platform. The codebase is built around a dual-file architecture using Python (.py) and YAML (.yml) files for each detection.
make test- Run all tests (unit tests + panther_analysis_tool tests)pipenv run panther_analysis_tool test- Run all detection testspipenv run panther_analysis_tool test --path rules/aws_cloudtrail_rules/- Test specific pathpipenv run panther_analysis_tool test --filter Severity=Critical- Test by severitypipenv run panther_analysis_tool test --filter LogTypes=AWS.GuardDuty- Test by log typemake global-helpers-unit-test- Run unit tests for global helpersmake data-models-unit-test- Run unit tests for data models
make lint- Run all linters (pylint, bandit, isort, black)make fmt- Format code using isort and blackmake run-pre-commit-hooks- Run pre-commit hooks on all files
make install- Install all dependenciesmake install-pre-commit-hooks- Install git pre-commit hookspipenv shell- Activate virtual environment
pipenv run panther_analysis_tool zip- Create zip file of detectionspipenv run panther_analysis_tool zip --filter Severity=Critical- Zip critical detections onlypipenv run panther_analysis_tool upload --api-key KEY --api-host HOST- Upload to Panther instance
- Rules (
/rules/): Analyze logs to detect malicious activity - Policies (
/policies/): Check cloud resource configurations for compliance - Queries (
/queries/): Scheduled queries and signals for threat hunting - Correlation Rules (
/correlation_rules/): Multi-step attack pattern detection
Every detection consists of two files:
.pyfile: Contains the detection logic (requiredrule()orpolicy()function).ymlfile: Contains metadata, configuration, and unit tests
Reusable utility functions organized by platform:
panther_base_helpers: Core utilities and common functionspanther_aws_helpers: AWS-specific helper functions- Platform-specific helpers:
panther_okta_helpers,panther_github_helpers, etc.
Normalize log data across different sources with field mappings and transformations.
Group related detections for deployment. Each pack is a YAML file listing detection IDs.
def rule(event):
# Main detection logic (required)
return boolean_condition
def title(event):
# Dynamic alert title (optional)
return "Alert title"
def alert_context(event):
# Additional context (optional)
return {"key": "value"}
def severity(event):
# Dynamic severity (optional)
return "HIGH"Always use safe field access methods:
event.get('field', default)event.deep_get('nested', 'field', default=None)- Helper functions from
panther_base_helpers
Every detection must include test cases in the YAML file:
Tests:
- Name: "Test description"
ExpectedResult: true
Log: {...}Import and use global helpers via GlobalID:
from panther_base_helpers import panther_base_helpers
from panther_aws_helpers import aws_rule_context- RuleID:
LogType.Source.DetectionName(e.g., "AWS.CloudTrail.Created") - Filename: Snake case matching detection purpose
- DisplayName: Human-readable description in title case
- Rules grouped by log source:
aws_cloudtrail_rules/,okta_rules/, etc. - Policies grouped by service:
aws_iam_policies/,aws_s3_policies/, etc. - Queries grouped by platform:
aws_queries/,crowdstrike_queries/, etc.
AnalysisType: "rule", "policy", or "scheduled_rule"Filename: Must match the Python filenameRuleID/PolicyID: Unique identifierDisplayName: Human-readable nameEnabled: Boolean flagLogTypes: Array of log types (for rules)ResourceTypes: Array of resource types (for policies)Severity: "INFO", "LOW", "MEDIUM", "HIGH", or "CRITICAL"
- Include both positive and negative test cases
- Test edge cases and error conditions
- Use realistic log samples from actual sources
- Validate alert context and title generation
- Python 3.11 compatibility
- Black formatting (line length 100)
- Pylint compliance
- Use of type hints where appropriate
- Comprehensive docstrings for complex functions
- Never hardcode credentials or secrets
- Implement proper error handling for external API calls
- Follow principle of least privilege in helper functions