Bulwark|Docs

Rule Conditions

Rules are the building blocks of policies. Each rule specifies a field to check, an operator, and a value to compare against.

Available Fields

Tool Information

FieldDescriptionExample Values
tool_nameThe name of the tool being calledBash, Edit, Write, Read
hook_event_nameThe type of hook eventpreToolUse, postToolUse

Tool Input Fields

Access nested values using dot notation:

FieldDescriptionExample
tool_input.commandBash command being runrm -rf ./tests
tool_input.file_pathFile being accessed/etc/passwd
tool_input.contentContent being writtenFile contents
tool_input.patternGlob pattern**/*.ts

Context Fields

FieldDescriptionExample
cwdCurrent working directory/Users/dev/project
session_idCurrent session IDabc-123

Operators

String Operators

OperatorDescriptionExample
equalsExact matchtool_name equals "Bash"
not_equalsNot an exact matchtool_name not_equals "Read"
containsSubstring matchtool_input.command contains "rm"
not_containsDoes not containcwd not_contains "node_modules"
starts_withPrefix matchtool_input.file_path starts_with "/etc"
ends_withSuffix matchtool_input.file_path ends_with ".env"
matchesRegex matchtool_input.command matches "rm.*-rf"

List Operators

OperatorDescriptionExample
inValue is in listtool_name in ["Bash", "Edit", "Write"]
not_inValue is not in listtool_name not_in ["Read", "Glob"]

Existence Operators

OperatorDescriptionExample
existsField is presenttool_input.file_path exists
not_existsField is not presenttool_input.timeout not_exists

Combining Rules

AND Logic

All rules must match:

tool_name equals "Bash"
AND
tool_input.command contains "rm"
AND
cwd contains "production"

OR Logic

Any rule can match:

tool_input.file_path ends_with ".env"
OR
tool_input.file_path ends_with ".secret"
OR
tool_input.file_path contains "credentials"

Nested Groups

Combine AND and OR for complex conditions:

(tool_name equals "Bash" AND tool_input.command contains "rm")
OR
(tool_name equals "Write" AND tool_input.file_path contains "config")

Common Patterns

Block Destructive Commands

tool_name equals "Bash"
AND
tool_input.command matches "(rm|rmdir|del).*(-rf|-r|-f)"

Protect Sensitive Files

tool_input.file_path matches "\.(env|secret|key|pem)$"
OR
tool_input.file_path contains "credentials"
OR
tool_input.file_path contains "password"

Restrict by Directory

cwd starts_with "/var/www/production"
AND
tool_name in ["Edit", "Write", "Bash"]

Warning

Regex patterns use standard regex syntax. Test your patterns carefully to avoid unintended matches.