Skip to content

Commit 62ca1ba

Browse files
authored
vfs: allow mounting in permission audit mode
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: #66745 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent a4231cf commit 62ca1ba

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎doc/api/cli.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ added: v26.9.0
324324
When using the [Permission Model][], a [virtual file system][] cannot be
325325
mounted by default: [`vfs.mount()`][] throws `ERR_INVALID_STATE` unless the
326326
user explicitly passes the `--allow-fs-vfs` flag when starting Node.js.
327+
In audit mode ([`--permission-audit`](#--permission-audit)), mounting is not
328+
refused and no message is published to the diagnostics channel.
327329

328330
A mounted VFS serves paths that the file system permissions do not describe,
329331
so mounting one is gated on its own flag rather than on `--allow-fs-read` or

‎doc/node.1‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ process.permission.has('fs.read', 'custom-require-2.js'); // true
206206
When using the Permission Model, a virtual file system cannot be
207207
mounted by default: \fBvfs.mount()\fR throws \fBERR_INVALID_STATE\fR unless the
208208
user explicitly passes the \fB--allow-fs-vfs\fR flag when starting Node.js.
209+
In audit mode (\fB--permission-audit\fR), mounting is not
210+
refused and no message is published to the diagnostics channel.
209211
A mounted VFS serves paths that the file system permissions do not describe,
210212
so mounting one is gated on its own flag rather than on \fB--allow-fs-read\fR or
211213
\fB--allow-fs-write\fR.

‎lib/internal/vfs/setup.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ let normalizedVfsRoot = null;
100100
let normalizedVfsRootPrefix = null;
101101

102102
function registerVFS(vfs) {
103-
if (permission.isEnabled() && !getOptionValue('--allow-fs-vfs')) {
103+
// TODO(rafaelgss): publish a diagnostics channel message in audit mode.
104+
if (permission.isEnabled() && !permission.isAuditMode() &&
105+
!getOptionValue('--allow-fs-vfs')) {
104106
throw new ERR_INVALID_STATE(
105107
'VFS cannot be used when the permission model is enabled. ' +
106108
'Use --allow-fs-vfs to allow it.',

‎test/parallel/test-permission-allow-fs-vfs-flags.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ spawnSyncAndExit(
2020
},
2121
);
2222

23+
// Mounting a VFS is refused under --permission without --allow-fs-vfs, but
24+
// audit mode only observes and lets the mount through.
25+
const mount = `
26+
require('node:vfs').create().mount();
27+
console.log('mounted');
28+
`;
29+
30+
spawnSyncAndExit(
31+
process.execPath,
32+
['--experimental-vfs', '--permission', '-e', mount],
33+
{
34+
status: 1,
35+
signal: null,
36+
stderr: /ERR_INVALID_STATE/,
37+
},
38+
);
39+
40+
spawnSyncAndAssert(
41+
process.execPath,
42+
['--experimental-vfs', '--permission-audit', '-e', mount],
43+
{
44+
stdout: /^mounted$/m,
45+
},
46+
);
47+
2348
if (process.config.variables.node_without_node_options) {
2449
common.skip('missing NODE_OPTIONS support');
2550
}

0 commit comments

Comments
 (0)