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

accessing files in virtual filesystems like /sys on linux without having to set --allow-all permissions #27564

Open
nirjan-dev opened this issue Jan 6, 2025 · 1 comment

Comments

@nirjan-dev
Copy link

version info

deno 2.1.4 (stable, release, x86_64-unknown-linux-gnu)
v8 13.0.245.12-rusty
typescript 5.6.2

context

I'm trying to create a home lab server monitoring app with Deno so I need to grab some system metrics. I found a library which gives me APIs to access system metrics which aren't provided my native Deno APIs. I'm trying to access the battery info but it's not working if I don't use --allow-all permissions. This is because the library is basically reading this file on linux: /sys/class/power_supply/BAT0/uevent. So, giving just read permission for that file doesn't seem to work (I suspect because it's inside a virtual filesystem but I don't have enough linux expertise to be certain).

limited replication

Try running this code without giving --allow-all permission acces

const batteryStatsRaw = await Deno.readFile(
    `/sys/class/power_supply/BAT0/uevent`
  );

  const powerStatsText = await new TextDecoder().decode(batteryStatsRaw);

  console.log(powerStatsText);

error messages

I get this error message when it tries to read that file (works fine if I do --allow-all)

error: Uncaught (in promise) NotCapable: Requires all access to "/sys/class/power_supply/BAT0/uevent", specify the required permissions during compilation using `deno compile --allow-all`
    at Object.readFile (ext:deno_fs/30_fs.js:753:24)
    at getBatteryStats (file:///tmp/deno-compile-agent/server-monitor-app/agent/main.ts:32:39)
    at Object.runMicrotasks (ext:core/01_core.js:683:26)
    at Array.processTicksAndRejections (ext:deno_node/_next_tick.ts:59:10)
    at eventLoopTick (ext:core/01_core.js:172:29)
    at async getMetrics (file:///tmp/deno-compile-agent/server-monitor-app/agent/main.ts:43:14)
    at async file:///tmp/deno-compile-agent/server-monitor-app/agent/main.ts:89:19
@gg-sr
Copy link

gg-sr commented Jan 9, 2025

deno 2.1.4 (stable, release, x86_64-unknown-linux-gnu)
v8 13.0.245.12-rusty
typescript 5.6.2


Similarly, writing to /dev/stdout seems to require --allow-all.

$ deno repl --allow-write=/dev/stdout
Deno 2.1.4
exit using ctrl+d, ctrl+c, or close()
> await Deno.writeTextFile('/dev/stdout', 'hello world')
Uncaught NotCapable: Requires all access to "/dev/stdout", run again with the --allow-all flag
    at writeFile (ext:deno_fs/30_fs.js:841:13)
    at Object.writeTextFile (ext:deno_fs/30_fs.js:883:12)
    at <anonymous>:1:33

I'd like to run commands that accept an output file path, and sometimes I want that "output file" to be /dev/stdout, which requires me to pass --allow-all (since --allow-all=/dev/stdout is not allowed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants