StreamHost¶
Raw TCP/UDP forwarding. gpm opens a proxy listener per listenPort (TCP, UDP,
or both) and forwards to the backend; listeners are reconciled on every reload
(ports added/removed, backend swapped, with no listener restart for unchanged
ports). UDP uses per-client sessions with an idle timeout.
A TCP stream can additionally be TLS-aware (tls): SNI-routed so several
hosts share one port, either passed through untouched or terminated at gpm. And
it can be gated at L4 (accessLists) on the client IP, evaluated before any
backend is dialled.
| Field | Type | Required | Notes |
|---|---|---|---|
listenPort |
int | yes | 1-65535. Publish this port from the container (compose ports:) so it is reachable, and avoid colliding with the proxy listener ports 80/443 or the admin port: a bind failure is logged and that one port is skipped, never fatal. |
protocol |
string | yes | tcp|udp|both. |
target |
StreamTarget | yes | The backend this port forwards to: {host, port}. Mirrors upstream's vocabulary minus the scheme: a raw stream carries an arbitrary protocol, so http/https means nothing here. |
tls |
StreamTLS | no | SNI routing and/or TLS termination. TCP only. |
accessLists |
[]string | no | L4 access lists evaluated on the client IP (below). |
idleTimeout |
string | no | TCP only. Go duration ("10m", "1h"). A connection that carries no data in either direction for this long is closed. Unset: no idle limit, a connection lasts until it is closed (TCP connection close). After a half-close this timeout is the only bound: a transfer that keeps moving is never cut. |
maxConnsPerSource |
int | no | TCP only. Open connections one client address (IPv6 by /56, as the UDP per-source cap) may hold to this host. A connection over the cap is closed after the access-list check and before the backend is dialled. Unset or 0: no cap. |
newSessionsPerMinute |
int | no | UDP only. New sessions one client address (IPv6 by /56) may open per minute, with a burst of the same size. The limit counts session attempts that reach the dial: a datagram dropped by another limit (full table, no free dial slot) costs nothing, a dial that fails still counts. A datagram that would open one over the limit is dropped silently (one log line per source) before the backend is dialled; datagrams on an open session are never limited. Unset or 0: no limit. |
name: postgres
listenPort: 5432
protocol: tcp
target:
host: db.internal
port: 5432
accessLists: [lan-only]
Removed fields¶
| Field | Status | Migration |
|---|---|---|
forwardHost |
Removed. Decoded only so the loader can reject it loudly. | Replace the pair with target: {host, port}. |
forwardPort |
Removed, same. | Same. |
A file still carrying either key is rejected at load with an error naming the new shape: it is never silently accepted with no backend. See Upgrading.
StreamTarget (target)¶
| Field | Type | Required | Notes |
|---|---|---|---|
host |
string | yes | Backend host. |
port |
int | yes | 1-65535. |
TCP connection close¶
A TCP stream forwards a half-close: a side that finishes sending does not end the connection for the other side.
| Event | What gpm does |
|---|---|
| One side finishes sending (EOF on read) | Shuts only the write side toward the other peer (TCP FIN; in terminate mode a TLS close_notify first) and keeps copying the other direction. |
| The other side finishes too | Closes the connection. |
With idleTimeout set: no data in the open direction for idleTimeout |
Closes the connection. An active transfer after a half-close is never cut. |
Without idleTimeout: 60 s pass after the first side finished and the other has not |
Resets both peers (TCP RST), so a cut reply surfaces as a connection error and is never read as a complete one. The 60 s linger bound is fixed. |
A read or write error in either direction (a reset, an idleTimeout expiry) |
Closes both sides at once. |
- Slot: the connection holds its
maxConnsPerSourceslot until it is closed or reset. - Long replies after a half-close: a client that half-closes and then waits for a reply (
nc -N, a request sent beforeshutdown(SHUT_WR)) gets the whole reply on a host withidleTimeout; without it, the reply must finish within 60 s of the half-close or the client sees a reset.
L4 access lists (accessLists)¶
A stream host may reference AccessList objects, exactly like a proxy host. Only
the IP/CIDR rules and the geo rules are evaluated: basic auth is an HTTP
challenge/response with nowhere to live in a raw stream, so referencing a list
that has (deprecated) basicAuth users is rejected at validation rather than
silently half-applied; moving those users to an auth middleware with
mode: basic removes the conflict, since that middleware is HTTP-only and is
never attached to a stream host. All referenced lists must allow, and the check runs before any
backend is dialled, so a denied client cannot make gpm open a socket to the
backend at all.
For UDP the list is evaluated once per session (the first packet from a source); a denied source creates no session and no upstream socket. Geo rules follow the same fail-closed rule as HTTP: with geo configured and no GeoIP database loaded, the port denies. UDP has no handshake, so a source address is not proven: a sender can put an allowed address on its datagrams and reach the backend one way (replies go to the real owner of that address). Treat a UDP access list as noise reduction, not authentication, for a service that acts on single datagrams.
Behind an L4 balancer, enable settings.proxyProtocol, otherwise every
connection looks like it came from the balancer and the rules match the wrong
address.
TCP limits are off unless set (idleTimeout, maxConnsPerSource, above);
both are rejected on a protocol: udp host and apply to the TCP side of
both. The UDP limit newSessionsPerMinute is off unless set, is rejected on a
protocol: tcp host and applies to the UDP side of both.
UDP session limits apply independently of any access list:
| Limit | Value | When reached |
|---|---|---|
| Sessions per listener | 4096 | A new source takes the slot of the session whose client was silent the longest, if that session has had no client traffic for at least 30 s; otherwise the new source is dropped. |
| Sessions per source address (IPv6 by /56) | 64 | Datagrams that would open another session from that source are dropped until one of its sessions ends. |
| Concurrent backend dials per listener | 64 | Datagrams that would open another session are dropped until a dial completes (a slow or unresolvable target.host). |
| Concurrent backend dials per source address (IPv6 by /56) | 8 | Datagrams from that source that would open another session are dropped until one of its dials completes, so one client cannot hold every dial slot of the listener. |
| Datagrams queued for a session being dialled | 32, and 64 KiB in total counting 64 bytes per datagram | Further datagrams from that client are dropped until the dial completes. The queue is written to the new backend within 1 s; whatever is left after that is dropped, and the session still opens. |
Sources tracked by newSessionsPerMinute |
4096 | A source whose budget has fully refilled is forgotten first (checked at most once a second, and on the 60 s reap); when none has, a new session from an untracked source is dropped, as with a full session table, and logged once per port. |
A new session's backend is dialled without holding up the listener: datagrams on
other sessions keep flowing during a slow dial (a DNS lookup for a hostname
target.host), and further datagrams from the new client are queued (within the
limits above) and delivered in order when the dial completes. A session that is
still being dialled counts against both session limits.
# WireGuard: at most 10 new sessions per source address per minute.
name: wireguard
listenPort: 51820
protocol: udp
target:
host: 192.0.2.20
port: 51820
newSessionsPerMinute: 10
StreamTLS (tls)¶
Makes a TCP stream port TLS-aware: several hosts can share one port, separated by the SNI in the ClientHello, and gpm can either forward the handshake untouched or terminate it.
| Field | Type | Required | Notes |
|---|---|---|---|
mode |
string | yes | passthrough | terminate. |
sniMatch |
[]string | see below | Server names this host claims. Exact (db.example.com) or a single-label wildcard (*.example.com). |
certificateRef |
string | terminate only | Names a Certificate. Required in terminate, forbidden in passthrough. |
passthroughpeeks the ClientHello (a bounded, stdlib-only parse of the record, handshake andserver_nameextension), routes on the SNI, and replays the peeked bytes to the backend. gpm never decrypts and never needs the key: the backend terminates, end to end.terminatecompletes the handshake at gpm withcertificateReffrom the normal certificate store (custom or ACME-issued) and forwards plaintext to the backend. The backend is dialled only after the handshake completes, and a client has 10 s after its ClientHello to finish it. The floor is TLS 1.2 with the same AEAD cipher suites the HTTPS listener uses, or TLS 1.3 whensettings.tls.minVersionraises it (a stream host has no per-host floor of its own). No ALPN is offered: what rides inside a stream is an arbitrary TCP protocol.
Port sharing. Two or more enabled stream hosts may share a TCP listenPort
only if every one of them sets sniMatch: that is the only thing that tells
their connections apart. Validation rejects a mixed or duplicate claim, so
routing can never fall back to "whichever host compiled last". A host alone on its
port may omit sniMatch and take every connection. On an SNI-routed port, a
connection whose server name no host claims (or that sends no SNI) is closed
rather than handed to an arbitrary backend, and a connection that is not TLS at
all is closed too.
UDP. tls requires protocol: tcp. A UDP datagram carries no ClientHello, so
udp and both are rejected at validation; two hosts can never share a UDP port
either.
# Two Postgres instances behind one public 5432, separated by SNI, never decrypted.
name: pg-blue
listenPort: 5432
protocol: tcp
target:
host: pg-blue.internal
port: 5432
accessLists: [lan-only]
tls:
mode: passthrough
sniMatch: [blue.db.example.com]
---
# TLS terminated at gpm, plaintext to a backend that speaks none.
name: mqtt
listenPort: 8883
protocol: tcp
target:
host: mosquitto.internal
port: 1883
tls:
mode: terminate
sniMatch: [mqtt.example.com]
certificateRef: wildcard