mirror of
https://scm.tikali.ai/tikali/applications/monky/monky-deployd.git
synced 2026-09-18 03:36:16 +00:00
1c42e913a8
Stdlib-only Python 3.12 agent for docker VMs and laptops: flock → checkin
(bearer = the agent's OpenBao token, bootstrapped from the install kit's
jwt-tenancy deploy grant) → action apply|none|down → bundle (sha256
verified) → refusal checks (unresolved ${VAR} names only, manifest paths
pinned to monky/data/<env>/see/, privileged/host-network, rollback, disk
need×1.5+headroom) → lease → POST /v1/auth/jwt-tenancy/login → KV reads →
.env 0600 → promote → compose pull/up → wait healthy → report; finally
renew-self / re-lease before max TTL, scrub. Exit 0/75/78/1. Redactor log
filter. Transports sdk (openziti) / proxy (ziti tunnel proxy 18443/18200) /
system. Laptop mode.
Packaging: hardened oneshot + 60 s timer + proxy unit, nfpm .deb with
/opt/monky-deployd/venv, install.sh for Ubuntu 26.04 (Gitea release
download, enrol, ACLs, bootstrap from stdin), ansible role skeleton for
osg1-07. CI: lint/test on every change; wheel (openziti on ubuntu:26.04) and
package (nfpm) allow_failure until runner egress is proven; GitLab release +
release:gitea on v* tags. Docs: README, PROTOCOL, OPERATIONS, CHANGELOG,
CLAUDE/AGENTS.
Divergence noted: monky-tenancy main (MR !15) still ships the AppRole lease
and kit; this agent implements the plan's Gate 1 RESULT (login_jwt, no
unwrap) and refuses an AppRole lease loudly (LEASE_SHAPE).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KLB7jieMNRkTsJ2epr4Ds1
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
import pytest
|
|
|
|
from monky_deployd import config as c
|
|
|
|
KIT = """\
|
|
# written by the install kit
|
|
env_id: env-qa-02
|
|
site: cbs
|
|
transport: sdk
|
|
identity: /opt/openziti/etc/identities/monky-host.env-qa-02.json
|
|
tenancy:
|
|
service: monky.tenancy.deploy
|
|
base_url: http://monky.tenancy.deploy:8081
|
|
bao:
|
|
service: openbao
|
|
addr: https://bao.cbs.tikali.net:8200 # intercept, not public DNS
|
|
ca_bundle: /etc/monky-deployd/openbao-ca.pem
|
|
mount: jwt-tenancy
|
|
role: see-env
|
|
kv_mount: monky
|
|
interval_s: 60
|
|
laptop_mode: false
|
|
volumes_on_absent: keep
|
|
"""
|
|
|
|
|
|
def test_yaml_subset_parses_nested_maps_and_types():
|
|
d = c.parse_yaml_subset(KIT)
|
|
assert d["env_id"] == "env-qa-02"
|
|
assert d["tenancy"]["base_url"] == "http://monky.tenancy.deploy:8081"
|
|
assert d["bao"]["addr"] == "https://bao.cbs.tikali.net:8200"
|
|
assert d["interval_s"] == 60 and d["laptop_mode"] is False
|
|
|
|
|
|
def test_yaml_subset_lists_quotes_and_comments():
|
|
d = c.parse_yaml_subset("a: \"x # not a comment\"\nb: 'q'\nlist:\n - one\n - 2\nn: ~\n")
|
|
assert d == {"a": "x # not a comment", "b": "q", "list": ["one", 2], "n": None}
|
|
|
|
|
|
def test_yaml_subset_refuses_flow_style_and_tabs():
|
|
with pytest.raises(c.ConfigError):
|
|
c.parse_yaml_subset("a: [1, 2]\n")
|
|
with pytest.raises(c.ConfigError):
|
|
c.parse_yaml_subset("a:\n\tb: 1\n")
|
|
|
|
|
|
def test_config_defaults_and_derivations():
|
|
cfg = c.from_dict(c.parse_yaml_subset(KIT))
|
|
assert cfg.tenancy.host == "monky.tenancy.deploy" and cfg.tenancy.port == 8081 and cfg.tenancy.scheme == "http"
|
|
assert cfg.bao_url == ("https", "bao.cbs.tikali.net", 8200)
|
|
assert cfg.deploy_dir == "/var/lib/monky-deployd/env-qa-02"
|
|
assert cfg.compose_project == "monky-env-qa-02"
|
|
assert str(cfg.token_path) == "/var/lib/monky-deployd/bao.token"
|
|
assert cfg.is_prod is False
|
|
assert cfg.bao.mount == "jwt-tenancy" and cfg.bao.role == "see-env"
|
|
|
|
|
|
def test_config_prod_detection_and_legacy_ids():
|
|
assert c.from_dict({"env_id": "env-prod-01", "site": "pdx"}).is_prod is True
|
|
assert c.from_dict({"env_id": "prod-cedar", "site": "cbs"}).is_prod is True
|
|
assert c.from_dict({"env_id": "dev-env-2", "site": "cbs"}).is_prod is False
|
|
with pytest.raises(c.ConfigError):
|
|
c.from_dict({"env_id": "dev-env-1", "site": "cbs"}) # retired 2026-09-04
|
|
|
|
|
|
def test_config_rejects_approle_and_unknown_keys():
|
|
with pytest.raises(c.ConfigError, match="approle"):
|
|
c.from_dict({"env_id": "env-dev-06", "site": "cbs", "bao": {"approle": {"path": "approle"}}})
|
|
with pytest.raises(c.ConfigError, match="unknown key"):
|
|
c.from_dict({"env_id": "env-dev-06", "site": "cbs", "tenancy": {"nope": 1}})
|
|
with pytest.raises(c.ConfigError, match="transport"):
|
|
c.from_dict({"env_id": "env-dev-06", "site": "cbs", "transport": "carrier-pigeon"})
|
|
with pytest.raises(c.ConfigError, match="site"):
|
|
c.from_dict({"env_id": "env-dev-06", "site": "sfo"})
|
|
|
|
|
|
def test_sdk_identity_defaults_to_host_identity():
|
|
cfg = c.from_dict({"env_id": "env-dev-07", "site": "cbs"})
|
|
assert cfg.identity == "/opt/openziti/etc/identities/monky-host.env-dev-07.json"
|