---
title: "Automating Cerbos Policy deployments with GitLab Runners"
description: "This guide shows you how to set up a GitLab CI/CD pipeline to upload your Cerbos policies to a Cerbos Hub store automatically."
author: "Alex Olivier"
date: "2026-07-08T10:30:00.000Z"
canonical: "https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-gitlab-runners"
image: "https://stylish-appliance-1c1cc1c30d.media.strapiapp.com/Automating_Cerbos_Policy_deployments_with_Git_Lab_Runners_5093772eab.png"
tags: ["documentation"]
source: "https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-gitlab-runners"
---

# Automating Cerbos Policy deployments with GitLab Runners

This guide shows you how to set up a GitLab CI/CD pipeline to automatically upload your Cerbos policies to a [Cerbos Hub store](https://docs.cerbos.dev/cerbos-hub/policy-stores.html) whenever you push changes to the `main` branch of your repository.

> **Note:** Cerbos Hub can also [connect a repository](https://docs.cerbos.dev/cerbos-hub/policy-stores-git-github.html) to a store directly if you are on GitHub. The pipeline below is what you want on any other CI service, or when you need control over exactly which commits trigger an upload.

## Prerequisites
* A GitLab account and a project.
* Access to Shared Runners (enabled by default on GitLab.com).
* The ID of your Cerbos Hub store, which you can find in the store section of the Cerbos Hub.
* Your `CERBOS_HUB_CLIENT_ID` and `CERBOS_HUB_CLIENT_SECRET` values generated in the **Client credentials** section of the Cerbos Hub store. Make sure to select the `Read & Write` option when creating the credentials to allow uploading policies.
* Nothing needs installing on the runner. The upload runs the [cerbosctl CLI](https://docs.cerbos.dev/cerbos-hub/policy-stores-cli-binary.html) inside a container.

## Step 1: Create the CI/CD File
1.  In the root directory of your project, create a file named `.gitlab-ci.yml`.
2.  Copy and paste the following code into it.
3.  Replace `[STORE_ID]` with the ID of your Cerbos Hub store. You can find this in the Cerbos Hub UI under the store settings.

```yaml
# .gitlab-ci.yml
upload-policies:
  image: docker:24.0.5
  services:
    - docker:24.0.5-dind
  script:
    - >
      docker run --rm \
      -e CERBOS_HUB_STORE_ID="[STORE_ID]" \
      -e CERBOS_HUB_CLIENT_ID=$CERBOS_HUB_CLIENT_ID \
      -e CERBOS_HUB_CLIENT_SECRET=$CERBOS_HUB_CLIENT_SECRET \
      -v "$CI_PROJECT_DIR":/app \
      ghcr.io/cerbos/cerbosctl:latest \
      hub store replace-files /app --message="Policy upload from GitLab"
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
```

## Step 2: Add Your Secrets
1.  In your GitLab project, go to **Settings > CI/CD**.
2.  Find the **Variables** section and click **Expand**.
3.  Click **Add variable**.
4.  For **Key**, enter `CERBOS_HUB_CLIENT_ID`. For **Value**, paste your client ID. Check the **Protect variable** and **Mask variable** boxes. Click **Add variable**.
5.  Repeat the process for `CERBOS_HUB_CLIENT_SECRET`.

## Step 3: Commit and Push
1.  Commit the `.gitlab-ci.yml` file.
2.  Push your changes to the `main` branch.

## Step 4: Verify the Run
1.  In your GitLab project, go to **CI/CD > Pipelines** in the left sidebar.
2.  You will see your new pipeline running. Click on its status to see the job logs.

## Next steps

Add your policy tests to the same workflow so a broken policy never reaches the store. Cerbos test suites live alongside your policies and `cerbos compile` [finds them automatically](https://docs.cerbos.dev/cerbos/latest/policies/compile.html#_testing), so a failing test stops the run before the upload step.

If you are still working out what the policies themselves should say, [mapping business requirements](https://www.cerbos.dev/blog/mapping-business-requirements-to-authorization-policy) covers that groundwork, and [GitOps makes the case](https://www.cerbos.dev/blog/why-using-gitops-for-authorization-and-access-control-is-a-good-idea) for keeping policies in version control to begin with.

PS. Here is the same setup for [GitHub Actions](https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-github-actions), [CircleCI](https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-circleci), [Bitbucket Pipelines](https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-bitbucket-pipelines), [Buildkite](https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-buildkite) and [Azure DevOps](https://www.cerbos.dev/blog/automating-cerbos-policy-deployments-with-azure-devops-pipelines).

## Wrapping up

Go to [Cerbos Hub](https://hub.cerbos.cloud/) to create a policy store and connect this pipeline to it, or [book a free session](https://www.cerbos.dev/workshop) if you'd like to consult with our team.

## FAQ

### How do I automatically upload Cerbos policies to Cerbos Hub from GitLab CI?

You upload Cerbos policies from GitLab CI by adding a job to your GitLab CI configuration that runs cerbosctl against your Cerbos Hub store when changes land on your main branch. The job runs the cerbosctl container, passes your store ID and client credentials as environment variables, and replaces the policy files in the store.

### What credentials does GitLab CI need to push policies to a Cerbos Hub store?

GitLab CI needs your Cerbos Hub store ID plus a client ID and client secret. Create the credentials in the Client credentials section of your store in Cerbos Hub with the Read and Write option selected, then add CERBOS_HUB_CLIENT_ID and CERBOS_HUB_CLIENT_SECRET as masked CI/CD variables in your GitLab project settings so they do not appear in job logs.

### Can I sync policies to Cerbos Hub from GitLab without a pipeline?

Cerbos Hub's native Git connector currently covers GitHub repositories, so for GitLab a CI job is the practical route. Cerbos Hub policy stores also accept uploads through the cerbosctl CLI, the Hub SDKs and direct browser upload, so a pipeline is one of several options rather than the only one.

### Should Cerbos policy tests run before uploading to Cerbos Hub from GitLab?

Yes, run your Cerbos policy tests as a job stage before the upload. Cerbos test suites sit next to your policies and are picked up automatically by cerbos compile, so a failing test can stop the pipeline before a broken policy reaches your decision points.

### Where do I check whether a Cerbos policy upload from GitLab CI succeeded?

Open the CI/CD section of your GitLab project and look at the most recent pipeline. The upload job shows a pass or fail status and the full job log. Failures usually come down to client credentials created without Read and Write permission, an incorrect store ID, or CI/CD variables that were added to the wrong environment scope.
