doc/ci/pipeline_security/_index.md
{{< details >}}
{{< /details >}}
Secrets management is the system that developers use to securely store sensitive data in a secure environment with strict access controls. A secret is a sensitive credential that should be kept confidential. Examples of a secret include:
Secrets that are the most sensitive and under the strictest policies should be stored in a secrets manager. When using a secrets manager solution, secrets are stored outside of the GitLab instance. There are a number of providers in this space, including HashiCorp's Vault, Azure Key Vault, and Google Cloud Secret Manager.
You can use the GitLab native integrations for certain external secret management providers to retrieve those secrets in CI/CD pipelines when they are needed.
CI/CD Variables are a convenient way to store and reuse data in a CI/CD pipeline, but variables are less secure than secrets management providers. Variable values:
Information suitable for storage in a variable should be data that can be exposed without risk of exploitation (non-sensitive).
Sensitive data should be stored in a secrets management solution. If you don't have a secrets management solution and want to store sensitive data in a CI/CD variable, be sure to always:
For passing parameters to CI/CD pipelines, use CI/CD inputs instead of pipeline variables.
Inputs provide:
Consider disabling pipeline variables when implementing inputs to prevent security vulnerabilities, because pipeline variables:
The key security principles of ensuring pipeline integrity include:
Always use SHA digests for Docker images to ensure client-side integrity verification. For example:
image: node@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdefimage: node:latestimage: python@sha256:9876543210abcdef9876543210abcdef9876543210abcdef9876543210abcdefimage: python:3.9You can find the SHA digest of an image with a specific tag using:
docker pull node:18.17.1
docker images --digests node:18.17.1
Prefer to pull from container registries that protect image integrity:
When possible, avoid using variables in container references as they can be modified to point to malicious images. For example:
image: my-registry.example.com/node:18.17.1image: ${CUSTOM_REGISTRY}/node:latestimage: node:${VERSION}You should lock down package dependencies in your jobs. Use exact versions, defined in lock files:
npm cinpm installyarn install --frozen-lockfileyarn installpip install -r requirements.txt --require-hashespip install -r requirements.lockpip install -r requirements.txtgo.sum:
go mod verifygo mod downloadgo get ./...For example, in a CI/CD job:
javascript-job:
script:
- npm ci
When installing tools in a job, always specify and verify exact versions. For example, in a Terraform job:
terraform_job:
script:
# Download specific version
- |
wget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip
# IMPORTANT: Always verify checksums
echo "c0ed7bc32ee52ae255af9982c8c88a7a4c610485cf1d55feeb037eab75fa082c terraform_1.5.7_linux_amd64.zip" | sha256sum -c
unzip terraform_1.5.7_linux_amd64.zip
mv terraform /usr/local/bin/
# Use the installed version
- terraform init
- terraform plan
Use version managers when possible:
node_build:
script:
# Use nvm to install and use a specific Node version
- |
nvm install 16.15.1
nvm use 16.15.1
- node --version # Verify version
- npm ci
- npm run build
When using the include keyword to add configuration
or CI/CD components to your pipeline, use a specific ref when possible. For example:
include:
- project: 'my-group/my-project'
ref: 8b0c8b318857c8211c15c6643b0894345a238c4e # Pin to a specific commit
file: '/templates/build.yml'
- project: 'my-group/security'
ref: v2.1.0 # Pin to a protected tag
file: '/templates/scan.yml'
- component: 'my-group/security-scans' # Pin to a specific version
version: '1.2.3'
Avoid versionless includes:
include:
- project: 'my-group/my-project' # Unsafe
file: '/templates/build.yml'
- component: 'my-group/security-scans' # Unsafe
- remote: 'https://example.com/security-scan.yml' # Unsafe
Instead of including remote files, download the file and save it in your repository. Then you can include the local copy:
include:
- local: '/ci/security-scan.yml' # Verified and stored in the repository