-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add configurable permissions for Workers (#8215)
This commit adds new option to "Worker" Web API that allows to configure permissions. New "Worker.deno.permissions" option can be used to define limited permissions to the worker thread by either: - inherit set of parent thread permissions - use limited subset of parent thread permissions - revoke all permissions (full sandbox) In order to achieve this functionality "CliModuleLoader" was modified to accept "initial permissions", which are used for top module loading (ie. uses parent thread permission set to load top level module of a worker).
- Loading branch information
Showing
33 changed files
with
1,062 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
cli/tests/subdir/fetching_worker.js → cli/tests/workers/fetching_worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
self.onmessage = async () => { | ||
const hrtime = await Deno.permissions.query({ name: "hrtime" }); | ||
const net = await Deno.permissions.query({ name: "net" }); | ||
const plugin = await Deno.permissions.query({ name: "plugin" }); | ||
const read = await Deno.permissions.query({ name: "read" }); | ||
const run = await Deno.permissions.query({ name: "run" }); | ||
const write = await Deno.permissions.query({ name: "write" }); | ||
self.postMessage( | ||
hrtime.state === "denied" && | ||
net.state === "denied" && | ||
plugin.state === "denied" && | ||
read.state === "denied" && | ||
run.state === "denied" && | ||
write.state === "denied", | ||
); | ||
self.close(); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { fromFileUrl } from "../../../std/path/mod.ts"; | ||
|
||
const worker = new Worker( | ||
new URL("./read_check_granular_worker.js", import.meta.url).href, | ||
{ | ||
type: "module", | ||
deno: { | ||
namespace: true, | ||
permissions: { | ||
read: [], | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
let received = 0; | ||
const messages = []; | ||
|
||
worker.onmessage = ({ data: childResponse }) => { | ||
received++; | ||
postMessage({ | ||
childHasPermission: childResponse.hasPermission, | ||
index: childResponse.index, | ||
parentHasPermission: messages[childResponse.index], | ||
}); | ||
if (received === messages.length) { | ||
worker.terminate(); | ||
} | ||
}; | ||
|
||
onmessage = async ({ data }) => { | ||
const { state } = await Deno.permissions.query({ | ||
name: "read", | ||
path: fromFileUrl(new URL(data.route, import.meta.url)), | ||
}); | ||
|
||
messages[data.index] = state === "granted"; | ||
|
||
worker.postMessage({ | ||
index: data.index, | ||
route: data.route, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
onmessage = async () => { | ||
const { state } = await Deno.permissions.query({ | ||
name: "read", | ||
}); | ||
|
||
const worker = new Worker( | ||
new URL("./read_check_worker.js", import.meta.url).href, | ||
{ | ||
type: "module", | ||
deno: { | ||
namespace: true, | ||
permissions: { | ||
read: false, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
worker.onmessage = ({ data: childHasPermission }) => { | ||
postMessage({ | ||
parentHasPermission: state === "granted", | ||
childHasPermission, | ||
}); | ||
close(); | ||
}; | ||
worker.postMessage(null); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { fromFileUrl } from "../../../std/path/mod.ts"; | ||
|
||
onmessage = async ({ data }) => { | ||
const { state } = await Deno.permissions.query({ | ||
name: "read", | ||
path: fromFileUrl(new URL(data.route, import.meta.url)), | ||
}); | ||
|
||
postMessage({ | ||
hasPermission: state === "granted", | ||
index: data.index, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
onmessage = async () => { | ||
const { state } = await Deno.permissions.query({ | ||
name: "read", | ||
}); | ||
postMessage(state === "granted"); | ||
close(); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.