Skip to content

Commit 57bb983

Browse files
RafaelGSSruyadorno
authored andcommitted
src,lib: stabilize permission model
Move permission model from 1.1 (Active Development) to 2.0 (Stable). PR-URL: #56201 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
1 parent ea53c4b commit 57bb983

File tree

53 files changed

+143
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+143
-147
lines changed

benchmark/fs/readfile-permission-enabled.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, {
1717
concurrent: [1, 10],
1818
}, {
1919
flags: [
20-
'--experimental-permission',
20+
'--permission',
2121
'--allow-fs-read=*',
2222
'--allow-fs-write=*',
2323
'--allow-child-process',

benchmark/permission/permission-processhas-fs-read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const rootPath = path.resolve(__dirname, '../../..');
1111

1212
const options = {
1313
flags: [
14-
'--experimental-permission',
14+
'--permission',
1515
`--allow-fs-read=${rootPath}`,
1616
'--allow-child-process',
1717
'--no-warnings',

benchmark/permission/permission-startup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function spawnProcess(script, bench, state) {
4848
function main({ count, script, nFiles, prefixPath }) {
4949
script = path.resolve(__dirname, '../../', `${script}.js`);
5050
const optionsWithScript = [
51-
'--experimental-permission',
51+
'--permission',
5252
`--allow-fs-read=${script}`,
5353
...mockFiles(nFiles, prefixPath).map((file) => '--allow-fs-read=' + file),
5454
script,

doc/api/cli.md

+37-26
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ require('nodejs-addon-example');
126126
```
127127

128128
```console
129-
$ node --experimental-permission --allow-fs-read=* index.js
129+
$ node --permission --allow-fs-read=* index.js
130130
node:internal/modules/cjs/loader:1319
131131
return process.dlopen(module, path.toNamespacedPath(filename));
132132
^
@@ -168,7 +168,7 @@ childProcess.spawn('node', ['-e', 'require("fs").writeFileSync("/new-file", "exa
168168
```
169169

170170
```console
171-
$ node --experimental-permission --allow-fs-read=* index.js
171+
$ node --permission --allow-fs-read=* index.js
172172
node:internal/child_process:388
173173
const err = this._handle.spawn(options);
174174
^
@@ -192,12 +192,15 @@ Error: Access to this API has been restricted
192192
<!-- YAML
193193
added: v20.0.0
194194
changes:
195+
- version: REPLACEME
196+
pr-url: https://github.com/nodejs/node/pull/56201
197+
description: Permission Model and --allow-fs flags are stable.
195198
- version: v20.7.0
196199
pr-url: https://github.com/nodejs/node/pull/49047
197200
description: Paths delimited by comma (`,`) are no longer allowed.
198201
-->
199202

200-
> Stability: 1.1 - Active development
203+
> Stability: 2 - Stable.
201204
202205
This flag configures file system read permissions using
203206
the [Permission Model][].
@@ -213,7 +216,7 @@ Examples can be found in the [File System Permissions][] documentation.
213216
The initializer module also needs to be allowed. Consider the following example:
214217

215218
```console
216-
$ node --experimental-permission index.js
219+
$ node --permission index.js
217220

218221
Error: Access to this API has been restricted
219222
at node:internal/main/run_main_module:23:47 {
@@ -226,20 +229,23 @@ Error: Access to this API has been restricted
226229
The process needs to have access to the `index.js` module:
227230

228231
```bash
229-
node --experimental-permission --allow-fs-read=/path/to/index.js index.js
232+
node --permission --allow-fs-read=/path/to/index.js index.js
230233
```
231234

232235
### `--allow-fs-write`
233236

234237
<!-- YAML
235238
added: v20.0.0
236239
changes:
240+
- version: REPLACEME
241+
pr-url: https://github.com/nodejs/node/pull/56201
242+
description: Permission Model and --allow-fs flags are stable.
237243
- version: v20.7.0
238244
pr-url: https://github.com/nodejs/node/pull/49047
239245
description: Paths delimited by comma (`,`) are no longer allowed.
240246
-->
241247

242-
> Stability: 1.1 - Active development
248+
> Stability: 2 - Stable.
243249
244250
This flag configures file system write permissions using
245251
the [Permission Model][].
@@ -283,7 +289,7 @@ new WASI({
283289
```
284290

285291
```console
286-
$ node --experimental-permission --allow-fs-read=* index.js
292+
$ node --permission --allow-fs-read=* index.js
287293

288294
Error: Access to this API has been restricted
289295
at node:internal/main/run_main_module:30:49 {
@@ -314,7 +320,7 @@ new Worker(__filename);
314320
```
315321

316322
```console
317-
$ node --experimental-permission --allow-fs-read=* index.js
323+
$ node --permission --allow-fs-read=* index.js
318324

319325
Error: Access to this API has been restricted
320326
at node:internal/main/run_main_module:17:47 {
@@ -970,24 +976,6 @@ added:
970976
971977
Enable experimental support for the network inspection with Chrome DevTools.
972978

973-
### `--experimental-permission`
974-
975-
<!-- YAML
976-
added: v20.0.0
977-
-->
978-
979-
> Stability: 1.1 - Active development
980-
981-
Enable the Permission Model for current process. When enabled, the
982-
following permissions are restricted:
983-
984-
* File System - manageable through
985-
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
986-
* Child Process - manageable through [`--allow-child-process`][] flag
987-
* Worker Threads - manageable through [`--allow-worker`][] flag
988-
* WASI - manageable through [`--allow-wasi`][] flag
989-
* Addons - manageable through [`--allow-addons`][] flag
990-
991979
### `--experimental-print-required-tla`
992980

993981
<!-- YAML
@@ -1807,6 +1795,28 @@ unless either the `--pending-deprecation` command-line flag, or the
18071795
are used to provide a kind of selective "early warning" mechanism that
18081796
developers may leverage to detect deprecated API usage.
18091797

1798+
### `--permission`
1799+
1800+
<!-- YAML
1801+
added: v20.0.0
1802+
changes:
1803+
- version: REPLACEME
1804+
pr-url: https://github.com/nodejs/node/pull/56201
1805+
description: Permission Model is now stable.
1806+
-->
1807+
1808+
> Stability: 2 - Stable.
1809+
1810+
Enable the Permission Model for current process. When enabled, the
1811+
following permissions are restricted:
1812+
1813+
* File System - manageable through
1814+
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
1815+
* Child Process - manageable through [`--allow-child-process`][] flag
1816+
* Worker Threads - manageable through [`--allow-worker`][] flag
1817+
* WASI - manageable through [`--allow-wasi`][] flag
1818+
* Addons - manageable through [`--allow-addons`][] flag
1819+
18101820
### `--preserve-symlinks`
18111821

18121822
<!-- YAML
@@ -3145,6 +3155,7 @@ one is included in the list below.
31453155
* `--openssl-legacy-provider`
31463156
* `--openssl-shared-config`
31473157
* `--pending-deprecation`
3158+
* `--permission`
31483159
* `--preserve-symlinks-main`
31493160
* `--preserve-symlinks`
31503161
* `--prof-process`

doc/api/permissions.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ If you find a potential security vulnerability, please refer to our
2828

2929
<!-- type=misc -->
3030

31-
> Stability: 1.1 - Active development
31+
> Stability: 2 - Stable.
3232
3333
<!-- name=permission-model -->
3434

3535
The Node.js Permission Model is a mechanism for restricting access to specific
3636
resources during execution.
37-
The API exists behind a flag [`--experimental-permission`][] which when enabled,
37+
The API exists behind a flag [`--permission`][] which when enabled,
3838
will restrict access to all available permissions.
3939

40-
The available permissions are documented by the [`--experimental-permission`][]
40+
The available permissions are documented by the [`--permission`][]
4141
flag.
4242

43-
When starting Node.js with `--experimental-permission`,
43+
When starting Node.js with `--permission`,
4444
the ability to access the file system through the `fs` module, spawn processes,
4545
use `node:worker_threads`, use native addons, use WASI, and enable the runtime inspector
4646
will be restricted.
4747

4848
```console
49-
$ node --experimental-permission index.js
49+
$ node --permission index.js
5050

5151
Error: Access to this API has been restricted
5252
at node:internal/main/run_main_module:23:47 {
@@ -64,7 +64,7 @@ flag. For WASI, use the [`--allow-wasi`][] flag.
6464

6565
#### Runtime API
6666

67-
When enabling the Permission Model through the [`--experimental-permission`][]
67+
When enabling the Permission Model through the [`--permission`][]
6868
flag a new property `permission` is added to the `process` object.
6969
This property contains one function:
7070

@@ -90,10 +90,8 @@ To allow access to the file system, use the [`--allow-fs-read`][] and
9090
[`--allow-fs-write`][] flags:
9191

9292
```console
93-
$ node --experimental-permission --allow-fs-read=* --allow-fs-write=* index.js
93+
$ node --permission --allow-fs-read=* --allow-fs-write=* index.js
9494
Hello world!
95-
(node:19836) ExperimentalWarning: Permission is an experimental feature
96-
(Use `node --trace-warnings ...` to show where the warning was created)
9795
```
9896

9997
The valid arguments for both flags are:
@@ -167,5 +165,5 @@ There are constraints you need to know before using this system:
167165
[`--allow-fs-write`]: cli.md#--allow-fs-write
168166
[`--allow-wasi`]: cli.md#--allow-wasi
169167
[`--allow-worker`]: cli.md#--allow-worker
170-
[`--experimental-permission`]: cli.md#--experimental-permission
168+
[`--permission`]: cli.md#--permission
171169
[`permission.has()`]: process.md#processpermissionhasscope-reference

doc/api/process.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3091,7 +3091,7 @@ added: v20.0.0
30913091
30923092
* {Object}
30933093
3094-
This API is available through the [`--experimental-permission`][] flag.
3094+
This API is available through the [`--permission`][] flag.
30953095
30963096
`process.permission` is an object whose methods are used to manage permissions
30973097
for the current process. Additional documentation is available in the
@@ -4428,8 +4428,8 @@ cases:
44284428
[`'exit'`]: #event-exit
44294429
[`'message'`]: child_process.md#event-message
44304430
[`'uncaughtException'`]: #event-uncaughtexception
4431-
[`--experimental-permission`]: cli.md#--experimental-permission
44324431
[`--no-deprecation`]: cli.md#--no-deprecation
4432+
[`--permission`]: cli.md#--permission
44334433
[`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
44344434
[`Buffer`]: buffer.md
44354435
[`ChildProcess.disconnect()`]: child_process.md#subprocessdisconnect

doc/node.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ Specify the
176176
.Ar module
177177
to use as a custom module loader.
178178
.
179-
.It Fl -experimental-permission
180-
Enable the experimental permission model.
179+
.It Fl -permission
180+
Enable the permission model.
181181
.
182182
.It Fl -experimental-shadow-realm
183183
Use this flag to enable ShadowRealm support.

lib/internal/process/permission.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ const { validateString, validateBuffer } = require('internal/validators');
99
const { Buffer } = require('buffer');
1010
const { isBuffer } = Buffer;
1111

12-
let experimentalPermission;
12+
let _permission;
1313

1414
module.exports = ObjectFreeze({
1515
__proto__: null,
1616
isEnabled() {
17-
if (experimentalPermission === undefined) {
17+
if (_permission === undefined) {
1818
const { getOptionValue } = require('internal/options');
19-
experimentalPermission = getOptionValue('--experimental-permission');
19+
_permission = getOptionValue('--permission');
2020
}
21-
return experimentalPermission;
21+
return _permission;
2222
},
2323
has(scope, reference) {
2424
validateString(scope, 'scope');

lib/internal/process/pre_execution.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,13 @@ function initializeClusterIPC() {
610610
}
611611

612612
function initializePermission() {
613-
const experimentalPermission = getOptionValue('--experimental-permission');
614-
if (experimentalPermission) {
613+
const permission = getOptionValue('--permission');
614+
if (permission) {
615615
process.binding = function binding(_module) {
616616
throw new ERR_ACCESS_DENIED('process.binding');
617617
};
618618
// Guarantee path module isn't monkey-patched to bypass permission model
619619
ObjectFreeze(require('path'));
620-
emitExperimentalWarning('Permission');
621620
const { has } = require('internal/process/permission');
622621
const warnFlags = [
623622
'--allow-addons',
@@ -669,7 +668,7 @@ function initializePermission() {
669668
ArrayPrototypeForEach(availablePermissionFlags, (flag) => {
670669
const value = getOptionValue(flag);
671670
if (value.length) {
672-
throw new ERR_MISSING_OPTION('--experimental-permission');
671+
throw new ERR_MISSING_OPTION('--permission');
673672
}
674673
});
675674
}

src/env.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ Environment::Environment(IsolateData* isolate_data,
931931
std::move(traced_value));
932932
}
933933

934-
if (options_->experimental_permission) {
934+
if (options_->permission) {
935935
permission()->EnablePermissions();
936936
// The process shouldn't be able to neither
937937
// spawn/worker nor use addons or enable inspector

src/node_options.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
475475
"experimental ES Module import.meta.resolve() parentURL support",
476476
&EnvironmentOptions::experimental_import_meta_resolve,
477477
kAllowedInEnvvar);
478-
AddOption("--experimental-permission",
478+
AddOption("--permission",
479479
"enable the permission system",
480-
&EnvironmentOptions::experimental_permission,
480+
&EnvironmentOptions::permission,
481481
kAllowedInEnvvar,
482482
false);
483+
AddAlias("--experimental-permission", "--permission");
483484
AddOption("--allow-fs-read",
484485
"allow permissions to read the filesystem",
485486
&EnvironmentOptions::allow_fs_read,

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class EnvironmentOptions : public Options {
134134
std::string input_type; // Value of --input-type
135135
std::string type; // Value of --experimental-default-type
136136
bool entry_is_url = false;
137-
bool experimental_permission = false;
137+
bool permission = false;
138138
std::vector<std::string> allow_fs_read;
139139
std::vector<std::string> allow_fs_write;
140140
bool allow_addons = false;

test/addons/no-addons/permission.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --experimental-permission --allow-fs-read=*
1+
// Flags: --permission --allow-fs-read=*
22

33
'use strict';
44

test/es-module/test-cjs-legacyMainResolve-permission.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
// Flags: --expose-internals --experimental-permission --allow-fs-read=* --allow-child-process
3+
// Flags: --expose-internals --permission --allow-fs-read=* --allow-child-process
44

55
require('../common');
66

@@ -40,7 +40,7 @@ describe('legacyMainResolve', () => {
4040
process.execPath,
4141
[
4242
'--expose-internals',
43-
'--experimental-permission',
43+
'--permission',
4444
...allowReadFiles,
4545
'-e',
4646
`
@@ -98,7 +98,7 @@ describe('legacyMainResolve', () => {
9898
process.execPath,
9999
[
100100
'--expose-internals',
101-
'--experimental-permission',
101+
'--permission',
102102
...allowReadFiles,
103103
'-e',
104104
`

0 commit comments

Comments
 (0)