mirror of
https://scm.tikali.ai/tikali/applications/monky/monky-deployd.git
synced 2026-09-18 07:16:16 +00:00
Compare commits
2 Commits
cc9dcebd7e
...
v0.1.8
| Author | SHA1 | Date | |
|---|---|---|---|
| 17a64843f1 | |||
| 43615a6fda |
@@ -1,6 +1,29 @@
|
|||||||
<!-- xlate:verbatim-fences -->
|
<!-- xlate:verbatim-fences -->
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.1.8 — onboarding: keep the identity readable, refuse a full disk (2026-09-09)
|
||||||
|
|
||||||
|
Three faults from one onboarding (env-dev-08, agent-managed, 2026-09-09), each of which sent the
|
||||||
|
diagnosis somewhere other than the fault.
|
||||||
|
|
||||||
|
- **The agent's read on the ziti identity now survives a tunneller rewrite.** `install.sh` granted it
|
||||||
|
with a POSIX ACL. `ziti-edge-tunnel` rewrites the identity file whenever the controller sends a config
|
||||||
|
update, and the rewrite drops the ACL — the agent had applied cleanly and was failing every tick six
|
||||||
|
minutes later. The durable grant is **group membership**: `install.sh` and the package's postinstall
|
||||||
|
now add `monky-deployd` to the identity file's group (`ziti`) when it exists, and a **default ACL** on
|
||||||
|
the identity directory carries the grant onto a freshly created file. The explicit ACLs stay.
|
||||||
|
- **An unusable identity says so.** `openziti.load()` accepts an unreadable or malformed identity, logs
|
||||||
|
"configuration is invalid" at the C layer and hands back a context that fails LATER, 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 first, and names the real fault (absent, not
|
||||||
|
readable by this uid, or not JSON) before anything touches the mesh.
|
||||||
|
- **A full disk is refused before the pull, and the right disk is measured.** The pre-flight ran only
|
||||||
|
when the bundle declared `disk_need_bytes`; a bundle without one sailed past it and 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. The pre-flight also 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
|
||||||
|
were on different filesystems — 93 GiB free where the agent looked, 2.8 GiB where the pull wrote.
|
||||||
|
|
||||||
## 0.1.7 — registry credential + a pull error you can read (2026-09-08)
|
## 0.1.7 — registry credential + a pull error you can read (2026-09-08)
|
||||||
|
|
||||||
- **No hand `docker login` on a new box** (monky-design-docs !225, doc 24 §4a). A manifest entry marked
|
- **No hand `docker login` on a new box** (monky-design-docs !225, doc 24 §4a). A manifest entry marked
|
||||||
|
|||||||
+9
-2
@@ -22,7 +22,13 @@ monky-deployd status --json | jq .
|
|||||||
Files: `/etc/monky-deployd/config.yaml` (0640 root:monky-deployd), `/etc/monky-deployd/openbao-ca.pem`,
|
Files: `/etc/monky-deployd/config.yaml` (0640 root:monky-deployd), `/etc/monky-deployd/openbao-ca.pem`,
|
||||||
`/etc/monky-deployd/bootstrap.jwt` (only until the first login), `/var/lib/monky-deployd/{bao.token,state.json,lock}`,
|
`/etc/monky-deployd/bootstrap.jwt` (only until the first login), `/var/lib/monky-deployd/{bao.token,state.json,lock}`,
|
||||||
`/var/lib/monky-deployd/<env>/releases/<sha>/` + `current` (the compose project dir, `.env` 0600),
|
`/var/lib/monky-deployd/<env>/releases/<sha>/` + `current` (the compose project dir, `.env` 0600),
|
||||||
`/opt/openziti/etc/identities/monky-host.<env>.json` (ziti:ziti 0600 + ACL `u:monky-deployd:r`).
|
`/opt/openziti/etc/identities/monky-host.<env>.json` (ziti:ziti 0640; the agent reads it as a member of
|
||||||
|
the `ziti` **group**, plus an explicit ACL `u:monky-deployd:r` and a default ACL on the directory).
|
||||||
|
|
||||||
|
> The group is the grant that matters. `ziti-edge-tunnel` rewrites the identity file whenever the
|
||||||
|
> controller sends a config update, and the rewrite drops POSIX ACLs — an ACL-only box works until the
|
||||||
|
> first refresh and then fails every tick (env-dev-08, 2026-09-09). On a host where the tunneller was
|
||||||
|
> installed independently of the kit, check `id monky-deployd` for `ziti` before anything else.
|
||||||
|
|
||||||
## Reading the journal
|
## Reading the journal
|
||||||
|
|
||||||
@@ -31,9 +37,10 @@ Files: `/etc/monky-deployd/config.yaml` (0640 root:monky-deployd), `/etc/monky-d
|
|||||||
| `checkin: action=none desired=… applied=…` then `healthy; heartbeat reported` | converged |
|
| `checkin: action=none desired=… applied=…` then `healthy; heartbeat reported` | converged |
|
||||||
| `checkin: action=apply …` → `read 3 secret(s): GEMINI_API_KEY, …` → `promoted release …` → `applied …` | a deploy |
|
| `checkin: action=apply …` → `read 3 secret(s): GEMINI_API_KEY, …` → `promoted release …` → `applied …` | a deploy |
|
||||||
| `refused: ENV_INCOMPLETE: unresolved: X` | the bundle needs a variable no manifest entry supplies — fix the descriptor / set the secret in the console; nothing was started |
|
| `refused: ENV_INCOMPLETE: unresolved: X` | the bundle needs a variable no manifest entry supplies — fix the descriptor / set the secret in the console; nothing was started |
|
||||||
| `refused: DISK_INSUFFICIENT: docker data-root has N MiB free, bundle needs M MiB` | free space (the env-dev-09 lesson): grow the data-root disk or prune |
|
| `refused: DISK_INSUFFICIENT: image storage (…) has N MiB free, …` | free space: grow the disk or prune. The paths in the message are every filesystem a pull can fill — docker's data-root AND containerd's root, which docker 29 fills with image layers and which is often a different disk (env-dev-08). A bundle that declares no size must still clear `disk.headroom_bytes` |
|
||||||
| `refused: PRIVILEGED_REFUSED` / `ROLLBACK_REFUSED` | the bundle needs `allow_privileged` / `allow_rollback` in its `agent` profile |
|
| `refused: PRIVILEGED_REFUSED` / `ROLLBACK_REFUSED` | the bundle needs `allow_privileged` / `allow_rollback` in its `agent` profile |
|
||||||
| `temporary network failure` (exit 75) | mesh/tenancy unreachable — check `ziti-edge-tunnel`, the identity's terminators, `monky.tenancy.deploy` health |
|
| `temporary network failure` (exit 75) | mesh/tenancy unreachable — check `ziti-edge-tunnel`, the identity's terminators, `monky.tenancy.deploy` health |
|
||||||
|
| `transport sdk: identity … is not readable by this user` | the agent lost its read on the identity file (usually a tunneller rewrite dropping the ACL) — `usermod -a -G ziti monky-deployd` |
|
||||||
| `AGENT_UNAUTHENTICATED: bearer refused` (exit 1) | the grant was superseded (kit re-revealed / retire) or the token revoked → re-run the install kit |
|
| `AGENT_UNAUTHENTICATED: bearer refused` (exit 1) | the grant was superseded (kit re-revealed / retire) or the token revoked → re-run the install kit |
|
||||||
| `AGENT_ENV_MISMATCH` (exit 78) | the token belongs to another env than `config.yaml` — fix the config or re-issue the identity; the timer keeps firing but every tick exits 78 immediately (no storm) |
|
| `AGENT_ENV_MISMATCH` (exit 78) | the token belongs to another env than `config.yaml` — fix the config or re-issue the identity; the timer keeps firing but every tick exits 78 immediately (no storm) |
|
||||||
| `failed: docker compose pull failed (rc=1)` | registry/pull problem; compose output is in the report's tail and in the journal |
|
| `failed: docker compose pull failed (rc=1)` | registry/pull problem; compose output is in the report's tail and in the journal |
|
||||||
|
|||||||
@@ -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`,
|
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."""
|
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)")
|
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"):
|
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")
|
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
|
need = b.disk_need_bytes
|
||||||
if need:
|
free = self.docker.free_bytes()
|
||||||
free = self.docker.free_bytes()
|
required = int(need * cfg.disk.factor + cfg.disk.headroom_bytes) if need else cfg.disk.headroom_bytes
|
||||||
required = int(need * cfg.disk.factor + cfg.disk.headroom_bytes)
|
if free is not None and free < required:
|
||||||
if free is not None and free < required:
|
sized = (
|
||||||
raise Refusal(
|
f"bundle needs {required // 2**20} MiB "
|
||||||
"DISK_INSUFFICIENT",
|
f"({need // 2**20} MiB x {cfg.disk.factor} + {cfg.disk.headroom_bytes // 2**20} MiB headroom)"
|
||||||
f"docker data-root has {free // 2**20} MiB free, bundle needs {required // 2**20} MiB "
|
if need
|
||||||
f"({need // 2**20} MiB x {cfg.disk.factor} + {cfg.disk.headroom_bytes // 2**20} MiB headroom)",
|
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 -------------------------------------------------------------------------------------
|
# -- credentials -------------------------------------------------------------------------------------
|
||||||
def _ensure_token(self) -> str:
|
def _ensure_token(self) -> str:
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ import time
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
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")
|
log = logging.getLogger("monky-deployd.compose")
|
||||||
|
|
||||||
|
|
||||||
@@ -100,8 +104,23 @@ class Docker:
|
|||||||
root = ""
|
root = ""
|
||||||
return root or "/var/lib/docker"
|
return root or "/var/lib/docker"
|
||||||
|
|
||||||
def free_bytes(self, path: str | None = None) -> int | None:
|
def storage_paths(self) -> list[str]:
|
||||||
p = path or self.data_root()
|
"""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):
|
while p and not os.path.exists(p):
|
||||||
p = os.path.dirname(p)
|
p = os.path.dirname(p)
|
||||||
try:
|
try:
|
||||||
@@ -110,6 +129,12 @@ class Docker:
|
|||||||
return None
|
return None
|
||||||
return st.f_bavail * st.f_frsize
|
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:
|
def image_prune(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.run(["image", "prune", "-f"], timeout=300)
|
self.run(["image", "prune", "-f"], timeout=300)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from __future__ import annotations
|
|||||||
import http.client
|
import http.client
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@@ -35,6 +36,27 @@ class TransportError(Exception):
|
|||||||
class Transport:
|
class Transport:
|
||||||
name = "base"
|
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
|
def connect(self, host: str, port: int, timeout: float) -> socket.socket: # pragma: no cover
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@@ -87,6 +109,13 @@ class SdkTransport(Transport):
|
|||||||
"transport sdk: the openziti module is not installed in this venv; "
|
"transport sdk: the openziti module is not installed in this venv; "
|
||||||
"use transport: proxy (monky-deployd-proxy.service) or system"
|
"use transport: proxy (monky-deployd-proxy.service) or system"
|
||||||
) from exc
|
) 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:
|
try:
|
||||||
self._ctx = openziti.load(self.identity_path)
|
self._ctx = openziti.load(self.identity_path)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@@ -213,8 +213,15 @@ fi
|
|||||||
# --- 4. config, ACLs, bootstrap grant -----------------------------------------------------------------
|
# --- 4. config, ACLs, bootstrap grant -----------------------------------------------------------------
|
||||||
install -d -m 0750 -o root -g monky-deployd "$ETC"
|
install -d -m 0750 -o root -g monky-deployd "$ETC"
|
||||||
install -d -m 0700 -o monky-deployd -g monky-deployd /var/lib/monky-deployd
|
install -d -m 0700 -o monky-deployd -g monky-deployd /var/lib/monky-deployd
|
||||||
|
# The identity file is the agent's only credential for the mesh. ziti-edge-tunnel rewrites it on
|
||||||
|
# every controller config update and the rewrite DROPS these ACLs, so the durable grant is group
|
||||||
|
# membership (the file stays <ziti>:<ziti> 0640 across rewrites); the ACLs below still cover the
|
||||||
|
# window before the agent's next login and hosts where the file has another group.
|
||||||
|
# A default ACL on the directory carries the grant onto a freshly created identity file.
|
||||||
|
if getent group ziti >/dev/null; then usermod -a -G ziti monky-deployd || true; fi
|
||||||
setfacl -m u:monky-deployd:r "$IDENTITY"
|
setfacl -m u:monky-deployd:r "$IDENTITY"
|
||||||
setfacl -m u:monky-deployd:rx "$IDENTITY_DIR"
|
setfacl -m u:monky-deployd:rx "$IDENTITY_DIR"
|
||||||
|
setfacl -d -m u:monky-deployd:r "$IDENTITY_DIR" 2>/dev/null || true
|
||||||
setfacl -m u:monky-deployd:x /opt/openziti/etc 2>/dev/null || true
|
setfacl -m u:monky-deployd:x /opt/openziti/etc 2>/dev/null || true
|
||||||
if [ -n "$BAO_CA" ]; then
|
if [ -n "$BAO_CA" ]; then
|
||||||
install -m 0644 "$BAO_CA" "$ETC/openbao-ca.pem"
|
install -m 0644 "$BAO_CA" "$ETC/openbao-ca.pem"
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ install -d -m 0700 -o monky-deployd -g monky-deployd /var/lib/monky-deployd
|
|||||||
install -d -m 0750 -o root -g monky-deployd /etc/monky-deployd
|
install -d -m 0750 -o root -g monky-deployd /etc/monky-deployd
|
||||||
# the agent drives docker compose: docker group membership (no root)
|
# the agent drives docker compose: docker group membership (no root)
|
||||||
if getent group docker >/dev/null; then usermod -a -G docker monky-deployd || true; fi
|
if getent group docker >/dev/null; then usermod -a -G docker monky-deployd || true; fi
|
||||||
|
# the agent reads the host's ziti identity (owned by the tunneller, mode 0640). ziti-edge-tunnel
|
||||||
|
# REWRITES that file whenever the controller sends a config update, and the rewrite drops any
|
||||||
|
# POSIX ACL granting the agent read — group membership is the grant that survives it.
|
||||||
|
# (env-dev-08, 2026-09-09: the agent went from applied to "no intercept" 6 minutes after a refresh.)
|
||||||
|
if getent group ziti >/dev/null; then usermod -a -G ziti monky-deployd || true; fi
|
||||||
# the venv is relocatable only to the path it was built at; refuse a broken interpreter early
|
# the venv is relocatable only to the path it was built at; refuse a broken interpreter early
|
||||||
/opt/monky-deployd/venv/bin/python -c 'import monky_deployd' || { echo "monky-deployd: venv unusable (python3 mismatch?)" >&2; exit 1; }
|
/opt/monky-deployd/venv/bin/python -c 'import monky_deployd' || { echo "monky-deployd: venv unusable (python3 mismatch?)" >&2; exit 1; }
|
||||||
if [ -d /run/systemd/system ]; then
|
if [ -d /run/systemd/system ]; then
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "monky-deployd"
|
name = "monky-deployd"
|
||||||
version = "0.1.7"
|
version = "0.1.8"
|
||||||
description = "Monky backend pull agent: checkin -> bundle -> lease -> OpenBao -> docker compose -> report, over the ziti mesh (MONKY-ADR-0028)"
|
description = "Monky backend pull agent: checkin -> bundle -> lease -> OpenBao -> docker compose -> report, over the ziti mesh (MONKY-ADR-0028)"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ def fake_docker(tmp_path, monkeypatch):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# the real agent also measures containerd's root; on a CI runner that path belongs to the
|
||||||
|
# runner's own docker and would make every disk assertion depend on the runner's free space.
|
||||||
|
monkeypatch.setattr("monky_deployd.compose.CONTAINERD_ROOTS", ())
|
||||||
monkeypatch.setenv("PATH", f"{FAKEBIN}:{os.environ['PATH']}")
|
monkeypatch.setenv("PATH", f"{FAKEBIN}:{os.environ['PATH']}")
|
||||||
monkeypatch.setenv("FAKE_DOCKER_LOG", str(log))
|
monkeypatch.setenv("FAKE_DOCKER_LOG", str(log))
|
||||||
monkeypatch.setenv("FAKE_DOCKER_STATE", str(state))
|
monkeypatch.setenv("FAKE_DOCKER_STATE", str(state))
|
||||||
|
|||||||
@@ -237,6 +237,30 @@ def test_disk_refusal(bootstrapped, tenancy, fake_docker):
|
|||||||
assert tenancy.leases == []
|
assert tenancy.leases == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_disk_refusal_without_a_declared_size(bootstrapped, tenancy, fake_docker, monkeypatch):
|
||||||
|
"""A bundle that declares no size still has to clear the headroom floor.
|
||||||
|
|
||||||
|
Without the floor a nearly-full box passes the pre-flight and dies mid-pull with
|
||||||
|
containerd's "no space left on device", which reads as a registry fault (env-dev-08).
|
||||||
|
"""
|
||||||
|
cfg = bootstrapped
|
||||||
|
cfg.disk.headroom_bytes = 2 * 1024**3
|
||||||
|
monkeypatch.setattr("monky_deployd.compose.Docker.free_bytes", lambda self, path=None: 32 * 2**20)
|
||||||
|
tenancy.set_files(make_files())
|
||||||
|
assert tick(cfg) == EX_FAIL
|
||||||
|
detail = tenancy.reports[-1]["detail"]
|
||||||
|
assert "DISK_INSUFFICIENT" in detail and "declares no size" in detail
|
||||||
|
assert tenancy.leases == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_ample_disk_without_a_declared_size_applies(bootstrapped, tenancy, fake_docker, monkeypatch):
|
||||||
|
cfg = bootstrapped
|
||||||
|
monkeypatch.setattr("monky_deployd.compose.Docker.free_bytes", lambda self, path=None: 500 * 2**30)
|
||||||
|
tenancy.set_files(make_files())
|
||||||
|
assert tick(cfg) == EX_OK
|
||||||
|
assert tenancy.reports[-1]["result"] == "applied"
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_approle_lease_is_refused_loudly(bootstrapped, tenancy, fake_docker):
|
def test_legacy_approle_lease_is_refused_loudly(bootstrapped, tenancy, fake_docker):
|
||||||
cfg = bootstrapped
|
cfg = bootstrapped
|
||||||
tenancy.lease_shape = "approle"
|
tenancy.lease_shape = "approle"
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ def test_sdk_transport_uses_openziti_monkeypatch(monkeypatch, tmp_path):
|
|||||||
srv = socket.socket()
|
srv = socket.socket()
|
||||||
srv.bind(("127.0.0.1", 0))
|
srv.bind(("127.0.0.1", 0))
|
||||||
srv.listen(1)
|
srv.listen(1)
|
||||||
|
# the transport pre-flights the identity file before handing it to the SDK
|
||||||
|
(tmp_path / "id.json").write_text('{"ztAPI": "https://example.invalid"}')
|
||||||
t = SdkTransport(str(tmp_path / "id.json"))
|
t = SdkTransport(str(tmp_path / "id.json"))
|
||||||
s = t.connect("127.0.0.1", srv.getsockname()[1], 2)
|
s = t.connect("127.0.0.1", srv.getsockname()[1], 2)
|
||||||
s.close()
|
s.close()
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
"""Free-space accounting across the filesystems a pull can fill.
|
||||||
|
|
||||||
|
docker 29 keeps image layers in containerd's store, which is frequently on a different
|
||||||
|
filesystem than DockerRootDir. env-dev-08 (2026-09-09) had 93 GiB free on the data-root and
|
||||||
|
2.8 GiB on the filesystem containerd was writing to; the pull died with "no space left on
|
||||||
|
device" after the pre-flight had reported plenty of room.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import monky_deployd.compose as compose_mod
|
||||||
|
from monky_deployd.compose import Docker
|
||||||
|
|
||||||
|
|
||||||
|
class _FixedDocker(Docker):
|
||||||
|
def __init__(self, root: str):
|
||||||
|
super().__init__()
|
||||||
|
self._root = root
|
||||||
|
|
||||||
|
def data_root(self) -> str:
|
||||||
|
return self._root
|
||||||
|
|
||||||
|
|
||||||
|
def test_storage_paths_include_containerd_root_when_present(tmp_path, monkeypatch):
|
||||||
|
root = tmp_path / "docker"
|
||||||
|
containerd = tmp_path / "containerd"
|
||||||
|
root.mkdir()
|
||||||
|
containerd.mkdir()
|
||||||
|
monkeypatch.setattr(compose_mod, "CONTAINERD_ROOTS", (str(containerd),))
|
||||||
|
assert _FixedDocker(str(root)).storage_paths() == [str(root), str(containerd)]
|
||||||
|
|
||||||
|
|
||||||
|
def test_storage_paths_skip_a_containerd_root_that_does_not_exist(tmp_path, monkeypatch):
|
||||||
|
root = tmp_path / "docker"
|
||||||
|
root.mkdir()
|
||||||
|
monkeypatch.setattr(compose_mod, "CONTAINERD_ROOTS", (str(tmp_path / "absent"),))
|
||||||
|
assert _FixedDocker(str(root)).storage_paths() == [str(root)]
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_bytes_reports_the_tightest_filesystem(tmp_path, monkeypatch):
|
||||||
|
root = tmp_path / "docker"
|
||||||
|
containerd = tmp_path / "containerd"
|
||||||
|
root.mkdir()
|
||||||
|
containerd.mkdir()
|
||||||
|
monkeypatch.setattr(compose_mod, "CONTAINERD_ROOTS", (str(containerd),))
|
||||||
|
d = _FixedDocker(str(root))
|
||||||
|
monkeypatch.setattr(d, "_free_at", lambda p: 900 if p == str(root) else 5)
|
||||||
|
assert d.free_bytes() == 5
|
||||||
|
# an explicit path is still measured on its own
|
||||||
|
assert d.free_bytes(str(root)) == 900
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_bytes_is_none_when_nothing_can_be_measured(tmp_path, monkeypatch):
|
||||||
|
root = tmp_path / "docker"
|
||||||
|
root.mkdir()
|
||||||
|
monkeypatch.setattr(compose_mod, "CONTAINERD_ROOTS", ())
|
||||||
|
d = _FixedDocker(str(root))
|
||||||
|
monkeypatch.setattr(d, "_free_at", lambda p: None)
|
||||||
|
assert d.free_bytes() is None
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
"""The SDK transport names an unusable identity file instead of failing at dial.
|
||||||
|
|
||||||
|
openziti.load() accepts an unreadable or malformed identity, logs "configuration is invalid"
|
||||||
|
at the C layer and returns a context that only fails when something dials through it — as a
|
||||||
|
bare TypeError that reads like a missing intercept. env-dev-08 (2026-09-09) lost its identity
|
||||||
|
ACL to a tunneller rewrite and spent every tick reporting a mesh fault it did not have.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from monky_deployd.transport import SdkTransport, TransportError
|
||||||
|
|
||||||
|
|
||||||
|
def _sdk(path):
|
||||||
|
t = SdkTransport(str(path))
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_identity_is_named(tmp_path):
|
||||||
|
with pytest.raises(TransportError) as e:
|
||||||
|
_sdk(tmp_path / "absent.json")._check_identity_readable()
|
||||||
|
assert "does not exist" in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_malformed_identity_is_named(tmp_path):
|
||||||
|
p = tmp_path / "id.json"
|
||||||
|
p.write_text("{not json")
|
||||||
|
with pytest.raises(TransportError) as e:
|
||||||
|
_sdk(p)._check_identity_readable()
|
||||||
|
assert "not valid JSON" in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unreadable_identity_points_at_the_group_grant(tmp_path, monkeypatch):
|
||||||
|
p = tmp_path / "id.json"
|
||||||
|
p.write_text(json.dumps({"ztAPI": "https://example.invalid"}))
|
||||||
|
|
||||||
|
def _denied(*a, **k):
|
||||||
|
raise PermissionError(13, "Permission denied")
|
||||||
|
|
||||||
|
monkeypatch.setattr("builtins.open", _denied)
|
||||||
|
with pytest.raises(TransportError) as e:
|
||||||
|
_sdk(p)._check_identity_readable()
|
||||||
|
msg = str(e.value)
|
||||||
|
assert "not readable" in msg and "group" in msg
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_good_identity_passes(tmp_path):
|
||||||
|
p = tmp_path / "id.json"
|
||||||
|
p.write_text(json.dumps({"ztAPI": "https://example.invalid"}))
|
||||||
|
_sdk(p)._check_identity_readable() # no raise
|
||||||
Reference in New Issue
Block a user