Cedar Syntax¶
Cedar is a policy language that uses a declarative syntax to express authorization rules. This guide covers the Cedar syntax as used in PipelineConductor.
Basic Structure¶
Effects¶
Permit¶
Allow an action when conditions are met:
Forbid¶
Deny an action when conditions are met:
forbid(
principal,
action == Action::"merge",
resource
)
when {
context.hasVulnerabilities == true
};
Principal, Action, Resource¶
In PipelineConductor:
- Principal - Always the CI system (
CISystem::"pipelineconductor") - Action - The CI/CD action being evaluated
- Resource - The repository being scanned
Use wildcards to match any:
// Match any principal, action, or resource
permit(principal, action, resource);
// Match specific action
permit(principal, action == Action::"build", resource);
Conditions¶
Boolean Comparisons¶
Numeric Comparisons¶
String Comparisons¶
Set Operations¶
Check if a set contains a value:
Check if a set contains any of several values:
Check if a set contains all values:
Logical Operators¶
AND (implicit when on separate lines, explicit with &&):
OR:
NOT:
Parentheses for Grouping¶
when {
(context.hasRenovate == true || context.hasDependabot == true) &&
context.hasVulnerabilities == false
};
Comments¶
// Single-line comment
/*
* Multi-line
* comment
*/
permit(
principal,
action == Action::"merge", // Merge action
resource
);
Multiple Policies¶
Multiple policies in a file are evaluated together:
// Policy 1: Require workflow
forbid(
principal,
action == Action::"merge",
resource
)
when {
context.hasWorkflow == false
};
// Policy 2: Block vulnerable repos
forbid(
principal,
action == Action::"merge",
resource
)
when {
context.hasVulnerabilities == true
};
// Policy 3: Allow when compliant
permit(
principal,
action == Action::"merge",
resource
)
when {
context.hasWorkflow == true &&
context.hasVulnerabilities == false
};
Policy Evaluation¶
Cedar policies are evaluated using a default-deny model:
- If any
forbidpolicy matches → Denied - If any
permitpolicy matches → Allowed - If no policies match → Denied (default)
Forbid Takes Precedence
If both permit and forbid policies match, forbid wins.
Type Reference¶
| Type | Examples |
|---|---|
| Boolean | true, false |
| Long | 0, 90, 365 |
| String | "ubuntu-latest", "myorg" |
| Set | ["a", "b"], context.languages |
| EntityUID | Action::"merge", Repository::"org/repo" |
Best Practices¶
- Use comments - Explain the intent of each policy
- Be specific - Target specific actions rather than using wildcards
- Test policies - Use
validatecommand before deploying - Group related policies - Organize by domain (security, CI, dependencies)
- Prefer forbid for security - Explicitly deny risky conditions