Skip to content

Commit ba025b9

Browse files
Copilotfproulx-boostsecurityclaude
authored
Add documentation for custom Rego rules (#363)
Document how to use custom Rego rules with poutine by: - Adding a Custom Rules section to README.md with configuration instructions and a complete working example - Enhancing .poutine.sample.yml with detailed comments and examples for the include directive This addresses user requests for clarification on writing and using custom rules at runtime. Fixes #255 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: François Proulx <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent c861b1b commit ba025b9

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.poutine.sample.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Include custom Rego rules from specified directories
2+
# Each path should contain *.rego files with package names following: package rules.<rule_name>
3+
# For more details, see: https://github.com/boost-rnd/poutine-rules
4+
# default: []
5+
# include:
6+
# - path: ./custom_rules
7+
# - path: ./github_actions
8+
19
# When using analyze_org, ignore forked repositories in the organization
210
# default: false
311
ignoreForks: true

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,83 @@ poutine analyze_org my-org/project --token "$GL_TOKEN" --scm gitlab --scm-base-u
117117

118118
See [.poutine.sample.yml](.poutine.sample.yml) for an example configuration file.
119119

120+
### Custom Rules
121+
122+
`poutine` supports custom Rego rules to extend its security scanning capabilities. You can write your own rules and include them at runtime.
123+
124+
#### Configuration
125+
126+
Create a `.poutine.yml` configuration file in your current working directory, or use a custom path with the `--config` flag:
127+
128+
```bash
129+
poutine analyze_local . --config my-config.yml
130+
```
131+
132+
In your configuration file, specify the path(s) to your custom rules using the `include` directive:
133+
134+
```yaml
135+
include:
136+
- path: ./custom_rules
137+
- path: ./github_actions
138+
```
139+
140+
#### Writing Custom Rules
141+
142+
Custom Rego rules must:
143+
1. Be saved as `*.rego` files in the included directory
144+
2. Follow the package naming convention: `package rules.<rule_name>`
145+
3. Define a `rule` variable with metadata
146+
4. Define a `results` set containing findings
147+
148+
**Example custom rule:**
149+
150+
```rego
151+
package rules.custom_injection
152+
153+
import data.poutine
154+
import rego.v1
155+
156+
# METADATA
157+
# title: Custom Injection Detection
158+
# description: Detects potential injection vulnerabilities in workflows
159+
# custom:
160+
# level: warning
161+
162+
rule := poutine.rule(rego.metadata.chain())
163+
164+
# Define pattern to detect (properly escaped for Rego)
165+
patterns.github contains `\\$\\{\\{[^\\}]+\\}\\}`
166+
167+
results contains poutine.finding(rule, pkg.purl, {
168+
"path": workflow.path,
169+
"line": step.lines.run,
170+
"job": job.id,
171+
"step": i,
172+
"details": "Potential injection found in step",
173+
}) if {
174+
pkg := input.packages[_]
175+
workflow := pkg.github_actions_workflows[_]
176+
job := workflow.jobs[_]
177+
step := job.steps[i]
178+
step.run # Ensure step has a run command
179+
regex.match(patterns.github[_], step.run)
180+
}
181+
```
182+
183+
**Key points:**
184+
- Use `import data.poutine` and `import rego.v1` for modern Rego syntax and poutine utilities
185+
- Use `rule := poutine.rule(rego.metadata.chain())` to extract metadata from METADATA comments
186+
- The `package` name determines the rule identifier (e.g., `package rules.custom_injection` → rule ID: `custom_injection`)
187+
- Add METADATA comments to describe the rule with `title`, `description`, and `level`
188+
- Set the severity `level` to `note`, `warning`, or `error`
189+
- Use `poutine.finding(rule, pkg.purl, {...})` to create findings that match the poutine schema
190+
- The `results` set should contain findings with fields like `path`, `line`, `job`, `step`, `details`
191+
192+
For more examples, see:
193+
- [poutine-rules repository](https://github.com/boost-rnd/poutine-rules) - External rule examples
194+
- Built-in rules in [opa/rego/rules/](./opa/rego/rules/) directory
195+
- [.poutine.sample.yml](.poutine.sample.yml) - Configuration examples
196+
120197
## AI Coding Assistant Integration (MCP)
121198

122199
`poutine` can be integrated with AI coding assistants like Claude Code, Gemini, etc. through the Model Context Protocol (MCP). This allows AI assistants to analyze repositories and validate CI/CD pipelines directly from your development environment.

0 commit comments

Comments
 (0)