Skip to content

Commit 31bb7ab

Browse files
authored
Merge pull request #223 from AreevAI/fix/bindings-credential-broker
Fix/bindings credential broker
2 parents f2a7b48 + abf0f1c commit 31bb7ab

23 files changed

Lines changed: 1428 additions & 262 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,15 @@ jobs:
361361
working-directory: crates/areev-js
362362
run: cargo metadata --locked --format-version 1 > /dev/null
363363

364+
# The #201 parity test drives one capability tool from the binding AND
365+
# from the CLI with the same declaration and grants, so the binary has
366+
# to exist here; without it that leg is skipped with a diagnostic.
367+
- name: Build the areev binary for the CLI parity leg
368+
run: cargo build -p areev --locked
364369
- name: Build the native addon + run smoke test
365370
working-directory: crates/areev-js
371+
env:
372+
AREEV_BIN: ${{ github.workspace }}/target/debug/areev
366373
run: |
367374
npm ci
368375
npx napi build --platform --release -- --locked

‎CHANGELOG.md‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,35 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
285285
could not leave the session namespace, so a host recording calls into
286286
per-domain child namespaces (`domain.phone`, `domain.spotify`) had to open a
287287
second handle — which the single-writer registry refuses (`STO-E002`).
288+
- **An empty `tool_env` / `toolEnv` in the bindings now means "clear to the
289+
minimal set", as the CLI's `--tool-env ""` does** (#197). Both bindings
290+
filtered the empty string out before building the policy, so the strictest
291+
request — clear the environment, admit nothing beyond what a command needs
292+
to start — was answered with the loosest posture, inherit everything. A host
293+
wanting the clear-only policy had to name a variable already in the minimal
294+
set just to select it. `None` / `null` keep the inherit default, unchanged.
295+
Pinned in both bindings' tests, on the run executors and the trigger
296+
connector.
297+
- **The credential broker reaches the bindings and `areev serve`** (#201).
298+
A `wasm32-areev-io` tool's `areev::fetch` is answered by the broker, and
299+
the broker was built only from CLI flags — so a host driving runs through
300+
Python or Node, which is what a service does, could persist a capability
301+
tool, pin it, point at the sandbox, and still have every fetch fail. The
302+
parser moved into `areev-run` as `EgressSpec`, the one behind
303+
`--credential`/`--allow-host`/`--tool-egress`/`--credential-ttl`/
304+
`--resolver-env`, and every surface calls it: the same-named parameters on
305+
`run_start`, `run_resume`, `trigger_run` and `trigger_deliver` in both
306+
bindings (`credentials`, `allow_hosts`, `tool_egress`, `credential_ttl_secs`,
307+
`resolver_env`; camelCase in Node) take the flags' spec strings verbatim,
308+
and `$AREEV_RUN_CREDENTIAL`, `$AREEV_RUN_ALLOW_HOST`,
309+
`$AREEV_RUN_TOOL_EGRESS`, `$AREEV_RUN_CREDENTIAL_TTL` and
310+
`$AREEV_RUN_RESOLVER_ENV` are the server-bound spellings for `areev serve`
311+
— and the out-of-band fallbacks for the CLI, like the rest of the family.
312+
The blob door (`{"blob": {"read": true}}`) is wired on the same path, a
313+
refusal from a binding-driven run is journaled exactly as from the CLI
314+
(`403` + `RUN-E022`, an Observation in `agent:harness`), and a parity test
315+
drives one capability tool from Node, Python, the CLI and the MCP server
316+
with one declaration and one set of grants.
288317

289318
### Changed
290319

@@ -312,15 +341,6 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
312341
`scripts/check_versions.py` asserts, alongside the other detached package
313342
(`areev-js`), and it gained the `--version` flag that makes the pairing
314343
checkable at all.
315-
- **An empty `tool_env` / `toolEnv` in the bindings now means "clear to the
316-
minimal set", as the CLI's `--tool-env ""` does** (#197). Both bindings
317-
filtered the empty string out before building the policy, so the strictest
318-
request — clear the environment, admit nothing beyond what a command needs
319-
to start — was answered with the loosest posture, inherit everything. A host
320-
wanting the clear-only policy had to name a variable already in the minimal
321-
set just to select it. `None` / `null` keep the inherit default, unchanged.
322-
Pinned in both bindings' tests, on the run executors and the trigger
323-
connector.
324344

325345
## [1.7.3] — 2026-09-07
326346

‎crates/areev-cli/src/main.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ COMMANDS:
285285
command may itself contain '@'. --resolver-env names the variables
286286
a resolver needs for its OWN authentication ($VAULT_TOKEN,
287287
$AWS_PROFILE): they are withheld from every other subprocess and
288-
re-admitted only for resolvers;
288+
re-admitted only for resolvers. All five also read their
289+
$AREEV_RUN_CREDENTIAL / _ALLOW_HOST / _TOOL_EGRESS /
290+
_CREDENTIAL_TTL / _RESOLVER_ENV variable (the flag wins), which
291+
is how `areev serve` and a heartbeat configure the broker;
289292
--allow-executor pins the content address of a code-carrying tool
290293
(a Definition whose executor_uri names a cas:// blob). Nothing
291294
code-carrying runs unpinned, because the blob travels with the
@@ -1432,8 +1435,9 @@ fn run() -> Result<(), String> {
14321435
// entry in the list above (#100). `Credential::bearer_from_env` registers
14331436
// the core seam for every host that reads one; this adds the loop mirror,
14341437
// and does it HERE rather than in `build_egress` because the choke point
1435-
// runs before any verb arm can spawn.
1436-
if let Some(list) = flag(&flags, "credential") {
1438+
// runs before any verb arm can spawn. The variable spelling (#201) is
1439+
// read here too: a secret named out of band is still a secret.
1440+
if let Some(list) = run_stack::flag_or_env(&flags, "credential", areev_run::egress_spec::ENV_CREDENTIAL) {
14371441
for pair in list.split(',') {
14381442
if let Some((_, spec)) = pair.split_once('=') {
14391443
let spec = spec.trim();
@@ -1475,7 +1479,7 @@ fn run() -> Result<(), String> {
14751479
// environment would put it inside every `--tool-cmd` subprocess — the #100
14761480
// leak reopened one level up. Withheld from every child here, and
14771481
// re-admitted only for resolver spawns (`CredentialSource::spawn_policy`).
1478-
if let Some(list) = flag(&flags, "resolver-env") {
1482+
if let Some(list) = run_stack::flag_or_env(&flags, "resolver-env", areev_run::egress_spec::ENV_RESOLVER_ENV) {
14791483
for var in list.split(',').map(str::trim).filter(|v| !v.is_empty()) {
14801484
areev_core::proc::deny_env_var(var);
14811485
areev_loop::proc::deny_env_var(var);
@@ -2559,6 +2563,7 @@ Nothing was written — apply the snippet yourself (or rerun with your own paths
25592563
}
25602564
let facade = apply_principal(facade, &flags)?;
25612565
let mut server = areev_mcp::McpServer::new(facade, None)
2566+
.with_memory_path(&db)
25622567
.assembly_manifest_sample_rate(assembly_manifest_sample_rate(&flags)?);
25632568
if flags.contains_key("no-destructive-ops") {
25642569
server = server.allow_destructive_ops(false);

‎crates/areev-cli/src/run_stack.rs‎

Lines changed: 21 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -57,185 +57,35 @@ impl HostToolExecutor for NoExecutor {
5757
}
5858
}
5959

60-
/// `--credential name=ENV_VAR`, `--allow-host URL`, `--tool-egress
61-
/// tool:cred+cred:METHOD+METHOD`. Returns None when no egress is configured,
62-
/// which leaves tools exactly as they were.
63-
pub fn build_egress(
64-
flags: &HashMap<String, String>,
65-
) -> Result<Option<areev_run::Broker>, String> {
66-
let (creds, hosts, tools) =
67-
(flag(flags, "credential"), flag(flags, "allow-host"), flag(flags, "tool-egress"));
68-
if creds.is_none() && hosts.is_none() && tools.is_none() {
69-
return Ok(None);
70-
}
71-
// How long a MINTED credential may be reused, and which variables a
72-
// resolver may see (#113). Both are host config and apply to every
73-
// dynamic source this process configures.
74-
let ttl_secs = match flag(flags, "credential-ttl") {
60+
/// `--credential`, `--allow-host`, `--tool-egress`, `--credential-ttl` and
61+
/// `--resolver-env` — or their `$AREEV_RUN_*` variables — as one spec. The
62+
/// parser lives in `areev-run` (#201) so the bindings and `areev serve` read
63+
/// exactly this grammar; a flag wins over its variable, as everywhere here.
64+
pub fn egress_spec(flags: &HashMap<String, String>) -> Result<areev_run::EgressSpec, String> {
65+
let ttl = match flag(flags, "credential-ttl") {
7566
None => None,
7667
Some(v) => Some(
7768
v.trim()
7869
.parse::<u64>()
7970
.map_err(|_| format!("--credential-ttl: expected whole seconds, got {v:?}"))?,
8071
),
8172
};
82-
let resolver_env: Vec<String> = flag(flags, "resolver-env")
83-
.iter()
84-
.flat_map(|v| v.split(','))
85-
.map(|s| s.trim().to_string())
86-
.filter(|s| !s.is_empty())
87-
.collect();
88-
89-
let mut credentials = std::collections::BTreeMap::new();
90-
// name -> owning run principal, for `--credential name=VAR@principal` and
91-
// its source-agnostic sibling `--credential name@principal=…`.
92-
let mut owners: Vec<(String, String)> = Vec::new();
93-
for pair in creds.iter().flat_map(|v| v.split(',')) {
94-
let pair = pair.trim();
95-
if pair.is_empty() {
96-
continue;
97-
}
98-
let (lhs, spec) = pair.split_once('=').ok_or_else(|| {
99-
format!(
100-
"--credential: expected name=ENV_VAR[@principal], name[@principal]=cmd:COMMAND, \
101-
or name[@principal]=vault:PATH#FIELD, got {pair:?} — note that a comma \
102-
separates credentials, so a resolver command containing one belongs in a script"
103-
)
104-
})?;
105-
// The principal may be named on the NAME side, which is the only
106-
// unambiguous place for a `cmd:` source: a command can contain '@'
107-
// anywhere, so splitting one on it would bind the credential to a
108-
// principal the operator never wrote (#113).
109-
let (name, name_owner) = match lhs.trim().split_once('@') {
110-
Some((n, p)) if !p.trim().is_empty() => (n.trim(), Some(p.trim().to_string())),
111-
Some(_) => {
112-
return Err(format!(
113-
"--credential {pair:?}: empty principal after '@' — write name=SOURCE for an \
114-
unbound credential, or name@principal=SOURCE to bind one"
115-
))
116-
}
117-
None => (lhs.trim(), None),
118-
};
119-
if name.is_empty() {
120-
return Err(format!("--credential {pair:?}: the credential has no name"));
121-
}
122-
// An env-var value is READ here from a variable the host named — a
123-
// secret on a command line is a secret in shell history and in `ps`.
124-
// A `cmd:`/`vault:` source reads nothing yet; it is minted per TTL
125-
// window at call time, inside the broker.
126-
let (source, spec_owner) = areev_run::CredentialSource::from_spec(spec.trim())?;
127-
let owner = match (name_owner, spec_owner) {
128-
(Some(_), Some(_)) => {
129-
return Err(format!(
130-
"--credential {pair:?}: names a principal on both sides of '=' — pick one"
131-
))
132-
}
133-
(a, b) => a.or(b),
134-
};
135-
let name = name.to_string();
136-
if let Some(o) = owner {
137-
owners.push((name.clone(), o));
138-
}
139-
credentials.insert(name, source.with_resolver_config(ttl_secs, &resolver_env));
73+
areev_run::EgressSpec {
74+
credentials: flag(flags, "credential").filter(|v| !v.trim().is_empty()),
75+
allow_hosts: flag(flags, "allow-host").filter(|v| !v.trim().is_empty()),
76+
tool_egress: flag(flags, "tool-egress").filter(|v| !v.trim().is_empty()),
77+
credential_ttl_secs: ttl,
78+
resolver_env: flag(flags, "resolver-env").filter(|v| !v.trim().is_empty()),
14079
}
141-
let policy = match &hosts {
142-
// Absent means unrestricted, and is reported as such rather than
143-
// silently reading as a policy.
144-
None => areev_run::EgressPolicy::unrestricted(),
145-
Some(list) => {
146-
let entries: Vec<serde_json::Value> = list
147-
.split(',')
148-
.map(str::trim)
149-
.filter(|h| !h.is_empty())
150-
.map(|h| serde_json::json!(h))
151-
.collect();
152-
areev_run::EgressPolicy::from_config(Some(&serde_json::json!({
153-
"int:allowed_outbound_hosts": entries
154-
})))?
155-
}
156-
};
157-
let mut grants = areev_run::EgressGrants::new();
158-
for spec in tools.iter().flat_map(|v| v.split(',')) {
159-
let spec = spec.trim();
160-
if spec.is_empty() {
161-
continue;
162-
}
163-
// A URL anywhere in the spec is an operator writing `cred@https://host`
164-
// for the #112 pairing. Split on ':' that would leave `https` sitting
165-
// in the host position — a pairing that matches nothing while reading
166-
// as a restriction. Caught here, where the whole spec is still intact
167-
// and the message can say what to write instead.
168-
if spec.contains("://") {
169-
return Err(format!(
170-
"--tool-egress {spec:?}: pair a credential with a BARE hostname \
171-
(cred@api.example.com), not a URL — this spec is colon-delimited, so a scheme \
172-
or port would tear it apart; scheme and port are narrowed by --allow-host"
173-
));
174-
}
175-
let mut parts = spec.split(':');
176-
let tool = parts.next().unwrap_or("").trim();
177-
if tool.is_empty() {
178-
return Err(format!(
179-
"--tool-egress: expected tool:cred[@host]+cred[@host]:METHOD+METHOD, got {spec:?}"
180-
));
181-
}
182-
let mut g = areev_run::CallerGrant::new();
183-
for c in parts.next().unwrap_or("").split('+').map(str::trim) {
184-
if c.is_empty() {
185-
continue;
186-
}
187-
// `cred@host` pairs the credential with where it may be sent
188-
// (#112); a bare `cred` keeps the older any-host meaning.
189-
g = match c.split_once('@') {
190-
Some((name, host)) => {
191-
let name = name.trim();
192-
if name.is_empty() {
193-
return Err(format!(
194-
"--tool-egress {spec:?}: {c:?} has no credential name before '@'"
195-
));
196-
}
197-
let host = areev_run::AllowedHost::parse_host_pattern(host, "--tool-egress")?;
198-
g.credential_for(name, vec![host])
199-
}
200-
None => g.credential(c),
201-
};
202-
}
203-
for m in parts.next().unwrap_or("").split('+').map(str::trim) {
204-
if m.is_empty() {
205-
continue;
206-
}
207-
// Validated rather than accepted verbatim: an unrecognized token
208-
// here used to become a method nothing would ever match, so a
209-
// typo — or a port that survived the colon split — produced a
210-
// grant that silently refused every write at runtime.
211-
let upper = m.to_ascii_uppercase();
212-
if !matches!(
213-
upper.as_str(),
214-
"GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE"
215-
) {
216-
// A field of digits is almost always a port that survived the
217-
// colon split (`cred@host:8443`), so say that rather than
218-
// leaving the operator to work back from "8443 is not a method".
219-
let hint = if m.chars().all(|c| c.is_ascii_digit()) {
220-
" — if you meant a port, drop it: a credential↔host pairing \
221-
names the host, and the port is narrowed by --allow-host"
222-
} else {
223-
""
224-
};
225-
return Err(format!(
226-
"--tool-egress {spec:?}: {m:?} is not an HTTP method; accepted: \
227-
GET, HEAD, POST, PUT, PATCH, DELETE{hint}"
228-
));
229-
}
230-
g = g.method(&upper);
231-
}
232-
grants = grants.grant(tool, g);
233-
}
234-
let broker = areev_run::Broker::start(policy, credentials, grants, "RUN-E022")?;
235-
for (name, owner) in owners {
236-
broker.bind_credential_owner(&name, &owner);
237-
}
238-
Ok(Some(broker))
80+
.with_env_fallback()
81+
}
82+
83+
/// The broker [`egress_spec`] describes, or None when it describes none —
84+
/// which leaves tools exactly as they were.
85+
pub fn build_egress(
86+
flags: &HashMap<String, String>,
87+
) -> Result<Option<areev_run::Broker>, String> {
88+
egress_spec(flags)?.build()
23989
}
24090

24191
/// `--executor-timeout`/`$AREEV_RUN_EXECUTOR_TIMEOUT`: the host override for

‎crates/areev-cli/src/trigger_cli.rs‎

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -176,59 +176,12 @@ fn evaluator(
176176
// Credentials are named on the command line and READ here, so a value
177177
// never appears in a grain, in shell history, or in the connector's
178178
// environment: `--credential gmail=GMAIL_TOKEN_VAR` names the variable.
179-
//
180-
// An unset variable is refused rather than dropped — the same rule
181-
// `run start` and both bindings already applied. A silently dropped
182-
// credential does not stay silent: it surfaces downstream as an
183-
// unexplained 401 from someone else's API, hours later, on a heartbeat
184-
// nobody is watching. `build_egress` above validated the same list, so
185-
// this cannot reach a different verdict; it is spelled out rather than
186-
// assumed, because the two would drift the first time either moved.
187-
// Resolver settings ride with each dynamic source, exactly as they do on
188-
// the run path — one parse, one meaning, both hosts.
189-
let ttl_secs = match flag(flags, "credential-ttl") {
190-
None => None,
191-
Some(v) => Some(
192-
v.trim()
193-
.parse::<u64>()
194-
.map_err(|_| format!("--credential-ttl: expected whole seconds, got {v:?}"))?,
195-
),
196-
};
197-
let resolver_env: Vec<String> = flag(flags, "resolver-env")
198-
.iter()
199-
.flat_map(|v| v.split(','))
200-
.map(|s| s.trim().to_string())
201-
.filter(|s| !s.is_empty())
202-
.collect();
203-
let mut credentials = std::collections::BTreeMap::new();
204-
if let Some(spec) = flag(flags, "credential") {
205-
for pair in spec.split(',') {
206-
let pair = pair.trim();
207-
if pair.is_empty() {
208-
continue;
209-
}
210-
let (lhs, spec) = pair.split_once('=').ok_or_else(|| {
211-
format!(
212-
"--credential: expected name=ENV_VAR[@principal], \
213-
name[@principal]=cmd:COMMAND, or name[@principal]=vault:PATH#FIELD, \
214-
got {pair:?}"
215-
)
216-
})?;
217-
// The `@principal` owner qualifier governs a credential's use in a
218-
// started RUN, and is enforced on that run's broker (built by
219-
// `build_egress` above). This is the connector-poll broker — the
220-
// trigger's own standing egress, not a per-user run — so the owner
221-
// is parsed off and dropped here rather than breaking the read.
222-
// Both spellings are dropped: on the name side (any source) and on
223-
// the value side (the env-var form's own grammar).
224-
let name = lhs.trim().split_once('@').map(|(n, _)| n).unwrap_or(lhs).trim();
225-
let (source, _owner) = areev_run::CredentialSource::from_spec(spec.trim())?;
226-
credentials.insert(
227-
name.to_string(),
228-
source.with_resolver_config(ttl_secs, &resolver_env),
229-
);
230-
}
231-
}
179+
// An unset variable is refused rather than dropped. The `@principal`
180+
// owner governs a credential's use in a started RUN, enforced on that
181+
// run's broker (built by `build_egress` above); this is the connector-poll
182+
// broker — the trigger's own standing egress — so the owner is dropped.
183+
// ONE parser for both (#201), so they cannot reach different verdicts.
184+
let credentials = run_stack::egress_spec(flags)?.unowned_credentials()?;
232185

233186
Ok((
234187
Evaluator {

0 commit comments

Comments
 (0)