Improper using of Terraform/Base.latest.gitlab-ci.yml leads to secrets disclosure to job artifacts
The Terraform CI template uploads the plan.cache artifact by default, and the public:false setting does not prevent public access, so secrets embedded in the Terraform plan can be downloaded from job artifacts. An attacker could access personal access tokens, runner tokens, and other credentials, leading to unauthorised access to repositories and cloud resources.
GitLab
Originally disclosed on GitLab
- Fixed in 26 days
- Disclosed after 26 days
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #2176373 by 0xn3va on 2023-09-21, assigned to @cmaxim:
Report | Attachments | How To Reproduce
Report
Summary
I am not sure how to consider this report as a vulnerability in the template that needs to be fixed or as just a leak of secrets.
The build step of the Terraform/Base.latest.gitlab-ci.yml template saves terraform artifacts plan.cache by default:
### https://gitlab.com/gitlab-org/gitlab/-/blob/73524d97650ba59e29e97bc4e377a6587d780841/lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml#L46
.terraform:build:
stage: build
script:
- gitlab-terraform plan
- gitlab-terraform plan-json
resource_group: ${TF_STATE_NAME}
artifacts:
# The next line, which disables public access to pipeline artifacts, may not be available everywhere.
# See: https://docs.gitlab.com/ee/ci/yaml/#artifactspublic
public: false
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
Despite the fact that public: false is set plan.cache will be uploaded to job artifacts because this feature does not work at the moment as can be seen at https://docs.gitlab.com/ee/ci/yaml/#artifactspublic As a result, extending this step may lead to secrets disclosure if builds are publicly available.
I found the https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test project that uses the vulnerable template at https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/blob/e22142995c91587e9c287d74399c99377d6e2344/.gitlab-ci.yml:
### https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/blob/e22142995c91587e9c287d74399c99377d6e2344/.gitlab-ci.yml#L11
cluster:plan:
extends: .terraform:build
stage: plan-infra
# ...
Due to this unexpected default behaviour a bunch of secrets, including PATs and GitLab Runner Token, leaked to the job artifacts. For example:
-
https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/jobs/5035769994
[REDACTED][REDACTED]
-
https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/jobs/5036815443
[REDACTED][REDACTED]
Steps to reproduce
- Open https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/jobs/5035769994
- Download artifacts.
- Unzip
artifacts.zip. - Unzip
plan.cache. - Open
tfplan. - Search for the
glpatkeyword. You should find[REDACTED] - Make a request to API to validate the token:
curl -H "PRIVATE-TOKEN: [REDACTED]" https://gitlab.com/api/v4/personal_access_tokens/self
Impact
This vulnerability allows an attacker to access sensitive data in plane.cache uploaded to job artifacts.
In case of https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test, an attacker can access the following secrets:
[REDACTED]personal access token with theapiscope for the user[REDACTED][REDACTED]personal access token with theapiscope for thegroup_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8abot user.[REDACTED]- GitLab Runner token for[REDACTED][REDACTED]- cluster agent token but I am not quite aware of this one.
REDACTED has the Owner role in gitlab-org/ci-cd/deploy-stage and the Developer role in gitlab-org, please, see [REDACTED] and [REDACTED]
group_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8a has the Maintainer permissions in
[REDACTED], please, see [REDACTED]
As a result, an attacker can use those secrets to:
- Access private repositories in
gitlab-org - Access and update repositories in
gitlab-org/ci-cd/deploy-stage - Access CI variables in
gitlab-org/ci-cd/deploy-stage, for example, https://gitlab.com/gitlab-org/ci-cd/deploy-stage/environments-group/examples/sf6-qa-chat :
[REDACTED]
- Access GCP abusing OIDC integration, see https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/blob/e22142995c91587e9c287d74399c99377d6e2344/.gitlab-ci.yml#L18
What is the current bug behavior?
Terraform CI template uploads plane.cache to job artifacts by default and sensitive data may leak to job artifacts.
What is the expected correct behavior?
Sensitive data are not leaked to job artifacts.
Relevant logs and/or screenshots
[REDACTED]
Output of checks
This bug happens on GitLab.com
Impact
This vulnerability allows an attacker to access sensitive data in plane.cache uploaded to job artifacts.
In case of https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test, an attacker can access the following secrets:
[REDACTED]personal access token with theapiscope for the user[REDACTED][REDACTED]personal access token with theapiscope for thegroup_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8abot user.[REDACTED]- GitLab Runner token forhttps://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test[REDACTED]- cluster agent token but I am not quite aware of this one.
[REDACTED] has the Owner role in gitlab-org/ci-cd/deploy-stage and the Developer role in gitlab-org, please, see [REDACTED]
group_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8a has the Maintainer permissions in
gitlab-org/ci-cd/deploy-stage/demos, please, see https://gitlab.com/groups/gitlab-org/ci-cd/deploy-stage/demos/-/group_members?search=group_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8a
As a result, an attacker can use those secrets to:
- Access private repositories in
gitlab-org - Access and update repositories in
gitlab-org/ci-cd/deploy-stage - Access CI variables in
gitlab-org/ci-cd/deploy-stage, for example, https://gitlab.com/gitlab-org/ci-cd/deploy-stage/environments-group/examples/sf6-qa-chat :
[REDACTED]
- Access GCP abusing OIDC integration, see https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/blob/e22142995c91587e9c287d74399c99377d6e2344/.gitlab-ci.yml#L18
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the Terraform CI template includes the plan.cache file in job artifacts, and the public:false option does not actually restrict access to those artifacts, so secrets in the plan are exposed.
Impact
An attacker could access sensitive data in plan.cache uploaded to job artifacts, including personal access tokens, a GitLab Runner token, and a cluster agent token, which could allow access to private repositories, CI variables, and GCP resources via OIDC integration.
What the attacker needed
Publicly accessible job artifacts; project uses the Terraform CI template
The fix
Sensitive data should not leak into job artifacts.
How it was found
- Open the job page for the affected pipeline.
- Download the job artifacts.
- Unzip the artifacts archive.
- Unzip the plan.cache file.
- Open the tfplan file and search for the glpat keyword to find a token.
- Use the token in an API request to validate it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A CI/CD pipeline is an automated build process. This report shows that a standard template used in such pipelines saved a file containing sensitive passwords (secrets) into a place that anyone could download. Because the setting meant to keep it private did not work, attackers could grab those secrets and use them to access private code and cloud systems.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.