endpoint
endpoint
¶
The memory gateway's Unix-socket endpoint (spec 02 BE1, BE2 teardown, BE7).
One listening socket per session, bound when the session opens
(:meth:MemoryEndpoint.open_session) and unlinked when it closes
(:meth:MemoryEndpoint.close_session). The session IS the socket: a request
never names a session, a principal or a scope.
Security property, stated exactly¶
Admission is same UID, read from SO_PEERCRED at accept. That stops other
users on the host. It does NOT stop another process of the same user that
learns the socket path: such a process is admitted to that session like any
other. The only protections against siblings are an unguessable per-dispatch
path (a SHA-256 prefix, see :mod:.paths), living inside a 0700
directory, and one session per socket. No sibling isolation is claimed beyond
that. No token travels on the channel.
Wire format (memory-gateway-wire/1)¶
Newline-delimited JSON, UTF-8, one frame per line.
- request:
{"id": <str|int>, "tool": <name>, "args": {...}, "budget_seconds"?: <number>} - success:
{"id": ..., "ok": true, "result": {...}} - failure:
{"id": ..., "ok": false, "error": {"code": "E#", "name": ..., "subtype": ..., "message": ..., "remedy": ...}}(errors/1)
Requests on one connection are served strictly in order. A client-supplied
session/session_id/principal/scope/permissions/... field
(top level or inside args) is dropped, audited as a refused attempt
(result_status: refused, ignored_fields), and echoed as
ignored_fields in the response; the call proceeds on the socket's session.
Failure policy: a malformed line, non-object, unknown tool or bad arguments
gets a typed E7 frame and the connection stays open (framing is intact). A
line over the length limit, a peer refused at accept, a connection over the
per-session limit and an idle connection are closed (after one frame where a
frame can be sent). The gateway's calls are synchronous and run in a worker
thread; if the client disconnects mid-call the wait is cancelled and the
endpoint audits cancelled (a thread cannot be interrupted, so the backend
call may still complete and the gateway will also record its own outcome).
Expiry of a session is enforced by the gateway on every call (E10); the
socket stays bound until close_session.
Classes¶
MemoryEndpoint
¶
MemoryEndpoint(gateway, *, run_dir, limits=None, peer_uid_reader=read_peer_uid, uid=None, blocking=None)
Hosts one Unix socket per gateway session under run_dir.
Source code in src/marianne/memory/gateway/endpoint.py
Methods:¶
open_session
async
¶
Admit a session on the gateway and bind its socket. Returns both.
Source code in src/marianne/memory/gateway/endpoint.py
close_session
async
¶
Stop listening, drop connections, wait (bounded) for in-flight calls, unlink.
Returns how many calls were still running when the wait ran out (0 when clean); each
such case is audited as in_flight_at_close. The gateway session is closed either way.
Source code in src/marianne/memory/gateway/endpoint.py
close
async
¶
Close every session; returns {session_id: calls still running} for any that remain.
Source code in src/marianne/memory/gateway/endpoint.py
Functions:¶
read_peer_uid
¶
The peer's UID from SO_PEERCRED (Linux), or None when unavailable.