mirror of
https://scm.tikali.ai/tikali/applications/monky/monky-deployd.git
synced 2026-09-18 04:36:15 +00:00
fix(onboarding): identity read that survives a rewrite, disk refused before the pull — 0.1.8
Three faults from one agent-managed onboarding (env-dev-08, 2026-09-09), each of which pointed the diagnosis away from the actual fault. 1. install.sh granted the agent's read on the ziti identity with a POSIX ACL. ziti-edge-tunnel rewrites that file on a controller config update and the rewrite drops the ACL: the agent applied cleanly at 01:21 and was failing every tick by 01:32. Group membership survives the rewrite (the file stays ziti:ziti 0640), so install.sh and the package postinstall now add monky-deployd to the `ziti` group, and a default ACL on the identity directory carries the grant onto a newly created file. The explicit ACLs stay for the boxes that need them. 2. openziti.load() accepts an unreadable or malformed identity: the C SDK logs "configuration is invalid" and returns a context that only fails at dial, as a bare TypeError, which the transport reported as a missing intercept or a policy gap. The SDK transport now reads and parses the identity itself and names the real fault first. 3. The disk pre-flight ran only when the bundle declared disk_need_bytes, so a bundle without one died mid-pull with containerd's "no space left on device" — which reads as a registry fault. A bundle that declares no size now has to clear the headroom floor, and the pre-flight measures containerd's root as well as the docker data-root: docker 29 keeps image layers in the containerd image store, and on env-dev-08 those sat on different filesystems (93 GiB free where the agent looked, 2.8 GiB where the pull wrote). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KLB7jieMNRkTsJ2epr4Ds1
This commit is contained in:
@@ -4,4 +4,4 @@ Dials monky-tenancy over the mesh with the box's host identity, fetches the rend
|
||||
leases a deploy grant, logs in to OpenBao, reads its own secrets, runs `docker compose`,
|
||||
reports. Stdlib only; the optional `openziti` SDK is the `sdk` transport."""
|
||||
|
||||
__version__ = "0.1.7"
|
||||
__version__ = "0.1.8"
|
||||
|
||||
+17
-9
@@ -353,16 +353,24 @@ class Agent:
|
||||
raise Refusal("PRIVILEGED_REFUSED", ", ".join(findings) + " (bundle.json allow_privileged is not set)")
|
||||
if self.state.is_rollback(b.sha) and not b.flag("allow_rollback"):
|
||||
raise Refusal("ROLLBACK_REFUSED", f"{b.sha[:12]} was applied before; allow_rollback is not set")
|
||||
# A bundle that declares its size gets the full sum; one that does not still has to clear
|
||||
# the headroom floor. Without the floor a nearly-full box sails past this check and dies
|
||||
# mid-pull with containerd's "no space left on device", which reads as a registry fault
|
||||
# and costs an SSH hunt (env-dev-08, 2026-09-09).
|
||||
need = b.disk_need_bytes
|
||||
if need:
|
||||
free = self.docker.free_bytes()
|
||||
required = int(need * cfg.disk.factor + cfg.disk.headroom_bytes)
|
||||
if free is not None and free < required:
|
||||
raise Refusal(
|
||||
"DISK_INSUFFICIENT",
|
||||
f"docker data-root has {free // 2**20} MiB free, bundle needs {required // 2**20} MiB "
|
||||
f"({need // 2**20} MiB x {cfg.disk.factor} + {cfg.disk.headroom_bytes // 2**20} MiB headroom)",
|
||||
)
|
||||
free = self.docker.free_bytes()
|
||||
required = int(need * cfg.disk.factor + cfg.disk.headroom_bytes) if need else cfg.disk.headroom_bytes
|
||||
if free is not None and free < required:
|
||||
sized = (
|
||||
f"bundle needs {required // 2**20} MiB "
|
||||
f"({need // 2**20} MiB x {cfg.disk.factor} + {cfg.disk.headroom_bytes // 2**20} MiB headroom)"
|
||||
if need
|
||||
else f"a pull needs at least {required // 2**20} MiB headroom (bundle declares no size)"
|
||||
)
|
||||
raise Refusal(
|
||||
"DISK_INSUFFICIENT",
|
||||
f"image storage ({', '.join(self.docker.storage_paths())}) has {free // 2**20} MiB free, {sized}",
|
||||
)
|
||||
|
||||
# -- credentials -------------------------------------------------------------------------------------
|
||||
def _ensure_token(self) -> str:
|
||||
|
||||
@@ -12,6 +12,10 @@ import time
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
# containerd's default root: docker 29's image store lives here, often on another filesystem
|
||||
# than DockerRootDir. Both are checked before a pull (see Docker.storage_paths).
|
||||
CONTAINERD_ROOTS = ("/var/lib/containerd",)
|
||||
|
||||
log = logging.getLogger("monky-deployd.compose")
|
||||
|
||||
|
||||
@@ -100,8 +104,23 @@ class Docker:
|
||||
root = ""
|
||||
return root or "/var/lib/docker"
|
||||
|
||||
def free_bytes(self, path: str | None = None) -> int | None:
|
||||
p = path or self.data_root()
|
||||
def storage_paths(self) -> list[str]:
|
||||
"""Every filesystem a `compose pull` can fill.
|
||||
|
||||
docker 29 keeps IMAGE layers in the containerd image store (containerd's own root,
|
||||
/var/lib/containerd by default), NOT under DockerRootDir. On a box where those two sit
|
||||
on different filesystems, measuring only the data-root reports plenty of room while the
|
||||
pull dies with "no space left on device" (env-dev-08, 2026-09-09: 93 GiB free on the
|
||||
data-root, 2.8 GiB on the root filesystem that held containerd).
|
||||
"""
|
||||
paths = [self.data_root()]
|
||||
for extra in CONTAINERD_ROOTS:
|
||||
if os.path.isdir(extra):
|
||||
paths.append(extra)
|
||||
return paths
|
||||
|
||||
def _free_at(self, path: str) -> int | None:
|
||||
p = path
|
||||
while p and not os.path.exists(p):
|
||||
p = os.path.dirname(p)
|
||||
try:
|
||||
@@ -110,6 +129,12 @@ class Docker:
|
||||
return None
|
||||
return st.f_bavail * st.f_frsize
|
||||
|
||||
def free_bytes(self, path: str | None = None) -> int | None:
|
||||
"""Free bytes on `path`, or the TIGHTEST of the image-storage filesystems."""
|
||||
paths = [path] if path else self.storage_paths()
|
||||
seen = [v for v in (self._free_at(p) for p in paths) if v is not None]
|
||||
return min(seen) if seen else None
|
||||
|
||||
def image_prune(self) -> None:
|
||||
try:
|
||||
self.run(["image", "prune", "-f"], timeout=300)
|
||||
|
||||
@@ -16,6 +16,7 @@ from __future__ import annotations
|
||||
import http.client
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
import ssl
|
||||
from dataclasses import dataclass
|
||||
@@ -35,6 +36,27 @@ class TransportError(Exception):
|
||||
class Transport:
|
||||
name = "base"
|
||||
|
||||
def _check_identity_readable(self) -> None:
|
||||
path = self.identity_path
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
raw = fh.read()
|
||||
except FileNotFoundError as exc:
|
||||
raise TransportError(f"transport sdk: identity {path} does not exist") from exc
|
||||
except PermissionError as exc:
|
||||
raise TransportError(
|
||||
f"transport sdk: identity {path} is not readable by this user "
|
||||
f"(uid {os.geteuid()}) — the file is owned by the tunneller and rewritten on every "
|
||||
"config refresh, which drops POSIX ACLs; add the agent's user to the file's group "
|
||||
"(usually `ziti`) so the grant survives"
|
||||
) from exc
|
||||
except OSError as exc:
|
||||
raise TransportError(f"transport sdk: identity {path} is unreadable: {exc}") from exc
|
||||
try:
|
||||
json.loads(raw)
|
||||
except ValueError as exc:
|
||||
raise TransportError(f"transport sdk: identity {path} is not valid JSON: {exc}") from exc
|
||||
|
||||
def connect(self, host: str, port: int, timeout: float) -> socket.socket: # pragma: no cover
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -87,6 +109,13 @@ class SdkTransport(Transport):
|
||||
"transport sdk: the openziti module is not installed in this venv; "
|
||||
"use transport: proxy (monky-deployd-proxy.service) or system"
|
||||
) from exc
|
||||
# openziti.load() does NOT raise on an unreadable or malformed identity: the C SDK logs
|
||||
# "Failed to load Ziti Identity ...: configuration is invalid" and hands back a context
|
||||
# that fails LATER, at dial, as a bare TypeError — which reads as a missing intercept or
|
||||
# a policy gap and sends you hunting the mesh instead of the file (env-dev-08,
|
||||
# 2026-09-09: ziti-edge-tunnel rewrote the identity and dropped the agent's ACL).
|
||||
# So check the file ourselves first and name the real fault.
|
||||
self._check_identity_readable()
|
||||
try:
|
||||
self._ctx = openziti.load(self.identity_path)
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user