Skip to content
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

doc: add section about using npx with permission model #56539

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

RafaelGSS
Copy link
Member

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Jan 9, 2025
@wraithgar
Copy link
Contributor

@RafaelGSS and I tested this locally w/ both npx and npm exec. This is the preferred way to set these flags, as it works in virtually all existing versions of npm already and does exactly what we need. Future changes to these flags only requires updating the flags you set via this parameter, and no changes to npm would be needed.

@AugustinMauroy
Copy link
Member

maybe add link to npx docs for people not 100% aware of what is npx

https://docs.npmjs.com/cli/v8/commands/npx

@wraithgar
Copy link
Contributor

If you link please link to the latest version, not npm 8

https://docs.npmjs.com/cli/commands/npx

@wraithgar
Copy link
Contributor

Realized that this won't work for packages installed globally and for packages installed in the npx cache. The example given is for if the package is installed in the current package at cwd.

Not sure if there's a good way to document what --allow-fs-read needs to be in other cases, and why. But here's what will work:

Examples using fish shell

# installed globally
$ npm ls -g
/Users/wraithgar/.nvm/versions/node/v22.13.0/lib
├── [email protected]
$ npx --node-options="--permission --allow-fs-read=$(npm prefix -g)" json --version
json 11.0.0
written by Trent Mick
https://github.com/trentm/json
# using npx cache
$ npx --node-options="--permission --allow-fs-read=$(npm config get cache)" semver parse 1.0.0
1.0.0

This seems like a lot to try to document for this flag.

@marco-ippolito
Copy link
Member

marco-ippolito commented Jan 10, 2025

Maybe we can wrap the permission model as an npx flag? As a new npx feature

@wraithgar
Copy link
Contributor

I would discourage adding a new npm config for this, as it would mean it wouldn't work for existing versions of npx, and in a way that it was silently ignored so you wouldn't know it wasn't working.

Also it would mean having to keep npm in sync w/ these params if they ever changed or were added to. It would be completely decoupled from Node.js config itself, meaning someone would just have to "remember" to do it if Node.js changed.

Showing users how to set the flags in npx is the best option, as it allows them to update the flags w/o having to wait on npm to update, and already works.

@RafaelGSS RafaelGSS force-pushed the mention-npx-node-options branch from 93ea0ab to 1105023 Compare January 10, 2025 17:20
@marco-ippolito
Copy link
Member

marco-ippolito commented Jan 10, 2025

I would discourage adding a new npm config for this, as it would mean it wouldn't work for existing versions of npx, and in a way that it was silently ignored so you wouldn't know it wasn't working.

Also it would mean having to keep npm in sync w/ these params if they ever changed or were added to. It would be completely decoupled from Node.js config itself, meaning someone would just have to "remember" to do it if Node.js changed.

Showing users how to set the flags in npx is the best option, as it allows them to update the flags w/o having to wait on npm to update, and already works.

If you add a command line flag to npx, in a version that does not support it, it should should throw an unrecognized flag, I'd not expect npx --foobar to fail silently (on the phone cant test but I expect it fails).
Unit tests that can keep "in sync" the permission model flags and npm if are removed from Node.
But anyways my suggestion applies only if npx cannot properly support passing permission model flags.
I also found some struggle resolving paths through shebang (I couldnt make it work properly) so if not possible or not ergonomic, we should find a better solution.

@wraithgar
Copy link
Contributor

wraithgar commented Jan 10, 2025

If you add a command line flag to npx, in a version that does not support it, it should should throw an unrecognized flag,

We are working towards having npm do this, unfortunately because it doesn't do that now nobody using npx today would get an error. npm 12 (and npx by extension) should throw on unknown config.

@RafaelGSS
Copy link
Member Author

To be honest, I think documenting it is the best approach we could do to users, they will be 100% aware of paths they are giving access to, and it does make total sense for me having to give access explicitly to npx cache folder for instance.

In the case of shebang, it goes a bit out of permission model scope, this is more unix path resolution, I don't think we should do something to make it "easier". This is a standard pattern.

@marco-ippolito
Copy link
Member

If you add a command line flag to npx, in a version that does not support it, it should should throw an unrecognized flag,

We are working towards having npm do this, unfortunately because it doesn't do that now nobody using npx today would get an error. npm 12 (and npx by extension) should throw on unknown config.

I see then it makes totally sense! Thanks

@RafaelGSS RafaelGSS force-pushed the mention-npx-node-options branch from 1105023 to b8b9f9c Compare January 10, 2025 18:14
@RafaelGSS RafaelGSS force-pushed the mention-npx-node-options branch from b8b9f9c to 0f25b8e Compare January 10, 2025 18:34
@RafaelGSS RafaelGSS added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 10, 2025
@jasnell jasnell added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 11, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jan 11, 2025
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/56539
✔  Done loading data for nodejs/node/pull/56539
----------------------------------- PR info ------------------------------------
Title      doc: add section about using npx with permission model (#56539)
Author     Rafael Gonzaga <[email protected]> (@RafaelGSS)
Branch     RafaelGSS:mention-npx-node-options -> nodejs:main
Labels     doc, author ready
Commits    1
 - doc: add section about using npx with permission model
Committers 1
 - RafaelGSS <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/56539
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruy Adorno <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/56539
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruy Adorno <[email protected]>
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - doc: add section about using npx with permission model
   ℹ  This PR was created on Thu, 09 Jan 2025 21:49:15 GMT
   ✔  Approvals: 2
   ✔  - Trivikram Kamat (@trivikr): https://github.com/nodejs/node/pull/56539#pullrequestreview-2541035334
   ✔  - Ruy Adorno (@ruyadorno) (TSC): https://github.com/nodejs/node/pull/56539#pullrequestreview-2541159264
   ✔  Last GitHub CI successful
   ℹ  Green GitHub CI is sufficient
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/12727899336

@marco-ippolito marco-ippolito removed the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Jan 13, 2025
@marco-ippolito marco-ippolito added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 13, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 13, 2025
@nodejs-github-bot nodejs-github-bot merged commit b22c3d3 into nodejs:main Jan 13, 2025
29 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in b22c3d3

targos pushed a commit that referenced this pull request Jan 13, 2025
Co-Authored-By: Gar <[email protected]>
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #56539
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruy Adorno <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Jan 13, 2025
Co-Authored-By: Gar <[email protected]>
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: nodejs#56539
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruy Adorno <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants