Skip to content

chore: install via lockfiles/cooldown - #8

Open
pieterocp wants to merge 5 commits into
usebruno:mainfrom
pieterocp:lockfile-approach
Open

pieterocp wants to merge 5 commits into
usebruno:mainfrom
pieterocp:lockfile-approach

Conversation

@pieterocp

Copy link
Copy Markdown

Summary

Install @usebruno/cli from committed, scannable lockfiles instead of resolving its dependency tree on every run, and add a release-age cooldown for anything that still resolves at run time. No existing bru-version value stops working.

Why

The action currently runs npm install -g @usebruno/cli@<version> on every job. That resolves Bruno's whole dependency tree (about 500 packages for 4.x) at run time. A compromised release of any transitive dependency would reach every consumer within minutes of being published.

With lockfiles, consumers get a fixed, reviewable dependency tree that can't change between runs. GitHub's dependency graph and Dependabot alerts cover every lockfile in the repo, so known vulnerabilities become visible instead of hidden inside a run-time install. Being visible doesn't mean the versions are free of vulnerabilities; see Known vulnerabilities in locked versions.

Weaknesses addressed

CWE How this PR helps
CWE-1357 Reliance on Insufficiently Trustworthy Component Consumers stop trusting whatever the registry serves at run time. The dependency tree is committed and reviewed.
CWE-829 Inclusion of Functionality from Untrusted Control Sphere The tree is fixed in git. --ignore-scripts stops dependency install scripts running on consumers' runners. scripts/add-version.sh rejects git, tarball and file sources.
CWE-494 Download of Code Without Integrity Check npm ci checks every package against the sha512 hash committed in the lockfile, not against hashes the registry supplies at install time.
CWE-506 Embedded Malicious Code The release-age cooldown gives a freshly hijacked release time to be spotted and unpublished before consumers install it. This applies to both the lockfile and fallback paths.
CWE-1395 Dependency on Vulnerable Third-Party Component Detection only. Dependabot and npm audit can now see the exact tree each version installs. This PR doesn't fix the vulnerabilities it reveals (see below).

The unlocked fallback (1.x/2.x releases without a lockfile, and new releases until their lockfile is merged) only gets the CWE-506 cooldown benefit.

What changes for consumers

  • bru-version is resolved to a concrete version the way npm resolves it: exact versions (with or without a leading v), ranges such as ^3, ~4.2 and 4.x, and dist-tags such as latest.
  • If the action ships a lockfile for that version, it installs with npm ci --ignore-scripts into $RUNNER_TEMP. Dependencies are not resolved at run time.
  • Otherwise, it falls back to the previous npm install -g, now with --min-release-age, and prints a ::warning::.
  • New cooldown-days input, default 2. Bruno and its dependencies must have been published at least this many days ago. 0 disables it.
  • The action now uses Node 24 instead of 22, because Node 22 ships npm 10, which has no --min-release-age.

Changes

  1. feat: add install cooldown for bruno cli: the cooldown-days input and the Node 24 bump.
  2. feat: install bruno cli from committed lockfiles:
    • 36 lockfiles: every 3.x and 4.x release, plus every 1.x and 2.x release with at least 500 downloads a week (about 95% of 1.x and 83% of 2.x downloads).
    • lib/resolve-version.js resolves versions, using semver.
    • New smoke tests cover locked ranges, the unlocked fallback and a nonexistent version.
    • The README gets only consumer-facing changes: the two input rows and a short "Locked installs" note. Maintainer docs go in a new CONTRIBUTING.md.
  3. feat: add lockfile generator and new-version workflow:
    • scripts/add-version.sh and scripts/missing-versions.sh.
    • A daily workflow that opens a draft PR per new release. It never auto-merges. CONTRIBUTING.md lists the branch-protection and CODEOWNERS settings that make human review mandatory.
    • This commit is self-contained and can be dropped if you'd rather add lockfiles by hand.
  4. chore: exclude maintainer-only folders from action archive: export-ignore for tests/, .github/, scripts/ and CONTRIBUTING.md, so consumers only download what the action needs at runtime.
  5. docs: recommend pinning the action to a commit SHA: the Versioning table showed @v1.0.0 as immutable, but tags can be moved. It now shows @104e180c2e7219a915dc48b6979ddbafe0940fcd # v1.0.0, the commit upstream's v1.0.0 tag points at.

Each commit message lists its own caveats in full.

Trade-offs

  • Download size: every consumer downloads about 1.5 MB more (6.5 MB uncompressed), almost all of it lockfiles.
  • Old versions: their lockfiles lock today's compatible dependencies, not the tree that shipped with that release. That's better for security, but it isn't byte-for-byte the original install. I checked 1.20.0 and 2.8.0 against the test collection locally.
  • New releases: they install through the unlocked fallback, with the cooldown, until their lockfile PR is merged and a release is cut.
  • Install scripts: --ignore-scripts skips protobufjs's install script, which bru doesn't need at runtime.
  • In-range fixes are frozen: the old npm install -g picked up dependency fixes within semver ranges on every run. A lockfile only picks them up when it's regenerated (FORCE=1 scripts/add-version.sh <version>).

Known vulnerabilities in locked versions (out of scope)

Every lockfile in this PR has known vulnerabilities. This PR doesn't introduce them: the old npm install -g path installs the same vulnerable packages, because most of them are pinned exactly in @usebruno/cli's own package.json. The lockfiles make them visible, and Dependabot will raise alerts for them once this is merged.

Fixing them means upgrading Bruno releases or overriding versions Bruno pins, which is out of scope here. Output of npm audit --package-lock-only on each lockfile:

Locked versions Critical High Notes
4.0.0 – 4.3.0 0 10–11 axios (CWE-1321) and form-data (CWE-93), both pinned exactly by Bruno; faker (CWE-95); js-yaml (CWE-400); @azure/msal-node (CWE-346)
3.2.2 – 3.5.3 0 9 Mostly the same pinned axios and form-data
1.40.0 – 3.2.1 18 2–8 Older pinned dependencies
1.20.0 – 1.38.3 3–9 1–3 Older pinned dependencies

npm audit fix doesn't help much. On 4.3.0 it only gets from 10 high to 8, and it does that by downgrading the @azure packages. The rest need new Bruno releases.

Recommendation for consumers: use the newest 4.x release. Older versions have lockfiles so existing pins keep working, not because they're considered safe. These findings should also be raised with the main Bruno project, since the exact pins are theirs.

Testing

  • All 15 smoke-test jobs pass on the fork: feat: install Bruno CLI from committed lockfiles pieterocp/bruno-cli-action#1. That includes:
    • ^3 → 3.5.3, v4.2.1 → 4.2.1 and ^1 → 1.40.0, installed from lockfiles
    • 2.1.0 through the unlocked fallback
    • a nonexistent version failing before bru runs
    • the existing run, docs and import jobs on 3.0.0, 4.3.0 and latest
  • The lockfile workflow only runs on a schedule or manual trigger, so it can't run from a PR. Its script was exercised locally against a scratch repo with a stubbed gh, covering a version that fails to lock, a reviewer request that fails, and a branch left without a PR.

Reviewer checklist

  • Happy with Node 24 as the action's runtime.
  • Happy with the download-size increase, or want fewer 1.x/2.x lockfiles.
  • Happy to ship lockfiles for old versions with known critical vulnerabilities (1.x–3.2.1), or want them removed so those versions use the fallback instead.
  • Expect a batch of Dependabot alerts after merging. They describe existing exposure, not new exposure.
  • Keep or drop the generator and workflow commit (3).
  • If keeping it: set the LOCKFILE_REVIEWERS variable, add CODEOWNERS for /lockfiles/, and require Code Owners review on main.
  • Cut a release after merging so @v1 consumers get the lockfiles, and update the pinned SHA in the README's Versioning section.
  • We might want to follow up with adding in a deprecation notice at install time for older versions. Given that this is only from May, we might want to add in a deprecation for older versions to get people to upgrade.

Apologies if the above is a lot, there's quite a few process assumptions baked in, I'm not 100% sold on the automation of getting lockfiles added, but it's hopefully okay enough to get working for now.

Install @usebruno/cli with npm's --min-release-age so the CLI and its
transitive dependencies must have been published at least cooldown-days
ago (default 2, 0 disables). This limits exposure to freshly published,
possibly compromised releases.

Bump setup-node from Node 22 to 24: Node 22 bundles npm 10.9.x, and
--min-release-age only exists from npm 11.10.0. Node 24 bundles npm 11.19.1.

Caveats:
- A pinned bru-version published within the cooldown window fails to
  install rather than falling back to an older version.
- The action now runs on Node 24, so report.js and bru itself run on
  Node 24 for every consumer.
- cooldown-days is passed straight to npm without validation; behaviour
  with a non-numeric value is untested.
Resolve bru-version to a concrete @usebruno/cli version and, when this
action ships a lockfile for it, install that pre-resolved dependency tree
with `npm ci --ignore-scripts` instead of resolving dependencies at run
time. GitHub's dependency graph / Dependabot alerts scan every lockfile.

- 36 lockfiles in lockfiles/<version>/: all 24 stable 3.x and 4.x
  releases (3.0.0 to 4.3.0), plus every 1.x and 2.x release with at
  least 500 downloads in the last week per npm's per-version stats:
  1.20.0, 1.30.0, 1.33.0, 1.34.1, 1.38.3, 1.40.0 (~95% of 1.x
  downloads) and 2.8.0, 2.8.1, 2.13.2, 2.14.2, 2.15.0, 2.15.1 (~83% of
  2.x downloads). Every package resolves from registry.npmjs.org.
  Generated with npm 11.19.1 using --package-lock-only --ignore-scripts
  and a 2-day --min-release-age.
- lib/resolve-version.js maps bru-version to a version the way npm does:
  exact versions (with or without a leading v), ranges (^3, ~4.2, 4.x)
  and dist-tags (latest), applying the cooldown-days cutoff. A tag picks
  the newest version <= the tag past the cooldown; a range prefers
  `latest` when it satisfies. Adds semver as an action dependency.
- Resolved versions without a lockfile (other 0.x/1.x/2.x releases, or
  newer than the newest lockfile) fall back to
  `npm install -g --min-release-age` with a ::warning::, so no existing
  bru-version value stops working.
- Locked installs go into $RUNNER_TEMP and are added to $GITHUB_PATH.
- Smoke tests: ranges, a v-prefixed version and ^1 install from
  lockfiles, 2.1.0 uses the fallback, and a nonexistent version fails
  before bru runs.

Caveats:
- `latest` still means npm's latest dist-tag, minus the cooldown. Until a
  lockfile is added for a new release, it is installed via the unlocked
  fallback.
- Lockfiles for old versions lock today's compatible dependencies, not
  the tree that shipped with that release. 1.20.0 and 2.8.0 were checked
  locally to install and pass a request against the test collection.
- Adds ~6.6 MB that every consumer downloads with the action.
- --ignore-scripts skips protobufjs's install script, which bru does not
  need at runtime. The unlocked fallback still runs install scripts, as
  before.
- Resolution now needs `npm view` against the registry before install
  (previously npm install did this implicitly).
- scripts/add-version.sh <version>...: generates lockfiles/<version>/
  with npm --package-lock-only --ignore-scripts and a release-age
  cooldown (COOLDOWN_DAYS, default 2). Works in a temp dir, checks the
  locked CLI version and that every package is from registry.npmjs.org,
  and needs FORCE=1 to regenerate an existing version.
- scripts/missing-versions.sh: lists every stable version >= MIN_VERSION
  (default 3.0.0) past the cooldown that has no lockfile, including
  backports to older lines (e.g. 3.5.4 after 4.3.0).
- add-bruno-version.yml: daily (and manual) workflow that opens one
  draft PR per missing version on branch bruno-lockfile/<version>, with
  a human-review checklist, and requests review from the
  LOCKFILE_REVIEWERS repo variable. It never enables auto-merge.
  - A version that fails to lock or push doesn't stop the others; the
    run fails at the end listing the failed versions.
  - A failed reviewer request (e.g. a team, which GITHUB_TOKEN can't
    resolve) is a warning, not a failure.
  - A branch left without a PR by an earlier failed run gets its PR
    opened on the next run. A branch whose PR was closed is not
    proposed again, which is how a version is declined.
- CONTRIBUTING.md: document the cooldown, how to add/regenerate versions,
  the workflow, and the repo settings that make human approval mandatory.

Caveats:
- Human review is only guaranteed once the repo has branch protection
  requiring an approving review plus Code Owners review for
  /lockfiles/. Draft + requested reviewers alone can be bypassed by an
  admin, or by the github-actions bot approving (the "create and approve
  pull requests" setting allows both).
- add-version.sh needs npm >= 11.10.0 for --min-release-age; the
  workflow uses Node 24 for that.
- PRs opened with GITHUB_TOKEN don't trigger other workflows, so smoke
  tests must be run manually.
- 1.x/2.x releases are not proposed automatically (MIN_VERSION).
  Deleting a 3.x+ lockfile without closing a PR for it means it is
  proposed again.
- The workflow script was exercised locally against a bare repo with a
  stubbed gh; it has not yet run on GitHub Actions.
Mark tests/, .github/, scripts/ and CONTRIBUTING.md as export-ignore so
they are left out of the tarball GitHub generates for a ref, which is
what the runner downloads when a workflow uses this action. None are
needed at runtime;
lib/ and lockfiles/ are, so they stay.

Notes:
- This only affects archives. The folders are still visible when
  cloning or browsing the repo and still count toward repo size. GitHub
  reads .github/workflows from the repo, not the archive, so CI is
  unaffected.
- Our own smoke tests use the checked-out working tree (uses: ./), so
  they are unaffected.
- scripts/ comes from the optional generator commit; the line is
  harmless if that commit is dropped.
- lockfiles/ (~6.5 MB uncompressed) is most of the archive and can't be
  excluded, since the action installs from it.
- GHES installs that copy actions with actions-sync may not honour
  export-ignore, and it is unverified how actions/publish-action
  packages releases.
- Check what consumers receive with: git archive HEAD | tar -t
Replace the `@v1.0.0` row in the Versioning table, which claimed a tag
is immutable, with the full commit SHA of the v1.0.0 release
(104e180, which upstream's v1.0.0 and v1
tags point at). Git tags can be moved, so only a SHA pin is immutable.

Also explain why, and show the `@<sha> # vX.Y.Z` form, which Dependabot
and Renovate keep up to date.

Caveat: the SHA has to be bumped in this README by hand on each release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant