Fix what a review of the whole app found, end to end (0.67.1)
A pass over every feature against a real Docker daemon, then clicking through the UI as admin and read-only user, on a desktop and a phone. Security. /ws/deploy ran compose up for the read-only role; it is admin-only now. A container's inspect view, a stack's compose file (POSTGRES_PASSWORD: hunter2) and the viewer's .env tab no longer show credentials to that role. Git branch and URL values that git would read as options (-x, ext::) are refused. SFTP host keys are checked: pinned on first use or entered by hand (key line or SHA256 fingerprint), a different key is refused before the password is sent. A backup name from the API can no longer reach outside the destination folder. The file browser refuses to move or rename a browse root, as delete did. Docker lifecycle. Closing the deploy console released the stack lock while compose was still running and logged rc=None as success; deploys and updates are now background runs that hold the lock to the end, report the real exit code and can be re-attached to. Every closed log view left a `compose logs -f` behind. A dozen open tabs exhausted the default thread pool and hung the API; event and exec streams have their own threads. Auto-update and the update endpoint ignored failed pulls. A deleted git stack was recreated and started by the next webhook or poll; deleting a stack now drops its git source, auto-update policy and schedule entries. Deleting no longer walks into mounted shares, is refused while a backup runs, and removes the containers even when the compose file is broken. Stack folders compose has to normalise (Nextcloud -> nextcloud) work everywhere and group correctly on the volumes, networks and images pages. Detection. Host port conflicts read the container's own network namespace; /proc/1/net is read instead. Images referenced as docker.io/… were never update-checked; local builds no longer report "needs credentials". NVIDIA GPUs are read from the driver's procfs. The backup dialog's "path mismatch" warning came from mountinfo's filesystem-relative root and fired for any stacks folder on its own disk, ZFS dataset or btrfs subvolume; the host path now comes from Docker's mounts. Backups and destinations. The download ignored the folder/volume selection (axios sent binds[]). Restoring under a new name kept the old one. A report header past nginx's buffer turned a good backup into a 502. SFTP/S3 errors were bare 500s and "Test" did not try to write. A destination used by a schedule could be deleted. Backup file names are in the schedule's or the browser's time zone instead of UTC. Editor and converter. `docker run` conversion produced invalid compose for --network host, named volumes and -dit; --gpus and --mount were dropped; a multi-line command pasted into the one-line field became `image: ' '` (now a textarea, and flattened continuations are read). Validation failed for env_file stacks. The editor overwrote unsaved edits on every container event, lost them on a stray click (now asks), threw when closing the diff, and its helper panel listed the starter service "app" for every existing stack. Monaco is bundled instead of loaded from jsdelivr, so the editor works offline (and monaco-editor 0.57 drops the dompurify advisory; axios and react-router updated). UI. All times were two hours off: offset-less UTC from SQLite was read as local time, and "next run" always said "just now". A token refresh mid-session duplicated deploys, reset terminals and doubled logs. A backend restart (update, self-update) signed everyone out on reload; the page now waits for it. The editor was unusable on a phone, tables and tabs overflowed, dialog text was black on the dark theme, and the file browser opened on an error with the default roots. Read-only users get "Admin only" pages instead of 403s; in-use networks offer no delete; "Scan all" covers StackPilot's own stacks only and runs in the background instead of timing out at 600s. Deployment. nginx passes the port in Host (the OIDC redirect URI lost :5009) and keeps an outer proxy's X-Forwarded-Proto. The frontend waits for a healthy backend (healthcheck probes every 2s while starting). The frontend image builds with npm ci. Secrets are 0644 in a 0700 folder so non-root containers can read them; existing files are fixed at startup. The test suite no longer starts real containers on a host with Docker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fx7gcuy8d6nPd95g43rGHu
This commit is contained in:
1 parent
270ddda51d
commit
d6cebb3371
88 files changed
+4752
-925
No files matched your search
+79
-17
@@ -9,6 +9,7 @@ from dataclasses import asdict
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Query, Request, UploadFile
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlmodel import Session, select
|
||||
from starlette.background import BackgroundTask
|
||||
|
||||
from auth import get_current_user, require_admin
|
||||
from database import get_session
|
||||
@@ -36,6 +37,7 @@ from services import (
|
||||
icon_service,
|
||||
logo_service,
|
||||
notify_service,
|
||||
stack_cleanup_service,
|
||||
stack_job_service,
|
||||
stack_lock_service,
|
||||
stats_service,
|
||||
@@ -131,7 +133,7 @@ def _stack_summary(
|
||||
total = running = 0
|
||||
status = "unknown"
|
||||
else:
|
||||
info = summaries.get(stack.id)
|
||||
info = summaries.get(compose_service.project_name(stack.id))
|
||||
total = info["total"] if info else 0
|
||||
running = info["running"] if info else 0
|
||||
if stack.id in busy:
|
||||
@@ -204,17 +206,30 @@ def create_stack(
|
||||
return _stack_summary(stack)
|
||||
|
||||
|
||||
def _by_stack_id(session: Session, per_project: dict) -> dict:
|
||||
"""Re-key per-compose-project data by stack id (they differ only for a
|
||||
folder whose name compose had to normalise, see project_name)."""
|
||||
ids = compose_service.stack_ids_by_project_in(session)
|
||||
return {ids.get(project, project): value for project, value in per_project.items()}
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
def stacks_stats(_user: User = Depends(get_current_user)) -> dict:
|
||||
def stacks_stats(
|
||||
session: Session = Depends(get_session),
|
||||
_user: User = Depends(get_current_user),
|
||||
) -> dict:
|
||||
"""Live CPU (cores) and memory usage per stack, with assigned limits."""
|
||||
return stats_service.stack_stats()
|
||||
return _by_stack_id(session, stats_service.stack_stats())
|
||||
|
||||
|
||||
@router.get("/updates")
|
||||
def stacks_updates(_user: User = Depends(get_current_user)) -> dict:
|
||||
def stacks_updates(
|
||||
session: Session = Depends(get_session),
|
||||
_user: User = Depends(get_current_user),
|
||||
) -> dict:
|
||||
"""Per-stack image-update availability, read from the cached registry
|
||||
digests (no live registry calls — safe for the list to poll)."""
|
||||
return update_service.stacks_update_summary()
|
||||
return _by_stack_id(session, update_service.stacks_update_summary())
|
||||
|
||||
|
||||
@router.get("/icons/search")
|
||||
@@ -275,7 +290,12 @@ def get_stack(
|
||||
# What is holding the stack, so the page can offer to stop it instead
|
||||
# of only showing a spinner that never ends.
|
||||
"lock": _lock_view(lock, stack_id),
|
||||
"yaml": compose_service.read_compose(stack_id),
|
||||
# Inline credentials masked for the read-only role, like the .env.
|
||||
"yaml": (
|
||||
compose_service.read_compose(stack_id)
|
||||
if user.role == "admin"
|
||||
else compose_service.mask_secrets(compose_service.read_compose(stack_id))
|
||||
),
|
||||
# The .env is where credentials live by convention, so it is withheld
|
||||
# from the read-only role — same reasoning as the admin-only file
|
||||
# browser. Non-admins still get status, services and the compose file.
|
||||
@@ -333,21 +353,49 @@ async def delete_stack(
|
||||
user: User = Depends(require_admin),
|
||||
) -> dict:
|
||||
stack = _get_stack_or_404(session, stack_id)
|
||||
# Deleting a stack in the middle of a backup, restore or deploy pulls the
|
||||
# folder out from under it — and a backup then starts the containers it
|
||||
# stopped again, for a stack that no longer exists.
|
||||
lock = stack_lock_service.info(session, stack_id)
|
||||
if lock:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail=f"Stack '{stack_id}' is busy: {lock['action']} in progress",
|
||||
)
|
||||
try:
|
||||
await compose_service.down(stack_id)
|
||||
except Exception: # noqa: BLE001 - best-effort teardown
|
||||
pass
|
||||
result = await compose_service.down(stack_id)
|
||||
down_ok = result.get("returncode") == 0
|
||||
except Exception: # noqa: BLE001 - fall back to the API below
|
||||
down_ok = False
|
||||
if not down_ok:
|
||||
# A compose file that no longer parses makes `down` fail, and the
|
||||
# containers would keep running with nothing left here to stop them.
|
||||
try:
|
||||
removed = await asyncio.to_thread(compose_service.force_remove_project, stack_id)
|
||||
logger.info("compose down failed for '%s'; removed %d container(s) directly",
|
||||
stack_id, removed)
|
||||
except DockerError as exc:
|
||||
logger.warning("Could not remove the containers of '%s': %s", stack_id, exc)
|
||||
kept: list[str] = []
|
||||
if delete_files:
|
||||
compose_service.delete_stack_files(stack_id)
|
||||
try:
|
||||
kept = compose_service.delete_stack_files(stack_id)
|
||||
except OSError as exc:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"The stack was stopped, but its folder could not be deleted: {exc}",
|
||||
) from exc
|
||||
icon_service.remove(stack_id)
|
||||
logo_service.forget(stack_id)
|
||||
stack_cleanup_service.forget_stack(session, stack_id)
|
||||
session.delete(stack)
|
||||
session.commit()
|
||||
audit_service.record(
|
||||
session, user=user.username, action="stack.delete", target=stack_id,
|
||||
detail=f"delete_files={delete_files}", ip=_client_ip(request),
|
||||
detail=f"delete_files={delete_files}" + (f" kept={len(kept)} mount(s)" if kept else ""),
|
||||
ip=_client_ip(request),
|
||||
)
|
||||
return {"ok": True}
|
||||
return {"ok": True, "kept": kept}
|
||||
|
||||
|
||||
@router.post("/{stack_id}/clone")
|
||||
@@ -365,7 +413,8 @@ def clone_stack(
|
||||
try:
|
||||
compose_service.clone_stack_files(stack_id, new_id)
|
||||
except compose_service.StackFileError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
status = 409 if "already exists" in str(exc) else 500
|
||||
raise HTTPException(status_code=status, detail=str(exc)) from exc
|
||||
stack = Stack(
|
||||
id=new_id,
|
||||
name=body.name,
|
||||
@@ -412,6 +461,8 @@ async def get_stack_icon(
|
||||
|
||||
|
||||
def _icon_response(path: str, media_type: str, filename: str) -> FileResponse:
|
||||
# A folder found on disk can be named anything; headers are latin-1.
|
||||
filename = filename.encode("ascii", "replace").decode("ascii").replace("?", "_")
|
||||
return FileResponse(
|
||||
path,
|
||||
media_type=media_type,
|
||||
@@ -516,6 +567,9 @@ async def _lifecycle(action_fn, action_name, stack_id, request, session, user):
|
||||
status_code=409,
|
||||
detail=f"Stack '{stack_id}' is busy: {exc.action} in progress",
|
||||
) from exc
|
||||
except compose_service.StackFileError as exc:
|
||||
# The compose call timed out; it may still be finishing on the host.
|
||||
raise HTTPException(status_code=504, detail=str(exc)) from exc
|
||||
audit_service.record(
|
||||
session, user=user.username, action=f"stack.{action_name}", target=stack_id,
|
||||
detail=f"rc={result.get('returncode')}", ip=_client_ip(request),
|
||||
@@ -683,7 +737,7 @@ async def unlock_stack(
|
||||
@router.get("/{stack_id}/logs")
|
||||
async def stack_logs(
|
||||
stack_id: str,
|
||||
tail: int = Query(200, le=2000),
|
||||
tail: int = Query(200, ge=0, le=2000),
|
||||
session: Session = Depends(get_session),
|
||||
_user: User = Depends(get_current_user),
|
||||
) -> dict:
|
||||
@@ -696,7 +750,7 @@ async def stack_logs(
|
||||
async def service_logs(
|
||||
stack_id: str,
|
||||
service: str,
|
||||
tail: int = Query(200, le=2000),
|
||||
tail: int = Query(200, ge=0, le=2000),
|
||||
session: Session = Depends(get_session),
|
||||
_user: User = Depends(get_current_user),
|
||||
) -> dict:
|
||||
@@ -721,13 +775,20 @@ def export_stack(
|
||||
if not os.path.isdir(directory):
|
||||
raise HTTPException(status_code=404, detail="Stack directory missing")
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".tar.gz")
|
||||
with tarfile.open(tmp.name, "w:gz") as tar:
|
||||
tar.add(directory, arcname=stack_id)
|
||||
tmp.close()
|
||||
try:
|
||||
with tarfile.open(tmp.name, "w:gz") as tar:
|
||||
tar.add(directory, arcname=stack_id)
|
||||
except BaseException:
|
||||
os.unlink(tmp.name)
|
||||
raise
|
||||
date = compose_service.now().strftime("%Y%m%d")
|
||||
return FileResponse(
|
||||
tmp.name,
|
||||
media_type="application/gzip",
|
||||
filename=f"stack-{stack_id}-{date}.tar.gz",
|
||||
# The archive is a temp file; without this every export stayed in /tmp.
|
||||
background=BackgroundTask(os.unlink, tmp.name),
|
||||
)
|
||||
|
||||
|
||||
@@ -765,6 +826,7 @@ def set_auto_update(
|
||||
session: Session = Depends(get_session),
|
||||
user: User = Depends(require_admin),
|
||||
) -> dict:
|
||||
_get_stack_or_404(session, stack_id)
|
||||
policy = auto_update_service.upsert_policy(session, stack_id, body.enabled, body.redeploy)
|
||||
audit_service.record(
|
||||
session, user=user.username, action="stack.auto_update",
|
||||
|
||||
Reference in new issue
Block a user