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

Can I use --experimental-permission in new worker_threads.Worder's execArgv? #1043

Closed
LongTengDao opened this issue Jul 5, 2023 · 6 comments

Comments

@LongTengDao
Copy link

The doc said that's "process-based permission". But it's actually based on execArgv, does it mean that, it can also be used for create worker by design (and "process-based" is a only provisional loose wording used to emphasize the difference from "module-based")?

@RafaelGSS
Copy link
Member

What do you mean by execArgv? If you want to create a worker when using the permission model, you should ensure to pass --experimental-permission + all the permissions the worker needs. We don't do it by default, it's up to the developer.

@LongTengDao
Copy link
Author

So actually --experimental-permission is not a "process-based permission", but "thread-based permission"?

@RafaelGSS
Copy link
Member

You can call main thread-based permission, yeah.

@RafaelGSS
Copy link
Member

What's your use case?

@LongTengDao
Copy link
Author

LongTengDao commented Jul 11, 2023

You can call main thread-based permission, yeah.

What about other threads?

What's your use case?

Thank you for your attentive.

I'm making a sandbox util to run code and keep them away from disk.

There are many codes to run, so if I can use new worker_threads.Worker 100 times instead of child_process.fork 100 times, the cost will be less.

Currently, my code looks like sample 1 because the docs said it's "process-based permission":

function fn (id) {
    return child_process.fork(`/path/to/${id}.js`, [], {
        execArgv: [ `--experimental-permission`, `--allow-fs-read=/path/to/${id}.js` ]
    });
}

And if actually it's "thread-based permission", I want to make it looking like sample 2:

function fn (id) {
    return new worker_threads.Worker(`/path/to/${id}.js`, {
        execArgv: [ `--experimental-permission`, `--allow-fs-read=/path/to/${id}.js` ]
    });
}

@RafaelGSS
Copy link
Member

Well, if you pass the correct arguments to the new Worker you should be fine, right? Unless you need to use the --experimental-permission in the main thread, in that case, you need to pass --allow-worker and make sure to load code that wouldn't bypass it (in the main-thread).

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