Skip to content

GitLab Pipelines

Overview

This page covers how to check out Britive profiles from within GitLab CI/CD pipelines so that jobs receive short-lived cloud credentials at runtime instead of relying on long-lived secrets stored as GitLab CI variables.

The two supported methods are:

MethodWhen to Use
Britive CLI (PyBritive)Standard approach for most pipelines — shell-based script blocks, before_script, reusable .gitlab-ci.yml includes
REST APIWhen calling from a custom Docker image entrypoint or a non-shell runtime — see the Britive API documentation

Prerequisites

RequirementDetails
Britive service identityCreate a service identity in the Britive console; generate a token
Britive profileThe profile must be active, have an expiration set, and have a policy granting the service identity access
GitLab CI/CD variablesStore BRITIVE_API_TOKEN and BRITIVE_TENANT as masked, protected CI/CD variables at the project or group level
Britive CLI (if using CLI method)Install PyBritive in the pipeline runner or add an install step to before_script

Environment Variables

VariableRequiredWhere to SetDescription
BRITIVE_API_TOKENYesGitLab CI/CD variable (masked, protected)Service identity token — PyBritive reads this automatically
BRITIVE_TENANTYesGitLab CI/CD variableBritive tenant subdomain (see Finding Your Tenant Name)
BRITIVE_PROFILENo.gitlab-ci.yml variables blockProfile to check out, as Application/Environment/Profile

CLI Usage

Installing the CLI

Add an install step in before_script or bake PyBritive into your runner image:

.gitlab-ci.yml
before_script:
  - pip install pybritive==2.3.2   # pin to your tested version

Checkout Step

pybritive checkout with -m env-nix prints export statements; eval them, then use the credentials in the same job:

.gitlab-ci.yml
deploy:
  variables:
    BRITIVE_PROFILE: "AWS Production/Prod Account/ci-deploy"
  script:
    - eval "$(pybritive checkout "$BRITIVE_PROFILE" -m env-nix)"
    - aws sts get-caller-identity

BRITIVE_API_TOKEN and BRITIVE_TENANT are picked up from the CI/CD variables automatically — no flags needed.

pybritive checkout Flags

FlagRequiredDefaultDescription
PROFILE (argument)YesProfile as application name/environment name/profile name
-m, --modeNotextOutput mode: env-nix (shell exports), json, integrate (write AWS credentials file), awscredentialprocess, gcloudauth, azlogin, and more
-j, --justificationNoJustification string if the profile policy requires one
-b, --blocktimeNo3 / 60Seconds to wait before polling for credentials (60 for approval-gated profiles)
-a, --aliasNoSave an alias for shorter future checkouts
--ticket-type / --ticket-idNoITSM ticket details if the profile requires a ticket

Environment variables set in one script line survive to subsequent lines in the same job, but not to other jobs. Run eval and the commands that use the credentials in the same job, or write to a dotenv artifact to pass them forward.


REST API Usage

When a shell isn’t available (custom Docker entrypoints, non-shell runtimes), call the Britive REST API directly. Authenticate with the service identity token in the Authorization: TOKEN <token> header. See the Britive API documentation for endpoint details.


Credential Injection

After checkout with -m env-nix and eval, credentials are exported into the job’s environment. The variables depend on the target cloud:

CloudCredential Variables Injected
AWSAWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
GCPGOOGLE_APPLICATION_CREDENTIALS
AzureAZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID
SnowflakeSNOWFLAKE_USER, SNOWFLAKE_PASSWORD, SNOWFLAKE_ACCOUNT

Security Considerations

PracticeWhy It Matters
Mark BRITIVE_API_TOKEN as maskedPrevents the token from appearing in job logs
Mark BRITIVE_API_TOKEN as protectedRestricts the variable to protected branches and tags only
Use group-level variables sparinglyPrefer project-level variables to limit blast radius
Match checkout duration to job runtimeShort-lived credentials reduce exposure if a job is compromised

Related

Last updated on