You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: runtime/fundamentals/configuration.md
+98-1Lines changed: 98 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -574,6 +574,96 @@ Then run with just `-P`:
574
574
$ deno run -P main.ts
575
575
```
576
576
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
+
577
667
### Test, bench, and compile permissions
578
668
579
669
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.
0 commit comments