refactor(ai): make the OpenCode transport a standard sandboxed transport
Some checks are pending
ci / test (push) Waiting to run
Some checks are pending
ci / test (push) Waiting to run
This commit is contained in:
parent
52dbdf4422
commit
aeb46aceee
9 changed files with 203 additions and 37 deletions
|
|
@ -5,6 +5,22 @@ this file is the curated, human-readable summary.
|
||||||
|
|
||||||
## Unreleased — Fast defaults with user-controlled source builds
|
## Unreleased — Fast defaults with user-controlled source builds
|
||||||
|
|
||||||
|
- **OpenCode is now a standard transport (2026-09-29).** The OpenCode backend was
|
||||||
|
special-cased twice: it ran **outside** the model sandbox (a comment called it
|
||||||
|
"a different trust boundary") and its endpoint policy was stricter than the
|
||||||
|
direct provider's (plain `http` only to loopback). Both are now unified. The
|
||||||
|
OpenCode transport runs in the **same OS-level sandbox** as the direct
|
||||||
|
transport unless `--no-sandbox` is given; its curl calls inline the request
|
||||||
|
body into the hidden stdin config (the sandbox's `PrivateTmp` would hide a
|
||||||
|
temp file). A **network** OpenCode server works over `https` as before, and a
|
||||||
|
remote plain-`http` server is permitted with the explicit
|
||||||
|
`--opencode-insecure-http` opt-in (credentials/prompts travel in cleartext, so
|
||||||
|
it is off by default; `PHOEBUS_OPENCODE_INSECURE_HTTP=1` also enables it).
|
||||||
|
VM re-verification with the real host agent (`serial-boot-20260929T114319Z-c43c2a92`,
|
||||||
|
driver PASS=8, sandbox on by default): `list`/`search` valid plans,
|
||||||
|
constrained install gated before mutation, hostile instruction refused. Gates:
|
||||||
|
`cargo fmt`, `clippy --workspace --all-targets -- -D warnings`, `cargo test
|
||||||
|
--workspace` 845 passed / 0 failed.
|
||||||
- **Headless read-only probes can no longer block; real-agent VM re-verification
|
- **Headless read-only probes can no longer block; real-agent VM re-verification
|
||||||
(2026-09-29).** Driving the powerful model (host `opencode` agent,
|
(2026-09-29).** Driving the powerful model (host `opencode` agent,
|
||||||
`deepseek-v4.1-flash`) with `sys` **inside the VM**, a `sys ask "search for
|
`deepseek-v4.1-flash`) with `sys` **inside the VM**, a `sys ask "search for
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,16 @@ commit it. It should be short and current; use `git log` for detail.
|
||||||
call (`sys ask` with a real provider is still VM/live NotRun) but it closes
|
call (`sys ask` with a real provider is still VM/live NotRun) but it closes
|
||||||
the "connected-model path only tested with fake transports" gap. Gates:
|
the "connected-model path only tested with fake transports" gap. Gates:
|
||||||
`cargo test --workspace` 841 passed / 0 failed.
|
`cargo test --workspace` 841 passed / 0 failed.
|
||||||
|
- **OpenCode transport standardized (2026-09-29, VM-VERIFIED):** the OpenCode
|
||||||
|
backend no longer runs outside the model sandbox and no longer has a stricter
|
||||||
|
endpoint policy than the direct provider. It is sandboxed by default (curl
|
||||||
|
body inlined on stdin because `PrivateTmp` hides a temp file); `https` servers
|
||||||
|
on the network work as before, and remote plain `http` is allowed only with
|
||||||
|
`--opencode-insecure-http` / `PHOEBUS_OPENCODE_INSECURE_HTTP=1`. Re-verified in
|
||||||
|
the VM with the real host agent (`serial-boot-20260929T114319Z-c43c2a92`,
|
||||||
|
driver PASS=8). Next confidence work: VM-prove the approval-ledger/effect-binding
|
||||||
|
paths, source-conversion/tuned-kernel journeys (multi-hour), a physical-seat
|
||||||
|
desktop pass, and configure a CI runner for the release gates.
|
||||||
- **VM live AI (2026-09-29, VM-VERIFIED):** from inside the installed guest,
|
- **VM live AI (2026-09-29, VM-VERIFIED):** from inside the installed guest,
|
||||||
the host's real `opencode` agent was reached through the loopback tunnel and
|
the host's real `opencode` agent was reached through the loopback tunnel and
|
||||||
`sys ask` produced a valid plan (`live-agent`), with a hostile instruction
|
`sys ask` produced a valid plan (`live-agent`), with a hostile instruction
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ Booting that recovery entry offline remains a manual gate.
|
||||||
| AI connected-model path over a real local stub | yes | yes (4 e2e cases: valid plan executes; request has no home path/credential; shell + smuggled key + malformed fail closed) | no (local stub, not a live model) | n/a |
|
| AI connected-model path over a real local stub | yes | yes (4 e2e cases: valid plan executes; request has no home path/credential; shell + smuggled key + malformed fail closed) | no (local stub, not a live model) | n/a |
|
||||||
| Live real-agent call (`opencode` backend) | yes | yes (`sys ask "list installed packages"` → valid plan + digest, exit 0; hostile shell/private-file instruction refused and downgraded; OpenCode tools disabled; no credential in the log) | yes — host direct (2026-09-28) and **from inside the installed VM through the loopback tunnel** (`serial-boot-20260929T102703Z-ffd1ec25`, `live-agent` + `live-agent-hostile-rejected`) with `opencode-go/deepseek-v4.1-flash` | n/a |
|
| Live real-agent call (`opencode` backend) | yes | yes (`sys ask "list installed packages"` → valid plan + digest, exit 0; hostile shell/private-file instruction refused and downgraded; OpenCode tools disabled; no credential in the log) | yes — host direct (2026-09-28) and **from inside the installed VM through the loopback tunnel** (`serial-boot-20260929T102703Z-ffd1ec25`, `live-agent` + `live-agent-hostile-rejected`) with `opencode-go/deepseek-v4.1-flash` | n/a |
|
||||||
| Local model through the direct sandbox (VM) | yes | yes (real Qwen2.5-1.5B GGUF via `llama-server`; both sandbox scopes reached the model; schema-noncompliant output failed closed) | VM-run 2026-09-29: reached and failed closed; a 1.5B model is too weak for exact typed plans and its 4096-token context was exceeded by the correction turn — a capable model is required (a capable agent produces valid plans) | n/a |
|
| Local model through the direct sandbox (VM) | yes | yes (real Qwen2.5-1.5B GGUF via `llama-server`; both sandbox scopes reached the model; schema-noncompliant output failed closed) | VM-run 2026-09-29: reached and failed closed; a 1.5B model is too weak for exact typed plans and its 4096-token context was exceeded by the correction turn — a capable model is required (a capable agent produces valid plans) | n/a |
|
||||||
|
| OpenCode transport parity (sandbox + network endpoint) | yes | yes (`CurlHttpClient::sandboxed` inlines the body under `PrivateTmp`; `--opencode-insecure-http` opt-in for remote plain http; endpoint-policy test) | yes (`serial-boot-20260929T114319Z-c43c2a92`: real host agent, OpenCode sandboxed by default, driver PASS=8) | n/a |
|
||||||
| Read-only host-root probes never block on a prompt | yes | yes (`CommandSpec::detached` runs host-root Flatpak in a new session via `setsid --wait`, no controlling terminal; field-preserving unit test) | yes (VM: real-agent `sys ask "search for firefox"` completed with zero auth prompts, `serial-boot-20260929T111941Z-2be30b89`) | n/a |
|
| Read-only host-root probes never block on a prompt | yes | yes (`CommandSpec::detached` runs host-root Flatpak in a new session via `setsid --wait`, no controlling terminal; field-preserving unit test) | yes (VM: real-agent `sys ask "search for firefox"` completed with zero auth prompts, `serial-boot-20260929T111941Z-2be30b89`) | n/a |
|
||||||
| Privilege derived only from the process identity | yes | yes (an environment variable cannot forge uid 0; the removed `PHOEBUS_ALLOW_UNPRIVILEGED_EXEC` regression test) | no | n/a |
|
| Privilege derived only from the process identity | yes | yes (an environment variable cannot forge uid 0; the removed `PHOEBUS_ALLOW_UNPRIVILEGED_EXEC` regression test) | no | n/a |
|
||||||
| AI OS sandbox (systemd hardened unit) | yes | yes (argv + sandboxed-send; system properties for root, user-manager subset for non-root) | yes (`serial-boot-20260929T092147Z-6f88907a`: `AI_ROOT_RC=0` system sandbox, `AI_USER_RC=0` `--user` sandbox; previously the user path hung on a polkit `manage-units` prompt) | no |
|
| AI OS sandbox (systemd hardened unit) | yes | yes (argv + sandboxed-send; system properties for root, user-manager subset for non-root) | yes (`serial-boot-20260929T092147Z-6f88907a`: `AI_ROOT_RC=0` system sandbox, `AI_USER_RC=0` `--user` sandbox; previously the user path hung on a polkit `manage-units` prompt) | no |
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,12 @@ the static `sys` built from HEAD; the base image was never modified.
|
||||||
`CommandSpec::detached()` fix the re-run completed with **zero auth prompts**.
|
`CommandSpec::detached()` fix the re-run completed with **zero auth prompts**.
|
||||||
The install investigation itself stopped on the model's own request-count /
|
The install investigation itself stopped on the model's own request-count /
|
||||||
formatting limits and failed closed (no `sys` defect).
|
formatting limits and failed closed (no `sys` defect).
|
||||||
|
- **OpenCode sandbox parity (`serial-boot-20260929T114319Z-c43c2a92`, driver
|
||||||
|
PASS=8):** re-ran the same four real-agent requests with the OpenCode transport
|
||||||
|
now sandboxed by default (`systemd-run --user` for the unprivileged `sys`).
|
||||||
|
All four passed with the sandbox enabled — `list`/`search` valid plans,
|
||||||
|
constrained install gated, hostile instruction refused — proving the OpenCode
|
||||||
|
transport works inside the same OS-level boundary as the direct provider.
|
||||||
|
|
||||||
## 2026-09-28 Headless dual-target golden install (Run 13) & detached boot proven
|
## 2026-09-28 Headless dual-target golden install (Run 13) & detached boot proven
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,11 +128,23 @@ pub trait HttpClient {
|
||||||
/// file. Redirects are disabled and the protocol is restricted to http/https.
|
/// file. Redirects are disabled and the protocol is restricted to http/https.
|
||||||
pub struct CurlHttpClient<'a> {
|
pub struct CurlHttpClient<'a> {
|
||||||
exec: &'a Exec,
|
exec: &'a Exec,
|
||||||
|
sandboxed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CurlHttpClient<'a> {
|
impl<'a> CurlHttpClient<'a> {
|
||||||
pub fn new(exec: &'a Exec) -> Self {
|
pub fn new(exec: &'a Exec) -> Self {
|
||||||
Self { exec }
|
Self {
|
||||||
|
exec,
|
||||||
|
sandboxed: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run the request inside the OS-level model sandbox (same boundary as the
|
||||||
|
/// direct provider transport). The body is inlined into the curl config on
|
||||||
|
/// stdin because the sandbox has a private `/tmp`.
|
||||||
|
pub fn sandboxed(mut self) -> Self {
|
||||||
|
self.sandboxed = true;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,16 +154,23 @@ impl HttpClient for CurlHttpClient<'_> {
|
||||||
fn request(&self, request: &HttpRequest) -> Result<HttpResponse, AiError> {
|
fn request(&self, request: &HttpRequest) -> Result<HttpResponse, AiError> {
|
||||||
let mut temp: Option<tempfile::NamedTempFile> = None;
|
let mut temp: Option<tempfile::NamedTempFile> = None;
|
||||||
let data_line = if let Some(body) = &request.body {
|
let data_line = if let Some(body) = &request.body {
|
||||||
let mut file = tempfile::Builder::new()
|
if self.sandboxed {
|
||||||
.prefix("phoebus-opencode.")
|
// Inline the body (escaped) into the curl config: the sandbox's
|
||||||
.tempfile()
|
// PrivateTmp would hide a temp file created here.
|
||||||
.map_err(|e| AiError::Provider(format!("temp file: {e}")))?;
|
let escaped = body.replace('\\', "\\\\").replace('"', "\\\"");
|
||||||
file.write_all(body.as_bytes())
|
format!("data = \"{escaped}\"\n")
|
||||||
.and_then(|_| file.flush())
|
} else {
|
||||||
.map_err(|e| AiError::Provider(format!("temp file: {e}")))?;
|
let mut file = tempfile::Builder::new()
|
||||||
let line = format!("data = \"@{}\"\n", file.path().display());
|
.prefix("phoebus-opencode.")
|
||||||
temp = Some(file);
|
.tempfile()
|
||||||
line
|
.map_err(|e| AiError::Provider(format!("temp file: {e}")))?;
|
||||||
|
file.write_all(body.as_bytes())
|
||||||
|
.and_then(|_| file.flush())
|
||||||
|
.map_err(|e| AiError::Provider(format!("temp file: {e}")))?;
|
||||||
|
let line = format!("data = \"@{}\"\n", file.path().display());
|
||||||
|
temp = Some(file);
|
||||||
|
line
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
@ -218,14 +237,23 @@ impl HttpClient for CurlHttpClient<'_> {
|
||||||
marker = STATUS_MARKER,
|
marker = STATUS_MARKER,
|
||||||
);
|
);
|
||||||
|
|
||||||
let out = self
|
let out = if self.sandboxed {
|
||||||
.exec
|
crate::sandbox::run(
|
||||||
.run(
|
self.exec,
|
||||||
CommandSpec::new("ai", "OpenCode request", "curl")
|
"curl",
|
||||||
.args(["-sS", "-K", "-"])
|
&["-sS".into(), "-K".into(), "-".into()],
|
||||||
.stdin(config.into_bytes()),
|
config.into_bytes(),
|
||||||
)
|
)
|
||||||
.map_err(|e| AiError::Provider(format!("transport error: {e}")))?;
|
.map_err(|e| AiError::Provider(format!("transport error: {e}")))?
|
||||||
|
} else {
|
||||||
|
self.exec
|
||||||
|
.run(
|
||||||
|
CommandSpec::new("ai", "OpenCode request", "curl")
|
||||||
|
.args(["-sS", "-K", "-"])
|
||||||
|
.stdin(config.into_bytes()),
|
||||||
|
)
|
||||||
|
.map_err(|e| AiError::Provider(format!("transport error: {e}")))?
|
||||||
|
};
|
||||||
drop(temp);
|
drop(temp);
|
||||||
|
|
||||||
let stdout = out.stdout_lossy();
|
let stdout = out.stdout_lossy();
|
||||||
|
|
@ -770,6 +798,8 @@ pub struct ExecOpenCodeTransport<'a> {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
max_body: u64,
|
max_body: u64,
|
||||||
resolve: Option<(String, u16, IpAddr)>,
|
resolve: Option<(String, u16, IpAddr)>,
|
||||||
|
sandboxed: bool,
|
||||||
|
allow_insecure_http: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExecOpenCodeTransport<'a> {
|
impl<'a> ExecOpenCodeTransport<'a> {
|
||||||
|
|
@ -789,9 +819,24 @@ impl<'a> ExecOpenCodeTransport<'a> {
|
||||||
timeout: Duration::from_secs(120),
|
timeout: Duration::from_secs(120),
|
||||||
max_body: 4 * 1024 * 1024,
|
max_body: 4 * 1024 * 1024,
|
||||||
resolve: None,
|
resolve: None,
|
||||||
|
sandboxed: false,
|
||||||
|
allow_insecure_http: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run the OpenCode requests inside the same OS-level sandbox as the direct
|
||||||
|
/// provider transport (DynamicUser/ProtectHome/... via `systemd-run`).
|
||||||
|
pub fn sandboxed(mut self) -> Self {
|
||||||
|
self.sandboxed = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Permit plain `http` to a non-loopback OpenCode server (explicit opt-in).
|
||||||
|
pub fn allow_insecure_http(mut self) -> Self {
|
||||||
|
self.allow_insecure_http = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_auth(mut self, password: Option<SecretString>) -> Self {
|
pub fn with_auth(mut self, password: Option<SecretString>) -> Self {
|
||||||
self.auth = password;
|
self.auth = password;
|
||||||
self
|
self
|
||||||
|
|
@ -855,12 +900,17 @@ impl ModelTransport for ExecOpenCodeTransport<'_> {
|
||||||
// address, so the adapter cannot be pointed at a plain-http remote.
|
// address, so the adapter cannot be pointed at a plain-http remote.
|
||||||
let endpoint = crate::opencode_server::Endpoint::parse(&self.base)
|
let endpoint = crate::opencode_server::Endpoint::parse(&self.base)
|
||||||
.map_err(|e| AiError::Rejected(format!("invalid OpenCode endpoint: {e}")))?;
|
.map_err(|e| AiError::Rejected(format!("invalid OpenCode endpoint: {e}")))?;
|
||||||
let target = endpoint.checked_target()?;
|
let target = endpoint.checked_target_with(self.allow_insecure_http)?;
|
||||||
let resolve =
|
let resolve =
|
||||||
self.resolve
|
self.resolve
|
||||||
.clone()
|
.clone()
|
||||||
.or(Some((endpoint.host.clone(), endpoint.port, target.ip())));
|
.or(Some((endpoint.host.clone(), endpoint.port, target.ip())));
|
||||||
let http = CurlHttpClient::new(self.exec);
|
let http = CurlHttpClient::new(self.exec);
|
||||||
|
let http = if self.sandboxed {
|
||||||
|
http.sandboxed()
|
||||||
|
} else {
|
||||||
|
http
|
||||||
|
};
|
||||||
let mut client = OpenCodeClient::new(&http, &self.base, &self.provider, &self.model)
|
let mut client = OpenCodeClient::new(&http, &self.base, &self.provider, &self.model)
|
||||||
.with_auth(self.auth.clone())
|
.with_auth(self.auth.clone())
|
||||||
.with_timeout(self.timeout)
|
.with_timeout(self.timeout)
|
||||||
|
|
@ -924,6 +974,44 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_sandboxed_request_runs_curl_under_systemd_run_with_the_body_inlined() {
|
||||||
|
if !crate::sandbox::available() {
|
||||||
|
eprintln!("systemd-run unavailable; sandboxed OpenCode transport not exercised here");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let runner = RecordingRunner::new();
|
||||||
|
runner.set_response(
|
||||||
|
"systemd-run",
|
||||||
|
CommandOutput {
|
||||||
|
status: 0,
|
||||||
|
success: true,
|
||||||
|
stdout: b"\n__PHOEBUS_STATUS__200".to_vec(),
|
||||||
|
stderr: Vec::new(),
|
||||||
|
duration: std::time::Duration::from_millis(1),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let dir = tempfile::tempdir().unwrap().keep();
|
||||||
|
let logger = crate::log::Logger::open(dir.join("l.log"), Redactor::new(), false);
|
||||||
|
let exec = crate::exec::Exec::new(Box::new(runner.clone()), logger, false, &dir, &dir);
|
||||||
|
let http = CurlHttpClient::new(&exec).sandboxed();
|
||||||
|
let request = HttpRequest::post("http://127.0.0.1:4096/session", r#"{"x":"y"}"#);
|
||||||
|
let response = http.request(&request).unwrap();
|
||||||
|
assert_eq!(response.status, 200);
|
||||||
|
|
||||||
|
let spec = &runner.recorded()[0];
|
||||||
|
assert_eq!(spec.program, "systemd-run");
|
||||||
|
let stdin = String::from_utf8(spec.stdin.clone().unwrap()).unwrap();
|
||||||
|
assert!(
|
||||||
|
stdin.contains(r#"data = "{\"x\":\"y\"}""#),
|
||||||
|
"the body must be inlined into the config: {stdin}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!stdin.contains("phoebus-opencode."),
|
||||||
|
"no temp file may be used under PrivateTmp: {stdin}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_bearer_token_is_redacted_too() {
|
fn a_bearer_token_is_redacted_too() {
|
||||||
let runner = RecordingRunner::new();
|
let runner = RecordingRunner::new();
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,19 @@ impl Endpoint {
|
||||||
|
|
||||||
/// Resolve the endpoint and enforce the transport policy.
|
/// Resolve the endpoint and enforce the transport policy.
|
||||||
///
|
///
|
||||||
/// Returns the address the connection must be pinned to. `http` requires
|
/// Returns the address the connection must be pinned to. Plain `http` must
|
||||||
/// every resolved address to be loopback; `https` requires a valid
|
/// resolve to loopback unless the caller explicitly opted in to an insecure
|
||||||
/// certificate (checked by curl, never disabled).
|
/// remote; `https` requires a valid certificate (checked by curl, never
|
||||||
|
/// disabled).
|
||||||
pub fn checked_target(&self) -> Result<SocketAddr, AiError> {
|
pub fn checked_target(&self) -> Result<SocketAddr, AiError> {
|
||||||
|
self.checked_target_with(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Like [`checked_target`], but permits plain `http` to a non-loopback host
|
||||||
|
/// when the operator explicitly opted in (`--opencode-insecure-http`). The
|
||||||
|
/// credential and prompts would then travel in cleartext, so the default is
|
||||||
|
/// strictly loopback.
|
||||||
|
pub fn checked_target_with(&self, allow_insecure_http: bool) -> Result<SocketAddr, AiError> {
|
||||||
let addrs: Vec<SocketAddr> = (self.host.as_str(), self.port)
|
let addrs: Vec<SocketAddr> = (self.host.as_str(), self.port)
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
.map_err(|e| AiError::Provider(format!("cannot resolve {}: {e}", self.host)))?
|
.map_err(|e| AiError::Provider(format!("cannot resolve {}: {e}", self.host)))?
|
||||||
|
|
@ -150,11 +159,12 @@ impl Endpoint {
|
||||||
self.host
|
self.host
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if self.scheme == Scheme::Http {
|
if self.scheme == Scheme::Http && !allow_insecure_http {
|
||||||
for addr in &addrs {
|
for addr in &addrs {
|
||||||
if !addr.ip().is_loopback() {
|
if !addr.ip().is_loopback() {
|
||||||
return Err(AiError::Rejected(format!(
|
return Err(AiError::Rejected(format!(
|
||||||
"refusing plain http to {} ({}); use https or a loopback tunnel",
|
"refusing plain http to {} ({}); use https or a loopback tunnel, or opt \
|
||||||
|
in explicitly with --opencode-insecure-http",
|
||||||
self.host,
|
self.host,
|
||||||
addr.ip()
|
addr.ip()
|
||||||
)));
|
)));
|
||||||
|
|
@ -535,6 +545,8 @@ mod tests {
|
||||||
let public = Endpoint::parse("http://93.184.216.34:80").unwrap();
|
let public = Endpoint::parse("http://93.184.216.34:80").unwrap();
|
||||||
let err = public.checked_target().unwrap_err().to_string();
|
let err = public.checked_target().unwrap_err().to_string();
|
||||||
assert!(err.contains("refusing plain http"), "{err}");
|
assert!(err.contains("refusing plain http"), "{err}");
|
||||||
|
// An explicit opt-in permits a remote plain-http server.
|
||||||
|
assert!(public.checked_target_with(true).is_ok());
|
||||||
// https is allowed (certificate verification happens in the transport).
|
// https is allowed (certificate verification happens in the transport).
|
||||||
let secure = Endpoint::parse("https://93.184.216.34:443").unwrap();
|
let secure = Endpoint::parse("https://93.184.216.34:443").unwrap();
|
||||||
assert!(secure.checked_target().is_ok());
|
assert!(secure.checked_target().is_ok());
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ pub struct AiOverrides {
|
||||||
pub opencode_provider: Option<String>,
|
pub opencode_provider: Option<String>,
|
||||||
pub opencode_model: Option<String>,
|
pub opencode_model: Option<String>,
|
||||||
pub opencode_password_file: Option<PathBuf>,
|
pub opencode_password_file: Option<PathBuf>,
|
||||||
|
/// Permit plain `http` to a non-loopback OpenCode server (explicit opt-in).
|
||||||
|
pub opencode_insecure_http: bool,
|
||||||
pub no_sandbox: bool,
|
pub no_sandbox: bool,
|
||||||
/// When true, environment variables are consulted between the explicit
|
/// When true, environment variables are consulted between the explicit
|
||||||
/// override and the installed configuration.
|
/// override and the installed configuration.
|
||||||
|
|
@ -49,6 +51,7 @@ pub struct ResolvedAi {
|
||||||
pub opencode_model: String,
|
pub opencode_model: String,
|
||||||
pub api_key_file: Option<PathBuf>,
|
pub api_key_file: Option<PathBuf>,
|
||||||
pub opencode_password_file: Option<PathBuf>,
|
pub opencode_password_file: Option<PathBuf>,
|
||||||
|
pub opencode_insecure_http: bool,
|
||||||
pub no_sandbox: bool,
|
pub no_sandbox: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,6 +186,9 @@ pub fn resolve(_root: &Path, ov: &AiOverrides, conf: Option<&AiConfig>) -> Resol
|
||||||
opencode_model,
|
opencode_model,
|
||||||
api_key_file,
|
api_key_file,
|
||||||
opencode_password_file,
|
opencode_password_file,
|
||||||
|
opencode_insecure_http: ov.opencode_insecure_http
|
||||||
|
|| env_var(ov.use_environment, "PHOEBUS_OPENCODE_INSECURE_HTTP").as_deref()
|
||||||
|
== Some("1"),
|
||||||
no_sandbox: ov.no_sandbox,
|
no_sandbox: ov.no_sandbox,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -236,15 +242,24 @@ impl ResolvedAi {
|
||||||
match self.backend {
|
match self.backend {
|
||||||
AiBackend::OpenCode => {
|
AiBackend::OpenCode => {
|
||||||
let password = self.load_opencode_password()?;
|
let password = self.load_opencode_password()?;
|
||||||
Ok(Box::new(
|
// The OpenCode agent is a standard transport: it runs in the
|
||||||
ExecOpenCodeTransport::new(
|
// same OS-level sandbox as the direct provider unless the
|
||||||
exec,
|
// operator disabled it, and a network server is allowed (https,
|
||||||
self.opencode_server.clone(),
|
// or plain http only with an explicit opt-in).
|
||||||
self.opencode_provider.clone(),
|
let mut transport = ExecOpenCodeTransport::new(
|
||||||
self.opencode_model.clone(),
|
exec,
|
||||||
)
|
self.opencode_server.clone(),
|
||||||
.with_auth(password),
|
self.opencode_provider.clone(),
|
||||||
))
|
self.opencode_model.clone(),
|
||||||
|
)
|
||||||
|
.with_auth(password);
|
||||||
|
if self.opencode_insecure_http {
|
||||||
|
transport = transport.allow_insecure_http();
|
||||||
|
}
|
||||||
|
if !self.no_sandbox {
|
||||||
|
transport = transport.sandboxed();
|
||||||
|
}
|
||||||
|
Ok(Box::new(transport))
|
||||||
}
|
}
|
||||||
AiBackend::Direct => {
|
AiBackend::Direct => {
|
||||||
let key = self.load_direct_key(exec)?;
|
let key = self.load_direct_key(exec)?;
|
||||||
|
|
@ -300,6 +315,7 @@ mod tests {
|
||||||
opencode_model: String::new(),
|
opencode_model: String::new(),
|
||||||
api_key_file: key_file,
|
api_key_file: key_file,
|
||||||
opencode_password_file: None,
|
opencode_password_file: None,
|
||||||
|
opencode_insecure_http: false,
|
||||||
no_sandbox: true,
|
no_sandbox: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -351,6 +367,7 @@ mod tests {
|
||||||
opencode_provider: Some("opencode-go".into()),
|
opencode_provider: Some("opencode-go".into()),
|
||||||
opencode_model: Some("muse-spark-1.3-contributor".into()),
|
opencode_model: Some("muse-spark-1.3-contributor".into()),
|
||||||
opencode_password_file: None,
|
opencode_password_file: None,
|
||||||
|
opencode_insecure_http: false,
|
||||||
no_sandbox: true,
|
no_sandbox: true,
|
||||||
use_environment: false,
|
use_environment: false,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -793,6 +793,15 @@ mod tests {
|
||||||
/// environment.
|
/// environment.
|
||||||
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||||
|
|
||||||
|
/// Take the environment lock without cascading a panic from another test
|
||||||
|
/// into every waiter (a poisoned mutex would otherwise fail all three
|
||||||
|
/// env-dependent tests).
|
||||||
|
fn env_lock() -> std::sync::MutexGuard<'static, ()> {
|
||||||
|
ENV_LOCK
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
||||||
|
}
|
||||||
|
|
||||||
struct EnvGuard {
|
struct EnvGuard {
|
||||||
key: &'static str,
|
key: &'static str,
|
||||||
original: Option<std::ffi::OsString>,
|
original: Option<std::ffi::OsString>,
|
||||||
|
|
@ -817,7 +826,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn personal_preferences_roundtrip_and_use_user_storage() {
|
fn personal_preferences_roundtrip_and_use_user_storage() {
|
||||||
let _env = ENV_LOCK.lock().unwrap();
|
let _env = env_lock();
|
||||||
let base = tempdir().unwrap();
|
let base = tempdir().unwrap();
|
||||||
let _guard = EnvGuard::set("PHOEBUS_PERSONAL_DIR", base.path().as_os_str());
|
let _guard = EnvGuard::set("PHOEBUS_PERSONAL_DIR", base.path().as_os_str());
|
||||||
|
|
||||||
|
|
@ -845,7 +854,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_failed_preference_save_is_reported_as_a_failure() {
|
fn a_failed_preference_save_is_reported_as_a_failure() {
|
||||||
let _env = ENV_LOCK.lock().unwrap();
|
let _env = env_lock();
|
||||||
let blocker = tempdir().unwrap();
|
let blocker = tempdir().unwrap();
|
||||||
let not_a_dir = blocker.path().join("file");
|
let not_a_dir = blocker.path().join("file");
|
||||||
std::fs::write(¬_a_dir, "x").unwrap();
|
std::fs::write(¬_a_dir, "x").unwrap();
|
||||||
|
|
@ -865,7 +874,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snooze_and_dismiss_persist_to_user_storage() {
|
fn snooze_and_dismiss_persist_to_user_storage() {
|
||||||
let _env = ENV_LOCK.lock().unwrap();
|
let _env = env_lock();
|
||||||
let base = tempdir().unwrap();
|
let base = tempdir().unwrap();
|
||||||
let _guard = EnvGuard::set("PHOEBUS_PERSONAL_DIR", base.path().as_os_str());
|
let _guard = EnvGuard::set("PHOEBUS_PERSONAL_DIR", base.path().as_os_str());
|
||||||
|
|
||||||
|
|
@ -876,7 +885,8 @@ mod tests {
|
||||||
|
|
||||||
let mut snooze = request("proactive_snooze");
|
let mut snooze = request("proactive_snooze");
|
||||||
snooze.duration_seconds = Some(3600);
|
snooze.duration_seconds = Some(3600);
|
||||||
assert!(handle_request(&exec, root, &plans, snooze).ok);
|
let resp = handle_request(&exec, root, &plans, snooze);
|
||||||
|
assert!(resp.ok, "snooze failed: {:?}", resp.error);
|
||||||
|
|
||||||
let mut dismiss = request("proactive_dismiss");
|
let mut dismiss = request("proactive_dismiss");
|
||||||
dismiss.fingerprint = Some("reboot_required".into());
|
dismiss.fingerprint = Some("reboot_required".into());
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,11 @@ struct Cli {
|
||||||
/// Read the OpenCode server password from a mode-0600 file.
|
/// Read the OpenCode server password from a mode-0600 file.
|
||||||
#[arg(long, value_name = "FILE")]
|
#[arg(long, value_name = "FILE")]
|
||||||
opencode_password_file: Option<PathBuf>,
|
opencode_password_file: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Permit plain http to a non-loopback OpenCode server. Credentials and
|
||||||
|
/// prompts then travel in cleartext; prefer https or a loopback tunnel.
|
||||||
|
#[arg(long)]
|
||||||
|
opencode_insecure_http: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SysConfirm {
|
struct SysConfirm {
|
||||||
|
|
@ -975,6 +980,7 @@ fn resolve_ai(cli: &Cli) -> phoebus_installer::ai_setup::ResolvedAi {
|
||||||
opencode_provider: cli.opencode_provider.clone(),
|
opencode_provider: cli.opencode_provider.clone(),
|
||||||
opencode_model: cli.opencode_model.clone(),
|
opencode_model: cli.opencode_model.clone(),
|
||||||
opencode_password_file: cli.opencode_password_file.clone(),
|
opencode_password_file: cli.opencode_password_file.clone(),
|
||||||
|
opencode_insecure_http: cli.opencode_insecure_http,
|
||||||
no_sandbox: cli.no_sandbox,
|
no_sandbox: cli.no_sandbox,
|
||||||
use_environment: true,
|
use_environment: true,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue