Load permission settings from config files #1074
Copy link
Copy link
Closed as not planned
Labels
Description
This issue is to discuss implementation of the point referenced in the title of #898.
My first concern would be on which flag to use to pass the file. The options that I can think of are:
- Use the
--experimental-policyflag. My main concern is this would imply the need to also set policy. - Add an optional file to the
--experimental-permissionflag (I'm still unsure that's even possible). - Creating a new flag (e.g.
--permission-file).
Another doubt I have is what would be the expected behaviour on precedence when permissions are set on both flags (e.g. --allow-fs-read) and file. Options:
- Fail when both set.
- Fail when both set for the same setting (e.g. not fail if permission to read set on file and permission to write set on flag but fail if read set on both) This doesn't make much sense IMO.
- Use the union of both.
- Use the intersection of both.
- Ignore file.
- Ignore flag.
I would go with:
1.2. Add an optional file to the --experimental-permission flag (If possible) as we wouldn't need a new flag.
2.1. Fail when both set. I'd assume that to be a mistake, and throw an error explaining the problem. Also this might prevent some sort of attacks using the unconfigured one.
Any ideas and suggestions are welcomed.
Reactions are currently unavailable
Activity
RafaelGSS commentedon Aug 17, 2023
As discussed in today's call. I have two questions:
Do we need this feature? With the addition of
.env(src: add built-in.envfile support node#48890) +NODE_OPTIONSeventually all the--allow-*flags can be passed byNODE_OPTIONSenvironment variable in.envfile.If we decide that we want to support it, we should be careful with the proposed design. While the addition of a new flag
--permission-fileseems ok, we're introducing a new experimental CLI flag which, IMO, is bad for the developer experience. On the other hand, adding an optional file to the--experimental-permissionflag seems far from ideal since we'll need to:--experimental-policyis passed with another file name--experimental-permissionis passed with no file. For instance, if we change theexperimental_permissiontostd::string, it will be empty when no file is passed. How would we identify that--experimental-permissionis true?We've also found this Deno discussion: denoland/deno#12763. We must discuss both points before a PR.
In any case, I'm pinging @nodejs/tsc, specially @tniessen and @bmeck to hear your thoughts.
GeoffreyBooth commentedon Aug 17, 2023
I would encourage people to avoid building config files for specific features; see nodejs/node#48852 and nodejs/node#43973 as attempts to create config files for the test runner and module loaders, respectively. I think users deserve to be able to configure Node in its entirety through a single config file. nodejs/node#48890 was a starting point; we can add support for configuration via a JSON (or other format) file if desired.
RafaelGSS commentedon Aug 18, 2023
The idea is to use an existing config file @GeoffreyBooth (
--experimental-policy=policy). But, as you said, looks like the env feature might solve it all.GeoffreyBooth commentedon Aug 18, 2023
Before
--experimental-policygoes stable we should probably figure out how to create a single unified config file for all of Node, and then what’s currently inpolicy.jsoncould live under apolicykey or something.bmeck commentedon Aug 18, 2023
@RafaelGSS there are a few major concerns I have with environment variables:
I'm pretty -1 on using ENV for this since it just isn't designed for complex usages or large values. I agree for very simple not fully specified things it would be fine but would cause a preference on large scale permissions grants due to problems at large scale constraints.
bmeck commentedon Aug 18, 2023
I would note I am not proposing that we ban these flags from .env etc. just that it seems a poor best practice at a glance.
RafaelGSS commentedon Aug 18, 2023
The concern I raised in this issue was that is not clear, at the first moment, what issue a separated config file for the permission model will solve. I mean, currently, it's annoying to allow a bunch of paths through the CLI. Imagine:
--allow-fs-read=/path1/ --allow-fs-read=/pat2and so on. While the wildcard would solve 70% of this issue, it migth be annoying for some use cases.However, due to the fact, you can pass the same flags through the
NODE_OPTIONSenv var, that could be a solution (or at very least, workaround) for these cases.As a separate discussion, but that overlaps with it. Have we ever considered a unified nodejs configuration file? Not by env vars, but a single file where I can define multiple rules of nodejs mechanism, such as policies.
bmeck commentedon Aug 18, 2023
@RafaelGSS simply put if you have finer grained / verbose levels of settings you end up with problems due to how shells work. On my machine:
Is the maxium space I can use up as seen with:
This includes normal environment variables and argv. It isn't too hard to hit this limit with any complex system.
GeoffreyBooth commentedon Aug 18, 2023
Yes, see https://github.com/orgs/nodejs/discussions/44975 and the issues it cites. Basically we thought that supporting
.envfiles would be a quick win and useful in its own right, separate from that feature’s ability to configure Node. But I think everyone agrees that something like--config node.config.jsonwould be nicer still, and complementary. The challenges there are figuring out how to parse JSON at that early point of startup, before V8 has loaded (which we thought would be really hard, but @anonrig seems to think might be doable without too much trouble thanks to simdjson) and the design challenge of finding a JSON schema that everyone can agree on. Maybe the latter isn’t insurmountable, if we use the flags as our starting point, and just go with camelcased versions of all of them, something like that. So yeah I think it’s very doable, at least now that nodejs/node#48890 has landed and paved the way.github-actions commentedon Nov 30, 2023
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
github-actions commentedon Feb 29, 2024
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.