Rules / GL095
GL095 Script reads the runner's own cloud or cluster credentials
Severity: error; warn for reaching the metadata host without a credential path
OWASP: CICD-SEC-4 – Poisoned Pipeline Execution
CWE: CWE-522 – Insufficiently Protected Credentials
What glsec checks
On a cloud VM or in a Kubernetes cluster, the runner holds an identity of its own: the instance role, exposed through the instance metadata service (IMDS), and the pod's service-account token. Those credentials belong to the infrastructure, not to the project. A script line that reads them takes an identity the pipeline was never granted, and can use it to move from the build into the surrounding cloud account or cluster. This is a known attack step (MITRE ATT&CK T1552.005) and the pivot several crypto-mining campaigns use to turn a compromised build into cloud access.
glsec looks at every script surface (script:, before_script:, after_script:, default:, hooks:, run: steps) and reports, as an error:
- a request to the instance metadata service that reaches a credential path: AWS
.../iam/security-credentials/...and the IMDSv2 token endpoint.../latest/api/token, GCP.../service-accounts/<name>/token, Azure.../identity/oauth2/token; - a read of the Kubernetes service-account token at
/var/run/secrets/kubernetes.io/serviceaccount/token.
Reaching the metadata host (169.254.169.254 or metadata.google.internal) for host facts such as the region or project id, without a credential path, is reported as a warn with the same advice.
A metadata address that appears only in a comment or in an echo/printf string is not an access and is not reported. Only the exact metadata IP 169.254.169.254 is matched, so an unrelated 169.254.x.x link-local service does not trigger the rule.
Trigger example(s)
read-instance-role:
script:
- curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/ci-runner-role
read-sa-token:
script:
- cat /var/run/secrets/kubernetes.io/serviceaccount/token
Safe alternative
Mint a scoped, keyless credential with id_tokens: and exchange it for short-lived cloud access, instead of borrowing the runner's ambient identity:
deploy:
id_tokens:
AWS_ID_TOKEN:
aud: https://gitlab.example.com
script:
- echo "authenticate with the OIDC token in AWS_ID_TOKEN, not the runner's instance role"
Reading the metadata host for a non-credential fact is downgraded to warn, but prefer a value the pipeline is given explicitly (a CI/CD variable, a predefined variable) over querying the runner's identity service.
Documentation for glsec 1.29.0. Source of this page · Rule implementation