fix(security): F23 (Astra P1) — DB-weiter Restore nur noch fuer System-Admins
Vorher: POST /api/v1/backups/{id}/restore war ueber automation:admin
eines Mandanten erreichbar — der Restore bearbeitet aber die GESAMTE
geteilte Datenbank ohne Mandantenfilter. Ein Tenant-Admin haette den
Zustand aller Mandanten ueberschreiben koennen.
Fix: Restore-Route auf require_admin umgestellt (echter System-Admin:
is_system_admin oder *:* via RBAC). Listen/Erstellen/Loeschen von
Backups bleibt mandantenbezogen auf automation:admin.
Abnahme (Astra): Ein Tenant-Admin kann keinen Gesamtrestore ausloesen —
erfuellt (Route-Introspektions-Tests pinnen die Verdrahtung).
Tests: test_s1_security_guards.py 12/12 (2 neue F23-Tests: restore nutzt
require_admin, restore nutzt NICHT require_permission).
This commit is contained in:
@@ -221,3 +221,45 @@ class TestF03SessionRevocation:
|
||||
assert _rejects("invited") is True
|
||||
# active membership → allow
|
||||
assert _rejects("active") is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestF23RestoreRequiresSystemAdmin:
|
||||
"""F23 (Astra P1): a full-database restore is a GLOBAL operations
|
||||
action — a tenant admin (automation:admin) must not be able to
|
||||
trigger it. Route introspection pins the dependency wiring.
|
||||
"""
|
||||
|
||||
def _find_restore_route(self):
|
||||
"""Find the POST /{backup_id}/restore route on the backups router."""
|
||||
from app.routes.backups import router
|
||||
|
||||
for route in router.routes:
|
||||
if "restore" in getattr(route, "path", ""):
|
||||
return route
|
||||
return None
|
||||
|
||||
async def test_restore_route_uses_require_admin(self):
|
||||
from app.deps import require_admin
|
||||
|
||||
route = self._find_restore_route()
|
||||
assert route is not None, "restore route not found"
|
||||
deps = list(getattr(route, "dependencies", []))
|
||||
assert any(getattr(d, "dependency", None) is require_admin for d in deps), (
|
||||
"F23: restore route must depend on require_admin (system admin), "
|
||||
"not automation:admin"
|
||||
)
|
||||
|
||||
async def test_restore_route_not_tenant_admin(self):
|
||||
from app.deps import require_permission
|
||||
|
||||
route = self._find_restore_route()
|
||||
assert route is not None
|
||||
deps = list(getattr(route, "dependencies", []))
|
||||
for d in deps:
|
||||
dep_fn = getattr(d, "dependency", None)
|
||||
assert dep_fn is not require_permission, (
|
||||
"F23: restore route must not use require_permission("
|
||||
"automation:admin) — a tenant admin must not trigger a "
|
||||
"full-database restore"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user