Skip to content

Switch nodespaced IPC transport from TCP to Unix Domain Sockets #1176

Closed

Description

@malibio

Overview

`nodespaced` currently binds on TCP `[::1]:50051`. This opens a port that any process on the machine can connect to without OS-level identity verification. ADR-031 explicitly deferred the transport selection to this follow-up. ADR-033 closes that deferred decision: switch to Unix Domain Sockets (macOS/Linux) and Named Pipes (Windows).

Problem Statement

Any local process — including malware, compromised browser renderers, or malicious npm packages running in a terminal — can connect to `[::1]:50051` and issue arbitrary gRPC calls against the user's knowledge graph. There is no authentication between daemon and clients.

UDS with `0600` permissions restricts connections to the owning user's processes only, enforced by the kernel. The kernel also exposes peer UID/GID/PID via `SO_PEERCRED` on every connection, enabling the daemon to reject unexpected callers before the gRPC layer is reached.

Proposed Solution

Replace TCP with Unix Domain Sockets on macOS/Linux and Named Pipes on Windows:

  • Socket path: `~/.nodespace/daemon.sock` (default), overridable via `NODESPACED_SOCKET` env var
  • Permissions: `0600` — only owning user can connect
  • Stale socket cleanup: remove socket file on daemon startup and graceful shutdown
  • Windows: Named Pipe at `\.\pipe\nodespace-daemon` — gated behind `#[cfg(windows)]`, not implemented until concrete Windows target exists

The Tauri app's in-process gRPC server (`grpc_client.rs`) is unaffected — it uses an OS-assigned ephemeral TCP port in-process and never opens a user-visible port.

Acceptance Criteria

  • `nodespaced` binds on `~/.nodespace/daemon.sock` instead of `[::1]:50051`
  • Socket file created with `0600` permissions
  • Stale socket removed on daemon startup; socket cleaned up on graceful shutdown
  • `NODESPACED_SOCKET` env var overrides socket path in daemon, CLI, and agent-tools
  • CLI connects via UDS connector (not TCP endpoint)
  • `@nodespace/agent-tools` TypeScript client uses `unix:` URI scheme
  • No TCP port opened by `nodespaced` on startup
  • Windows path gated behind `#[cfg(windows)]` — fails loudly if not implemented
  • `cargo build --workspace` succeeds
  • `bun run test:all` passes
  • `bun run quality:fix` passes

Technical Specifications

Reference Files

  • `packages/daemon/src/main.rs` — replace `bind_addr()` + TCP listener with `UnixListener`
  • `packages/cli/src/lib.rs` — replace `DEFAULT_ENDPOINT` + `connect()` with UDS connector
  • `packages/agent-tools/src/client.ts` — change `resolveAddress()` to emit `unix:` URI
  • `packages/desktop-app/src-tauri/src/grpc_client.rs` — no change needed

Daemon implementation pattern

```rust
#[cfg(unix)]
async fn serve_grpc(...) -> Result<()> {
use tokio::net::UnixListener;
use tokio_stream::wrappers::UnixListenerStream;
use std::os::unix::fs::PermissionsExt;

let path = socket_path(); // ~/.nodespace/daemon.sock
let _ = tokio::fs::remove_file(&path).await;
let listener = UnixListener::bind(&path)?;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600))?;

Server::builder()
    .add_service(/* all services */)
    .serve_with_incoming_shutdown(UnixListenerStream::new(listener), shutdown)
    .await

}
```

CLI connection pattern

```rust
#[cfg(unix)]
pub async fn connect() -> Result<NodeServiceClient> {
use tokio::net::UnixStream;
use tonic::transport::{Endpoint, Uri};
use tower::service_fn;

let path = socket_path();
let channel = Endpoint::from_static("http://[::]:50051")
    .connect_with_connector(service_fn(move |_: Uri| {
        UnixStream::connect(path.clone())
    }))
    .await?;
Ok(NodeServiceClient::new(channel))

}
```

TypeScript client (one-line change)

```typescript
function resolveAddress(): string {
const sock = process.env.NODESPACED_SOCKET
?? `${process.env.HOME}/.nodespace/daemon.sock`;
return `unix:${sock}`;
}
```

No Cargo dependencies added

`tokio` (with `net` feature) and `tokio-stream` are already in the dependency tree.

Related Issues

Activity

  1. malibio commented on May 19, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 129 files, 3921 tests passed

  2. self-assigned this
    on May 19, 2026
  3. added a commit that references this issue on May 19, 2026
    5c92b22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions