This feature is only available on Chainloop’s platform paid plans.
Overview
Chainloop provides a set of built-in policies that enforce pull request quality standards in your CI/CD pipeline. These policies evaluate PR metadata automatically gathered by the Chainloop CLI and can act as control gates to block workflows when requirements aren’t met. When used as control gates, PR policies help ensure:- Code reviews are properly conducted
- PRs have meaningful descriptions and linked issues
- Security requirements like code owner approval are satisfied
- Conversation resolution and stale review dismissal rules are followed
Available PR Policies
The following PR policies are available:| Policy Name | Description |
|---|---|
pr-review-required | Ensures PRs require a minimum number of reviewers before merging |
pr-code-owner-review-required | Verifies that code owners have reviewed and approved changes |
pr-conversation-resolution-required | Checks that all PR conversations are resolved before merging |
pr-description-required | Ensures PRs have meaningful descriptions |
pr-stale-reviews-dismissed | Verifies that stale reviews are dismissed when new commits are pushed |
pr-user-story-linked | Ensures PRs reference a user story or issue for traceability |
How It Works
- Automatic PR Detection: The Chainloop CLI automatically detects when running in a pull request context and gathers PR metadata
- Material Collection: PR information is collected as a
CHAINLOOP_PR_INFOmaterial type - Policy Evaluation: Attached PR policies evaluate the gathered metadata
- Control Gate: If a policy is configured as a gate and fails, the workflow is blocked (exit code != 0)
Quick Start
Prerequisites
- Chainloop CLI Enterprise Edition (EE) with runner context gathering enabled
- A GitHub or GitLab access token configured (see Runner Context guide)
- A workflow contract configured in Chainloop
Step 1: Create a Contract with PR Policies
Create a workflow contract that includes PR policies attached with thegate: true flag:
pr-quality-gate.contract.yaml
Step 2: Set Up GitHub Workflow
Configure your GitHub Actions workflow to use the Chainloop CLI with runner context gathering:.github/workflows/pr-quality-gate.yml
Step 3: Configure Control Gate Enforcement
Enable control gate enforcement at the organization level or per-policy:- Organization-wide
- Per-policy (in contract)
Policy Configuration Examples
Example 1: Branch-specific Review Requirements
Require different numbers of reviewers based on target branch:Example 2: Enforce Conversation Resolution
Ensure all PR discussions are resolved before merge:Example 3: Require Meaningful PR Descriptions
Enforce PR descriptions with specific sections:Example 4: Ensure Stale Reviews Are Dismissed
Verify that old approvals are dismissed when new code is pushed:Handling Policy Failures
When a PR policy control gate fails:- The workflow is blocked:
chainloop attestation pushreturns a non-zero exit code - The attestation is still recorded: Chainloop tracks the non-compliant activity for audit purposes
- Developers see clear error messages: Policy violations are displayed in the CLI output
Bypassing Control Gates (Emergency Use)
In urgent situations (hotfixes, false positives), you can bypass control gates:Best Practices
- Start with non-blocking policies: Test policies without
gate: truefirst to ensure they work as expected - Use branch-specific requirements: Apply stricter rules to production branches (main, release/*) and lighter rules to development branches
- Combine multiple policies: Use multiple PR policies together for comprehensive quality checks
- Monitor policy violations: Review Chainloop’s UI regularly to identify patterns in policy failures
- Document bypass procedures: Establish clear guidelines for when and how to use
--exception-bypass-policy-check - Keep policies updated: Review and adjust policy parameters based on team feedback and compliance requirements
Troubleshooting
PR Info Not Being Gathered
Problem: TheCHAINLOOP_PR_INFO material is not being collected automatically.
Solutions:
- Ensure you’re using Chainloop CLI Enterprise Edition (EE)
- Check that the workflow is triggered by a pull request event
Policy Always Passes Despite Invalid PR State
Problem: Policy evaluates successfully even when PR doesn’t meet requirements. Solutions:- Verify the policy’s
branchesparameter includes the target branch - Check that the PR metadata is being gathered correctly (inspect attestation in Chainloop UI)
- Review policy parameters in the contract’s
withsection - Ensure the policy is compatible with your CI/CD platform (GitHub vs GitLab)
Control Gate Not Blocking Workflow
Problem: Workflow continues even when policy fails. Solutions:- Verify
gate: trueis set in the policy attachment - Check organization-wide enforcement settings (
chainloop org describe) - Ensure you’re not using
--exception-bypass-policy-checkflag - Confirm the workflow doesn’t have error handling that catches the non-zero exit code
