Skip to content

Commit bb929b2

Browse files
authored
Add documentation for allow, deny, and ignore in permission configurations (#1)
1 parent 7e0f50f commit bb929b2

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

runtime/fundamentals/configuration.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,96 @@ Then run with just `-P`:
574574
$ deno run -P main.ts
575575
```
576576

577+
### Allow, deny, and ignore
578+
579+
For finer control over permissions, you can use the object form with `allow`,
580+
`deny`, and `ignore` keys. This is especially useful when you need more granular
581+
permission control than simple boolean or array values provide.
582+
583+
#### Object form syntax
584+
585+
Instead of specifying a permission as a boolean or array:
586+
587+
```jsonc
588+
{
589+
"permissions": {
590+
"default": {
591+
"read": true, // Simple boolean form
592+
"write": ["./data"] // Simple array form
593+
}
594+
}
595+
}
596+
```
597+
598+
You can use the object form:
599+
600+
```jsonc
601+
{
602+
"permissions": {
603+
"default": {
604+
"read": {
605+
"allow": ["./data", "./config"],
606+
"deny": ["./data/secrets"],
607+
"ignore": ["./data/cache"]
608+
},
609+
"write": {
610+
"allow": ["./output"],
611+
"deny": ["./output/system"]
612+
}
613+
}
614+
}
615+
}
616+
```
617+
618+
#### Available permissions
619+
620+
The `allow`, `deny`, and `ignore` keys work differently depending on the
621+
permission type:
622+
623+
- **`read` and `env`**: Support `allow`, `deny`, and `ignore`
624+
- **`write`, `net`, `run`, `ffi`, `sys`, and `import`**: Support `allow` and
625+
`deny` (but not `ignore`)
626+
627+
#### Behavior
628+
629+
- **`allow`**: Explicitly grant access to specific resources. Can be `true` (to
630+
allow all), `false` (to allow none), or an array of specific paths/values to
631+
allow.
632+
- **`deny`**: Explicitly deny access (throw [PermissionDenied](https://docs.deno.com/api/deno/~/Deno.errors.PermissionDenied)) to specific resources, even if they would
633+
otherwise be allowed. Can be `true` (to deny all), `false` (to deny none), or
634+
an array of specific paths/values to deny.
635+
- **`ignore`**: (Only for `read` and `env` permissions) Silently ignore access
636+
attempts to specific resources without throwing errors. Can be `true`, `false`,
637+
or an array of specific paths/values to ignore.
638+
639+
#### Example
640+
641+
```jsonc
642+
{
643+
"permissions": {
644+
"default": {
645+
// Allow reading from data directory, but deny access to secrets
646+
// and silently ignore cache files
647+
"read": {
648+
"allow": ["./data"],
649+
"deny": ["./data/secrets"],
650+
"ignore": ["./data/cache"]
651+
},
652+
// Allow all environment variables except API keys
653+
"env": {
654+
"allow": true,
655+
"ignore": ["API_KEY", "SECRET_TOKEN"]
656+
},
657+
// Allow all, but deny 'rm', 'sudo'
658+
"run": {
659+
"allow": true,
660+
"deny": ["rm", "sudo"]
661+
}
662+
}
663+
}
664+
}
665+
```
666+
577667
### Test, bench, and compile permissions
578668

579669
Permissions can be optionally specified within the `"test"`, `"bench"`, or
@@ -644,7 +734,14 @@ If you're ok with this risk, then this feature will be useful for you.
644734
},
645735
"permissions": {
646736
"default": {
647-
"read": ["./src/testdata/"]
737+
"read": {
738+
"allow": ["./src/"],
739+
"deny": ["./src/secrets/"]
740+
},
741+
"env": {
742+
"allow": true,
743+
"ignore": ["TEMP_*"]
744+
}
648745
}
649746
},
650747
"lint": {

0 commit comments

Comments
 (0)