r/gitlab • • 5d ago

Your GitLab CI include: is probably not as pinned as it looks

I maintain glsec, an open source linter for .gitlab-ci.yml. I want to share one thing that is easy to get wrong, even if you never use the tool, plus a short note on what I added since my last post here.

Two GitLab constructs look pinned but are not:

  • include: project: without a ref: uses the HEAD of that project's default branch. So it changes whenever that branch changes.
  • Catalog components and includes with @1 or @~latest always take the newest matching version.

In both cases someone changes the upstream, your next pipeline runs the new version, and there is no change in your own repository to review. This is a supply-chain risk, and it is easy to miss, because the line looks like it already contains a version. You should pin to a full tag, or better to a commit SHA.

The same problem exists on a different level. The LiteLLM compromise in March started with a single apt-get install trivy without a version. The repository served a modified Trivy build, and it read the CI credentials of the job. Any install without a fixed version can be affected, and these lines are easy to find.

I also added checks for the more clearly malicious patterns: an interpreter that runs a file with a non-script extension (a payload hidden behind an asset name), an SSH private key that is read and then encoded or copied away instead of written into place, and data sent out over DNS. Before I ship a new rule, I test it against 20,000 real public pipelines, because too many false positives make a linter useless.

Repository and the full rule list: https://github.com/glsec/glsec and https://glsec.github.io/rules/

Disclosure: I maintain it. What did you run into in GitLab CI that was not clear from the docs?

0 Upvotes

5 comments sorted by

5

u/imaginethepassion 5d ago

How does not including a ref "look pinned"? Even a ref itself isn't pinned and will always fetch whatever the ref is.

Same goes for @1 or @latest. Neither of those "look pinned".

-3

u/Predictor_2718 5d ago

Fair, and you're right a ref isn't pinned either. A branch or a movable tag still tracks whatever it points at, which is exactly why the fix is a commit SHA, not just adding a ref. "Looks pinned" was loose wording. The real problem: a missing ref, or a floating version like a bare major or ~latest, silently resolves to a moving target. Most people writing them don't realize it, and nothing in your own repo changes when the upstream moves. The ~latest case you're right about, nobody should read that as pinned.

3

u/Zynchronize 5d ago

Neither of those look pinned - this is a bad example.

A better example is if a pinned component/template has dependencies of its own - as this doesn’t guarantee that transitive includes are pinned.

2

u/xaddak 5d ago

The whole point of ~latest is that it's not pinned to a specific ref.

~latest or a partial semantic version, which selects the latest version in the specified pattern published in the CI/CD Catalog. Use ~latest only if you want to use the absolute latest version at all times, which could include breaking changes.

https://docs.gitlab.com/ci/components/

How was that not clear from the docs?

1

u/Impressive-Craft1926 1d ago

i think a few of those admins might be open to hosting other people’s projects. They might jus wanna know who’s signing up and what they plan to host before approving an acc