credential_proxy_lifecycle
credential_proxy_lifecycle
¶
Credential proxy lifecycle management.
Manages the terok-credential-proxy daemon: start, stop, status, and
pre-task health checks. Supports systemd socket activation (preferred)
and a manual daemon fallback.
The systemd socket unit listens on both the Unix socket and the TCP
port used by containers. A connection to either triggers the service.
:func:ensure_proxy_reachable also performs an explicit start as a
belt-and-suspenders measure before task creation.
CredentialProxyStatus(mode, running, healthy, socket_path, db_path, routes_path, routes_configured, credentials_stored)
dataclass
¶
Current state of the credential proxy.
mode
instance-attribute
¶
"systemd", "daemon", or "none".
running
instance-attribute
¶
Whether the proxy is active (systemd socket listening or daemon alive).
healthy
instance-attribute
¶
Whether the proxy responded to an HTTP health check.
socket_path
instance-attribute
¶
Configured Unix socket path.
db_path
instance-attribute
¶
Configured credential database path.
routes_path
instance-attribute
¶
Configured proxy routes JSON path.
routes_configured
instance-attribute
¶
Number of routes in routes.json (0 if missing or invalid).
credentials_stored
instance-attribute
¶
Provider names with stored credentials.
is_systemd_available()
¶
Check whether the systemd user session is reachable.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
is_socket_installed()
¶
Check whether the terok-credential-proxy.socket unit file exists.
is_socket_active()
¶
Check whether the terok-credential-proxy.socket unit is active.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
is_service_active()
¶
Check whether the terok-credential-proxy.service unit is active.
Unlike :func:is_socket_active, this tells whether the proxy daemon
itself is running (TCP ports bound), not just whether the socket is
listening. Does not trigger socket activation.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
install_systemd_units(cfg=None)
¶
Render and install systemd socket+service units, then enable+start the socket.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
uninstall_systemd_units(cfg=None)
¶
Disable+stop the socket and remove unit files.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
start_daemon(cfg=None)
¶
Start the credential proxy as a background daemon.
The proxy listens on a Unix socket and reads credentials from a sqlite3 database. A routes JSON file must exist at the configured path (generated by terok-agent from the YAML registry).
Writes a PID file to runtime_root() / "credential-proxy.pid".
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
stop_daemon(cfg=None)
¶
Stop the managed proxy daemon by sending SIGTERM.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
is_daemon_running(cfg=None)
¶
Check whether the managed proxy daemon is alive via its PID file.
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
get_proxy_port(cfg=None)
¶
get_ssh_agent_port(cfg=None)
¶
get_proxy_status(cfg=None)
¶
Return the current credential proxy status.
Populates route count from the routes JSON (0 if missing/invalid) and credential provider names from the database (empty if DB doesn't exist).
Source code in src/terok_sandbox/credential_proxy_lifecycle.py
ensure_proxy_reachable(cfg=None)
¶
Verify the credential proxy is running and its TCP ports are up.
For systemd socket activation the service may not have started yet
(e.g. after a fresh boot). This function triggers a start via
systemctl --user start and waits for the HTTP and SSH agent TCP
ports to become reachable via /-/health and raw TCP probes.
For daemon mode the /-/health endpoint is probed on the TCP port.
Raises SystemExit with an actionable message if the proxy is
unreachable. Called before task creation when credential proxy is enabled.