Skip to content
Browse documentation

Workload identity

GitLab CI/CD

Give a protected GitLab.com job access to one Bulgur environment.

Before you start

Use Bulgur CLI or Node SDK 1.3.0 or newer, a Bulgur Cloud project and workload identity policy, and a trusted job image. This provider accepts GitLab.com tokens; self-managed GitLab is not supported. GitLab.com CLI and SDK reads have been verified against hosted Bulgur Cloud.

Create a policy

In Bulgur organization settings, create a GitLab.com identity with the numeric project and namespace IDs, an exact full ref such as refs/heads/main, the exact job environment such as production, and permitted pipeline sources (push, web, or schedule). Select one Bulgur project and non-Shared environment; inherited Shared values are included.

Find the project ID in GitLab project settings and the namespace ID through the GitLab project API. The GitLab ref must be protected. Merge request, fork and parent-pipeline sources are excluded. Bulgur verifies signed job and project/namespace IDs; project and group paths are not authority.

People who can change trusted project pipeline configuration are privileged. The environment name is declared in job YAML and is not an independent approval gate.

Configure the job

Protect main in GitLab and allow the desired pipeline sources in the Bulgur policy. Replace the image and identity placeholders with your trusted image containing Bulgur 1.3.0 or newer and identity ID. The 10-minute timeout controls the job and token lifetime; keep it at or below one hour.

yaml
deploy:
  image: YOUR_TRUSTED_IMAGE_WITH_BULGUR_1_3_OR_NEWER
  timeout: 10m
  environment:
    name: production
  id_tokens:
    BULGUR_GITLAB_ID_TOKEN:
      aud: https://api.bulgur.dev
  variables:
    BULGUR_AUTH: gitlab-oidc
    BULGUR_IDENTITY_ID: "<identity-id>"
  rules:
    - if: '$CI_COMMIT_BRANCH == "main" && $CI_COMMIT_REF_PROTECTED == "true" && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "web" || $CI_PIPELINE_SOURCE == "schedule")'
    - when: never
  script:
    - bulgur run -- ./deploy.sh

Do not print the ID token or store it in an artifact. The CLI uses BULGUR_GITLAB_ID_TOKEN; it does not fall back to a stored token or .env credentials.

Use the Node SDK

The server-side SDK requires Bulgur 1.3.0 or newer and Node.js 18 or newer; install it with npm install bulgur@^1.3.0. It needs no GitLab peer dependency. loadValues returns a request-local object and leaves process.env unchanged.

js
const { loadValues } = require("bulgur");

async function main() {
  const secrets = await loadValues({
    auth: "gitlab-oidc",
    identityId: "YOUR_IDENTITY_ID",
  });
  // Use secrets in your application.
}

main().catch(() => {
  console.error("Could not load secrets");
  process.exitCode = 1;
});

Explicit GitLab mode never falls back to token credentials, even with optional mode.

Troubleshooting

If exchange is denied, check the numeric project and namespace IDs, protected full ref, declared job environment and permitted pipeline source against the policy. Confirm the job requests an ID token for https://api.bulgur.dev and supplies it as BULGUR_GITLAB_ID_TOKEN.

Use bulgur pull --auth gitlab-oidc --identity <identity-id> --out .env --yes when a private dotenv file is needed. Changes to the trusted pipeline can grant access to the bound environment, so restrict who may edit it.

Token lifetime

GitLab job ID tokens can be reused until their expiry; they are not subject to a one-use replay ledger. Each Bulgur session lasts at most five minutes and never beyond source-token expiry. Changing or disabling the policy invalidates its Bulgur sessions.