Skip to main content

SKY-D322 · CI/CD pipelines

GitLab CI runner tag set from a variable

Medium

GitLab sends a job to a runner whose tags match the job's tags: list. SKY-D322 reports a tag built from a CI/CD variable, such as $RUNNER_TAG, because the variable decides at run time which machine runs the job.

Languages
GitLab CI
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
GitLab CI dynamic runner tag
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Variables can be set by whoever starts a pipeline with variables or a trigger token. Setting RUNNER_TAG=prod-deployer can move a job onto a privileged runner that holds production credentials or keeps state between jobs, where its script then runs.

What Skylos flags

.gitlab-ci.yml · YAMLReported on line 11
stages: [deploy] variables:  RUNNER_TAG: shared-small deploy-staging:  stage: deploy  image: bitnami/kubectl:1.31.2  timeout: 20 minutes  tags:    - $RUNNER_TAG  script:    - kubectl apply -f k8s/

What Skylos leaves alone

.gitlab-ci.yml · YAML
stages: [deploy] variables:  KUBE_NAMESPACE: staging deploy-staging:  stage: deploy  image: bitnami/kubectl:1.31.2  timeout: 20 minutes  tags:    - shared-small  script:    - kubectl apply -n "$KUBE_NAMESPACE" -f k8s/

Why Skylos leaves it alone

A variable still steers the job, but only inside the script. The runner tag is a fixed word, so the variable cannot pick the machine.

How Skylos decides

  1. Runs with --danger (and -a). Reads every file named exactly .gitlab-ci.yml in the scanned folder, skipping .git, node_modules, .venv, venv, build, dist and cache folders. Files pulled in with include: are not read, and a file PyYAML's safe loader cannot read (for example one that uses !reference) is skipped.
  2. Reads the tags under default: and each job's own tags, hidden .template jobs included. Tags a job gets through extends: are not looked up.
  3. Reports every tag that contains $, which covers $NAME, ${NAME} and tags with a variable inside a longer word.
  4. One MEDIUM finding per tag, on the first line of the file that contains the tag's text.

How to fix it

Write the runner tag as a fixed word. To use different runners for different targets, write one job per target, each with its own fixed tags and its own rules:.

.gitlab-ci.yml · YAML · the fix, against the flagged file
stages: [deploy] Removed: variables:Removed:   RUNNER_TAG: shared-smallRemoved:  deploy-staging:  stage: deploy  image: bitnami/kubectl:1.31.2  timeout: 20 minutes  tags:Removed:     - $RUNNER_TAGAdded:     - shared-small  script:    - kubectl apply -f k8s/

When it can be wrong

  • A tag from a parallel: matrix: value that the file itself lists is reported, although only those listed values can be used.
  • A variable only maintainers can set, such as a protected project variable, is reported the same as one anyone can pass in.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put # skylos: ignore[SKY-D322] and a reason on the reported line, or on the line directly above it. Skylos looks for that exact text, so write one rule per marker, with the ID in upper case.

    YAML
    tags:  # skylos: ignore[SKY-D322] values come from the matrix below  - $RUNNER_TAG
  • [tool.skylos] ignore = ["SKY-D322"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.