-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add lavamoat allow-scripts #4207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MichaelAJay
wants to merge
20
commits into
bitpay:master
Choose a base branch
from
MichaelAJay:lavamoat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
13684a2
fresh-install
MichaelAJay 91dccc3
add lavamoat config to bitcore package package.jsons
MichaelAJay 094c38c
Merge branch 'master' of https://github.com/bitpay/bitcore into lavamoat
MichaelAJay a42105a
update build job for new lavamoat flow
MichaelAJay f330cf8
add debugging to failing job
MichaelAJay c4ed344
rm allow-scripts check
MichaelAJay 2a54230
update compile script to compile bcn first
MichaelAJay 126c3db
update compile script 2/n
MichaelAJay c942978
compile script updates 3/n
MichaelAJay 2478422
fixes & rework new build process for improevd dev ergonomics
MichaelAJay 607b039
lint
MichaelAJay 1260de0
add script description
MichaelAJay 0677cab
remove versioning from all package.json lavamoat.allowScripts which a…
MichaelAJay e6bcb6f
fix os-specific validation failures
MichaelAJay cabde5b
review fixes
MichaelAJay 72941c9
Merge branch 'master' of https://github.com/bitpay/bitcore into lavamoat
MichaelAJay acef257
fix root scripts & use lerna more fully
MichaelAJay d662df5
add warning about defining package level lifecycle scripts
MichaelAJay 954058d
Merge branch 'master' of https://github.com/bitpay/bitcore into lavamoat
MichaelAJay 911605b
address feedback
MichaelAJay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ignore-scripts=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # Bitcore development setup | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| CircleCI uses Node.js 22.13.1 and npm 10.9.2. Use those versions locally. | ||
| Some package workflows also require Python or Docker. | ||
|
|
||
| ## Set up a checkout | ||
|
|
||
| From the repository root, run: | ||
|
|
||
| ```sh | ||
| npm run setup | ||
| ``` | ||
|
|
||
| This is the supported setup command locally and in CI. It: | ||
|
|
||
| 1. Runs `npm ci --ignore-scripts` for the root dependency tree. | ||
| 2. Runs `lerna bootstrap --ci --concurrency 1 --ignore-scripts` to install and | ||
| link managed packages without lifecycle scripts. | ||
| 3. Validates every managed package's committed LavaMoat policy before any | ||
| approved dependency script can run. | ||
| 4. Runs `allow-scripts` in each managed package, executing only approved | ||
| dependency lifecycle scripts. | ||
| 5. Compiles the monorepo in its required order while automatic `pre*` and | ||
| `post*` companions remain disabled. | ||
|
|
||
| The root `.npmrc` sets `ignore-scripts=true`, and setup also passes the option | ||
| explicitly. Lerna's `--ci` option gives local and CI bootstrap the same clean, | ||
| lockfile-based behavior. Bootstrap is serialized because parallel fresh Lerna | ||
| installs were observed to omit dependency files on macOS. | ||
|
|
||
| `npm ci` alone installs only the root dependencies; it does not bootstrap or | ||
| compile the monorepo. Do not replace `npm run setup` with a bare | ||
| `lerna bootstrap`. | ||
|
|
||
| ## Compile and run | ||
|
|
||
| After setup, recompile with: | ||
|
|
||
| ```sh | ||
| npm run compile | ||
| ``` | ||
|
|
||
| Use this command instead of calling `lerna run compile` directly. It explicitly: | ||
|
|
||
| 1. Compiles `bitcore-logging` and `crypto-wallet-core` prerequisites. | ||
| 2. Runs the `bitcore-node` production build formerly triggered by | ||
| `bitcore-client`'s suppressed `precompile` hook. | ||
| 3. Uses Lerna to compile the remaining packages in dependency order. | ||
| 4. Compiles `bitcore-node` normally after its dependencies. | ||
| 5. Creates the `bitcore-cli` executable link formerly created by its suppressed | ||
| `postbuild` hook. | ||
|
|
||
| The compile scripts pass `--ignore-scripts` or | ||
| `npm_config_ignore_scripts=true`, so explicitly requested scripts run without | ||
| automatically invoking their `pre*` or `post*` companions. | ||
|
|
||
| Common commands include: | ||
|
|
||
| ```sh | ||
| npm run test:bitcore-client | ||
| npm run test:crypto-wallet-core | ||
| npm run test:bitcore-node | ||
| npm run node | ||
| npm run bws | ||
| ``` | ||
|
|
||
| ## Dependency lifecycle policy | ||
|
|
||
| Each managed package has a path-sensitive `lavamoat.allowScripts` policy: | ||
|
|
||
| - Versionless `false` entries deny a dependency script by default, including | ||
| after dependency upgrades. | ||
| - Exact, versioned `true` entries approve only the reviewed release. | ||
|
|
||
| The only current approval is `bcrypt#5.1.0` in | ||
| `@bitpay-labs/bitcore-client`. Bitcore Node reaches the same physical dependency | ||
| through Lerna's link to `bitcore-client`, so its nested policy denies the script | ||
| instead of executing it again. | ||
|
|
||
| Before `allow-scripts run`, `npm run allow-scripts:validate` fails if any managed | ||
| package has: | ||
|
|
||
| - a missing dependency policy; | ||
| - a non-boolean decision; | ||
| - a `true` approval that isn't versioned, or an inactive approval; | ||
| - a top-level `preinstall`, `install`, `postinstall`, `prepublish`, or `prepare` | ||
| hook; | ||
| - a top-level `binding.gyp`, which implies an install hook. | ||
|
|
||
| Inactive denials are accepted because platform-specific dependencies may be | ||
| absent. Inactive approvals are rejected. No approved dependency script runs | ||
| unless validation succeeds for every managed package. | ||
|
|
||
| The root dependency `@lavamoat/preinstall-always-fail` is an installation | ||
| canary: setup succeeds only while the root install remains inert. Keep trusted | ||
| first-party setup work in explicitly named root scripts, not workspace install | ||
| hooks. | ||
|
|
||
| > **Warning: package-level lifecycle scripts run unconditionally when | ||
| > `allowScripts` is configured.** If a managed package has any | ||
| > `lavamoat.allowScripts` entries, `allow-scripts run` will also execute that | ||
| > package's own `install`, `postinstall`, `prepublish`, and `prepare` hooks — | ||
| > regardless of whether those hooks appear in the `allowScripts` policy. | ||
| > The policy only gates *dependency* lifecycle scripts. This is by design in | ||
| > LavaMoat, but it means adding a top-level lifecycle script to a package with | ||
| > an active `allowScripts` config will cause that script to execute during | ||
| > `npm run setup`. Validate the intended behavior before adding such hooks. | ||
|
|
||
| ## Update dependencies | ||
|
|
||
| When adding or updating a dependency: | ||
|
|
||
| 1. Update its manifest and lockfile. | ||
| 2. Install without lifecycle scripts: | ||
|
|
||
| ```sh | ||
| npm ci --ignore-scripts | ||
| npm run bootstrap:inert | ||
| ``` | ||
|
|
||
| 3. Populate new lifecycle paths as versionless denials: | ||
|
|
||
| ```sh | ||
| npm run allow-scripts:config | ||
| ``` | ||
|
|
||
| 4. Review every policy change. Approve a script only when Bitcore requires its | ||
| generated artifact, and use an exact versioned `true` entry. | ||
| 5. Run `npm run allow-scripts:validate`. | ||
| 6. Run `npm run setup` from clean dependency trees and confirm Linux CI. | ||
|
kajoseph marked this conversation as resolved.
Outdated
|
||
|
|
||
| `allow-scripts:config` uses Lerna to inspect every managed dependency tree with | ||
| the root-locked executable. It does not use `npx` or approve scripts | ||
| automatically. Always review the manifest changes it produces. | ||
|
|
||
| ## CI, Docker, and Insight | ||
|
|
||
| CircleCI runs `npm run setup`. Dockerfiles split the equivalent flow into: | ||
|
|
||
| ```sh | ||
| npm ci --ignore-scripts | ||
| npm run setup:installed | ||
| ``` | ||
|
|
||
| `setup:installed` assumes root dependencies are already installed; developers | ||
| should normally use `npm run setup`. | ||
|
|
||
| `packages/insight` is excluded by `lerna.json`, so standard setup does not | ||
| install, inspect, or compile it. Use `npm run insight:build` for that separate | ||
| package. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - Unconfigured dependency: run `npm run allow-scripts:config`, review the new | ||
| denial, and rerun setup. Do not approve it without reviewing its script. | ||
| - Forbidden workspace hook: move trusted work to an explicit root setup or | ||
| compile script; do not bypass validation. | ||
| - Missing `bcrypt` native binding: rerun setup. If the version changed, review | ||
| the new release before updating the pinned approval. | ||
| - Missing generated output after dependency or branch changes: remove the root | ||
| and package `node_modules` directories, then run `npm run setup`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,5 @@ RUN set -x \ | |
| WORKDIR /bitcore | ||
|
|
||
| ADD . . | ||
| RUN npm ci | ||
| RUN npm ci --ignore-scripts | ||
| RUN npm run setup:installed | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.