feat: prepare isolated ZITADEL v4 local backend (Docker verification pending)
This commit is contained in:
1 parent
8f54ccb304
commit
433a0a32f8
9 files changed
+500
-68
No files matched your search
@@ -1,3 +1,40 @@
|
||||
# ZITADEL backend integration
|
||||
# ZitPlane — ZITADEL local backend (P02)
|
||||
|
||||
Reserved for version-pinned **official ZITADEL image** configuration and setup instructions in Phase 02. No Go source vendoring or image download in Phase 01.
|
||||
The **official ZITADEL Go backend is not vendored** here. The dev stack pins:
|
||||
- `ghcr.io/zitadel/zitadel:v4.20.4` (backend)
|
||||
- `ghcr.io/zitadel/zitadel-login:v4.20.4` (temporary, unmodified UI dependency for usable Admin Console)
|
||||
- `postgres:17.10-alpine`, `traefik:v3.7.7` (development infrastructure)
|
||||
|
||||
Upstream references:
|
||||
- https://zitadel.com/docs/self-hosting/deploy/compose
|
||||
- https://github.com/zitadel/zitadel/blob/v4.20.4/deploy/compose/docker-compose.yml
|
||||
- https://zitadel.com/docs/apis/observability/health
|
||||
|
||||
## Prerequisites
|
||||
- Docker Desktop **Linux containers** with `docker compose` (not installed automatically).
|
||||
- Python 3.10+ (stdlib only), local loopback port 8080 available.
|
||||
- Do not start this dev Compose stack on a public server.
|
||||
|
||||
## Local commands (from repository root)
|
||||
```powershell
|
||||
py core/backend/zitadel/dev.py init
|
||||
py core/backend/zitadel/dev.py config
|
||||
py core/backend/zitadel/dev.py up
|
||||
py core/backend/zitadel/dev.py check
|
||||
py core/backend/zitadel/dev.py ps
|
||||
py core/backend/zitadel/dev.py down
|
||||
```
|
||||
|
||||
`init` generates four random secrets into ignored root `.env` (never prints values). It is idempotent and never overwrites an existing .env. `down` stops services **without deleting persistent volumes**. Do not run `docker compose down -v` on a database you need.
|
||||
|
||||
Once running, use **http://localhost:8080/ui/console** with username `zitadel-admin@zitadel.localhost` and the bootstrap admin password found locally in `.env` (never share it). A password change is required. For the first admin setup, local email verification is pre-verified; **never use this development shortcut for production users**. The initial admin password and most `FIRSTINSTANCE_` settings only apply the first time a database is initialized. No SMTP is configured; password-recovery emails won't work locally until a later, separately approved integration.
|
||||
|
||||
## Boundaries
|
||||
- HTTP is bound to `127.0.0.1:8080` only (no LAN/public exposure). PostgreSQL and API/login ports are internal-only.
|
||||
- The official Login V2 **container** is a runtime dependency, **not the customized Login V2 source import**. Phase 03 will replace/import at its separately approved scope.
|
||||
- The shared bootstrap PAT and database survive restarts via Docker named volumes. Its configured initial expiration is 2028-01-01; renewal/rotation needs planning before then.
|
||||
- Avoid deleting `.env` (especially `ZITADEL_MASTERKEY`) while retaining volumes, because the master key protects encrypted data.
|
||||
- When ready for production, design a **separate** hardened stack with HTTPS, durable secrets, backups and role-restricted database access. This Compose file must never be used as-is in Coolify.
|
||||
|
||||
## Initial machine audit (2026-11-22)
|
||||
The connected Windows host has Python 3.12, but no Docker CLI/Docker Desktop was detected. Runtime startup, real readiness, Admin Console login and volume persistence **cannot be certified on this host** until Docker is installed and running. Static tests cannot substitute for live integration tests.
|
||||
@@ -0,0 +1,145 @@
|
||||
"""Local-only ZitPlane backend helper (Python stdlib, no dependencies).
|
||||
|
||||
Run from any folder:
|
||||
py core/backend/zitadel/dev.py init
|
||||
py core/backend/zitadel/dev.py up
|
||||
py core/backend/zitadel/dev.py check
|
||||
py core/backend/zitadel/dev.py down
|
||||
|
||||
No credentials are printed, committed or transmitted by this script.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
import shutil
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
COMPOSE = ROOT / "deployment" / "docker" / "compose.backend.dev.yaml"
|
||||
ENV = ROOT / ".env"
|
||||
VARIABLES = (
|
||||
"POSTGRES_PASSWORD",
|
||||
"ZITADEL_MASTERKEY",
|
||||
"ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD",
|
||||
"LOGIN_SESSION_COOKIE_SECRET",
|
||||
)
|
||||
|
||||
|
||||
def random_chars(alphabet: str, length: int) -> str:
|
||||
return "".join(secrets.choice(alphabet) for _ in range(length))
|
||||
|
||||
|
||||
def create_dev_env() -> bool:
|
||||
"""Generate local secrets once and never overwrite an existing .env."""
|
||||
if ENV.exists():
|
||||
print("Existing .env preserved (credentials were not regenerated).")
|
||||
return False
|
||||
alphabet = string.ascii_letters + string.digits
|
||||
values = {
|
||||
"POSTGRES_PASSWORD": random_chars(alphabet, 48),
|
||||
"ZITADEL_MASTERKEY": random_chars(alphabet, 32),
|
||||
"ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD": (
|
||||
"Zp!7" + random_chars(alphabet, 29)
|
||||
),
|
||||
"LOGIN_SESSION_COOKIE_SECRET": random_chars(alphabet, 48),
|
||||
}
|
||||
lines = [
|
||||
"# Local ZitPlane development only. NEVER COMMIT or deploy to Coolify.",
|
||||
"# The first admin is zitadel-admin@zitadel.localhost.",
|
||||
"# Keep this file: rotating the ZITADEL master key will break existing encrypted data.",
|
||||
]
|
||||
lines.extend(f"{key}={value}" for key, value in values.items())
|
||||
try:
|
||||
with ENV.open("x", encoding="utf-8", newline="\n") as fh:
|
||||
fh.write("\n".join(lines) + "\n")
|
||||
except FileExistsError:
|
||||
print("Existing .env preserved (race-safe).")
|
||||
return False
|
||||
if os.name != "nt":
|
||||
os.chmod(ENV, 0o600)
|
||||
print("Created ignored .env with random development credentials; values hidden.")
|
||||
return True
|
||||
|
||||
|
||||
def validate_env() -> None:
|
||||
if not ENV.is_file():
|
||||
raise RuntimeError("Missing .env. Run: py core/backend/zitadel/dev.py init")
|
||||
data: dict[str, str] = {}
|
||||
for line in ENV.read_text(encoding="utf-8").splitlines():
|
||||
if not line.strip() or line.lstrip().startswith("#"):
|
||||
continue
|
||||
if "=" not in line:
|
||||
raise RuntimeError("Invalid .env entry.")
|
||||
key, value = line.split("=", 1)
|
||||
data[key] = value
|
||||
if any(not data.get(key) for key in VARIABLES):
|
||||
raise RuntimeError("Local .env is missing one or more required variables.")
|
||||
if len(data["ZITADEL_MASTERKEY"]) != 32:
|
||||
raise RuntimeError("ZITADEL_MASTERKEY must be exactly 32 characters.")
|
||||
if len(data["LOGIN_SESSION_COOKIE_SECRET"]) < 32:
|
||||
raise RuntimeError("LOGIN_SESSION_COOKIE_SECRET must be >= 32 characters.")
|
||||
if len(data["ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD"]) < 16:
|
||||
raise RuntimeError("Admin password too short.")
|
||||
|
||||
|
||||
def docker_compose(*args: str) -> None:
|
||||
if not shutil.which("docker"):
|
||||
raise RuntimeError(
|
||||
"Docker CLI is not installed or not on PATH. Install/start Docker Desktop "
|
||||
"with Linux containers; no Docker installation is performed automatically."
|
||||
)
|
||||
command = ["docker", "compose", "--env-file", str(ENV), "-f", str(COMPOSE), *args]
|
||||
completed = subprocess.run(command, cwd=ROOT, check=False)
|
||||
if completed.returncode:
|
||||
raise RuntimeError(f"Docker Compose exited with code {completed.returncode}.")
|
||||
|
||||
|
||||
def check_ready() -> None:
|
||||
url = "http://localhost:8080/debug/ready"
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=8) as response:
|
||||
if response.status != 200:
|
||||
raise RuntimeError(f"Readiness HTTP status: {response.status}")
|
||||
print(f"PASS: ZITADEL ready at {url}")
|
||||
print("Admin console: http://localhost:8080/ui/console")
|
||||
except (urllib.error.URLError, TimeoutError) as exc:
|
||||
raise RuntimeError(f"ZITADEL not ready at {url}: {exc}") from exc
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="ZitPlane local-only ZITADEL backend")
|
||||
parser.add_argument("action", choices=["init", "up", "check", "down", "ps", "config"])
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
if args.action == "init":
|
||||
create_dev_env()
|
||||
validate_env()
|
||||
return 0
|
||||
if args.action == "check":
|
||||
check_ready()
|
||||
return 0
|
||||
validate_env()
|
||||
if args.action == "up":
|
||||
docker_compose("up", "-d", "--wait")
|
||||
check_ready()
|
||||
elif args.action == "down":
|
||||
docker_compose("down") # never remove volumes
|
||||
elif args.action == "ps":
|
||||
docker_compose("ps")
|
||||
elif args.action == "config":
|
||||
docker_compose("config", "--quiet")
|
||||
except RuntimeError as exc:
|
||||
print(f"BLOCKED: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user