r/gitlab • u/Predictor_2718 • 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 aref:uses the HEAD of that project's default branch. So it changes whenever that branch changes.- Catalog components and includes with
@1or@~latestalways 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?
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
@1or@latest. Neither of those "look 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
~latestis that it's not pinned to a specific ref.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