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.

fix(plugins): make plugin/template features fail honestly, not silently (audit H2)

Juan Denisa34064d15a83
diff --git a/backend/app/services/agent_plugin_service.py b/backend/app/services/agent_plugin_service.py
index 6bd44d6c..b4aef1d4 100644
--- a/backend/app/services/agent_plugin_service.py
+++ b/backend/app/services/agent_plugin_service.py
@@ -152,27 +152,15 @@ class AgentPluginService:
install.config = config
db.session.add(install)
+ # Agent-side plugin execution is NOT implemented: the Go agent has no
+ # plugin_install handler and there is no panel gateway to route one to.
+ # The previous code called a non-existent get_agent_gateway() and
+ # swallowed the resulting ImportError, leaving the row stuck in
+ # 'installing' forever. Fail honestly so the UI reflects reality.
+ install.status = AgentPluginInstall.STATUS_ERROR
+ install.error_message = 'Agent-side plugin support is not implemented yet'
db.session.commit()
- # Send install command to agent
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw:
- gw.send_command(server.agent_id, 'plugin_install', {
- 'plugin_name': plugin.name,
- 'version': plugin.version,
- 'manifest': plugin.manifest,
- 'config': install.config,
- 'permissions': plugin.permissions,
- 'resource_limits': {
- 'max_memory_mb': plugin.max_memory_mb,
- 'max_cpu_percent': plugin.max_cpu_percent,
- }
- })
- except Exception as e:
- logger.warning(f'Could not send plugin install command: {e}')
-
return install
@staticmethod
@@ -181,20 +169,11 @@ class AgentPluginService:
if not install:
return False
+ # No agent-side plugin runtime exists to notify; uninstall is local-only
+ # bookkeeping. (Previously dispatched to a non-existent get_agent_gateway.)
install.status = AgentPluginInstall.STATUS_UNINSTALLING
db.session.commit()
- # Send uninstall command to agent
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw and install.server:
- gw.send_command(install.server.agent_id, 'plugin_uninstall', {
- 'plugin_name': install.plugin.name,
- })
- except Exception as e:
- logger.warning(f'Could not send plugin uninstall command: {e}')
-
return True
@staticmethod
@@ -211,19 +190,10 @@ class AgentPluginService:
install = AgentPluginInstall.query.get(install_id)
if not install:
return None
+ # Local-only state change; no agent-side plugin runtime to notify.
install.status = AgentPluginInstall.STATUS_DISABLED
db.session.commit()
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw and install.server:
- gw.send_command(install.server.agent_id, 'plugin_disable', {
- 'plugin_name': install.plugin.name,
- })
- except Exception as e:
- logger.warning(f'Could not send plugin disable command: {e}')
-
return install
@staticmethod
@@ -247,20 +217,10 @@ class AgentPluginService:
install = AgentPluginInstall.query.get(install_id)
if not install:
return None
+ # Local-only config persistence; no agent-side plugin runtime to notify.
install.config = config
db.session.commit()
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw and install.server:
- gw.send_command(install.server.agent_id, 'plugin_configure', {
- 'plugin_name': install.plugin.name,
- 'config': config,
- })
- except Exception as e:
- logger.warning(f'Could not send plugin config update: {e}')
-
return install
@staticmethod
diff --git a/backend/app/services/server_template_service.py b/backend/app/services/server_template_service.py
index b034ae9f..f3d1e68a 100644
--- a/backend/app/services/server_template_service.py
+++ b/backend/app/services/server_template_service.py
@@ -316,22 +316,17 @@ class ServerTemplateService:
if not assignment:
return None
- assignment.status = ServerTemplateAssignment.STATUS_CHECKING
+ # Agent-side config drift checking is NOT implemented (the agent has no
+ # config_drift_check handler, and the old code dispatched to a
+ # non-existent get_agent_gateway()). Report honestly instead of leaving
+ # the assignment stuck in 'checking' forever.
+ assignment.status = ServerTemplateAssignment.STATUS_UNKNOWN
+ assignment.drift_report = {
+ 'error': 'Agent-side configuration drift checking is not implemented yet',
+ }
+ assignment.last_check_at = datetime.utcnow()
db.session.commit()
- # Send drift check command to agent
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw and assignment.server:
- spec = assignment.template.get_merged_spec()
- gw.send_command(assignment.server.agent_id, 'config_drift_check', {
- 'assignment_id': assignment.id,
- 'spec': spec,
- })
- except Exception as e:
- logger.warning(f'Could not send drift check command: {e}')
-
return assignment
@staticmethod
@@ -359,21 +354,16 @@ class ServerTemplateService:
if not assignment:
return None
- assignment.status = ServerTemplateAssignment.STATUS_REMEDIATING
+ # Agent-side remediation is NOT implemented (no config_remediate handler;
+ # old code dispatched to a non-existent get_agent_gateway()). Report
+ # honestly instead of leaving the assignment stuck in 'remediating'.
+ assignment.status = ServerTemplateAssignment.STATUS_UNKNOWN
+ assignment.drift_report = {
+ 'error': 'Agent-side template remediation is not implemented yet',
+ }
+ assignment.last_remediation_at = datetime.utcnow()
db.session.commit()
- try:
- from app.agent_gateway import get_agent_gateway
- gw = get_agent_gateway()
- if gw and assignment.server:
- spec = assignment.template.get_merged_spec()
- gw.send_command(assignment.server.agent_id, 'config_remediate', {
- 'assignment_id': assignment.id,
- 'spec': spec,
- })
- except Exception as e:
- logger.warning(f'Could not send remediate command: {e}')
-
return assignment
@staticmethod
diff --git a/backend/tests/test_agent_features_honest.py b/backend/tests/test_agent_features_honest.py
new file mode 100644
index 00000000..38c42728
--- /dev/null
+++ b/backend/tests/test_agent_features_honest.py
@@ -0,0 +1,65 @@
+"""
+Regression tests for audit H2: the Agent Plugin and Server Template features
+used to dispatch to a non-existent `get_agent_gateway()` (ImportError, swallowed)
+and leave DB rows stuck in an in-progress state forever. The agent implements
+none of these commands. These tests assert the operations now report honestly
+instead of silently pretending to work.
+"""
+from app import db
+from app.models.server import Server
+from app.models.agent_plugin import AgentPlugin, AgentPluginInstall
+from app.models.server_template import ServerTemplate, ServerTemplateAssignment
+from app.services.agent_plugin_service import AgentPluginService
+from app.services.server_template_service import ServerTemplateService
+
+
+def test_plugin_install_reports_unimplemented_not_stuck_installing(app):
+ with app.app_context():
+ plugin = AgentPluginService.create_plugin({
+ "name": "demo-plugin",
+ "display_name": "Demo Plugin",
+ "version": "1.0.0",
+ })
+ server = Server(name="srv", agent_id="agent-h2-1")
+ db.session.add(server)
+ db.session.commit()
+
+ install = AgentPluginService.install_plugin(plugin.id, server.id)
+
+ # Honest failure, not a permanent 'installing' limbo.
+ assert install.status == AgentPluginInstall.STATUS_ERROR
+ assert install.status != AgentPluginInstall.STATUS_INSTALLING
+ assert "not implemented" in (install.error_message or "").lower()
+
+
+def test_template_drift_check_reports_unimplemented_not_stuck_checking(app):
+ with app.app_context():
+ tmpl = ServerTemplate(name="base-template", version="1.0.0")
+ server = Server(name="srv2", agent_id="agent-h2-2")
+ db.session.add_all([tmpl, server])
+ db.session.commit()
+ assignment = ServerTemplateAssignment(template_id=tmpl.id, server_id=server.id)
+ db.session.add(assignment)
+ db.session.commit()
+
+ result = ServerTemplateService.check_drift(assignment.id)
+
+ assert result.status == ServerTemplateAssignment.STATUS_UNKNOWN
+ assert result.status != ServerTemplateAssignment.STATUS_CHECKING
+ assert "not implemented" in (result.drift_report.get("error") or "").lower()
+
+
+def test_template_remediate_reports_unimplemented(app):
+ with app.app_context():
+ tmpl = ServerTemplate(name="base-template-2", version="1.0.0")
+ server = Server(name="srv3", agent_id="agent-h2-3")
+ db.session.add_all([tmpl, server])
+ db.session.commit()
+ assignment = ServerTemplateAssignment(template_id=tmpl.id, server_id=server.id)
+ db.session.add(assignment)
+ db.session.commit()
+
+ result = ServerTemplateService.remediate(assignment.id)
+
+ assert result.status == ServerTemplateAssignment.STATUS_UNKNOWN
+ assert "not implemented" in (result.drift_report.get("error") or "").lower()