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:
All policies support both GitHub and GitLab.
The code review policies (
pr-review-required, pr-code-owner-review-required, pr-conversation-resolution-required and pr-stale-reviews-dismissed) check the repository settings (branch protection rules and rulesets on GitHub, protected branches and approval settings on GitLab), not the pull request itself. They read the runner context, which you gather with chainloop gather-runner-context (see the quick start below). To check the approvals of the pull request, use pr-min-approvals, which reads the PR metadata. The description, user story and bot author policies read the PR metadata too. For what each code review policy checks and the setting to change when it fails, see SCM Protection Policies.
The Chainloop CLI collects PR metadata only for
pull_request and pull_request_target events on GitHub. To read the review states it needs GITHUB_TOKEN in the environment of the step (env: GITHUB_TOKEN: ${{ github.token }}, with the pull-requests: read permission). On GitLab the CLI does not collect merge request approvals, so pr-min-approvals reports 0 approvals for merge requests collected by the CLI.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 configured in GitHub Actions or GitLab CI
- A workflow contract configured in Chainloop with PR policies attached that runs in PR or MR events
- Chainloop CLI Enterprise Edition and a token to read the repository settings, see CI/CD Runner Context
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
gather-runner-context step needs a token that can read the repository settings. The default GITHUB_TOKEN cannot read classic branch protection, so use a GitHub App or a personal access token. See CI/CD Runner Context for the permissions, and for GitLab. The permissions of the job in the example include contents: read and pull-requests: read.
The branches input of the code review policies selects which repository branches’ protection settings are checked. It is not the target branch of the pull request. Use the same patterns in --branches so that the collected data includes those branches. * does not cross / (release/* matches release/1.0), ** does.
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 approvals in the protection settings of each 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:Gating Bot-Authored PRs
In addition to enforcing quality on human PRs, you can use Chainloop to verify and gate bot-authored PRs from tools like Dependabot or Renovate. This ensures only approved bots can create PRs in your repository and provides an attestation trail for automated dependency updates.How Bot Detection Works
- GitHub
- GitLab
GitHub bot accounts have a platform-reserved
[bot] suffix (e.g., dependabot[bot], renovate[bot]) and a type: "Bot" field on the user object. The Chainloop CLI detects this automatically during attestation init when running in a pull request context.The approach uses two layers of defense:- Workflow trigger: A GitHub Actions workflow triggers for any bot-authored PR using
github.event.pull_request.user.type == 'Bot' - Policy gate: The
pr-bot-author-allowedpolicy restricts which specific bots are permitted. An unrecognized bot triggers the workflow but fails the policy gate.
Recommended Setup for Renovate on GitLab
If you use self-hosted Renovate on GitLab, choose one of these approaches so thepr-bot-author-allowed policy works correctly:
- Option A: GitLab Service Account (Preferred)
- Option B: Project or Group Access Token
Provision the Renovate user as a GitLab service account (requires GitLab 16.1+, Premium or Ultimate). Service accounts have
author.bot = true automatically, so the policy detects them as bots without additional configuration.- Create a service account via the GitLab Groups API
- Generate a personal access token for the service account
- Configure Renovate to authenticate with that token
- No
allowed_botsoverride is needed — the default policy configuration works
Contract
bot-pr-gate.contract.yaml
CI Configuration
- GitHub Actions
- GitLab CI
.github/workflows/bot-pr-attestation.yml
pr-bot-author-allowed policy supports both string-based author names (e.g., "dependabot[bot]") and structured author objects with explicit bot type detection, ensuring backwards compatibility with existing attestations.
GitHub vs GitLab: Bot Detection Differences
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:
- Check that the workflow is triggered by a
pull_requestorpull_request_targetevent, the CLI collects PR info only for these - On GitHub, export
GITHUB_TOKENin the step (env: GITHUB_TOKEN: ${{ github.token }}) so the CLI can read the reviews - On GitLab, the CLI does not collect merge request approvals
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 branch whose protection settings you want to check (for the code review policies this is a repository branch, not the pull request target) - 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
