Skip to content

Commit e0f0830

Browse files
edsadraduh95
authored andcommitted
doc: document --permission-audit audit mode behavior
Expand the documentation for the --permission-audit flag, which was fixed in 51c09ea to no longer throw ERR_ACCESS_DENIED on denied operations. The previous docs only had a two-sentence description in cli.md and no mention in the permissions guide or process.permission API docs. - permissions.md: add enforce vs audit mode overview, a new "Audit Mode" subsection listing the diagnostics channel names (node:permission-model:*) and the { permission, resource } message shape, and a usage example. Update the Runtime API section to mention both --permission and --permission-audit. - cli.md: expand the --permission-audit section to clarify that --permission is not required, --allow-* flags are not needed, errors are not thrown, and --permission takes precedence when both are set. Add a cross-reference from --permission to --permission-audit. - process.md: note that process.permission is available under both flags, and clarify permission.has() and permission.drop() behavior in audit mode. - node.1: regenerated via `make node.1`. Refs: #64426 Signed-off-by: Adrian Estrada <edsadr@gmail.com> PR-URL: #64791 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent efbede6 commit e0f0830

4 files changed

Lines changed: 107 additions & 9 deletions

File tree

doc/api/cli.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,9 @@ changes:
23162316
Enable the Permission Model for current process. When enabled, the
23172317
following permissions are restricted:
23182318

2319+
> See also [`--permission-audit`](#--permission-audit) for an audit-only mode
2320+
> that logs violations without denying access.
2321+
23192322
* File System - manageable through
23202323
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
23212324
* Network - manageable through [`--allow-net`][] flag
@@ -2331,9 +2334,22 @@ following permissions are restricted:
23312334
added: v25.8.0
23322335
-->
23332336

2334-
Enable audit only for the permission model. When enabled, permission checks
2335-
are performed but access is not denied. Instead, a warning is emitted for
2336-
each permission violation via diagnostics channel.
2337+
Enable audit mode for the permission model. When enabled, permission checks
2338+
are performed but access is **not** denied — no `ERR_ACCESS_DENIED` error is
2339+
thrown. Instead, each permission violation is published through the
2340+
`node:diagnostics_channel` module, and execution continues normally.
2341+
2342+
This flag does not require [`--permission`](#--permission) to be specified. The
2343+
`--allow-*` flags are not needed in audit mode, since no
2344+
access is denied.
2345+
2346+
Audit mode is useful for discovering what permissions your application
2347+
requires before deploying with [`--permission`](#--permission). See the
2348+
[Permission Model][] documentation for the list of diagnostics channel names
2349+
and the message format.
2350+
2351+
If both [`--permission`](#--permission) and `--permission-audit` are specified,
2352+
`--permission` takes precedence and the Permission Model runs in enforce mode.
23372353

23382354
### `--preserve-symlinks`
23392355

doc/api/permissions.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ will restrict access to all available permissions.
4848
The available permissions are documented by the [`--permission`][]
4949
flag.
5050

51+
The Permission Model has two operational modes:
52+
53+
* **Enforce mode** (default when using [`--permission`][]): Access is denied and
54+
an `ERR_ACCESS_DENIED` error is thrown for any operation the process has not
55+
been granted permission to perform.
56+
* **Audit mode** (when using [`--permission-audit`][]): Permission checks are
57+
performed and violations are published through the diagnostics channel, but
58+
access is **not** denied. Execution continues normally. This mode is useful
59+
for discovering what permissions your application requires before deploying
60+
with enforce mode.
61+
5162
When starting Node.js with `--permission`,
5263
the ability to access the file system through the `fs` module, access the network,
5364
spawn processes, use `node:worker_threads`, use native addons, use WASI, use
@@ -77,8 +88,8 @@ flag. For WASI, use the [`--allow-wasi`][] flag. For FFI, use the
7788
#### Runtime API
7889

7990
When enabling the Permission Model through the [`--permission`][]
80-
flag a new property `permission` is added to the `process` object.
81-
This property contains the following functions:
91+
or [`--permission-audit`][] flags, a new property `permission` is added to the
92+
`process` object. This property contains the following functions:
8293

8394
##### `permission.has(scope[, reference])`
8495

@@ -127,6 +138,56 @@ process.permission.has('fs.read', '/etc/myapp/config.json'); // false
127138
process.permission.drop('child');
128