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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(servers): require developer role for agent self-update (audit H3)
Juan Denis6eb447182946
diff --git a/backend/app/api/servers.py b/backend/app/api/servers.pyindex 753da23d..cf79622e 100644--- a/backend/app/api/servers.py+++ b/backend/app/api/servers.py@@ -2115,11 +2115,16 @@ def get_agent_checksums():@servers_bp.route('/<server_id>/agent/update', methods=['POST'])@jwt_required()+@developer_requireddef trigger_agent_update(server_id):"""Trigger an agent update on a specific server.Sends a command to the agent to check for and install updates.++ Developer role required — this replaces the agent binary and restarts the+ service across the fleet, so it must not be reachable by read-only viewers+ (every other state-changing server route is already @developer_required)."""server = Server.query.get(server_id)if not server:diff --git a/backend/tests/test_agent_update_authz.py b/backend/tests/test_agent_update_authz.pynew file mode 100644index 00000000..4b93a10a--- /dev/null+++ b/backend/tests/test_agent_update_authz.py@@ -0,0 +1,62 @@+"""+Authorization regression test for the agent self-update endpoint.++POST /api/v1/servers/<id>/agent/update replaces the agent binary and restarts+the service. It used to be @jwt_required() only, so a read-only `viewer` could+trigger fleet-wide updates/restarts — every other state-changing server route is+@developer_required. This locks it to developer+ and proves both directions.+"""+from flask_jwt_extended import create_access_token+from werkzeug.security import generate_password_hash++from app import db+from app.models import User+from app.models.server import Server+++def _user(role):+ u = User(+ email=f"{role}@authz.local",+ username=f"{role}-authz",+ password_hash=generate_password_hash("x"),+ role=role,+ is_active=True,+ )+ db.session.add(u)+ db.session.commit()+ return u+++def _headers(user):+ return {"Authorization": f"Bearer {create_access_token(identity=user.id)}"}+++def _server():+ s = Server(name="authz-srv", agent_id="authz-agent")+ db.session.add(s)+ db.session.commit()+ return s.id+++def test_viewer_cannot_trigger_agent_update(client, app):+ with app.app_context():+ headers = _headers(_user(User.ROLE_VIEWER))+ server_id = _server()++ resp = client.post(f"/api/v1/servers/{server_id}/agent/update",+ headers=headers, json={})+ assert resp.status_code == 403, resp.get_data(as_text=True)+++def test_developer_passes_the_role_gate(client, app):+ """A developer clears the role gate. The request then fails downstream+ (503, no agent connected) — which is exactly what proves the gate let them+ through rather than blocking with 403."""+ with app.app_context():+ headers = _headers(_user(User.ROLE_DEVELOPER))+ server_id = _server()++ resp = client.post(f"/api/v1/servers/{server_id}/agent/update",+ headers=headers, json={})+ assert resp.status_code != 403, resp.get_data(as_text=True)+ assert resp.status_code == 503, resp.get_data(as_text=True) # agent offline