Why do you use `npm ci` and lockfiles in CI, and what does it protect against?
IntermediateScenarioSupply Chain Security
Answer
Situation read → npm install may update versions, so two builds of the same commit can differ.
What I'd do →
- Commit
package-lock.json,poetry.lock,go.sum,Cargo.lock. - In CI use
npm ci(fails if the lockfile does not matchpackage.json),pip install --require-hashes -r requirements.txt,go mod verify. - Review lockfile diffs in PRs.
- Block registry-source changes in lockfile with a check.
Why → Reproducible installs mean a poisoned new release does not enter automatically.
Interview tip → Lockfile integrity hashes also detect tampered tarballs.
More on Supply Chain Security
What is an SBOM, and at which point in the pipeline do you generate it?BeginnerA customer asks for an SBOM for your product. What do you give them?BeginnerHow do you sign container images in GitHub Actions without managing private keys?IntermediateYou signed images in CI. How do you make sure the cluster only runs signed images?IntermediateLeadership wants "SLSA compliance". What do you propose?IntermediateWhat is typosquatting and how do you protect developers from it?Beginner