[Design Discussion] Bi-directional communication channel for private Data Plane to Control Plane communication #4271
Replies: 3 comments 1 reply
Pros and Cons of Using WebSockets vs. VPN for Connecting a Private Data Plane (PDP)Option 1: WebSocketPros
Cons
Option 2: VPNPros
Cons
|
Architectural Decision Matrix: In-App WebSocket vs. Product-Managed Tunnel/VPN SidecarBy having the product team package and manage an automated network tunnel or overlay VPN (e.g., a bundled WireGuard, Tailscale, or Cloudflare Tunnel sidecar/agent), we maintain a strict separation of concerns. This keeps the core ThunderID Identity Provider (IdP) codebase focused purely on identity services (using standard REST/gRPC endpoints) while offloading complex connection state and firewall traversal to a dedicated, battle-tested networking component. Scoring Scale
Decision Matrix Table
Key Architectural Takeaways
|
CP↔DP transport — decision matrixOptions
Scale assumption: 10k DPs × 3 pods = 30k pods Scoring: 3 = High (optimal outcome, minimal effort, low operational risk) · 2 = Medium (acceptable trade-off, moderate effort) · 1 = Low (high friction, disproportionate overhead, high operational risk). Half-points where merged criteria disagreed.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Related Feature Issue
#4247
Problem Summary
Data Plane instances deployed in private networks or corporate VPCs cannot accept inbound traffic from the Control Plane due to strict firewall and NAT restrictions. This prevents the Control Plane from pushing real-time updates and operational commands without forcing users to expose endpoints or configure complex, insecure network rules. To resolve this, we need an outbound "phone-home" architecture where the Data Plane initiates a persistent, bi-directional channel (such as WebSockets or gRPC streaming) back to the Control Plane.
High-Level Approach
To solve the private network connectivity problem, we propose implementing an outbound agent model ("Phone-Home") where the Data Plane (DP) initiates and maintains a long-lived outbound connection to the Control Plane (CP).
Primary Recommendation: WebSocket Agent Architecture
We lean toward a WebSocket (WSS over Port 443) implementation due to its minimal network requirements and ease of integration across standard cloud infrastructure.
Connection Lifecycle:
Reverse RPC Protocol:
Alternative Approaches Under Consideration
To ensure we choose the optimal long-term architecture for ThunderID, we want to evaluate three alternative patterns alongside WebSockets:
gRPC Bidirectional Streaming (HTTP/2)
Overview: Similar to WebSockets, but uses persistent HTTP/2 streams and binary Protocol Buffers.
Pros/Cons: Offers superior performance and strict schema contracts, but requires intermediate load balancers and reverse proxies to fully support end-to-end HTTP/2 multiplexing.
Centralized Message Broker (e.g., NATS / RabbitMQ)
Overview: Both CP and DP connect as clients to a central message broker using Request-Reply patterns.
Pros/Cons: Completely decouples CP and DP state management and handles offline command queuing automatically, but introduces an extra stateful infrastructure dependency to operate.
Reverse Network Tunneling (e.g., WireGuard / Cloudflare Tunnel / frp)
Overview: DP runs a tunnel agent establishing an encrypted network bridge, allowing CP to make standard HTTP/REST calls as if DP were locally accessible.
Pros/Cons: Allows us to keep plain REST APIs on the DP without custom socket wrappers, but increases operational complexity by requiring external tunnel management or sidecars.
Architecture Overview
1. High-Level Architecture Concept
ThunderID utilizes an Agent-Driven, Outbound WebSocket Architecture (commonly known as the "Phone-Home" pattern) to bridge the communication gap between the Control Plane (CP) and Data Plane (DP).
In enterprise environments, Data Planes are frequently deployed within isolated private networks, VPCs, or edge environments protected by strict firewalls that disallow inbound traffic. To circumvent these restrictions without introducing security vulnerabilities or requiring custom network configurations, the Data Plane acts as an active client that establishes a persistent outbound WebSocket connection (
wss://) to the Control Plane.Once established, this continuous full-duplex stream enables bi-directional communication, allowing the CP to push real-time commands, configuration updates, and operational tasks down to the DP via a structured JSON-RPC 2.0 protocol over WebSocket frames.
2. System Components & Topology
Component Breakdown
Data Plane WS Agent (Client):
Control Plane WS Gateway (Server):
3. Communication Workflows
Phase 1: Connection & Authentication Handshake
Phase 2: Reverse RPC Command Dispatch
When the Control Plane needs to trigger an action on a specific Data Plane (e.g., updating access rules):
Security Considerations
Because the Data Plane operates inside a private network with administrative capabilities over local workloads, the persistent WebSocket channel between the Control Plane (CP) and Data Plane (DP) must be secured against unauthorized access, command injection, and session hijacking.
1. Authentication & Identity Verification
DataPlaneID.Authorizationheader during the initial HTTPUpgraderequest.2. Transport Layer Security (TLS / WSS)
ws://) connections are strictly prohibited. All communication must occur overwss://on port 443.3. Command Validation & Least Privilege
Policy.Sync,Agent.Ping, etc.).MethodNotFound (-32601)error.params) must be validated against a strict JSON Schema before execution to protect against command injection, memory corruption, or path traversal attacks.DataPlaneIDbound to the socket, preventing cross-tenant command leakage.4. Replay Attack & Tamper Prevention
request_idalong with a timestamp.request_idwithin a given cache TTL.5. Connection Hijacking & Session Management
DataPlaneID.DataPlaneID, the CP must authenticate the new request, forcefully terminate the legacy socket, and log a security audit event.6. Denial of Service (DoS) & Resource Isolation
7. Audit Logging & Observability
request_id,method,origin_user_id, and timestamp.Impacted Areas
Implementing the outbound WebSocket communication channel affects several core components across the ThunderID codebase, deployment infrastructure, and operational tooling.
1. Control Plane (CP) Components
/pkg/cp/gatewayor equivalent):Upgraderequests, authenticate DP agents, manage active connection states, and handle TCP keep-alives/heartbeats./pkg/cp/dispatcher):/pkg/cp/auth):2. Data Plane (DP) Components
/pkg/dp/agent):wss://connections, managing reconnection backoff timers with full jitter, and responding to ping/pong keep-alives./pkg/dp/rpc):Policy.Sync,Key.Rotate, etc.) to local DP services, and formats success/error responses back into frame payloads./pkg/dp/config):3. Shared Infrastructure & Storage
DataPlaneID -> ControlPlaneNodeID) in Redis/Etcd. This enables any scaled CP instance to locate which specific node holds the open socket for a given Data Plane and publish messages to it via Pub/Sub.4. Deployment, Packaging & DevOps
Ingressresources, Load Balancer rules, and open firewall ports previously required for the DP can now be removed from deployment templates.5. Observability & Telemetry
/pkg/telemetry):thunderid_cp_active_websocket_connectionsthunderid_dp_reconnection_attempts_totalthunderid_rpc_roundtrip_latency_secondsAlternatives Considered
During the architectural design phase for ThunderID's Control Plane (CP) to Data Plane (DP) communication channel, several architectural patterns were evaluated. While the primary objective was solving the private network firewall traversal issue, factors such as operational overhead, network compatibility, performance, and alignment across WSO2 teams were heavily weighed.
1. Decision Matrix & Evaluation Summary
High - 3
Medium - 2
Low - 1
Cannot consider - 0
2. Detailed Breakdown of Alternatives
Alternative 1: gRPC Bidirectional Streaming (HTTP/2)
Alternative 2: Centralized Message Broker (NATS / RabbitMQ / Apache Kafka)
Alternative 3: Reverse Network Tunneling (WireGuard / Cloudflare Tunnel / frp)
3. Rationale for Selecting WebSockets
WebSocket emerged as the clear winner with a Total Weighted Score of 7.25, driven by key decisive factors:
wss://(Port 443), seamlessly bypassing enterprise firewalls, NATs, and legacy proxies without requiring special L7 infrastructure rules.Questions for Community Input
To finalize the design and implementation plan for the Control Plane (CP) to Data Plane (DP) communication channel, we would love input from the community on the following technical and operational questions:
1. Protocol & Framing
2. Authentication & Security
3. Resilience & Connection Lifecycle
4. Scalability & State Management
All reactions