@operad-io/access-match 0.0.1 → 0.1.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 +7 -160
- package/package.json +3 -3
- package/src/index.ts +6 -4
package/README.md
CHANGED
|
@@ -1,166 +1,13 @@
|
|
|
1
1
|
# @operad-io/access-match
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
may run under the `denyPaths`, `denyCommands` and `askCommands` of an access profile
|
|
5
|
-
(`docs/backlog/operad-sandbox.md` decisions 1 and 4,
|
|
6
|
-
`docs/backlog/operad-harness-pi.md` decision 7). Harnesses call it in their
|
|
7
|
-
tool-call hook: pi today, Claude and the command adapter later.
|
|
3
|
+
**Access profiles matched against agent tool calls.** Says whether one tool call of an agent may run under an access profile's `denyPaths`, `denyCommands` and `askCommands`. The harnesses call it before a tool runs.
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
match(profile, { tool, input, cwd }):
|
|
11
|
-
| { allow: true }
|
|
12
|
-
| { allow: false, reason, rule? } // refused
|
|
13
|
-
| { allow: false, ask: true, reason, rule, kind: "command" | "path", value, tool? } // asks a person
|
|
14
|
-
```
|
|
5
|
+
This package is part of [operad](https://github.com/operad-io/operad). Most people install only [`@operad-io/cli`](https://www.npmjs.com/package/@operad-io/cli).
|
|
15
6
|
|
|
16
|
-
|
|
17
|
-
`denyCommands` or `denyPaths` anywhere is refused, whatever `askCommands` says,
|
|
18
|
-
and nobody is asked; a call that matches only `askCommands` asks; any other call
|
|
19
|
-
is allowed. An `alwaysAllow` entry lifts an ask for its exact call and cwd; it
|
|
20
|
-
never lifts a deny. A caller that does not know `ask` sees `allow: false` and refuses,
|
|
21
|
-
never passes.
|
|
7
|
+
## Documentation
|
|
22
8
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
the `home` option). `test/match.test.ts` follows the tables below.
|
|
9
|
+
- User guide: [docs/user/access.md](https://github.com/operad-io/operad/blob/main/docs/user/access.md)
|
|
10
|
+
- Website: <https://operad.io>
|
|
11
|
+
- Developer reference: `REFERENCE.md` in this directory
|
|
27
12
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| field | type | meaning |
|
|
31
|
-
|---|---|---|
|
|
32
|
-
| `denyPaths` | string[], optional | a call that touches a path under one of these is refused |
|
|
33
|
-
| `denyCommands` | string[], optional | a `bash` command part that matches one of these is refused |
|
|
34
|
-
| `askPaths` | string[], optional | paths a write asks about (`~/.zshrc`, `~/.*profile`); `*` stays within one path segment and a path under a match counts. Judged for `write` and `edit`, and for a `bash` redirect (`>`, `>>`) to such a path, which asks with the whole command. Deny wins over it |
|
|
35
|
-
| `readOnly` | boolean, optional | the call's working directory is read-only: a write under it (`write`, `edit`, a `bash` redirect) asks, as if the directory were in `askPaths`. Deny wins over it |
|
|
36
|
-
| `readPaths` | array of paths, optional | directories the agent may read although `denyPaths` covers an ancestor: a read tool (`read`, `grep`, `find`, `ls`) or a `bash` command that only reads may touch a path under one. A write there asks (the entries count as `askPaths`); every other denied path stays denied |
|
|
37
|
-
| `allowMcp` | string[], optional | MCP tools that run without asking, as `<server>.<tool>` or `<server>.*`. The field's presence (even empty) puts MCP tools under the profile: a call with `tool: "mcp"` and `input: { server, tool }` that is not listed counts as a write and asks (`kind: "command"`, value `mcp <server>.<tool>`), per `operad-sandbox.md` decision 9. When the field is absent, MCP tools are not under the profile and are allowed |
|
|
38
|
-
| `askCommands` | string[], optional | rules in the shape of `denyCommands`; a `bash` command part that matches one of these asks a person (`operad-sandbox.md` decisions 1 and 3). Writes to shell profiles are `askPaths` |
|
|
39
|
-
|
|
40
|
-
| `alwaysAllow` | `{ kind: "command" \| "path", value, cwd, tool? }[]`, optional | calls a person answered `allow_always` for. A command entry is the exact command text and cwd; a path entry is the tool, the path and cwd. Such a call is allowed when it would otherwise ask. A deny still wins, and a harness leaves the entries out of a run no person's message started (`operad-sandbox.md` decisions 4, 5, 8 and 11) |
|
|
41
|
-
|
|
42
|
-
| `grants` | `{ waitId, kind: "command" \| "path", value, tool? }[]`, optional | one-time permissions not yet used; see `findGrant` |
|
|
43
|
-
|
|
44
|
-
`findGrant(profile, call)` returns the grant that covers a call, or `undefined`:
|
|
45
|
-
a `command` grant covers a `bash` call whose command equals `value` character
|
|
46
|
-
for character, a `path` grant a call of the one `tool` it names (not another path tool) on the same file; a path grant without a `tool` covers nothing. It is
|
|
47
|
-
pure. The caller must use the grant up (the engine writes `grant_used`) before it
|
|
48
|
-
lets the call run, and match the call as usual when it cannot.
|
|
49
|
-
|
|
50
|
-
Other fields of the access profile (`cwd`, `outside`, `network`) are not read
|
|
51
|
-
here. `readProfile(value)` checks an untrusted object
|
|
52
|
-
and names the field at fault.
|
|
53
|
-
|
|
54
|
-
## Call
|
|
55
|
-
|
|
56
|
-
| tool | what is checked |
|
|
57
|
-
|---|---|
|
|
58
|
-
| `read`, `write`, `edit` | `input.path` (or `input.file_path`) against `denyPaths` |
|
|
59
|
-
| `grep`, `find`, `ls` | `input.path`, when given, against `denyPaths` |
|
|
60
|
-
| `bash` | `denyCommands` and inline code, then every path-like argument against `denyPaths` |
|
|
61
|
-
| anything else | allowed |
|
|
62
|
-
|
|
63
|
-
A missing or non-string path argument of a checked tool is allowed: the tool
|
|
64
|
-
itself reports that error.
|
|
65
|
-
|
|
66
|
-
## Splitting a `bash` command
|
|
67
|
-
|
|
68
|
-
Outside quotes the command is split into parts at these operators. Each part
|
|
69
|
-
remembers the operator before it.
|
|
70
|
-
|
|
71
|
-
| operator | note |
|
|
72
|
-
|---|---|
|
|
73
|
-
| `&&`, `\|\|`, `;`, `\|`, `\|&`, `&` | `\|\|` and `&&` are read before `\|` and `&` |
|
|
74
|
-
| newline | a backslash before the newline joins the lines instead |
|
|
75
|
-
| `(` and `)` | read as separators; `$(` is inline code, see below |
|
|
76
|
-
|
|
77
|
-
Quotes: `'…'` keeps everything literal; `"…"` keeps operators literal and
|
|
78
|
-
still lets `\"`, `\\`, `` \` `` and `\$` escape; outside quotes a backslash
|
|
79
|
-
escapes the next character. An operator inside quotes or after a backslash
|
|
80
|
-
does not split. An unterminated quote runs to the end of the command.
|
|
81
|
-
|
|
82
|
-
## Matching a part against `denyCommands`
|
|
83
|
-
|
|
84
|
-
The words of a part are unquoted. Leading `NAME=value` words are skipped. The
|
|
85
|
-
command name is the first word without its directory (`/bin/rm` is `rm`).
|
|
86
|
-
These wrappers are looked through, and the rule is tried at every level:
|
|
87
|
-
`env`, `command`, `exec`, `nohup`, `time`, `builtin`, `sudo`, `doas`. After a
|
|
88
|
-
wrapper, `NAME=value` words and words starting with `-` are skipped.
|
|
89
|
-
|
|
90
|
-
A rule is a pattern of words; `*` in a word matches any characters.
|
|
91
|
-
|
|
92
|
-
| pattern word | matches |
|
|
93
|
-
|---|---|
|
|
94
|
-
| the first word | the command name, whole (`git`) |
|
|
95
|
-
| a word like `-rf` (one dash, letters) | the union of the single-dash letters of the part's arguments contains every letter, so `-fr`, `-rfv` and `-r -f` all match `-rf` |
|
|
96
|
-
| any other word | an argument of the part equal to it (a trailing `/` ignored, except for `/` itself), in any position, so `git -C x push --force` matches `git push --force*` |
|
|
97
|
-
| `…` or `...` | nothing; it only reads well. It adds no condition |
|
|
98
|
-
| `\|` between words | the rule spans a pipeline: each side matches one part, and the parts follow each other joined by `\|`, so `curl … \| sh` matches `curl x \| sh` and `curl x \| tee y \| sh` does not |
|
|
99
|
-
|
|
100
|
-
The reason is `part "<part>" is refused by denyCommands rule "<rule>"`.
|
|
101
|
-
|
|
102
|
-
`askCommands` rules are matched the same way, after every deny check has passed
|
|
103
|
-
(precedence above). The reason is `part "<part>" matches askCommands rule
|
|
104
|
-
"<rule>"`, and the verdict's `value` is the whole command of the call: that is
|
|
105
|
-
what a person is asked about and what a one-time permission (`findGrant`) covers.
|
|
106
|
-
Inline code (below) asks while `askCommands` is set, with the rule `inline code`:
|
|
107
|
-
what it runs cannot be matched (`operad-sandbox.md` decision 4).
|
|
108
|
-
|
|
109
|
-
## Inline code
|
|
110
|
-
|
|
111
|
-
Refused whatever the rules say, but only when the profile has at least one
|
|
112
|
-
`denyCommands` rule (an empty profile means no checking). The reason is
|
|
113
|
-
`part "<part>" runs inline code (<form>); it is refused while denyCommands is set`.
|
|
114
|
-
|
|
115
|
-
| form | seen as |
|
|
116
|
-
|---|---|
|
|
117
|
-
| `bash -c`, `sh -c`, `zsh -c`, `dash -c` | the command name and a single-dash argument with the letter `c` (`-lc` too) |
|
|
118
|
-
| `python -c`, `python3 -c` | the command name and a single-dash argument with `c` |
|
|
119
|
-
| `node -e`, `bun -e`, `osascript -e` | the command name and a single-dash argument with `e` |
|
|
120
|
-
| `find … -exec`, `-execdir`, `-ok`, `-okdir` | the command name `find` and such an argument |
|
|
121
|
-
| `xargs` | the command name |
|
|
122
|
-
| `eval` | the command name |
|
|
123
|
-
| `` `…` ``, `$(…)`, `<(…)`, `>(…)` | in the command text outside single quotes (also inside double quotes) |
|
|
124
|
-
|
|
125
|
-
## Paths
|
|
126
|
-
|
|
127
|
-
For `bash`, every word of every part is a candidate, the command name
|
|
128
|
-
included. A word is path-like when it contains `/` or starts with `~` or `.`.
|
|
129
|
-
Two readings are tried: the word with a leading redirect (`>`, `>>`, `<`,
|
|
130
|
-
`2>`, `&>`) removed, and the text after the first `=` of that word
|
|
131
|
-
(`--out=/x`). Each path-like reading is normalised:
|
|
132
|
-
|
|
133
|
-
| step | rule |
|
|
134
|
-
|---|---|
|
|
135
|
-
| `~` | `~` and `~/…` become the home directory; `~name` is left as it is |
|
|
136
|
-
| relative | joined to `cwd` |
|
|
137
|
-
| `.` and `..` | resolved, so `a/../../x` leaves `cwd`; `..` above `/` stays at `/` |
|
|
138
|
-
| trailing `/` | removed |
|
|
139
|
-
|
|
140
|
-
A `denyPaths` entry is normalised the same way (so `.git/config` means the
|
|
141
|
-
one under `cwd`). A path is refused when it equals an entry or is below it
|
|
142
|
-
(`/a/b` is below `/a`; `/ab` is not). The comparison is case-sensitive. The
|
|
143
|
-
reason is `path "<path>" is under denyPaths entry "<entry>"`, with the path as
|
|
144
|
-
written in the call.
|
|
145
|
-
|
|
146
|
-
## What it cannot see
|
|
147
|
-
|
|
148
|
-
Lexical means the file system is never asked. These pass:
|
|
149
|
-
|
|
150
|
-
- a symlink, hard link or mount that leads into a denied path;
|
|
151
|
-
- case differences on a case-insensitive disk;
|
|
152
|
-
- shell variables and globs (`$HOME/.ssh`, `~/.s*`), and `~name`;
|
|
153
|
-
- a path built by a program the command starts, or read from a file;
|
|
154
|
-
- paths in a script the agent wrote and then runs.
|
|
155
|
-
|
|
156
|
-
The profile is a guard rail, not a boundary (`operad-sandbox.md` decision 7).
|
|
157
|
-
|
|
158
|
-
## Shell expansion in bash paths
|
|
159
|
-
|
|
160
|
-
The matcher is a guardrail: where it cannot tell, it asks, and a deny always wins over an ask.
|
|
161
|
-
|
|
162
|
-
**Expansion.** `~`, `$HOME` and `${HOME}` become the matcher's home before a path word, a redirect target or a `cd` target is matched. Any other expansion in a path or `cd` target (`$OTHER`, `${…}`, `$(…)`, backticks, `<(…)`, `$((…))`, `$1`, `$@`, `~user`, a `$'…'` word with escapes) asks. Only words that look like paths (they hold a `/`, or start with `~` or `.`) are judged, so `cat $OTHER` is not.
|
|
163
|
-
|
|
164
|
-
**Directory.** Only a plain top-level `cd <path>` in a chain (`&&`, `||`, `;`, `|`) moves the directory the later relative paths are read against; `<path>` is literal or starts with `~`, `$HOME` or `${HOME}`, and `-L`, `-P` and `--` are skipped. Everything else that can change the directory makes it unknown for the rest of the command, and then every later relative path (or command name with a `/`) asks: brace groups `{ }`, subshells `( )`, `if`, `for`, `while`, `until`, `case`, `select`, functions, `eval`, `source` and `.`, `exec`, the `builtin`, `command` and `env` wrappers, `time`, `trap`, `pushd` and `popd` in any form, `cd -`, `cd` with no operand, a `cd` in a pipeline or the background, a `CDPATH` word, and a `cd` target with an unresolved expansion or a glob.
|
|
165
|
-
|
|
166
|
-
**Globs.** A path word with a glob character (`*`, `?`, `[`, `{`, or an extended glob such as `@(…)`) is judged by the literal text before the first one, not by evaluating the pattern: it is refused when a denied entry starts with that prefix or the prefix starts with a denied entry. A `..` after the glob asks.
|
|
13
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/access-match",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@operad-io/engine": "0.
|
|
9
|
+
"@operad-io/engine": "0.1.1"
|
|
10
10
|
},
|
|
11
|
-
"description": "operad: access profiles matched against agent tool calls
|
|
11
|
+
"description": "operad: access profiles matched against agent tool calls",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/operad-io/operad.git",
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface AccessGrant {
|
|
|
22
22
|
* A call a person allowed always, from the access profile's user layer. A
|
|
23
23
|
* command entry is the exact command text and its working directory; a path
|
|
24
24
|
* entry is the tool, the path and the working directory
|
|
25
|
-
* (
|
|
25
|
+
* (ADR 0025 D3 and D7).
|
|
26
26
|
*/
|
|
27
27
|
export interface AlwaysAllowEntry {
|
|
28
28
|
readonly kind: "command" | "path";
|
|
@@ -60,7 +60,8 @@ export interface AccessProfile {
|
|
|
60
60
|
/**
|
|
61
61
|
* The MCP tools that run without asking, as `<server>.<tool>` or `<server>.*`.
|
|
62
62
|
* Having the field at all (even empty) puts MCP tools under the profile: a tool
|
|
63
|
-
* not listed counts as a write and asks (
|
|
63
|
+
* not listed counts as a write and asks (the MCP-tool rule in
|
|
64
|
+
* `docs/backlog/operad-sandbox.md`, not in an ADR yet).
|
|
64
65
|
*/
|
|
65
66
|
readonly allowMcp?: readonly string[] | undefined;
|
|
66
67
|
/** Permissions not yet used; the caller uses one up before it lets a call through. */
|
|
@@ -68,7 +69,8 @@ export interface AccessProfile {
|
|
|
68
69
|
/**
|
|
69
70
|
* Calls a person answered `allow_always` for: they run without asking, and
|
|
70
71
|
* only after every deny passed. The harness leaves them out in a background
|
|
71
|
-
* run (`operad-sandbox.md`
|
|
72
|
+
* run (`docs/backlog/operad-sandbox.md` for the background run; ADR 0025 D7
|
|
73
|
+
* for the user layer).
|
|
72
74
|
*/
|
|
73
75
|
readonly alwaysAllow?: readonly AlwaysAllowEntry[] | undefined;
|
|
74
76
|
}
|
|
@@ -487,7 +489,7 @@ function redirectTarget(word: string, next: string | undefined): string | undefi
|
|
|
487
489
|
/**
|
|
488
490
|
* The ask verdict of a command, when no deny applied. A command that hides what
|
|
489
491
|
* it runs (inline code) cannot be matched, so it asks while `askCommands` is
|
|
490
|
-
* set (
|
|
492
|
+
* set (ADR 0025 D3).
|
|
491
493
|
*/
|
|
492
494
|
function askBash(profile: AccessProfile, command: string, asked: AskedPaths | undefined, cwd: string, home: string): Verdict {
|
|
493
495
|
const texts = profile.askCommands ?? [];
|