Skip to content
Info disclosure Disclosed report Beginner

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:

YAML
###  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:

YAML
###  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:

Steps to reproduce
  1. Open https://gitlab.com/gitlab-org/ci-cd/deploy-stage/demos/gcp-oidc-test/-/jobs/5035769994
  2. Download artifacts.
  3. Unzip artifacts.zip.
  4. Unzip plan.cache.
  5. Open tfplan.
  6. Search for the glpat keyword. You should find [REDACTED]
  7. Make a request to API to validate the token:
Bash
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 the api scope for the user [REDACTED]
  • [REDACTED] personal access token with the api scope for the group_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8a bot 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:

[REDACTED]

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 the api scope for the user [REDACTED]
  • [REDACTED] personal access token with the api scope for the group_72590210_bot_e9ffa66ffc0a2d9a41cd306a605a7a8a bot user.
  • [REDACTED] - GitLab Runner token for https://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:

[REDACTED]

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

  1. Open the job page for the affected pipeline.
  2. Download the job artifacts.
  3. Unzip the artifacts archive.
  4. Unzip the plan.cache file.
  5. Open the tfplan file and search for the glpat keyword to find a token.
  6. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.