Skip to content

TLS Certificate Pinning & Token Authentication

StackPilot secures all communication between the Central Hub and remote Host Agents using cryptographic certificate pinning and rotating bearer tokens.


1. Dual-Phase Host Enrollment Flow

sequenceDiagram autonumber actor Admin as Administrator participant Hub as Central Hub participant Node as Managed Linux Host Admin->>Hub: Click "Add Host" Hub->>Hub: Generate Short-Lived Enrollment Token Hub-->>Admin: Display 1-line curl enrollment command Admin->>Node: Execute curl command Node->>Hub: GET /api/agents/install.sh (Bearer Enrollment Token) Note over Node,Hub: Hub verifies enrollment token and returns installer script Node->>Node: Generate RSA 2048-bit Key & Self-Signed TLS Cert Node->>Hub: POST /api/agents/fingerprint (Sends Cert PEM) Hub->>Hub: Calculate & Pin SHA-256 Fingerprint Hub->>Hub: Generate Dedicated Node Runtime Token Hub-->>Node: Return Runtime Token Node->>Node: Save Token to ~/.stackpilot_agent_token (0600) Node->>Node: Start Agent Service with TLS Listener (:9091) Hub->>Node: GET /api/status (Header: X-Agent-Token) Node-->>Hub: Return Node Metrics & Container List

2. Pinned CA Verification

When the Central Hub operates over HTTPS: 1. The Hub's public TLS certificate is embedded directly into the installer script dynamically. 2. All download operations (curl) and Python API calls (urllib.request) enforce --cacert verification against the embedded CA certificate. 3. This prevents active adversary MitM attacks on local networks during initial node onboarding.

The initial command that downloads the installer also verifies TLS. It uses the operating-system trust store and never adds curl -k. A Hub using a private or self-signed certificate must therefore be accessed through a trusted reverse proxy, have its CA installed on the target host, or be downloaded with an explicitly supplied --cacert /path/to/hub-ca.pem option obtained through a separate trusted channel.


3. Token Storage & Permissions

  • Agent Host: The runtime bearer token is written exclusively to ~/.stackpilot_agent_token with strict permissions:
    chmod 600 ~/.stackpilot_agent_token
    
  • Central Hub: Stored in ~/.config/stackpilot/agent-tokens.json (also permissions 0600).
  • Rotation: Tokens can be rotated at any time from the Hub's host settings without restarting host containers.

4. Agent Listener Security

The agent fails closed if its TLS certificate or private key cannot be created, read, or loaded. It does not silently expose the management API over plaintext HTTP.

Installed services set these defaults explicitly:

Environment=STACKPILOT_AGENT_BIND=0.0.0.0
Environment=STACKPILOT_AGENT_ALLOW_INSECURE_HTTP=false

STACKPILOT_AGENT_BIND may be set to a specific management-interface address to reduce network exposure.

Plain HTTP is available only for local development by setting STACKPILOT_AGENT_ALLOW_INSECURE_HTTP=true. In that mode, the agent accepts only a loopback bind address such as 127.0.0.1 or ::1; it refuses to start if configured on a non-loopback address.