socket
socket
¶
Shared socket-hardening helpers for every AF_UNIX server in this package.
The ingester + clearance-hub binds need the same private-parent check,
0600-via-umask, and post-bind lstat confirmation. One copy here
means one place to review if the security posture needs to change.
runtime_socket_path(basename)
¶
Return $XDG_RUNTIME_DIR/<basename> with a /run/user/<uid> fallback.
default_clearance_socket_path()
¶
Return the canonical clearance-socket path under $XDG_RUNTIME_DIR.
ensure_private_parent(path, label)
¶
Refuse to bind under a parent that isn't uid-owned + mode 0700-ish.
label is interpolated into the error message so the operator can
tell at a glance which socket raised. Creates the parent on the
first pass (with mode=0o700) so a fresh XDG runtime dir also
works.
Source code in src/terok_clearance/wire/socket.py
bind_hardened(factory, path, label)
async
¶
Bind a unix-socket server via factory with the full hardening ritual.
Verifies the parent, unlinks any stale socket path, sets umask
0o177 so bind() produces a 0600 file atomically, and
confirms the path is a socket afterwards. factory is awaited
with the socket path as its sole argument and must return the
server object.