feat (helper): daemon-reload via helper; verwijder D-Bus afhankelijkheid

- podman-helper: voeg daemon-reload toe aan ALLOWED_ACTIONS; actions
  in NO_UNIT_ACTIONS slaan unit-validatie over en bouwen cmd zonder
  unit argument
- app_system: /daemon-reload endpoint gebruikt nu _helper_call in
  plaats van directe subprocess; verwijder subprocess import
- app_system: health check legt systemd_reachable af van helper_ok
  in plaats van systemctl --user list-units — de helper draait als
  host-user en impliceert systemd bereikbaarheid
- CLAUDE.md: verwijder DBUS_SESSION_BUS_ADDRESS env var; D-Bus mount
  is niet meer nodig

Deploy: kopieer podman-helper.py naar host, daemon-reload, restart
helper, rebuild backend image, herstart container zonder bus mount.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 11:39:10 +01:00
parent 5196e7840f
commit ed94ee31f4
3 changed files with 19 additions and 25 deletions
+13 -8
View File
@@ -6,13 +6,14 @@ Unix socket helper die op de HOST draait als de gewone gebruiker.
Ontvangt JSON verzoeken van de API container en voert systemctl --user uit.
Beveiligingsmodel:
- Alleen start / stop / restart toegestaan
- Alleen .service units
- Unit naam mag alleen letters, cijfers, punt, koppelteken en underscore bevatten
- Alleen start / stop / restart / daemon-reload toegestaan
- start/stop/restart: alleen .service units met veilige tekens
- daemon-reload: geen unit naam, wordt genegeerd
- Meerdere gelijktijdige verbindingen worden afgehandeld via asyncio
Protocol:
Inkomend: {"action": "start"|"stop"|"restart", "unit": "naam.service"}
{"action": "daemon-reload", "unit": ""}
Uitkomend: {"ok": true, "output": "..."} of {"ok": false, "error": "..."}
"""
@@ -42,22 +43,26 @@ logging.basicConfig(
log = logging.getLogger("podman-helper")
# ── Whitelist ─────────────────────────────────────────────────────────────────
ALLOWED_ACTIONS = {"start", "stop", "restart"}
UNIT_PATTERN = re.compile(r'^[a-zA-Z0-9._\-]+\.service$')
ALLOWED_ACTIONS = {"start", "stop", "restart", "daemon-reload"}
UNIT_PATTERN = re.compile(r'^[a-zA-Z0-9._\-]+\.service$')
NO_UNIT_ACTIONS = {"daemon-reload"}
def validate(action: str, unit: str) -> str | None:
"""Geeft een foutmelding terug als het verzoek niet toegestaan is, anders None."""
if action not in ALLOWED_ACTIONS:
return f"Actie '{action}' niet toegestaan. Gebruik: {', '.join(sorted(ALLOWED_ACTIONS))}"
if not UNIT_PATTERN.match(unit):
if action not in NO_UNIT_ACTIONS and not UNIT_PATTERN.match(unit):
return f"Ongeldige unit naam '{unit}'. Alleen .service units met veilige tekens."
return None
async def run_systemctl(action: str, unit: str) -> dict:
"""Voert systemctl --user <action> <unit> uit en geeft het resultaat terug."""
cmd = ["systemctl", "--user", action, unit]
"""Voert systemctl --user <action> [unit] uit en geeft het resultaat terug."""
if action in NO_UNIT_ACTIONS:
cmd = ["systemctl", "--user", action]
else:
cmd = ["systemctl", "--user", action, unit]
log.info("Uitvoeren: %s", " ".join(cmd))
try: