@jalaxy33/pi-permission 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -62
- package/docs/configuration.md +24 -10
- package/index.ts +2 -0
- package/package.json +1 -1
- package/rules/index.json +11 -6
- package/rules/packs/dynamic-exec.json +111 -0
- package/src/argv.ts +11 -1
- package/src/config.ts +5 -2
- package/src/decide.ts +177 -10
- package/src/gate.ts +44 -19
- package/src/match.ts +2 -1
- package/src/ops.ts +47 -10
- package/src/paths.ts +24 -6
- package/src/prefixes.ts +87 -0
- package/src/program.ts +19 -0
- package/src/rulesets.ts +17 -2
- package/src/scripts.ts +121 -0
- package/src/tokenize.ts +410 -34
- package/src/unlayer.ts +48 -0
package/README.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# pi-permission
|
|
2
2
|
|
|
3
|
-
A permission gate for pi. Every tool call
|
|
3
|
+
A permission gate for pi. Every tool call is allowed, asks, or is blocked, checked in this order:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. **Path rules** — file tools and bash paths, by operation: `read`, `write`, `delete`.
|
|
6
|
+
2. **Outside the workspace** — writes and deletes outside the session `cwd`.
|
|
7
|
+
3. **Commands** — every command in a bash string.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
2. **Outside the workspace** — a write or delete outside the session `cwd` asks first, unless the path is on the allow list.
|
|
9
|
-
3. **Commands** — each command in a bash string is matched against command rules. Text inside heredocs, quotes and comments is never matched.
|
|
10
|
-
|
|
11
|
-
When nothing matches, `defaultPermission` decides: `allow` (default), `ask`, or `deny`.
|
|
9
|
+
Unmatched calls fall to `defaultPermission`, `allow` by default.
|
|
12
10
|
|
|
13
11
|
## Install
|
|
14
12
|
|
|
@@ -16,8 +14,6 @@ When nothing matches, `defaultPermission` decides: `allow` (default), `ask`, or
|
|
|
16
14
|
pi install npm:@jalaxy33/pi-permission
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
From the repository:
|
|
20
|
-
|
|
21
17
|
```bash
|
|
22
18
|
pi install git:github.com/jalaxy33/pi-permission
|
|
23
19
|
```
|
|
@@ -29,49 +25,34 @@ Then run `/reload`.
|
|
|
29
25
|
| Key | Action |
|
|
30
26
|
|---|---|
|
|
31
27
|
| `y` / `Enter` | allow once |
|
|
32
|
-
| `a` | allow this rule with these flags, this rule and operation, or this
|
|
28
|
+
| `a` | allow this rule with these flags, this rule and operation, or this path, for the rest of the session |
|
|
33
29
|
| `n` / `Esc` / `Ctrl+C` | deny; the turn continues |
|
|
34
30
|
| `s` | deny and stop the turn |
|
|
35
|
-
| `j` / `k` / `↑` / `↓` · `o` | scroll · expand the command
|
|
31
|
+
| `j` / `k` / `↑` / `↓` · `o` | scroll · expand the command |
|
|
36
32
|
|
|
37
|
-
Without a UI
|
|
33
|
+
Without a UI, a call that would ask is blocked.
|
|
38
34
|
|
|
39
35
|
## Commands
|
|
40
36
|
|
|
41
37
|
| Command | Action |
|
|
42
38
|
|---|---|
|
|
43
|
-
| `/permission` |
|
|
39
|
+
| `/permission` | active preset, rulesets, defaults, sources, warnings |
|
|
44
40
|
| `/permission:reload` | re-read the config without restarting pi |
|
|
45
41
|
|
|
46
|
-
## Concepts
|
|
47
|
-
|
|
48
|
-
| Concept | What it is |
|
|
49
|
-
|---|---|
|
|
50
|
-
| **ruleset** | A leaf bundle of rules. It never includes another ruleset, so references cannot form a cycle. |
|
|
51
|
-
| **preset** | A permission level: `minimal`, `standard`, `cautious`, `paranoid`. A flat list of rulesets. |
|
|
52
|
-
| **config file** | Picks one preset, adds rulesets, and may override rules. |
|
|
53
|
-
|
|
54
|
-
Presets and include lists are single values: the last config file that declares one replaces the value below it. Rules merge, and a config rule overrides a bundled rule with the same `id`.
|
|
55
|
-
|
|
56
42
|
## Configuration
|
|
57
43
|
|
|
58
44
|
| File | Scope |
|
|
59
45
|
|---|---|
|
|
60
46
|
| `~/.pi/agent/permission.json` | all projects |
|
|
61
|
-
| `<project>/.pi/permission.json` | one project,
|
|
47
|
+
| `<project>/.pi/permission.json` | one project, after the project is trusted |
|
|
62
48
|
|
|
63
49
|
```json
|
|
64
50
|
{
|
|
65
51
|
"preset": { "id": "cautious", "remove": ["bulk-delete"] },
|
|
66
|
-
"include": [
|
|
67
|
-
"git-local",
|
|
68
|
-
{ "id": "git-remote", "remove": ["gh-delete"] }
|
|
69
|
-
],
|
|
52
|
+
"include": ["git-local", { "id": "publish", "remove": ["gh-delete"] }],
|
|
70
53
|
"defaultPermission": { "commands": "allow", "paths": "allow" },
|
|
71
54
|
"outsideCwd": { "mode": "ask", "allowPaths": ["~/work/shared/**"] },
|
|
72
|
-
"rulesets": {
|
|
73
|
-
"local": "./rules/local.json"
|
|
74
|
-
},
|
|
55
|
+
"rulesets": { "local": "./rules/local.json" },
|
|
75
56
|
"commands": {
|
|
76
57
|
"allow": [{ "id": "git-push", "program": "git", "args": ["push"] }]
|
|
77
58
|
},
|
|
@@ -81,46 +62,40 @@ Presets and include lists are single values: the last config file that declares
|
|
|
81
62
|
}
|
|
82
63
|
```
|
|
83
64
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
## Presets
|
|
66
|
+
|
|
67
|
+
| Preset | Includes |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `minimal` | `irreversible`, `secrets`, `dynamic-exec` |
|
|
70
|
+
| `standard` | `minimal` + `privilege` |
|
|
71
|
+
| `cautious` | `standard` + `bulk-delete`, `database`, `infra`, `git-remote`, `publish` |
|
|
72
|
+
| `paranoid` | `cautious` + `git-local` |
|
|
87
73
|
|
|
88
|
-
|
|
74
|
+
The default is `standard`.
|
|
89
75
|
|
|
90
|
-
##
|
|
76
|
+
## Rulesets
|
|
91
77
|
|
|
92
|
-
| Ruleset |
|
|
78
|
+
| Ruleset | Guards |
|
|
93
79
|
|---|---|
|
|
94
|
-
| `irreversible` | git history rewrites
|
|
95
|
-
| `secrets` | `.env` files and private keys
|
|
96
|
-
| `privilege` | `sudo
|
|
80
|
+
| `irreversible` | git history rewrites, `dd of=`, `mkfs*`, `wipefs`, `blkdiscard`, `fdisk`, `shred` |
|
|
81
|
+
| `secrets` | `.env` files and private keys |
|
|
82
|
+
| `privilege` | `sudo`, `doas`, `pkexec`, privileged containers, recursive `chmod 777`/`chown` |
|
|
97
83
|
| `bulk-delete` | `rm -r`, `find -delete`, `xargs rm`, `truncate`, `rsync --delete`, `git clean`, stash drop, worktree remove |
|
|
98
|
-
| `git-local` | `git add`, `commit`, `merge`, `reset --hard`, discard, branch
|
|
84
|
+
| `git-local` | `git add`, `commit`, `merge`, `reset --hard`, discard, branch and tag delete |
|
|
99
85
|
| `git-remote` | `git push`; `--force-with-lease` stays allowed |
|
|
100
|
-
| `publish` | package publishing
|
|
86
|
+
| `publish` | package publishing, `gh delete` |
|
|
101
87
|
| `database` | `dropdb`, SQL `DROP`/`TRUNCATE`, Redis `FLUSH` |
|
|
102
|
-
| `infra` | terraform
|
|
103
|
-
|
|
104
|
-
## Presets
|
|
105
|
-
|
|
106
|
-
| Preset | Level | Adds |
|
|
107
|
-
|---|---|---|
|
|
108
|
-
| `minimal` | 1 | `irreversible`, `secrets` |
|
|
109
|
-
| `standard` | 2 | `minimal` + `privilege` |
|
|
110
|
-
| `cautious` | 3 | `standard` + `bulk-delete`, `database`, `infra`, `git-remote`, `publish` |
|
|
111
|
-
| `paranoid` | 4 | `cautious` + `git-local` |
|
|
112
|
-
|
|
113
|
-
The shipped default is `standard`: `git add`/`commit` and `rm -rf node_modules` stay quiet, while `sudo`, `.env`, device writes and git history rewrites are still gated. Move up a level for more prompts, or list the rulesets you want.
|
|
88
|
+
| `infra` | terraform, kubectl delete/drain, helm uninstall, docker prune |
|
|
89
|
+
| `dynamic-exec` | commands whose real program cannot be read: `env -S`, `xargs`, `find -exec`, `eval`, `source`, `python -c`, `node -e`, `pwsh`, `busybox` |
|
|
114
90
|
|
|
115
91
|
## Limits
|
|
116
92
|
|
|
117
|
-
A guard, not a sandbox
|
|
93
|
+
A guard, not a sandbox: it reads the command text, and a program's own behaviour is out of reach.
|
|
118
94
|
|
|
119
|
-
- `
|
|
120
|
-
-
|
|
121
|
-
- Reads outside the workspace
|
|
122
|
-
-
|
|
123
|
-
- Tools other than `bash`, `powershell` and the file tools (`read`, `grep`, `find`, `ls`, `write`, `edit`) are not inspected.
|
|
95
|
+
- Not covered: code downloaded and run later (`npx`, `at`, `cron`), remote execution (`ssh host '…'`, `docker exec`), project scripts (`make`, `npm run`), `rm` without `-r`.
|
|
96
|
+
- A script on stdin (`curl … | bash`) asks and cannot be granted. `python job.py` asks once per script file; a changed file asks again.
|
|
97
|
+
- Reads outside the workspace pass; only a path rule stops them.
|
|
98
|
+
- Only `bash`, `powershell` and the file tools are inspected.
|
|
124
99
|
|
|
125
100
|
## Development
|
|
126
101
|
|
|
@@ -128,8 +103,8 @@ A guard, not a sandbox. It sees the command text and the paths in it, so anythin
|
|
|
128
103
|
bun test
|
|
129
104
|
```
|
|
130
105
|
|
|
131
|
-
`pi-tui`, `pi-coding-agent` and `ajv`
|
|
106
|
+
`pi-tui`, `pi-coding-agent` and `ajv` are symlinks in `node_modules/`; the first two are peer dependencies that pi provides at runtime.
|
|
132
107
|
|
|
133
108
|
## Similar extensions
|
|
134
109
|
|
|
135
|
-
- [`@aliou/pi-guardrails`](https://pi.dev/packages/%40aliou/pi-guardrails)
|
|
110
|
+
- [`@aliou/pi-guardrails`](https://pi.dev/packages/%40aliou/pi-guardrails) — the inspiration for this plugin.
|
package/docs/configuration.md
CHANGED
|
@@ -33,6 +33,9 @@ A permission level. Only the shipped index defines presets; a user config select
|
|
|
33
33
|
|
|
34
34
|
```json
|
|
35
35
|
{ "preset": "cautious" }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```json
|
|
36
39
|
{ "preset": { "id": "cautious", "remove": ["bulk-delete"] } }
|
|
37
40
|
```
|
|
38
41
|
|
|
@@ -73,7 +76,7 @@ A file path resolves from the file that names it. Redefining a shipped ruleset i
|
|
|
73
76
|
`include` adds rulesets to the active preset:
|
|
74
77
|
|
|
75
78
|
```json
|
|
76
|
-
{ "preset": "standard", "include": ["git-local", { "id": "
|
|
79
|
+
{ "preset": "standard", "include": ["git-local", { "id": "publish", "remove": ["gh-delete"] }] }
|
|
77
80
|
```
|
|
78
81
|
|
|
79
82
|
`remove` lists **rule ids of that ruleset**. It cannot reach another ruleset, so equal ids in unrelated packs cannot cause a cross-pack deletion. Removing an id the ruleset does not define is a warning.
|
|
@@ -82,7 +85,7 @@ The same ruleset id cannot appear twice in one `include` list. To turn one rule
|
|
|
82
85
|
|
|
83
86
|
## Shipped rulesets and presets
|
|
84
87
|
|
|
85
|
-
See [README](../README.md#
|
|
88
|
+
See [README](../README.md#rulesets) for what each pack gates and [README](../README.md#presets) for the four levels. The shipped default is `preset: "standard"`.
|
|
86
89
|
|
|
87
90
|
## Command rules
|
|
88
91
|
|
|
@@ -115,9 +118,21 @@ Matching notes:
|
|
|
115
118
|
- `subcommand` is the safer choice for command families: a commit message or a flag value cannot pass for the subcommand. For git, `-C`, `-c`, `--git-dir`, `--work-tree`, `--namespace`, `--exec-path` and `--super-prefix` are skipped with their value, so `git -C dir push` still matches `subcommand: ["push"]`.
|
|
116
119
|
- `args` matches any positional, so for programs without a value-flag table it also matches flag values. Use it for operands, not for subcommands.
|
|
117
120
|
- One string can hold several commands (`&&`, `;`, `|`, substitutions); the strictest verdict wins.
|
|
118
|
-
- `sh -c '...'` and other shell `-c` scripts are checked like top-level commands
|
|
121
|
+
- `sh -c '...'` and other shell `-c` scripts are checked like top-level commands, three levels deep. A deeper script, and a script that reads a variable (`sh -c "$DEPLOY"`), asks.
|
|
122
|
+
- `$(...)`, backticks, `<(...)` and `>(...)` are parsed as commands and checked with the same rules, including inside double quotes. Single-quoted text stays text.
|
|
123
|
+
- Text the splitter cannot resolve — an unterminated quote, `$(` or heredoc — asks with the reason `gate cannot inspect this command`. It is never treated as an allow.
|
|
124
|
+
- Wrappers with a closed option table are peeled before matching, so the inner command decides: `time`, `nice`, `nohup`, `setsid`, `timeout`, `stdbuf`, `command`, and `env` when it only carries `VAR=VAL` words. A shape the table does not cover (`env -C dir`, `env -S`, `timeout -v`, `strace -o file`) is left whole and reaches the `dynamic-exec` rules, which ask.
|
|
125
|
+
- Shell keywords are peeled too: `then`, `do`, `else`, `elif`, `if`, `while`, `until`, `!`, `{` and `coproc` precede a command; `for`, `in`, `case`, `fi`, `done`, `esac` and `}` never carry one. Word-exact and position zero only, so `cp a in` keeps its operand. A `)` ends the command before it, so a subshell or a `case` arm is judged like any other command.
|
|
126
|
+
- Bash syntax that names the command is read the way bash reads it: `$(...)`, backticks, `<(...)` and `>(...)` are commands; `$'...'` is decoded; a backslash-newline joins lines; `2>file` is a descriptor, not an argument; `${x:-a)b}` stays one word; a lone `[` is the test builtin, not a glob.
|
|
127
|
+
- A word containing an expansion, escape or glob cannot name a program: `"$CMD"`, `\rm` and `r[m]` ask instead of matching. A quoted name (`'git'`) is still a name.
|
|
128
|
+
- A program's script input is judged when the gate can see it. When a here-string and a heredoc are on one command, the here-string is what the program reads.
|
|
129
|
+
- a shell script in a file (`bash deploy.sh`) or a heredoc body on a shell (`bash <<EOF`) is tokenized and judged like the command line, and its paths go through the path rules;
|
|
130
|
+
- a script in another language (`python job.py`) asks once per file content, granted as `opaque:<program>:file:<hash>`, or as `opaque:<program>:<path>` when the file cannot be read;
|
|
131
|
+
- inline code written in the command (`python3 - <<'PY'`) asks and is granted as `opaque:<program>:heredoc`, because the text was on screen and can be approved;
|
|
132
|
+
- a script that arrives on a pipe or a redirect (`curl … | bash`, `bash < f`, `sh -s`, `<<<`) asks and carries no grant key, because that text does not exist when the decision is made.
|
|
133
|
+
- `-c` names inline code and is followed instead of read; when that code also reads stdin (`bash -c 'sh' <<EOF`), it asks. `-n`/`--noexec` parses without running, so neither the script nor its paths are followed. A clustered option keeps working: `bash -euo pipefail -c '…'` is still followed, and `bash -euo pipefail f.sh` still reads `f.sh`.
|
|
119
134
|
- Precedence inside one simple command: `deny` → `allow` → `ask` → `defaultPermission.commands`.
|
|
120
|
-
- "Allow for this session" remembers the rule and the
|
|
135
|
+
- "Allow for this session" remembers the rule, the flags, and what the rule matched on: the subcommand (`terraform apply` does not approve `terraform destroy`), the argument, or — for a rule that matches the whole line or a flag carrying code — that exact line (`bun -e 'a'` does not approve `bun -e 'b'`). After allowing `rm -r build`, `rm -r dist` still runs without asking, while `rm -rf dist` asks again. Flag order does not matter, and a deny rule still blocks a granted command.
|
|
121
136
|
|
|
122
137
|
## Path rules
|
|
123
138
|
|
|
@@ -155,14 +170,14 @@ Matching:
|
|
|
155
170
|
|---|---|
|
|
156
171
|
| `**` | every path under the project; never `../outside` |
|
|
157
172
|
| no slash (`.env`, `*.pem`) | the basename, at any depth |
|
|
158
|
-
| starts with
|
|
173
|
+
| starts with `~`, `/`, `C:/` or `//` | the absolute path |
|
|
159
174
|
| anything else (`config/*.yml`) | the path relative to the project; never `../outside` |
|
|
160
175
|
|
|
161
176
|
- The target is resolved to an absolute path first: `~` expanded, `..` normalized, and a path reached through `cd` in the same command pinned to that directory.
|
|
162
177
|
- If the path exists, its real path is matched as well, so symlinks do not bypass a rule. A symlink whose target does not exist yet is followed too.
|
|
163
178
|
- `*` does not cross `/`; `**` does.
|
|
164
179
|
|
|
165
|
-
For bash commands the gate reads redirections, path arguments of known programs, path-looking arguments of unknown ones, `sed -i`, `mv` sources (as deletes), and nested `sh -c` (three levels); `cd` inside the string changes the directory for later commands. Globs are expanded before matching, so `cat .env*` is caught for files that exist; `$VAR` operands match by basename only.
|
|
180
|
+
For bash commands the gate reads redirections, path arguments of known programs, path-looking arguments of unknown ones, `sed -i`, `mv` sources (as deletes), and nested `sh -c` (three levels); `cd` inside the string changes the directory for later commands. Globs are expanded before matching, so `cat .env*` is caught for files that exist; `$VAR` operands match by basename only, with or without a file extension.
|
|
166
181
|
|
|
167
182
|
"Allow for this session" remembers `path:<rule id>:<op>`: allowing a read leaves writes and deletes asking.
|
|
168
183
|
|
|
@@ -180,7 +195,7 @@ What happens when no rule matches:
|
|
|
180
195
|
| `ask` | prompt for the program | prompt for the path |
|
|
181
196
|
| `deny` | only `allow` rules run | only `allow` path rules are reachable |
|
|
182
197
|
|
|
183
|
-
- Config-level only
|
|
198
|
+
- Config-level only: a ruleset that carries it is rejected, and a preset never has one.
|
|
184
199
|
- Grants: `default:<program>:<flags>` for commands, `path:default:<op>:<absolute path>` for paths. A path fallback grant covers exactly one path.
|
|
185
200
|
- The path fallback does not bypass `outsideCwd`; that gate keeps its own `mode`.
|
|
186
201
|
- With `paths: "deny"`, use an allow rule for the workspace: `{ "id": "workspace", "patterns": ["**"], "action": "allow" }`.
|
|
@@ -200,7 +215,7 @@ Built-in allow list: `/tmp/**`, `/dev/**`, `~/.pi/agent/**`, `~/.cache/**`, `~/.
|
|
|
200
215
|
|
|
201
216
|
Only writes and deletes are checked. Reads outside the workspace are not gated, and `mode: block` does not stop them either; use a path rule for files that must never be read.
|
|
202
217
|
|
|
203
|
-
Paths are resolved to their real location first, so a symlink inside the workspace that points outside is outside, and the allow list is matched against where the write lands rather than the link itself. A symlinked workspace stays inside. "Allow for this session" remembers the
|
|
218
|
+
Paths are resolved to their real location first, so a symlink inside the workspace that points outside is outside, and the allow list is matched against where the write lands rather than the link itself. A symlinked workspace stays inside. "Allow for this session" remembers the exact path that was approved. A directory grant belongs in `outsideCwd.allowPaths`, where it is written down and visible.
|
|
204
219
|
|
|
205
220
|
## `enabled`
|
|
206
221
|
|
|
@@ -220,7 +235,7 @@ Fatal — the config cannot be honored and every gated tool is blocked:
|
|
|
220
235
|
- an unknown `include` or `preset` id, or two equal ids in one `include` list;
|
|
221
236
|
- the same rule id defined twice inside one ruleset or one config file;
|
|
222
237
|
- the same rule id in two selected rulesets;
|
|
223
|
-
- a selected ruleset file that is missing or invalid.
|
|
238
|
+
- a config file that is not valid JSON or cannot be read; a selected ruleset file that is missing or invalid.
|
|
224
239
|
|
|
225
240
|
Warnings:
|
|
226
241
|
|
|
@@ -229,7 +244,6 @@ Warnings:
|
|
|
229
244
|
- a config rule that moves a bundled `deny` rule to `ask` or `allow`;
|
|
230
245
|
- an unknown field name;
|
|
231
246
|
- a bad `argvRegex` (the rule is dropped);
|
|
232
|
-
- invalid JSON in a user file (that file is skipped);
|
|
233
247
|
- `presets` in a user file (ignored; presets are shipped only).
|
|
234
248
|
|
|
235
249
|
## Schema
|
package/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ export default async function permission(pi: ExtensionAPI) {
|
|
|
8
8
|
const sessionGrants = new SessionGrants();
|
|
9
9
|
|
|
10
10
|
const reload = (cwd: string, trusted: boolean, notify: (message: string) => void) => {
|
|
11
|
+
// Grants name decisions made under the old rules; they cannot outlive a reload.
|
|
12
|
+
sessionGrants.clear();
|
|
11
13
|
config = loadConfig(cwd, trusted);
|
|
12
14
|
for (const warning of config.warnings) notify(`pi-permission: ${warning}`);
|
|
13
15
|
};
|
package/package.json
CHANGED
package/rules/index.json
CHANGED
|
@@ -10,15 +10,17 @@
|
|
|
10
10
|
"git-remote": "./packs/git-remote.json",
|
|
11
11
|
"publish": "./packs/publish.json",
|
|
12
12
|
"database": "./packs/database.json",
|
|
13
|
-
"infra": "./packs/infra.json"
|
|
13
|
+
"infra": "./packs/infra.json",
|
|
14
|
+
"dynamic-exec": "./packs/dynamic-exec.json"
|
|
14
15
|
},
|
|
15
16
|
"presets": {
|
|
16
17
|
"minimal": {
|
|
17
18
|
"level": 1,
|
|
18
|
-
"description": "Unrecoverable damage and
|
|
19
|
+
"description": "Unrecoverable damage, secrets, and commands the gate cannot read.",
|
|
19
20
|
"include": [
|
|
20
21
|
"irreversible",
|
|
21
|
-
"secrets"
|
|
22
|
+
"secrets",
|
|
23
|
+
"dynamic-exec"
|
|
22
24
|
]
|
|
23
25
|
},
|
|
24
26
|
"standard": {
|
|
@@ -27,7 +29,8 @@
|
|
|
27
29
|
"include": [
|
|
28
30
|
"irreversible",
|
|
29
31
|
"secrets",
|
|
30
|
-
"privilege"
|
|
32
|
+
"privilege",
|
|
33
|
+
"dynamic-exec"
|
|
31
34
|
]
|
|
32
35
|
},
|
|
33
36
|
"cautious": {
|
|
@@ -41,7 +44,8 @@
|
|
|
41
44
|
"database",
|
|
42
45
|
"infra",
|
|
43
46
|
"git-remote",
|
|
44
|
-
"publish"
|
|
47
|
+
"publish",
|
|
48
|
+
"dynamic-exec"
|
|
45
49
|
]
|
|
46
50
|
},
|
|
47
51
|
"paranoid": {
|
|
@@ -56,7 +60,8 @@
|
|
|
56
60
|
"infra",
|
|
57
61
|
"git-remote",
|
|
58
62
|
"publish",
|
|
59
|
-
"git-local"
|
|
63
|
+
"git-local",
|
|
64
|
+
"dynamic-exec"
|
|
60
65
|
]
|
|
61
66
|
}
|
|
62
67
|
},
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../schema.json",
|
|
3
|
+
"description": "Programs that run another command, or code the gate cannot read. A wrapper whose options the gate can peel is judged by the command inside it; a shape it cannot peel lands here and asks.",
|
|
4
|
+
"commands": {
|
|
5
|
+
"allow": [
|
|
6
|
+
{
|
|
7
|
+
"id": "env-print",
|
|
8
|
+
"program": "env",
|
|
9
|
+
"argvRegex": "^env(\\s+-[^\\s]+)*$",
|
|
10
|
+
"reason": "prints the environment"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "command-query",
|
|
14
|
+
"program": "command",
|
|
15
|
+
"argvRegex": "^command\\s+-[vV]\\s+\\S+$",
|
|
16
|
+
"reason": "reports what a name resolves to"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"ask": [
|
|
20
|
+
{
|
|
21
|
+
"id": "exec-relay",
|
|
22
|
+
"program": ["env", "command", "builtin", "exec", "eval", "source", "."],
|
|
23
|
+
"reason": "runs a command the gate cannot read"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "exec-wrapper",
|
|
27
|
+
"program": [
|
|
28
|
+
"time",
|
|
29
|
+
"nice",
|
|
30
|
+
"nohup",
|
|
31
|
+
"setsid",
|
|
32
|
+
"timeout",
|
|
33
|
+
"stdbuf",
|
|
34
|
+
"watch",
|
|
35
|
+
"strace",
|
|
36
|
+
"ltrace",
|
|
37
|
+
"ionice",
|
|
38
|
+
"chrt",
|
|
39
|
+
"taskset",
|
|
40
|
+
"unbuffer",
|
|
41
|
+
"script",
|
|
42
|
+
"expect"
|
|
43
|
+
],
|
|
44
|
+
"reason": "wraps a command the gate cannot read"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "exec-applet",
|
|
48
|
+
"program": "busybox",
|
|
49
|
+
"reason": "runs an applet the gate cannot read"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "exec-runtime-args",
|
|
53
|
+
"program": ["xargs", "parallel"],
|
|
54
|
+
"reason": "builds the command's arguments at runtime"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "exec-tree",
|
|
58
|
+
"program": ["find", "gfind"],
|
|
59
|
+
"anyFlag": ["-exec", "-execdir", "-ok", "-okdir", "-delete"],
|
|
60
|
+
"reason": "runs commands while walking the tree"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "exec-shell-host",
|
|
64
|
+
"program": ["pwsh", "powershell", "osascript"],
|
|
65
|
+
"reason": "runs code the gate cannot parse"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"id": "exec-python",
|
|
69
|
+
"program": "python*",
|
|
70
|
+
"anyFlag": ["-c"],
|
|
71
|
+
"reason": "runs inline code"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"id": "exec-node",
|
|
75
|
+
"program": ["node", "nodejs"],
|
|
76
|
+
"anyFlag": ["-e", "--eval", "-p", "--print"],
|
|
77
|
+
"reason": "runs inline code"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "exec-bun",
|
|
81
|
+
"program": "bun",
|
|
82
|
+
"anyFlag": ["-e", "--eval", "-p"],
|
|
83
|
+
"reason": "runs inline code"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"id": "exec-bun-runner",
|
|
87
|
+
"program": "bun",
|
|
88
|
+
"args": ["x"],
|
|
89
|
+
"reason": "runs a downloaded package"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"id": "exec-deno",
|
|
93
|
+
"program": "deno",
|
|
94
|
+
"args": ["eval"],
|
|
95
|
+
"reason": "runs inline code"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "exec-script-lang",
|
|
99
|
+
"program": ["perl", "ruby", "php", "lua"],
|
|
100
|
+
"anyFlag": ["-e", "-r"],
|
|
101
|
+
"reason": "runs inline code"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "exec-awk-system",
|
|
105
|
+
"program": ["awk", "gawk", "mawk", "nawk"],
|
|
106
|
+
"argvRegex": "system\\s*\\(|\\|\\s*(sh|bash|getline)",
|
|
107
|
+
"reason": "runs shell commands from the awk script"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/argv.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Turns the argv of one simple command into the pieces rules match on. */
|
|
2
2
|
|
|
3
|
+
import { normalizeProgram } from "./program";
|
|
4
|
+
|
|
3
5
|
export interface Args {
|
|
4
6
|
program: string;
|
|
5
7
|
positional: string[];
|
|
@@ -14,11 +16,19 @@ const GLOBAL_VALUE_FLAGS: Record<string, Set<string>> = {
|
|
|
14
16
|
git: new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--super-prefix"]),
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
/** Index of the word that names the program; -1 for a line of assignments only. */
|
|
20
|
+
export function programWordIndex(argv: string[]): number {
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
if (!ASSIGNMENT.test(argv[i] as string)) return i;
|
|
23
|
+
}
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
function programOf(argv: string[]): { program: string; index: number } | undefined {
|
|
18
28
|
for (let i = 0; i < argv.length; i++) {
|
|
19
29
|
const token = argv[i] as string;
|
|
20
30
|
if (ASSIGNMENT.test(token)) continue;
|
|
21
|
-
return { program: token
|
|
31
|
+
return { program: normalizeProgram(token), index: i };
|
|
22
32
|
}
|
|
23
33
|
return undefined;
|
|
24
34
|
}
|
package/src/config.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
readJson,
|
|
15
15
|
resolveSelection,
|
|
16
16
|
type LoadedRuleSet,
|
|
17
|
+
type ReadFailure,
|
|
17
18
|
} from "./rulesets";
|
|
18
19
|
import type {
|
|
19
20
|
Action,
|
|
@@ -102,14 +103,16 @@ export function loadConfig(
|
|
|
102
103
|
|
|
103
104
|
const scopePaths = [options.globalPath ?? globalConfigPath()];
|
|
104
105
|
if (trusted) scopePaths.push(options.projectPath ?? projectConfigPath(cwd));
|
|
106
|
+
let fatal: string | undefined;
|
|
105
107
|
for (const path of scopePaths) {
|
|
106
|
-
const
|
|
108
|
+
const failures: ReadFailure[] = [];
|
|
109
|
+
const file = readJson(path, warnings, "config", failures);
|
|
110
|
+
for (const failure of failures) fatal ??= `pi-permission: ${failure.path}: ${failure.reason}`;
|
|
107
111
|
if (!file) continue;
|
|
108
112
|
sources.push(path);
|
|
109
113
|
scopes.push({ path, baseDir: dirname(path), file });
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
let fatal: string | undefined;
|
|
113
116
|
const rulesets = new Map<string, LoadedRuleSet>();
|
|
114
117
|
for (const scope of scopes) {
|
|
115
118
|
const shape = shapeError(scope.file, scope.path);
|