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

Deno no longer allows permission to os.cpus with --allow-sys=osRelease after 1.39.2 #22221

Closed
KlaasSkelteAtEnatom opened this issue Feb 1, 2024 · 1 comment · Fixed by #22260
Labels
cli related to cli/ dir good first issue Good for newcomers permissions related to --allow-* flags

Comments

@KlaasSkelteAtEnatom
Copy link

Version: Deno 1.39.2 and newer (#21697)

Reproducer:

import os from "node:os";

console.log(os.cpus());

Run with deno run --allow-sys=osRelease main.ts.

Under Deno 1.39.1 and earlier, this shows cpu information, with 1.39.2 and newer, an error is shown (or when an interactive shell is used, a prompt):

error: Uncaught (in promise) PermissionDenied: Requires sys access to "cpus", run again with the --allow-sys flag

With Deno 1.39.2, we're now forced to just give a blanket --allow-sys permission for non-interactive deployments, rather than the granular osRelease like before, as allow-sys only allows providing granular permissions for functions in the Deno namespace.

(A solution could be to extend --allow-sys with something like node: prefixes, so that just granting cpus permission would be --allow-sys=node:cpus)

@littledivy
Copy link
Member

littledivy commented Feb 1, 2024

os.cpus() was not implemented (It returned a list with empty fields) in 1.39.1 or before. Keeping --allow-sys=osRelease was wrong because os.cpus() relied on other platform system info. (eg: /proc/cpuinfo on Linux)

We actualy check for --allow-sys=cpus but this was not added as a valid option.

Adding "cpus" to this match arm will allow deno run --allow-sys=cpus:

"hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces"
| "systemMemoryInfo" | "uid" | "gid" => Ok(kind),

@littledivy littledivy added good first issue Good for newcomers cli related to cli/ dir permissions related to --allow-* flags labels Feb 1, 2024
littledivy pushed a commit that referenced this issue Feb 7, 2024
Fixes #22221 with the suggested fix, and added "cpus" to the existing
tests.
littledivy pushed a commit that referenced this issue Feb 8, 2024
Fixes #22221 with the suggested fix, and added "cpus" to the existing
tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir good first issue Good for newcomers permissions related to --allow-* flags
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants