Keep operator telemetry live-only with bounded volatile state

This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 10:54:35 +03:00
parent 15a60e7e31
commit 8bf6571ce2
14 changed files with 450 additions and 570 deletions
+6 -24
View File
@@ -24,9 +24,7 @@ PLACEHOLDER: Final = "replace-with-"
AGENT_REGISTRY_SCHEMA: Final = "missioncore.telemetry-agent-credential-registry/v1"
AGENT_PAYLOAD_SCHEMA: Final = "missioncore.telemetry-agent-provisioning-payload/v1"
AGENT_BUNDLE_SCHEMA: Final = "missioncore.telemetry-agent-bundle/v1"
SAFE_IDENTIFIER: Final = re.compile(
r"^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
)
SAFE_IDENTIFIER: Final = re.compile(r"^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$")
SAFE_INTERVAL: Final = re.compile(r"^[1-9][0-9]{0,2}s$")
WINDOWS_BUNDLE_FILES: Final = (
"Install-NdcMissionCoreTelemetryRecovery.ps1",
@@ -62,10 +60,6 @@ def _initialize_environment(bind_address: str, *, overwrite: bool = False) -> No
"MISSIONCORE_MQTT_BIND_ADDRESS": normalized_bind_address,
"MISSIONCORE_MQTT_PORT": "1883",
"MISSIONCORE_TELEMETRY_QUERY_PORT": "18030",
"MISSIONCORE_DB_NAME": "missioncore_telemetry",
"MISSIONCORE_DB_USER": "missioncore_ingest",
"MISSIONCORE_DB_PASSWORD": secrets.token_urlsafe(36),
"MISSIONCORE_DB_INGEST_PASSWORD": secrets.token_urlsafe(36),
"MISSIONCORE_MQTT_INGEST_USER": "missioncore-ingest",
"MISSIONCORE_MQTT_INGEST_PASSWORD": secrets.token_urlsafe(36),
}
@@ -91,17 +85,6 @@ def _environment() -> dict[str, str]:
def _migrate_environment() -> None:
values = _environment()
additions: dict[str, str] = {}
if "MISSIONCORE_DB_INGEST_PASSWORD" not in values:
additions["MISSIONCORE_DB_INGEST_PASSWORD"] = secrets.token_urlsafe(36)
if additions:
with ENV_PATH.open("a", encoding="utf-8", newline="\n") as stream:
for name, value in additions.items():
stream.write(f"{name}={value}\n")
stream.flush()
os.fsync(stream.fileno())
os.chmod(ENV_PATH, 0o600)
values.update(additions)
_migrate_legacy_worker(values)
@@ -301,12 +284,12 @@ def _private_mqtt_host(value: str) -> None:
try:
address = ipaddress.ip_address(value)
except ValueError:
if not value.endswith(".local") or len(value) > 253 or any(
SAFE_IDENTIFIER.fullmatch(label) is None for label in value[:-6].split(".")
if (
not value.endswith(".local")
or len(value) > 253
or any(SAFE_IDENTIFIER.fullmatch(label) is None for label in value[:-6].split("."))
):
raise RuntimeError(
"MQTT host must be a private IP or stable .local hostname"
) from None
raise RuntimeError("MQTT host must be a private IP or stable .local hostname") from None
else:
if not address.is_private or address.is_unspecified or address.is_multicast:
raise RuntimeError("MQTT host must be a private IP or stable .local hostname")
@@ -391,7 +374,6 @@ def _prepare_plane() -> None:
agents = _read_agent_registry()
ingest_user = _required(values, "MISSIONCORE_MQTT_INGEST_USER")
ingest_password = _required(values, "MISSIONCORE_MQTT_INGEST_PASSWORD")
_required(values, "MISSIONCORE_DB_PASSWORD")
RUNTIME.mkdir(mode=0o700, parents=True, exist_ok=True)
password_path = RUNTIME / "passwords"
_prepare_password_entries(password_path, ingest_user, ingest_password, agents)