-
Notifications
You must be signed in to change notification settings - Fork 0
Security and Clustering
This page explains web/network/SSL security and the host/subhost clustering model with its workflows and APIs.
The WebSecurityManager (Modules/security/web_security.py) provides web application security through multiple integrated components:
Rate Limiting:
- The
RateLimiterclass implements sliding window rate limiting. - Tracks request counts per IP address within configurable time windows.
- Configurable limits per endpoint or globally.
Account Lockout:
- The
AccountLockoutclass protects against brute-force attacks. - After 5 failed login attempts within 5 minutes, the account is locked for 15 minutes.
- Lockout status and remaining attempts are communicated in API responses.
CSRF Protection:
- The
CSRFProtectionclass generates and validates CSRF tokens for form submissions. - Tokens are tied to user sessions and have configurable expiration.
Input Validation:
- The
InputValidatorclass detects and blocks common attack patterns:- SQL Injection — Detects common SQL injection patterns (UNION SELECT, OR 1=1, DROP TABLE, etc.).
-
XSS (Cross-Site Scripting) — Detects script injection attempts (
<script>,javascript:,onerror=, etc.). -
Path Traversal — Detects directory traversal patterns (
../,..\\,%2e%2e).
Client-Side XSS Prevention:
- The
escapeHtml()utility function in the web interface sanitises API response data before rendering into the DOM. - All dynamic content rendered via
innerHTMLis escaped to prevent stored/reflected XSS from server data.
Path Security:
- The
PathSecurityclass provides safe path joining that prevents directory traversal. - All file paths are validated to ensure they remain within allowed directories.
IP Security:
- The
IPSecurityclass manages IP allowlisting for sensitive operations.
Security Headers: The web server applies standard security headers to all responses:
-
Content-Security-Policy(CSP) — Restricts resource loading origins. -
Strict-Transport-Security(HSTS) — Enforces HTTPS when SSL is enabled. -
X-Frame-Options— Prevents clickjacking (set to DENY). -
X-Content-Type-Options— Prevents MIME-type sniffing (set to nosniff). -
X-XSS-Protection— Enables browser XSS filters. -
Referrer-Policy— Controls referrer information leakage.
The network security module (Modules/security/network_security.py) provides Flask decorators for network-level access control:
@require_allowed_network() — Restricts access to requests from allowed network ranges. Default allowed networks include:
-
127.0.0.0/8— Localhost (always allowed) -
10.0.0.0/8— Private network (Class A) -
172.16.0.0/12— Private network (Class B) -
192.168.0.0/16— Private network (Class C)
@require_cluster_network_security() — Additional restrictions for cluster API endpoints, ensuring only authorised cluster nodes can communicate.
The SSL utilities module (Modules/security/ssl_utils.py) manages SSL/TLS certificates for secure HTTPS communication:
Self-Signed Certificate Generation:
- Generates RSA 2048-bit key pairs.
- Creates X.509 certificates with Subject Alternative Names (SANs) that include all local IP addresses, the hostname, and localhost.
- Certificate validity is set to 1 year by default.
- Certificates and keys are stored in the
ssl/directory asserver.crtandserver.key.
Certificate Verification:
- Validates existing certificates for expiration, key matching, and SAN coverage.
- Reports certificate details including issuer, subject, validity period, and SANs.
Auto-Provisioning:
- If SSL is enabled but no certificate exists, one is automatically generated.
- If an existing certificate is expired or invalid, it is regenerated.
CLI Interface:
python Modules/security/ssl_utils.py generate # Generate a new self-signed certificate
python Modules/security/ssl_utils.py verify # Verify the existing certificate
python Modules/security/ssl_utils.py info # Display certificate detailsThe cluster security module (Modules/security/cluster_security.py, SimpleClusterManager) manages cluster membership:
- Master/Node Topology — A single Host acts as the cluster master, with Subhost nodes joining as members.
- Join Request Workflow — Nodes must request to join, and the Host admin must approve each request. This prevents unauthorized nodes from joining the cluster.
- Dual Storage — Cluster role configuration is stored in both the Windows Registry and the cluster database for redundancy.
- Token-Based Authentication — Cluster communication uses token-based authentication with expiration and revocation support.
Server Manager supports a basic clustering model with two roles:
Host:
- Acts as the central management server.
- Runs the full web interface, API, and dashboard.
- Processes join requests from Subhost nodes.
- Can remotely manage servers on connected Subhosts by proxying API calls.
- Maintains the cluster database with all node information.
Subhost:
- Connects to an existing Host node.
- Runs a local dashboard on port 5002.
- Sends periodic heartbeats to the Host to report status.
- Responds to remote management commands forwarded by the Host.
- Sets the
CLUSTER_HOST_URLenvironment variable for Host discovery.
Communication Protocol: All cluster communication uses HTTP/HTTPS REST API calls between nodes. The Host proxies requests to Subhosts by forwarding them to the Subhost's API endpoint and returning the response.
The cluster join workflow follows a request-and-approval pattern:
-
Request: A Subhost sends a join request to the Host:
POST /api/cluster/request-joinwith node name and IP address. The request is stored in thepending_requeststable. -
Review: The Host administrator views pending requests in the dashboard or cluster management web page. Each request shows the requesting node's name, IP address, and request timestamp.
-
Approve or Reject: The administrator can:
-
Approve (
POST /api/cluster/requests/<id>/approve) — The node is added to thecluster_nodestable with "approved" status, and an authentication token is generated. -
Reject (
POST /api/cluster/requests/<id>/reject) — The request is removed from the pending queue.
-
Approve (
-
Polling: The Subhost periodically checks
GET /api/cluster/check-approval/<id>to see if its request has been approved. Once approved, it receives its authentication token and begins sending heartbeats. -
Heartbeat: Approved Subhosts send periodic heartbeats (
POST /api/cluster/heartbeat) to update theirlast_pingtimestamp. The heartbeat includes node name, IP, port, and server count. Nodes that stop sending heartbeats are eventually marked as offline. -
Revocation: The Host administrator can revoke a node at any time (
DELETE /api/cluster/nodes/<id>), which removes it from the cluster.
The cluster API is implemented as a Flask Blueprint (api/cluster.py) and registered under /api/cluster/:
Join Workflow:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/cluster/request-join |
Submit a join request |
| GET | /api/cluster/requests |
List pending join requests |
| POST | /api/cluster/requests/<id>/approve |
Approve a join request |
| POST | /api/cluster/requests/<id>/reject |
Reject a join request |
| GET | /api/cluster/check-approval/<id> |
Check approval status |
Node Management:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/cluster/nodes |
List all cluster nodes |
| DELETE | /api/cluster/nodes/<id> |
Revoke (remove) a node |
Subhost Management:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/cluster/subhosts |
List subhosts with status |
| POST | /api/cluster/heartbeat |
Send node heartbeat |
Status:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/cluster/status |
Get cluster status summary |
| GET | /api/cluster/host-status |
Get host status details |
| GET | /api/cluster/role |
Get this node's cluster role |
Remote Server Operations (Host Only):
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/cluster/subhost/<id>/servers |
List servers on a subhost |
| POST | /api/cluster/subhost/<id>/servers |
Create a server on a subhost |
| DELETE | /api/cluster/subhost/<id>/servers/<name> |
Remove a server from a subhost |
| POST | /api/cluster/subhost/<id>/servers/<name>/start |
Start a server on a subhost |
| POST | /api/cluster/subhost/<id>/servers/<name>/stop |
Stop a server on a subhost |
| POST | /api/cluster/subhost/<id>/servers/<name>/restart |
Restart a server on a subhost |
All remote server operations are forwarded to the target Subhost's API via _forward_request_to_subhost().
The Agent Manager (Modules/ui/agents.py) provides a Tkinter GUI for cluster administration:
The GUI includes:
- Cluster Status Panel — Shows the current cluster role, number of registered nodes, and overall cluster health.
- Pending Requests Section — A tree view of pending join requests with Approve and Reject buttons. Each request shows the node name, IP address, and request time.
- Registered Nodes Section — A tree view of all cluster nodes with status indicators (online/offline). An "Add Node" form allows manually registering nodes. A right-click context menu provides: Ping Node, View Servers, Remove Node.
- Background Polling — The GUI polls the cluster database every 5 seconds to update node statuses and detect new join requests.
Node Pinging: The ping_node() method sends an HTTP request to GET /api/status on the target node to verify connectivity and retrieve basic status information.