Skip to content

Lesson 1 of 9 · 24m

Permissions Are the Runtime Contract

Understand Deno's capability-based permission model as a deployment contract rather than a command-line inconvenience.

The first time most teams meet Deno, they treat permissions as friction. A script fails with PermissionDenied, someone adds --allow-all, and the runtime's best idea dies in the first hour. That is backwards. Permissions are not a papercut; they are the runtime contract between code you control and dependencies you merely downloaded.

Capabilities are explicit

Node historically gave every package the powers of the user running the process: filesystem, network, environment variables, child processes, and native loading. Deno flips the default to deny:

deno run server.ts
# error: Requires net access to "0.0.0.0:8000", run again with the --allow-net flag

deno run --allow-net=0.0.0.0:8000 server.ts

The important detail is granularity. --allow-net can be scoped by host and port, --allow-read and --allow-write by path, --allow-env by variable name, and --allow-run by command. Production flags should read like a firewall policy, not like a shrug.

Model the blast radius

Imagine an image service that reads uploads from /var/lib/images, calls one internal metadata API, and writes thumbnails:

deno run   --allow-read=/var/lib/images   --allow-write=/var/lib/images/thumbs   --allow-net=metadata.internal:443   --allow-env=IMAGE_SIGNING_KEY   --deny-run   server.ts

If a dependency is compromised, its useful blast radius shrinks dramatically. It cannot read SSH keys, enumerate the environment, or launch curl to exfiltrate data unless those powers were deliberately granted.

Permission prompts are development-only thinking

Interactive prompts make experimentation pleasant:

deno run --allow-read=config.toml dev.ts

But do not design production startup around a human answering prompts inside a container. Declare permissions in service configuration, review them in code review, and test startup with exactly the production flag set.

Runtime checks are not sandbox escapes

Deno.permissions.query() and Deno.permissions.request() let applications adapt behavior:

const status = await Deno.permissions.query({ name: "read", path: "/data" });
if (status.state !== "granted") {
  console.error("missing /data read permission");
  Deno.exit(2);
}

Use these checks for clear failure messages and capability detection. Do not use them as a decision engine that begs for every permission at startup; that recreates --allow-all with extra steps.

Field notes

  • Permission flags apply to the whole process, not per dependency. Least privilege still helps, but it is not strong component isolation.
  • Wildcards deserve scrutiny. --allow-net alone means outbound access to the entire network.
  • --allow-env exposes secrets. Scope it to names the program genuinely needs.
  • Worker threads do not automatically inherit all permissions; explicitly configured worker permissions matter for defense in depth.
  • If a service needs --allow-all, treat that as architectural debt and write down why before shipping it.

Was this lesson helpful?

Sign in to rate