Connectors
For developers who add a target type. A connector serves one resource type on the gateway; the server, UI and connect hints take the type from the registry.
Pipeline
Section titled “Pipeline”A front accepts the user in its own protocol and produces a session of one kind. A connector serves the kinds it declares. A new front or connector costs M+N, not M×N.
- Kinds:
terminal,exec,stream,datagram(httpandoperationcome later). - Front
ssh: shell and exec with a PTY giveterminal; exec without a PTY givesexec;direct-tcpipgivesstream; the channeldatagram@werbot.com(onlywerbot connect) givesdatagram. - Fronts
tunnel,mcpandwebare on the roadmap. - The interfaces live in
internal/gatewayand move tosdkunchanged in wave 1.
The Connector interface
Section titled “The Connector interface”type Connector interface { Type() string Kinds() []Kind Serve(ctx context.Context, s *Session) error // ctx is canceled on terminate and drain}Session carries the fields of its kind: Terminal, Exec, Stream or Datagram (a Datagrams with Recv, Send and Close), plus Target, PinKey, Recording, Resource, Secret and Dial. Dial connects to the target; on the embedded gateway it refuses local addresses. A connector that reaches its target through Dial (telnet, tcp, udp) also implements TargetDialer (DialsTarget()), so the pipeline checks the host before it starts the session.
What the pipeline does
Section titled “What the pipeline does”- Enforces
WERBOT_GATEWAY_MAX_SESSIONSandWERBOT_GATEWAY_SPOOL_MAX. - Authenticates the user and checks the policy
<type>.connect. - Checks that the kind is in
Kinds(). - Fetches the credential through the server for one session.
- Records the session.
- Recovers panics: the session ends with
internal_error, neighbours live. - Cancels
ctxon terminate and drain. - Delivers
EndSessionthrough the spool. - Counts metrics and logs the error from
Servewithout the secret value.
What a connector must do
Section titled “What a connector must do”- Work only through
Session. - Not log: return the error.
- Start nothing before the first
Serve(0 goroutines, 0 listeners). - Return from
Servewhenctxis canceled. - Write output and input to
Recording.OutputandRecording.Input. - Verify the target host key through
PinKey(TOFU through the server). - Take copy buffers from the shared
sync.Pool.
Adding a connector
Section titled “Adding a connector”- Add the resource type package
internal/connector/<type>:connector.Registerwith itsKinds(server, UI and the connect hint read it),Recorded(a subset ofKinds) and, forstreamordatagram,Endpoint. - Add the gateway package
internal/gateway/<type>connectorwith theConnectorandgateway.RegisterConnector(c)(a duplicate type or emptyKindspanics). Blank-import both packages ininternal/app/connectors.go: without the import the server does not know the type and the gateway does not serve it. - Add the Cedar action
<type>.connect. - Add a
_test.gowithconnectortest.Run(t, c, target). - Instances announce their connectors at enrollment and in every heartbeat: a resource of the new type is served only by a pool where every online instance has the connector.
Contract test
Section titled “Contract test”connectortest.Run checks that:
- every declared
Kindworks with the test target; - a canceled
ctxendsServewithin 1 s; - no goroutine is left;
- the secret value is not in the error from
Serveor in the log; Recording.OutputandRecording.Inputare used for the recorded kinds only;- no goroutine starts between registration and the first session;
Kinds()equals the type on the server;- a
TargetDialerdials only throughSession.Dial.
connectortest.Echo is an example (stream, reachable with ssh -L).
Built-in connectors
Section titled “Built-in connectors”| Type | Level | Kinds | Recorded | Notes |
|---|---|---|---|---|
ssh |
L2 | terminal, exec, stream |
terminal, exec |
port_forwarding is off by default; stream is ssh -L. remote_forwarding is off by default; with it, ssh -R is a stream (see below). |
telnet |
L2 | terminal, stream |
terminal, stream |
Auto-login and recording. The gateway to target leg is plain text: run the gateway next to the equipment. |
tcp |
L1 | stream |
none | Several ports, RBAC per port; only bytes are counted. |
udp |
L1 | datagram |
none | Request-response protocols only: DNS, SNMP, syslog, NTP, RADIUS. RTP and VoIP do not fit: UDP rides over TCP. flow_idle (default 2m), up to 32 flows per session, 8192 bytes per datagram. |
Endpoint sets the host and ports a stream or datagram session may reach (and the TCP health check); Recorded sets the kinds whose payload is recorded as asciicast. The health check is a TCP connect from two instances of the pool; udp has none.
Remote forwarding (ssh -R)
Section titled “Remote forwarding (ssh -R)”A resource of type ssh with remote_forwarding on accepts remote forwards on a direct login (<login>+<resource>). The gateway asks the target to listen on the bind address and opens a forwarded-tcpip channel to the client for every connection that arrives there.
- Policy: the request is decided as
ssh.connect(with the MFA rules, so the second factor comes from the login) and then asssh.remote_forward, both with the bind port ascontext.port. Bindings and JIT grants already coverssh.remote_forward; narrow it with a custom Cedarforbidon the action. Agents never get it: their baseline permits onlyexec. - Bind address: only
localhost,127.0.0.1,::1or an empty host (the target’slocalhost). Any other host,0.0.0.0included, and port0are refused, as is a second forward of the same address on the connection. The client gets back the bind host it sent. - Session: one
streamsession per forward, target<bind_host>:<bind_port>(an empty host islocalhost), not recorded; only bytes are counted. Port-bound bindings limit the bind port. - End:
cancel-tcpip-forwardor closing the connection ends the session asclosed. When the gateway ends it (access_revoked,terminated,idle_timeout,max_duration, a target failure), it closes the whole SSH connection, its other channels included, so the client learns that the forward is gone. - Idle timeout: a forward without traffic idles out like any
stream. Raise the resourceidle_timeout(up to 24 h) for long-lived forwards. - Run
ssh -Ras a separatesshwith-N -o ExitOnForwardFailure=yes: a refused forward then fails the command, and a gateway-ended forward does not take other sessions with it.
Presets
Section titled “Presets”A preset is a resource type without code: a name on top of the tcp or udp connector. Owners and admins manage presets in the web UI (Access, Presets) or through ResourcePresetService; every member sees them in the resource type list next to the built-in types.
- Fields:
name(^[a-z][a-z0-9-]{0,31}$, cannot be a built-in type name),base_type(tcporudp),display_name,icon(a name from the web icon registry, empty for the base type icon),default_ports(1 to 16 ranges),categoryandlaunch_hint.nameandbase_typenever change after creation. launch_hintis shown as text on the resource page.{host}becomes127.0.0.1and{port}the local port ofwerbot connect, for examplepsql -h {host} -p {port}.- A resource made from a preset is stored with the base type and the
preset_id. The connector, the config and the policy are those of the base type; the preset only supplies default ports, the category and the hint in the UI. - A preset that resources still use cannot be deleted (
FailedPrecondition); delete or move the resources first.
Heavy and third-party connectors
Section titled “Heavy and third-party connectors”A heavy connector (for example guacd for RDP) or a third-party one implements the same Connector through an adapter to an external process (go-plugin or a sidecar), passes the same connectortest.Run and runs only on specialised pools, so other pools do not pay for it. There is no adapter in v0.x: it comes with the first heavy connector.