Reject external Compose backend networks before service startup
ABSDEV Framework CI / framework-ci (push) Successful in 24s

This commit is contained in:
Mark Gregory
2026-11-29 13:59:44 +00:00
parent 2719378f67
commit 89418ea21a
4 changed files with 59 additions and 2 deletions
+21 -2
View File
@@ -4,6 +4,7 @@ The command runner must be supplied by the caller.
This module does not execute subprocesses directly.
"""
import json
import os
import stat
import tempfile
@@ -37,6 +38,7 @@ class ServiceLifecycle:
stop_timeout=90,
*,
site_secrets=None,
topology_runner=None,
):
require(
@@ -86,6 +88,8 @@ class ServiceLifecycle:
self._queue = docker["queue_service"]
self._scheduler = docker["scheduler_service"]
self._backend_network = docker["backend_network"]
self._topology_runner = topology_runner
self._runner = runner
self._stop_timeout = stop_timeout
@@ -114,6 +118,18 @@ class ServiceLifecycle:
f"Service operation failed: {operation}",
)
def _require_project_backend(self):
require(callable(self._topology_runner), "Trusted Compose topology runner required")
command = (*self._prefix, "config", "--format", "json")
try:
model = json.loads(self._topology_runner(command, timeout=30))
backend = model["networks"][self._backend_network]
except Exception:
raise ServiceError("Unable to verify Compose backend network") from None
require(isinstance(backend, dict), "Invalid Compose backend network")
require(backend.get("external", False) is False,
"External Compose backend networks are prohibited")
def quiesce(self):
self._execute(
@@ -130,6 +146,7 @@ class ServiceLifecycle:
def restart_php(self):
self._require_project_backend()
self._execute(
"restart PHP",
(
@@ -181,6 +198,7 @@ class ServiceLifecycle:
def resume(self):
self._require_project_backend()
self._execute(
"resume workers",
(
@@ -203,8 +221,9 @@ class ContainedServiceLifecycle(ServiceLifecycle):
"""
def __init__(self, config, runner, *, gate_directory, ingress_sealed,
worker_running, stop_timeout=90, site_secrets=None):
super().__init__(config, runner, stop_timeout, site_secrets=site_secrets)
worker_running, stop_timeout=90, site_secrets=None, topology_runner=None):
super().__init__(config, runner, stop_timeout, site_secrets=site_secrets,
topology_runner=topology_runner)
require(callable(ingress_sealed) and callable(worker_running),
"Containment probes are required")
self._gate_directory = Path(gate_directory)