Skip to content

Conversation

@billyjbryant
Copy link

@billyjbryant billyjbryant commented Oct 9, 2025

Background

This PR adds support for managing all four types of Panther detections as Terraform resources. This is part of breaking up the larger PR (#59) into smaller, more focused PRs as requested in the review feedback at #59 (comment).

Changes

This PR implements all four detection resource types available in Panther:

1. Rule Resource (panther_rule)

  • Standard Python-based detection rules for log analysis
  • Uses log_types array to specify which logs to analyze
  • Python body field contains the rule logic
  • Includes dedup_period_minutes, threshold, runbook fields

2. Policy Resource (panther_policy)

  • Python-based policies for cloud resource compliance
  • Uses resource_types array to specify which resources to check
  • Python body field contains the policy logic
  • Simpler schema - no dedup/threshold/runbook fields

3. ScheduledRule Resource (panther_scheduled_rule)

  • Python-based rules that analyze scheduled query results
  • Uses scheduled_queries array instead of log_types
  • Python body field evaluates aggregated query results
  • Includes dedup_period_minutes, threshold, runbook fields

4. SimpleRule Resource (panther_simple_rule)

  • YAML-based detection rules requiring no Python knowledge
  • Uses detection field with YAML syntax (compiles to Python automatically)
  • Uses log_types like standard Rule
  • Includes SimpleRule-specific fields: alert_context, alert_title, dynamic_severities, group_by, inline_filters
  • Read-only python_body field shows compiled Python code

Implementation Details

  • REST Client Implementation:

    • Added types for all four detection resources
    • Implemented REST endpoints at /rules, /policies, /scheduled-rules, /simple-rules
    • Proper error handling and response parsing for each type
  • Generated Schema:

    • Using OpenAPI-generated schemas with proper validation
    • Generated in resource_*/resource_gen.go directories
    • ID fields added manually with proper configuration
  • Configuration Files:

    • Updated generator_config.yml to include all detection resources
    • Updated provider-code-spec.json with all schemas
  • Comprehensive Documentation:

    • Full resource documentation for each type
    • Examples demonstrating realistic use cases
    • Updated full-examples/detection-rules with all four types
  • Test Coverage:

    • Proper tests for each resource type based on actual schemas
    • Tests validate resource-specific fields (not just copying rule tests)
    • All tests passing

Testing

  • go build successful
  • ✅ All resource files generated correctly
  • ✅ REST client methods implemented for all types
  • ✅ Provider registers all detection resources
  • ✅ Documentation generated successfully
  • Acceptance tests included for all resources (requires PANTHER_API_URL and PANTHER_API_TOKEN)

Related

Part of breaking up #59 into focused PRs:

AI Usage

This PR was developed with assistance from Claude Code for:

  • Schema validation and type definitions based on OpenAPI specs
  • Test creation with proper field validation for each type
  • Documentation structure and examples
  • Commit message formatting

Implements REST-based rule resource with full CRUD operations:

## New Resource Added:
- **panther_rule**: REST-based detection rule management using generated schema

## Key Features:
- Full CRUD operations (Create, Read, Update, Delete)
- Import support using rule IDs
- Generated schema from OpenAPI specification
- Support for all rule fields including tests, severity levels, log types
- Deduplication period and threshold configuration
- Tag and report management
- Runbook and summary attributes

## Client Implementation:
- Added Rule types to REST client interface
- Implemented REST endpoints at /rules
- Added Rule, CreateRuleInput, and UpdateRuleInput types
- Generic doRuleRequest helper for clean REST calls

## Code Generation:
- Updated generator_config.yml to include rule resource
- Updated provider-code-spec.json with rule schema
- Generated rule_resource_gen.go with complete schema validation

## Documentation:
- Added comprehensive docs/resources/rule.md
- Included detection-rules examples with main.tf, outputs.tf, rules.tf
- Added panther_rule resource example

## Testing:
- Included resource_rule_test.go for acceptance testing
- Provider successfully builds with new rule resource

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
billyjbryant and others added 2 commits October 9, 2025 16:45
Add Policy resource for managing Panther policies (cloud resource detection rules) using the REST API. Policies are similar to Rules but analyze cloud resources instead of logs.

Key changes:
- Add Policy types and REST methods to client
- Add generator config for policy, scheduled_rule, and simple_rule resources
- Implement panther_policy resource with CRUD operations
- Generate schema files for all detection resource types
- Manually add Id field to generated model structs (workaround for generator limitation)

Policies differ from Rules:
- Use ResourceTypes instead of LogTypes
- Simpler schema (no dedupPeriodMinutes, threshold, runbook, etc.)
- Include Suppressions field for ignoring specific resources

Also prepared infrastructure for scheduled_rule and simple_rule resources (types and client methods added, but resource implementations deferred to future work).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds two additional detection resource types to complement Rule and Policy:

- ScheduledRule: Detection rules that run on scheduled query results
  - Uses scheduled_queries instead of log_types
  - Analyzes aggregated data from scheduled queries
  - Includes dedup_period_minutes and threshold fields

- SimpleRule: YAML-based detection rules with no Python required
  - Uses detection field with YAML syntax instead of Python body
  - Compiles to Python automatically (read-only python_body field)
  - Includes SimpleRule-specific fields: alert_context, alert_title, dynamic_severities, group_by, inline_filters
  - Uses log_types like standard Rule

Also adds comprehensive test coverage for Policy, ScheduledRule, and SimpleRule resources with proper field validation based on actual schemas.

Includes documentation and examples demonstrating all four detection resource types with realistic use cases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@billyjbryant billyjbryant changed the title feat: Add panther_rule resource for detection rule management feat: Add detection resources (Rule, Policy, ScheduledRule, SimpleRule) Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant