Podcast about DevSecOps

#46 - Software supply chain attacks

A clean CI scan expires as new vulnerabilities emerge in packages already running in production.

17 min read

We are happy to welcome back Jacob Lärfors, CEO and Senior Consultant from Verifa, to talk about software supply chain attacks. It feels important to raise this topic since those attacks start to be utilized more often by sophisticated adversaries. At the same time, software supply chain security is something that companies often overlook. We as practitioners have so many things to consider and do that, in most cases, we do not have enough cognitive capacity left when looking into our library sources. What are the things we need to be aware of, and what are the low-hanging fruits we could utilize to help developers do their job securely?

Discuss the episode or ask us anything on LinkedIn


The code you didn’t write is most of what you ship

Open your last release and count what came from outside. The npm or pip packages. The base image, and everything its authors put inside it. The Actions that ran your build. The Bash script someone dropped on a shared file system five years ago, which nobody can trace to a repository. All of that is your software supply chain: the things you didn’t write that end up in the artifact you run in production or hand to a customer.

Hardly any of us has cognitive capacity left to read the source of a library before installing it. We review our own pull requests and take the rest on trust. Attackers have worked this out: a supply chain attack doesn’t bother with the application you wrote, it gets into the way that application is built and shipped, which is where your deployment credentials live.

Our guest is Jacob Lärfors, a consultant with the Nordic consultancy Verifa, who spends most of his time inside platform teams, the people who keep CI running and own a chunk of the infrastructure. He has also worked on embedded software, where you can be on the hook for a release for 15 to 30 years.

The difference between Log4Shell and Codecov

The distinction sounds academic until it decides which of your controls is relevant.

What makes something a supply chain attack?

Someone changed what you pull in, so what you built with isn’t what you meant to build with.

When Log4Shell landed in December 2021, we were patching a flaw in a library we had legitimately chosen and legitimately received. Nothing in the chain had been tampered with. That is exploitation: there was little to do beyond finding every copy and upgrading.

Codecov is the other shape. Its security update describes unauthorised alterations to the Bash Uploader script from 31 January 2021, found on 1 April when a customer’s checksum comparison failed, and disclosed on 15 April. The modified script exported environment variables out of CI jobs to a third-party server, and CI environments are full of secrets. HashiCorp’s HCSEC-2021-12, published on 22 April, reported that the GPG private key signing the SHA256SUMS files for its downloads had been exposed through that script, then revoked and replaced. A key that signs the hashes people check before running a new Vault binary is as load-bearing as keys get.

HashiCorp said in the same advisory that it found no evidence of unauthorised use of the key, and none of malicious modification to its code or binaries. The product looked fine. The process that built and published it was not, and the key had to be rotated anyway.

The ways in, from laptop to registry

If the process is the target, every stage of that process is a way in.

Where does the malicious code actually get in?

Anywhere between a developer’s laptop and the thing you deploy: a package whose maintainer changed hands, an infected developer machine, an infected CI worker, a Kubernetes manifest carrying one more sidecar than you reviewed.

Social engineering is one of those routes. The pattern that keeps working is a real library, documented, with stars, that depends on something nefarious. Snyk’s post-mortem of event-stream is the textbook run: a contributor offered to help, was given publish rights by a maintainer who no longer wanted the work, and added a dependency that turned malicious after publication. It sat in the tree from September to November 2018. Nobody picked flatmap-stream. They picked event-stream, which picked it for them.

Ownership is the part nobody tracks. A repository changes hands and the package keeps publishing. There is no link between the code you read on GitHub and the tarball on npm: publishing and commit rights are separate, so the two can diverge with nobody notified. npm is addressing the account half, with 2FA enforcement reaching maintainers of high-impact packages on 1 November 2022. That raises the cost of a takeover, and says nothing about whether a published artifact matches its source.

Motives beyond money showed up this year. Snyk’s write-up of node-ipc describes versions 10.1.1 and 10.1.2, published in March and tracked as CVE-2022-23812, which overwrote file contents with a heart emoji on machines the package geolocated to Russia or Belarus. Version 9.2.2 did something milder. It pulled in peacenotwar, which wrote a WITH-LOVE-FROM-AMERICA.txt file to the desktop. Vue CLI was exposed to that version as a transitive dependency. A maintainer was writing to your desktop through dependencies you never chose. In one of the countries involved we heard engineers say they had stopped updating at all, because you no longer know what you get.

A scan in CI is a snapshot, and the snapshot expires

Everyone should be running a scanner. The argument is about what you may conclude from a clean run.

Why isn’t a passing scan in CI enough?

Because a clean run means the scanner found nothing it knew to look for on the day you built, which is not the same as there being nothing there.

Build with fairly recent dependencies and the flaws in them haven’t been discovered yet, or have been discovered and not yet reported. Be responsible for an embedded release for 15 to 30 years and build time is a very small slice of that window. Web services aren’t exempt: a month between deploys is ordinary, and disclosures land in a month. The scanner is software too, so last quarter’s result came from last quarter’s scanner and last quarter’s database. Whatever you shipped has to be scanned again after it ships, not only on the way out.

There’s a second gap, quieter. Image scanners that work from the package manager database see what apt and apk installed, and a binary that arrived some other way can be invisible to them. Drop an old jq into /usr/local/bin with curl and a scanner of that kind has nothing to report: as far as it can tell, nothing is installed. How far this bites depends on the tool, so find out what yours inspects, and bring software into a build in a way that is reproducible, verifiable later, and visible to the thing you pay to look at it.

Then there is the data behind the verdict. CVE is formal and slow, and plenty of vulnerabilities never get a number; what you buy from a commercial scanner is largely a curated database aggregated from mailing lists, advisories and the vendor’s own research. OSV.dev is the open attempt at the same thing, with an API you query per package and version that also names the release carrying the fix. When that data is free and good, the commercial pitch changes.

Pinning and vendoring are not the same control

Both get recommended in the same breath, and they answer different questions.

What does pinning actually protect you from?

Surprises, not malice, and only if what you pinned is a recorded selection rather than a range.

That distinction matters more than the word suggests. A constraint such as ^4.2.0, or Terraform’s required_providers, says which versions are allowed, and an allowed range still lets a new release arrive between two builds. What stops that is a recorded selection: a committed package-lock.json, or Terraform’s .terraform.lock.hcl, which records the provider versions chosen and keeps them until terraform init -upgrade. A constraint without a committed lock file is a preference. Vendoring goes further and copies the code into your repository so the build fetches nothing, as go mod vendor and a vendor directory do.

This is where we don’t agree. Mattias’s objection is that pinning buys nothing against a package that was malicious when you chose it: pin as hard as you like and you stay pinned to the bad version. Andrey’s answer is that those are two different problems. Pinning and vendoring make what you bring in explicit; checking what it is, who publishes it and whether that organisation looks real is a separate step that happens when you add something or bump it. The first is mechanical. The second needs a person.

Vendoring earns its keep on practicality before security. You can still build when GitHub is down, which sounds silly until the morning it saves you. The vendored folder is also readable: notice a package making a network call it has no business making, and trace it back to whatever pulled it in. What it doesn’t add is integrity, because a lock file already checks content rather than names. package-lock.json records an integrity hash and the URL each package resolved from, and .terraform.lock.hcl records provider checksums that terraform init compares against the download and errors on a mismatch. The weak reference is the bare one with nothing behind it to check: a Docker tag or a Git tag can be moved to point at different bytes, so pin those by digest or commit SHA.

One rule if you vendor: don’t edit the copy. Fork the project, send the pull request upstream, and keep your vendored tree clean, or every bump turns into a merge you do badly at 6pm.

A registry you control is where you get to say no

Pinning and reading code are per-team work. The next control is a single place every dependency has to pass through.

What can a registry proxy do that a scanner can’t?

Refuse. A scanner reports; the proxy is the one point in the chain where a package can be stopped from arriving.

The ordinary benefits come first: a cache cuts network cost, survives an upstream registry’s bad day, and gives you one record of what entered. Artifactory and Nexus do it for packages, Harbor for container images.

The gate has sharp edges. Dependency confusion is the one to understand, and JFrog’s February 2021 analysis sets out the mechanism. pip resolves a package name across the public index and your private one without telling them apart, and it prefers the newer version. So an attacker who publishes your-internal-lib at 99.0.0 can win the resolution with your own copy sitting right there. A registry that falls through to the public one is one route in, not the only one, because precedence between sources is the real problem. Harbor keeps a proxy cache project separate from a local one, which is clumsier than an Artifactory virtual repository and harder to get wrong.

Blocking is where the tools disappointed us. A developer posted in Slack that a taken-over npm package was sitting in Artifactory, asking for it to be blocked. Xray blocks artifacts with reported vulnerabilities against them, and as far as we could tell there’s no way to report one by hand, so the package could be found and not stopped. The workaround we talked through on air is untested: if the proxy is the only permitted route, turn off remote proxying on that repository and delete the cached copy, and the name should stop resolving. It is blunt, because remote proxying is a repository-wide switch: every package there that isn’t already cached stops resolving too.

None of this exists unless the proxy is mandatory. If a developer or a CI job can reach the public registry directly, what you have is a cache.

A signature says who signed it, not that it’s safe

Blocking by name is reactive. The other direction is to allow only artifacts you made yourself.

What does a signed image prove?

That this artifact matches a signature made with a key or identity you chose to trust, and hasn’t changed since. Nothing whatsoever about what’s inside it.

The setup is less work than it used to be. CI assumes a role allowed to use a key in a key management service, and Cosign asks that service to sign. The private half of an asymmetric KMS key never leaves the service, so your pipeline holds permission to sign rather than the key itself. Cosign stores the signature as a second artifact in the registry, which Harbor recognises as a signature for the image rather than listing it separately. A project’s deployment security policy then refuses to serve unsigned artifacts, so a cluster that pulls only from Harbor gets a real gate. Sigstore reached general availability in October 2022, which takes most of the key handling off your plate.

The care goes into verification. Cosign checks an artifact against a key or an identity you name: the public key you expect, or in the keyless flow the signer identity and OIDC issuer you expect. A signature that merely verifies against some key tells you nothing.

So the stamp reads: this artifact was signed by that key. It becomes a claim about your build on two conditions. Signing has to be restricted to CI, so no human and no other job can produce the same signature. Provenance has to be recorded alongside it, naming the source and workflow that produced the artifact. Without both, the key proves custody and nothing more.

Why don’t the package registries do this for us? Linux distributions have signed packages for decades, and we haven’t heard of many supply chain attacks on them, which is an absence of reports rather than a measurement. Signing isn’t the only difference either: a distribution package goes through a maintainer and some amount of checking before anyone can download it, where an npm or pip publish reaches the registry on the publisher’s say-so. Public key infrastructure is also miserable to use: few of us have typed a PGP command without looking it up, and the tooling answers yes or no with nothing to debug. Security added after the fact is error-prone.

An SBOM is a list, and a list you can’t search is a file

Signing tells you where an artifact came from. The remaining question is what is in it.

What is an SBOM actually for?

Answering “are we using this?” on the morning when the answer matters.

We had a bill of materials, we added an S, and that’s a software bill of materials: everything you pull in and deliver. Scanners hand you something like one in a format of their own, which is most of why this is annoying. SPDX is the one worth knowing, because it became ISO/IEC 5962:2021 and can be read by somebody else’s tool.

Having the data is not the same as being able to answer with it. In the Log4j week we had a registry that knew every package and a monitoring stack that knew what was running in production, and the join between the two was the piece that didn’t exist. So start cheap: log every dependency and image digest your pipeline builds or pulls, into Elastic, into a log file, into anything you can grep. When the next name lands in your Slack channel, you can answer in minutes.

Platform teams are standing in the right place

Someone has to own this, and the org chart doesn’t obviously say who.

Who should own supply chain security?

The team that is already in the build, the deploy and the monitoring, because nobody else sees all three.

Whose job it is to fix a critical vulnerability in the official nginx image is genuinely unclear, and a critical finding rarely stops anyone using an image that works. There is a real divide between developers and security people, and platform or DevOps teams sit across it: involved in building, in deploying, in watching what runs. That is the bridge, and taking the job is a decision rather than a budget. The failure mode we would most like to retire is the checkbox: we run a scanner in CI, therefore we are secure.

Production is where the gap shows. Starboard from Aqua Security, the same people behind Trivy, watches what is running in your cluster and writes the findings back as Kubernetes resources. Check the name before you build on it. The maintainers announced in May 2022 that Starboard is joining the Trivy family: starboard-operator becomes trivy-operator, and the CLI is replaced by a trivy k8s command. They also said they would stop adding features and releases to Starboard. Either way you run it and maintain it yourself, which still beats opening a procurement cycle with a large security vendor.

The pipeline deserves to be treated as a product. CI machines that are never torn down stay infected once they are infected, and the trade-off against caching is a cost decision somebody should make deliberately. Who can redeploy, what goes into an audit log and who reads it are design questions, not paperwork.

What this means for teams

Security work here is the usual loop: discover, enumerate, mitigate. Discover what you depend on, write it down somewhere you can query, then close the paths you can actually close. An adversary who has picked you specifically is hard to defend against, and that isn’t the threat most of us face. The spray attacks, the taken-over package, the typo’d name, the transitive dependency nobody chose, are what the controls below are for. They narrow the ways a package can reach your build and shorten how long a bad one sits there unnoticed, which is a smaller promise than stopping every attack, and a keepable one.

Four things to do this week:

  • Pin everything that isn’t pinned, and commit the lock file, not just the constraint. Make CI install from it with npm ci or your language’s equivalent, so the build can’t quietly resolve something new.
  • Make your registry proxy the only permitted route, then test what you can actually block in it. Pick a harmless package and try, before the day it’s urgent.
  • Log the dependency list and image digests of every build into something searchable, even a flat file. It is the cheapest insurance here.
  • Scan what’s running, not only what’s building, and put the result where developers already look.

Common questions, answered

How do I block a specific malicious npm package across my organisation?

Delete the cached copy from your internal registry and turn off remote proxying on that repository. That should stop the name resolving for builds that go through the proxy, though we have not tested it. It only helps if the proxy is the only permitted route: anyone who can reach the public registry directly will fetch the package anyway. Remote proxying is also a repository-wide switch, so turning it off stops every other uncached package there. Check what your tooling can refuse before you need it. Xray blocks artifacts with reported vulnerabilities, and as far as we could tell there’s no way to report one by hand.

Should I vendor my dependencies or just pin them?

Pin first, and commit the lock file rather than relying on a version range, because a range still lets a new release in between two builds. Vendoring adds a copy of the code in your repository: builds that survive an upstream outage, and code you can read and grep. It is not what makes a dependency immutable, since a lock file already records an integrity hash or a checksum for what it resolved; the reference that can move under you is a bare Docker or Git tag. The cost of vendoring is a bigger repository and real upgrade work. If you vendor, don’t edit the vendored copy: fork upstream and send a pull request, or every bump becomes a merge conflict.

How do I find out whether we’re running a vulnerable library like Log4j?

Log the full dependency list and image digests at build time into a searchable store, so the question becomes a query instead of an investigation. Pair it with something that inspects what is running now, because a service deployed a year ago is exposed to everything disclosed since, and its build-time scan knows none of it.

Resources

Since we recorded

The missing link between a GitHub repository and the package published from it got an answer: npm shipped package provenance in April 2023, which signs a statement of the source repository, commit and workflow through Sigstore and shows it on the registry. SLSA published its first stable release the same month, reorganised into tracks beginning with build, so the four levels described above no longer map onto the current numbering. We came back to the topic in episode 53, on an open reference framework for the attacks themselves.