Add safe daemon Unix socket listen#7
Conversation
ea65f75 to
e4df953
Compare
Daemon servers need a kit-owned startup primitive so applications do not reimplement stale Unix socket cleanup around net.Listen. Without serialization, concurrent starts can both classify a socket as stale and one process can remove the other process's newly bound socket. This adds a daemon.Listen helper that holds an inter-process listen lock across stale socket probing, removal, and bind. The listen lock is separate from the Manager auto-start lock so detached child daemons can bind while the parent waits for discovery. Validation: go test ./daemon; go test ./... 🤖 Generated with [OpenAI Codex](https://openai.com/codex) Co-authored-by: OpenAI Codex <noreply@openai.com>
e4df953 to
a349861
Compare
roborev: Combined Review (
|
Daemon lock acquisition now runs safefile private-directory hardening before taking the file lock. A bare relative lock path would make the lock directory resolve to the process working directory, so the hardening step could unexpectedly chmod the caller's cwd. Rejecting relative lock paths preserves the safefile protection without letting arbitrary process state become the lock directory. The regression covers both explicit relative LockPath input and relative Unix endpoint-derived lock paths. Validation: go test ./daemon; go test ./... 🤖 Generated with [OpenAI Codex](https://openai.com/codex) Co-authored-by: OpenAI Codex <noreply@openai.com>
roborev: FailMedium-risk issues found; no Critical or High findings were reported. Medium
Panel: ci_default_security | Synthesis: codex, 10s, ~$0.02 | Members: codex_default (codex/default, done, 5m24s, ~$0.69), codex_security (codex/security, done, 2m21s, ~$0.46) | Total: 7m55s, ~$1.18 | Job: 19549 |
The Unix listen helper now validates the socket path itself before using any store or explicit lock path. That keeps callers from placing the API socket in a shared directory while the lock lives somewhere private, and preserves ParseEndpoint's absolute-path invariant even for manually constructed Endpoint values. The stale probe also treats ENOENT as a free socket race, which lets startup proceed when another listener closes and unlinks between Lstat and Dial. Validation: go test ./daemon; go test ./... 🤖 Generated with [OpenAI Codex](https://openai.com/codex) Co-authored-by: OpenAI Codex <noreply@openai.com>
roborev: FailHigh-risk issue remains: the daemon can chmod arbitrary existing runtime parent directories before path validation. High
Medium
Panel: ci_default_security | Synthesis: codex, 18s | Members: codex_default (codex/default, done, 4m51s), codex_security (codex/security, done, 24s) | Total: 5m33s | Job: 19552 |
Daemon Unix socket parent checks must reject unsafe directories without chmodding arbitrary caller paths such as $HOME or /tmp. Add a validation-only safefile primitive and use it for socket parents, while keeping repair-capable EnsurePrivateDir for runtime directories that kit intentionally owns. RuntimeStore now rejects relative directories before preparation so store-derived lock paths cannot trigger caller-relative directory creation or chmod. Validation: go test ./daemon ./safefileio; go test ./... 🤖 Generated with [OpenAI Codex](https://openai.com/codex) Co-authored-by: OpenAI Codex <noreply@openai.com>
Validation-only private directory checks on Windows must enforce the same trust boundary that EnsurePrivateDir repairs to. Otherwise a current-user-owned directory with broad DACL grants could be accepted as private. ValidatePrivateDir now rejects unprotected DACLs, deny/unknown ACEs, and allowed ACEs for principals outside the current user, token owner, SYSTEM, and Administrators. The Windows test covers a deliberately broadened DACL. Validation: go test ./safefileio; GOOS=windows GOARCH=amd64 go test -c ./safefileio -o /tmp/kit-safefileio-windows.test.exe; go test ./... 🤖 Generated with [OpenAI Codex](https://openai.com/codex) Co-authored-by: OpenAI Codex <noreply@openai.com>
daemon.Listen is a public API meant for callers like kata, so requiring an explicit options struct for normal use makes the common path noisier than it needs to be. The branch is not released yet, so prefer the conventional Go WithXYZ option style before consumers adopt it. This keeps the listen configuration extensible without preserving the clunkier ListenOptions call shape. Validation: go test ./daemon ./safefileio; GOOS=windows GOARCH=amd64 go test -c ./daemon -o /tmp/kit-daemon-windows.test.exe; GOOS=windows GOARCH=amd64 go test -c ./safefileio -o /tmp/kit-safefileio-windows.test.exe; go test ./... Generated with OpenAI Codex Co-authored-by: OpenAI Codex <noreply@openai.com>
roborev: Combined Review (
|
Summary
daemon.Listen(ctx, ep, opts)for daemon server startupRuntimeStore.ListenLockPath()so server listen locking stays separate fromManager.Ensureauto-start lockingKata API
Kata daemon server startup should use:
If kata does not have a
RuntimeStorein that startup path, pass a stable explicitLockPathor rely on the default lock derived from the Unix socket path.Validation
go test ./daemongo test ./...