Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(workspaces): extend per-site ACL grants across all app blueprints (#33)

Juan Denis35642187c6ea
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index 32cad79c..ad9e0a97 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -368,21 +368,15 @@ def set_app_workspace(app_id):
def _can_access_app(user, app):
- """Read access (#33 ACL): owner, admin, or ANY grant (viewer or editor).
- Uses user.id (int) — get_jwt_identity() is the stringified token id."""
- if user.is_admin or app.user_id == user.id:
- return True
+ """Read access (#33 ACL) — delegates to the shared seam."""
from app.services.resource_grant_service import ResourceGrantService
- return ResourceGrantService.user_has_grant(user.id, 'application', app.id)
+ return ResourceGrantService.can_access_app(user, app)
def _can_edit_app(user, app):
- """Write/operate access (#33 ACL): owner, admin, or an EDITOR grant. A viewer
- grant confers read access only."""
- if user.is_admin or app.user_id == user.id:
- return True
+ """Write/operate access (#33 ACL) — delegates to the shared seam."""
from app.services.resource_grant_service import ResourceGrantService
- return ResourceGrantService.grant_role(user.id, 'application', app.id) == 'editor'
+ return ResourceGrantService.can_edit_app(user, app)
@apps_bp.route('/<int:app_id>', methods=['GET'])
diff --git a/backend/app/api/builds.py b/backend/app/api/builds.py
index ccce7760..278d23d5 100644
--- a/backend/app/api/builds.py
+++ b/backend/app/api/builds.py
@@ -13,6 +13,7 @@ from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application, Deployment
from app.services.build_service import BuildService
from app.services.deployment_service import DeploymentService
+from app.services.resource_grant_service import ResourceGrantService
builds_bp = Blueprint('builds', __name__)
@@ -44,7 +45,7 @@ def get_build_config(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
config = BuildService.get_app_build_config(app_id)
@@ -110,7 +111,7 @@ def detect_build_method(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
detection = BuildService.detect_build_method(app.root_path)
@@ -128,7 +129,7 @@ def get_nixpacks_plan(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
result = BuildService.get_nixpacks_plan(app.root_path)
@@ -148,7 +149,7 @@ def trigger_build(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -169,7 +170,7 @@ def get_build_logs(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
limit = request.args.get('limit', 20, type=int)
@@ -188,7 +189,7 @@ def get_build_log_detail(app_id, timestamp):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
log = BuildService.get_build_log_detail(app_id, timestamp)
@@ -219,7 +220,7 @@ def deploy_app(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -246,7 +247,7 @@ def get_deployments(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
limit = request.args.get('limit', 20, type=int)
@@ -273,7 +274,7 @@ def get_deployment(deployment_id):
return jsonify({'error': 'Deployment not found'}), 404
app = Application.query.get(deployment.app_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
include_logs = request.args.get('include_logs', 'false').lower() == 'true'
@@ -292,7 +293,7 @@ def get_deployment_diff(deployment_id):
return jsonify({'error': 'Deployment not found'}), 404
app = Application.query.get(deployment.app_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
diff = DeploymentService.get_deployment_diff(deployment_id)
@@ -314,7 +315,7 @@ def rollback(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -340,7 +341,7 @@ def get_current_deployment(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
deployment = DeploymentService.get_current_deployment(app_id)
diff --git a/backend/app/api/databases.py b/backend/app/api/databases.py
index c0cb94e5..fbbb0674 100644
--- a/backend/app/api/databases.py
+++ b/backend/app/api/databases.py
@@ -3,6 +3,7 @@ from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.database_service import DatabaseService
from app.middleware.rbac import admin_required
+from app.services.resource_grant_service import ResourceGrantService
databases_bp = Blueprint('databases', __name__)
@@ -621,7 +622,7 @@ def get_app_databases(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if app.app_type != 'docker' or not app.root_path:
diff --git a/backend/app/api/deploy.py b/backend/app/api/deploy.py
index 78e0aa5f..7556cfd6 100644
--- a/backend/app/api/deploy.py
+++ b/backend/app/api/deploy.py
@@ -2,6 +2,7 @@ from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.git_service import GitService
+from app.services.resource_grant_service import ResourceGrantService
deploy_bp = Blueprint('deploy', __name__)
@@ -31,7 +32,7 @@ def get_deploy_config(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
config = GitService.get_app_config(app_id)
@@ -93,7 +94,7 @@ def trigger_deploy(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -113,7 +114,7 @@ def pull_changes(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -133,7 +134,7 @@ def get_git_status(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
status = GitService.get_git_status(app.root_path)
@@ -151,7 +152,7 @@ def get_commit_info(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
commit_info = GitService.get_commit_info(app.root_path)
@@ -206,7 +207,7 @@ def get_branches(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
result = GitService.get_remote_branches(app.root_path)
diff --git a/backend/app/api/domains.py b/backend/app/api/domains.py
index 5608ee43..1a2beed6 100644
--- a/backend/app/api/domains.py
+++ b/backend/app/api/domains.py
@@ -5,6 +5,7 @@ from app import db
from app.models import Domain, Application, User
from app.services.nginx_service import NginxService
from app.services.ssl_service import SSLService
+from app.services.resource_grant_service import ResourceGrantService
domains_bp = Blueprint('domains', __name__)
@@ -111,7 +112,7 @@ def get_domain(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
return jsonify({'domain': domain.to_dict()}), 200
@@ -150,7 +151,7 @@ def create_domain():
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
# For Docker apps, validate port configuration
@@ -229,7 +230,7 @@ def update_domain(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json()
@@ -263,7 +264,7 @@ def delete_domain(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
application_id = domain.application_id
@@ -308,7 +309,7 @@ def enable_ssl(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
data = request.get_json() or {}
@@ -360,7 +361,7 @@ def disable_ssl(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
domain.ssl_enabled = False
@@ -383,7 +384,7 @@ def renew_ssl(domain_id):
return jsonify({'error': 'Domain not found'}), 404
app = Application.query.get(domain.application_id)
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if not domain.ssl_enabled:
diff --git a/backend/app/api/private_urls.py b/backend/app/api/private_urls.py
index 790da1e6..fd1e32a4 100644
--- a/backend/app/api/private_urls.py
+++ b/backend/app/api/private_urls.py
@@ -6,6 +6,7 @@ from app import db
from app.models import Application, User
from app.services.private_url_service import PrivateURLService
from app.services.nginx_service import NginxService
+from app.services.resource_grant_service import ResourceGrantService
private_urls_bp = Blueprint('private_urls', __name__)
@@ -30,7 +31,7 @@ def enable_private_url(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
# Check if already enabled
@@ -92,7 +93,7 @@ def get_private_url(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
return jsonify({
@@ -122,7 +123,7 @@ def update_private_url(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if not app.private_url_enabled:
@@ -174,7 +175,7 @@ def disable_private_url(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if not app.private_url_enabled:
@@ -211,7 +212,7 @@ def regenerate_private_url(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_edit_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if not app.private_url_enabled:
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.py
index dc73328e..df8de2dc 100644
--- a/backend/app/api/templates.py
+++ b/backend/app/api/templates.py
@@ -13,6 +13,7 @@ from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.deployment_job_service import DeploymentJobService
from app.services.template_service import TemplateService
+from app.services.resource_grant_service import ResourceGrantService
templates_bp = Blueprint('templates', __name__)
@@ -305,7 +306,7 @@ def check_app_update(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
result = TemplateService.check_updates(app_id)
@@ -338,7 +339,7 @@ def get_app_template_info(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
info = TemplateService.get_installed_info(app_id)
diff --git a/backend/app/services/resource_grant_service.py b/backend/app/services/resource_grant_service.py
index 72722a94..a163d7d3 100644
--- a/backend/app/services/resource_grant_service.py
+++ b/backend/app/services/resource_grant_service.py
@@ -39,6 +39,24 @@ class ResourceGrantService:
).first()
return row.role if row else None
+ # --- access helpers (the shared seam used by every app-related blueprint) ---
+
+ @staticmethod
+ def can_access_app(user, app):
+ """Read access to an application: owner, admin, or ANY grant (#33 ACL).
+ Uses user.id (int) — get_jwt_identity() is the stringified token id."""
+ if user.is_admin or app.user_id == user.id:
+ return True
+ return ResourceGrantService.user_has_grant(user.id, 'application', app.id)
+
+ @staticmethod
+ def can_edit_app(user, app):
+ """Write/operate access to an application: owner, admin, or an EDITOR
+ grant (#33 ACL). A viewer grant confers read access only."""
+ if user.is_admin or app.user_id == user.id:
+ return True
+ return ResourceGrantService.grant_role(user.id, 'application', app.id) == 'editor'
+
@staticmethod
def list_for_resource(resource_type, resource_id):
from app.models.workspace import ResourceGrant
diff --git a/backend/tests/test_resource_grants.py b/backend/tests/test_resource_grants.py
index a996e672..b5daa280 100644
--- a/backend/tests/test_resource_grants.py
+++ b/backend/tests/test_resource_grants.py
@@ -163,6 +163,29 @@ def test_grant_role_validation_and_default(app, client):
assert r.status_code == 400
+def test_grant_extends_to_other_app_blueprints(app, client):
+ """The grant-aware helper now gates the other app blueprints too — verify the
+ sweep wired it into builds.py (a separate blueprint from apps.py)."""
+ from app import db
+ from app.models import Application
+ from app.services.resource_grant_service import ResourceGrantService
+
+ owner = _mk_user(db, 'bp_owner')
+ grantee = _mk_user(db, 'bp_grantee')
+ stranger = _mk_user(db, 'bp_stranger')
+ a = Application(name='bp-app', app_type='php', user_id=owner.id)
+ db.session.add(a)
+ db.session.commit()
+
+ url = f'/api/v1/builds/apps/{a.id}/deployments' # GET, read
+ assert client.get(url, headers=_token(stranger.id)).status_code == 403
+ assert client.get(url, headers=_token(owner.id)).status_code == 200
+
+ ResourceGrantService.grant(user_id=grantee.id, resource_type='application',
+ resource_id=a.id, granted_by=owner.id, role='viewer')
+ assert client.get(url, headers=_token(grantee.id)).status_code == 200
+
+
def test_grant_enables_wordpress_per_site_routes(app, client):
from app import db
from app.models import Application, WordPressSite
diff --git a/docs/WORDPRESS_ROADMAP.md b/docs/WORDPRESS_ROADMAP.md
index 0159f8b9..0a341630 100644
--- a/docs/WORDPRESS_ROADMAP.md
+++ b/docs/WORDPRESS_ROADMAP.md
@@ -291,7 +291,7 @@ Highest-effort, broadest surface — but by now the `WordPressSite` is a first-c
- **Done when:** Each site exposes scoped SFTP credentials.
- **Assessment / why deferred:** The roadmap's host-sshd-chroot approach doesn't fit the Docker model — a managed site's files live in the `wordpress_html` **named volume**, not a host path, so a host-level chroot would target the wrong place. The **Docker-correct** design is a per-site **SFTP sidecar container** (e.g. `atmoz/sftp`) mounting `wordpress_html`, injected into the compose stack exactly like #23's redis (`_ensure_*_in_stack` + additive `compose up -d`), with a generated credential surfaced once and a new mapped port (via the template's port-allocation). That is genuinely implementable on the proven pattern — but it (a) opens a **publicly-exposed, security-sensitive file-access surface** that should be firewalled and that I cannot runtime-verify from the dev host, and (b) consumes a port + a container per site. Shipping security-sensitive infra blind violates the quality bar, so this is deferred for a focused pass on a real Docker host (where the sidecar, chroot perms, and firewall can be exercised). No code shipped.
-### #33 — Agency scale (workspaces, RBAC, white-label, reports) `[XL]` 🟡 — 🟡 In progress (✅ reports · workspace_id foundation · selector · brand color · resource reassignment · WP-hub scoping · **per-site ACL** (backend + sharing UI + viewer/editor roles + operate access); remaining: grant-awareness for env-vars/databases/domains blueprints, workspace↔User role reconciliation)
+### #33 — Agency scale (workspaces, RBAC, white-label, reports) `[XL]` 🟡 — 🟡 In progress (✅ reports · workspace_id foundation · selector · brand color · resource reassignment · WP-hub scoping · **per-site ACL** (backend + sharing UI + viewer/editor roles + operate access); remaining: workspace↔User role reconciliation, python.py helper split, workspace scoping for databases/domains)
- **Today:** No `workspace_id` FK on `Application`/`WordPressSite`/`Server`; permissions are global with no per-site ACL; white-label lives in `localStorage` and never reads `Workspace.logo_url`/`primary_color`.
- **Do:** Add `workspace_id` FKs + per-site ACL rows + environment-tier RBAC in promote/sync/bulk endpoints; server-side branding scoped to workspace; monthly client reports aggregating uptime/updates/backups/security.
- **Reuse:** `workspace_service`, `permission_service`, `audit_service`.
@@ -303,7 +303,7 @@ Highest-effort, broadest surface — but by now the `WordPressSite` is a first-c
- **Landed (workspace-scoped brand color):** the visible payoff — selecting a client workspace now recolors the whole panel to that client's brand. A workspace's `primary_color` (already on the model; now editable via a color picker added to the Workspaces create modal) is mirrored by the `WorkspaceSwitcher` into a `workspace_accent` localStorage key, and `ThemeContext` applies it via the existing `applyAccentToDOM` with **precedence over the user's personal accent** (`workspace_accent || accentColor`) — recoloring the logo gradient, buttons, and highlights. Deterministic (no effect-ordering races) because switching reloads and the value is read once on mount; cleared on logout and on a stale selection; reverts to the user accent on "All workspaces". Default color is the app accent, so a workspace is unbranded unless a custom color is chosen. Verified: frontend lint-clean (no new warnings) + production build. *(Deferred: per-workspace logo swap in the sidebar brand — the accent recolor is the high-impact piece and the default logo already recolors with the accent.)*
- **Landed (resource reassignment):** completes the organizing loop — existing resources were stuck wherever the backfill put them (Default); now they can be moved into client workspaces. New endpoints `PUT /apps/<id>/workspace` (owner-or-admin on the app) and `PUT /servers/<id>/workspace` (developer+), both requiring the **target** be a workspace the caller can access (member or admin); a null target moves a resource back to Default. UI: an **Apps** management modal on each Workspaces card (mirrors the Members modal) listing the workspace's apps with move-in/move-out — it fetches with `allWorkspaces` (an empty `X-Workspace-Id` header) so it can see apps in other workspaces to move them in, sidestepping the ambient scope. **Fixed a real bug** caught by tests: the ownership check compared `app.user_id` to the *stringified* `get_jwt_identity()` (int≠str → spurious 403); now uses `user.id`. Verified: backend `py_compile`, **2 new endpoint tests** (ownership + target-membership + null→Default + role gates), full suite **122 passed**, frontend lint-clean + production build. The management modal now handles **both apps and servers** (a "Resources" modal on each Workspaces card), each with move-in/move-out; servers fetch with the same `allWorkspaces` header bypass.
- **Landed (WordPress hub workspace scoping):** the active-workspace switcher now also filters the **WordPress sites hub**, not just apps/servers (it was the inconsistent gap). WP sites carry no `workspace_id` of their own, so `WordPressService.get_sites(workspace_id=…)` scopes **join-based** through the site's parent `Application.workspace_id`; `list_sites` resolves the active workspace and passes it. The hub is global today, so with no workspace context behavior is unchanged (additive, narrow-only). **No frontend change** — the WP hub already fetches through the header-injecting `api.request`, so it auto-scopes on the ambient `X-Workspace-Id`. Verified: backend `py_compile`, a new API test (global vs workspace-scoped), full suite **123 passed**. *(Follow-on for broad adoption: databases/domains are murkier — server-level vs app-child — and need their own analysis before scoping.)*
-- **Landed (per-site ACL — backend):** per-resource **sharing** — an owner/admin can grant a specific user access to a specific application (transitively its WordPress site / DB / domains) without that user owning it (access-level; per-grant view/edit roles reserved for later via a `role` column). New `ResourceGrant` model (Alembic **016**, unique per user×resource) + `ResourceGrantService` (grant/revoke/list/`user_has_grant`/`granted_ids`). **Enforcement at the cleanest seams:** `WorkspaceService.scope_query` gained `grant_resource_type` so granted apps appear in the apps list (own **OR** granted, then workspace-narrowed); `get_app` and — crucially — the WordPress `_owner_or_admin_app` helper became grant-aware, so **one change opens every WP per-site route** to a grantee. Grant-management API on `apps.py` (`GET/POST/DELETE /apps/<id>/grants`, owner-or-admin; can't grant to the owner; revoke is resource-scoped so you can't revoke another app's grant by id). Also uses `user.id` (int) not the stringified `get_jwt_identity()`. Verified: **4 new ACL tests** (visibility via list, get_app, WP route access, management perms + idempotency + revoke), full suite **127 passed**, end-to-end `alembic upgrade` to `016`. **Sharing UI (shipped):** a per-app **Share** action in the Workspaces "Resources" modal opens an inline sub-view (grant a user → access list with revoke; the owner and existing grantees are filtered out of the add-list); client methods `getAppGrants`/`grantAppAccess`/`revokeAppAccess`. Verified: frontend lint-clean + build. **Viewer/editor roles + operate access (shipped):** grants now carry a real **role** — `editor` (view + operate) or `viewer` (read-only) — and the generic app **operate** endpoints became grant-aware. Two helpers split it: `_can_access_app` (owner/admin/**any** grant) gates reads (`get_app`, `/linked`, `/logs`, `/container-logs`, `/containers`, `/status`), `_can_edit_app` (owner/admin/**editor** grant) gates mutations (`/link`, `/unlink`, `/environment`, `PUT`, `/start`, `/stop`, `/restart`); `ResourceGrantService.grant_role` backs the split. **Delete stays owner-or-admin** (an editor can't delete — tested). The grant POST validates `role ∈ {viewer, editor}` (default editor); the Sharing UI gained a role selector. The same sweep **fixed the latent int-vs-str ownership bug** across ~14 app endpoints (they compared `app.user_id` to the stringified `get_jwt_identity()` — now `user.id`). Verified: **3 more ACL tests** (viewer read-only + can't-operate, editor operates + can't-delete, role validation/default), full suite **130 passed**, frontend lint-clean + build. *(Still owner-only / not-yet-grant-aware: the separate env-vars / databases / domains endpoints in other blueprints — a follow-up sweep.)*
+- **Landed (per-site ACL — backend):** per-resource **sharing** — an owner/admin can grant a specific user access to a specific application (transitively its WordPress site / DB / domains) without that user owning it (access-level; per-grant view/edit roles reserved for later via a `role` column). New `ResourceGrant` model (Alembic **016**, unique per user×resource) + `ResourceGrantService` (grant/revoke/list/`user_has_grant`/`granted_ids`). **Enforcement at the cleanest seams:** `WorkspaceService.scope_query` gained `grant_resource_type` so granted apps appear in the apps list (own **OR** granted, then workspace-narrowed); `get_app` and — crucially — the WordPress `_owner_or_admin_app` helper became grant-aware, so **one change opens every WP per-site route** to a grantee. Grant-management API on `apps.py` (`GET/POST/DELETE /apps/<id>/grants`, owner-or-admin; can't grant to the owner; revoke is resource-scoped so you can't revoke another app's grant by id). Also uses `user.id` (int) not the stringified `get_jwt_identity()`. Verified: **4 new ACL tests** (visibility via list, get_app, WP route access, management perms + idempotency + revoke), full suite **127 passed**, end-to-end `alembic upgrade` to `016`. **Sharing UI (shipped):** a per-app **Share** action in the Workspaces "Resources" modal opens an inline sub-view (grant a user → access list with revoke; the owner and existing grantees are filtered out of the add-list); client methods `getAppGrants`/`grantAppAccess`/`revokeAppAccess`. Verified: frontend lint-clean + build. **Viewer/editor roles + operate access (shipped):** grants now carry a real **role** — `editor` (view + operate) or `viewer` (read-only) — and the generic app **operate** endpoints became grant-aware. Two helpers split it: `_can_access_app` (owner/admin/**any** grant) gates reads (`get_app`, `/linked`, `/logs`, `/container-logs`, `/containers`, `/status`), `_can_edit_app` (owner/admin/**editor** grant) gates mutations (`/link`, `/unlink`, `/environment`, `PUT`, `/start`, `/stop`, `/restart`); `ResourceGrantService.grant_role` backs the split. **Delete stays owner-or-admin** (an editor can't delete — tested). The grant POST validates `role ∈ {viewer, editor}` (default editor); the Sharing UI gained a role selector. The same sweep **fixed the latent int-vs-str ownership bug** across ~14 app endpoints (they compared `app.user_id` to the stringified `get_jwt_identity()` — now `user.id`). Verified: **3 more ACL tests** (viewer read-only + can't-operate, editor operates + can't-delete, role validation/default), full suite **130 passed**, frontend lint-clean + build. **Cross-blueprint sweep (shipped):** the per-resource grant now extends to every app-related blueprint, not just apps.py + WordPress. The two access helpers were promoted to a shared seam (`ResourceGrantService.can_access_app` / `can_edit_app`; `apps.py` delegates), and **33 ownership checks across 6 blueprints** were made grant-aware, categorized read-vs-mutate (via a parallel mapping workflow): `builds.py` (12), `domains.py` (7, incl. SSL enable/disable/renew + domain CRUD = editor), `deploy.py` (6), `private_urls.py` (5), `templates.py` (2), `databases.py` (1). Reads → any grant; mutates → editor grant. The sweep also **fixed the same latent int-vs-str ownership bug** in all 33 (now `user.id`). Verified: a cross-blueprint integration test (grantee reaches `builds` deployments; stranger 403), full suite **131 passed**. *(Deferred: `python.py`'s single `get_app_or_404` helper gates read+mutate+delete together — needs per-method splitting before it's safe to make grant-aware.)*
### #34 — Horizontal scaling `[XL]` ❌ — ⏸️ Deferred (XL + blocked on the same per-site reverse-proxy/upstream layer as #21)
- **Today:** `nginx_advanced_service` has load-balancing primitives (round-robin/least-conn/IP-hash) but WP containers are stateful (local uploads, no shared object cache).