The internal listener
The internal listener is the TLS listener of the control role for the servers of the install. New servers enroll on it (Enrollment and the install PKI), and enrolled servers keep their control channel on it (the control channel). The edge servers call EdgeService on it, and send it the requests of the clients of the API and the console (the edge role). The code is in internal/control and internal/api.
Listener
Section titled “Listener”| Item | Value |
|---|---|
| Address | control.internal_listen of the bootstrap config, by default 127.0.0.1:7443 (the bootstrap config of hopboxd) |
| Address rules | An IP address and a port. A host name, even localhost, is refused. Any IP address works, also one that is not loopback. Port 0 picks a free port. |
| Transport | TLS 1.3 only |
| HTTP versions | HTTP/2 and HTTP/1.1, picked with ALPN |
| HTTP/2 frames | At most 64 KiB for each frame that a peer sends. A client of HTTP/2 holds a buffer of that size for each request body that it streams. So the edge holds 64 KiB for each request that it forwards, not 512 KiB. |
| Protocols | Connect, gRPC, and gRPC-Web, with the binary protobuf and JSON codecs. ControlService takes no gzip: a request in gzip fails with unimplemented and the message unknown compression "gzip", and no response uses gzip (the control channel). The other services of the listener take gzip and answer in it. |
| Services | hopbox.cluster.v1.EnrollmentService, hopbox.cluster.v1.ControlService, hopbox.cluster.v1.ControlPeerService, hopbox.cluster.v1.EdgeService, gRPC reflection, and gRPC health. A forwarded request reaches the public API instead. See Forwarded requests. |
| Server certificate | the control certificate of the install CA, with the URI SAN hopbox://control (Enrollment and the install PKI) |
| Client certificate | asked for in every handshake. A client can send none. A certificate that it sends must chain to the install CA and allow client auth, or the handshake fails. A server certificate and the control certificate of another control process both pass (Callers). |
| Unit | internal listener, after api and before admin socket (hopboxd) |
| Stop timeout | 5 s. A stop ends every open stream at once, so every control channel ends (the API server). |
| Metrics | the label listener="internal" for the cluster API, and listener="edge" for the forwarded requests (Metrics) |
On an install with one server, the listener stays on 127.0.0.1, and the channel unit of the same server dials it on loopback. With more servers, it listens on the peer address of the control server, such as 203.0.113.11:7443, so the other servers can reach it. The host firewall takes its port on the public interface only from the peer addresses of the servers, the internal listeners of the live control processes, and the registered addresses of the enrollment tokens that work (the host firewall). Each other server then lists the listener of one or more control servers in channel.control_urls (the bootstrap config of hopboxd). The control role sends each server the listeners on the peer addresses of the live control processes, and the server dials them first (the control channel). A listener on loopback or on a private address is not in that list.
Each control process records the URL of its listener in its row of control_processes (internal_url, Control store tables), as https:// and the address of the listener. The other control processes forward data streams to that URL (the control channel). A listener on every address, such as 0.0.0.0:7443, names no address, so its row has no URL, and no data stream reaches its channels from another control process. With several control servers, set control.internal_listen to the peer address of the server and port 7443. hopboxd install --internal-listen sets it (hopboxd).
Move the first server to its peer address
Section titled “Move the first server to its peer address”The first server of an install has every role, and its listener stays on loopback while it is the only server. Before a second server enrolls, the listener moves to the peer address of the first server. The Terraform provider runs this step at an update of the first server (hopbox Terraform provider). To run it by hand, take these steps on the first server.
-
Make sure that the server has its peer address. The line
peer_addressofsudo hopboxd admin server get <id>names it. If it is empty, set it withsudo hopboxd admin server set-peer-address <id> <address>(hopboxd). The install refuses a listener on another address than the stored peer address. -
Run the install with the peer address and port 7443:
sudo hopboxd install --roles control,node,dns,edge --internal-listen 203.0.113.11:7443
The install writes control.internal_listen = "203.0.113.11:7443". It writes https://203.0.113.11:7443 in the place of each loopback URL of channel.control_urls, or of the default https://127.0.0.1:7443. Then it restarts hopboxd, and the roles of the server dial the listener at the new URL. No loopback URL stays: the listener has one address. The machines keep running through the restart.
After the restart, these things hold:
- The control role publishes
https://203.0.113.11:7443, so each server keeps that URL in<data_dir>/server/control-urls(the control channel). - The roles of the first server dial the listener from the peer address, not from loopback. The enrollment takes a call from the address of the control server itself as a call from loopback, so a token without a peer address still adds a role to the first server (Enrollment and the install PKI).
- The host firewall takes port 7443 of the public interface from the set
peersand the setregisteredalone. A connection of the server to its own address goes over loopback, so the firewall takes it.
Then make the token of the second server with its peer address, and enroll the server at https://203.0.113.11:7443 (Enrollment and the install PKI).
The HTTP server has the timeouts and limits of the API listener (the API server): the header read timeout, the body read timeout of a unary call, the idle timeout, and the largest request message of 4 MiB.
In maintenance mode, the listener refuses every call of the cluster API with unavailable, and takes only health and reflection. No method of hopbox.cluster.v1 has the option (hopbox.v1.read_only). The forwarded requests of the edge servers get the refusals of the public API (the API server).
Before the first key-encryption key
Section titled “Before the first key-encryption key”The certificate of the listener comes from the install CA, and the CA needs a key-encryption key to seal its key (Enrollment and the install PKI). A fresh install has no such key. So the listener starts without a certificate, and logs this warning:
{"time":"2026-10-16T09:00:00Z","level":"WARN","msg":"the internal listener has no certificate yet","err":"failed precondition: the keyring has no key-encryption key to seal or open the value. Run hopboxd admin kek rotate to make the first one"}Until then, each TLS handshake fails, and the HTTP server logs http: TLS handshake error from <peer>: the internal listener has no certificate: ... with component=http. hopboxd install makes the first key-encryption key, so a server that it set up never logs this. On another server, run sudo hopboxd admin kek rotate (hopboxd). The next handshake then makes the CA and the certificate, without a restart.
Any other failure to read the CA stops the start of the unit.
Callers
Section titled “Callers”The request gate of the listener has one resolver, the server-certificate resolver (the API server):
| Case | Caller |
|---|---|
| The connection has no client certificate. | anonymous |
The certificate names hopbox://control, and so is the control certificate of another control process. |
control, with no account and no credential ID |
| The certificate passes the checks of Enrollment and the install PKI. | server, with the ID of the server |
| The certificate fails those checks, for example its serial is unknown or its server is decommissioned. | none. The call ends with unauthenticated and the message the credential is not valid. |
The TLS handshake already checked that the install CA signed a certificate that names hopbox://control. The control caller has no audit credential and no idempotency scope. The policy lets it do only control.forward_stream, besides the actions that every caller may do (GetInstallInfo, health, and reflection).
Every procedure of the listener needs a server certificate or a control certificate, except EnrollmentService.Enroll, whose enrollment token is its credential. An anonymous call of another procedure ends with unauthenticated and the message this call needs a server certificate. This rule runs after the gate and before the policy check. So it covers health and reflection too, which the policy allows for every caller on the other listeners.
| Procedure | Without a certificate | With a server certificate |
|---|---|---|
EnrollmentService.Enroll |
allowed | allowed |
ControlService.Channel, ControlService.AttachStream |
unauthenticated |
allowed for the server itself (the control channel) |
ControlPeerService.ForwardStream |
unauthenticated |
permission_denied. Only the control certificate of another control process is allowed. |
EdgeService.ExchangeMachineCode, EdgeService.AuthorizeMachineRequest, EdgeService.AuthorizeSSH |
unauthenticated |
allowed for a server whose certificate carries the role edge. Another server gets permission_denied. |
grpc.health.v1.Health, reflection |
unauthenticated |
allowed |
ControlPeerService
Section titled “ControlPeerService”hopbox.cluster.v1.ControlPeerService lets a control process forward a data stream to the control process that holds the channel of a server (the control channel). It takes no gzip, as ControlService does not. Each call needs the control certificate of another control process, which is also a client certificate: the control certificate has the extended key usage client auth (Enrollment and the install PKI).
| Procedure | Policy action | Description |
|---|---|---|
/hopbox.cluster.v1.ControlPeerService/ForwardStream |
control.forward_stream |
Opens a data stream of a kind to a server whose channel this process holds, and carries its bytes both ways. The first request names the server and the kind. The first response has no bytes and tells that the server attached the stream. |
The messages and the errors are in the control channel.
EdgeService
Section titled “EdgeService”hopbox.cluster.v1.EdgeService serves the sign-in of private machine URLs (the edge role) and of the SSH front door (the SSH front door) to the edge servers. Each call needs the certificate of a server with the edge role.
| Procedure | Policy action | Description |
|---|---|---|
/hopbox.cluster.v1.EdgeService/ExchangeMachineCode |
server.exchange_machine_url_code |
Trades the one-time code of a private machine URL for the token of the cookie __Host-hopbox_machine of that URL. The code works once, within 60 s, and only for its machine. The new token replaces any older token of the same console session and machine. |
/hopbox.cluster.v1.EdgeService/AuthorizeSSH |
server.authorize_ssh |
Checks that the account of an SSH key can open a shell, as a Linux user, in the machine of an SSH port now. Each answer that allows also records a use of the machine, and each allowed sign-in writes the audit entry machine.ssh. The request, the response, and the rules are in the SSH front door. |
/hopbox.cluster.v1.EdgeService/WakeForConnection |
server.wake_for_connection |
Resumes or wakes a sleeping machine for a connection that passed its check of access at the edge, with the actor system. The request, the response, and the rules are in the edge role. |
/hopbox.cluster.v1.EdgeService/AuthorizeMachineRequest |
server.authorize_machine_url |
Checks that the account of a token can open the private URL of the machine now. Each answer that allows also records a use of the console session, as a call of the console does (Sessions, cookies, and sign-in links). |
| Message | Field | Type | Description |
|---|---|---|---|
ExchangeMachineCodeRequest |
machine |
string | The name of the machine of the host of the request, such as box1 for box1.example.com. |
ExchangeMachineCodeRequest |
code |
string | The code of the query of the request. |
ExchangeMachineCodeResponse |
token |
string | The value of the cookie __Host-hopbox_machine, valid only for that machine. |
AuthorizeMachineRequestRequest |
machine |
string | The name of the machine of the host of the request. |
AuthorizeMachineRequestRequest |
token |
string | The value of the cookie __Host-hopbox_machine. |
AuthorizeMachineRequestResponse |
machine_id |
string | The ID of the machine, a UUID. |
AuthorizeMachineRequestResponse |
account_id |
string | The account of the token, a UUID. |
AuthorizeMachineRequestResponse |
valid_for |
google.protobuf.Duration |
How long the edge can keep the answer: at most 1 minute, and never past the end of the console session. A change event of the access ends it sooner (the control channel). |
AuthorizeMachineRequest checks four rules. Each must hold:
- The token names a row of
machine_url_sessions, and the console session of that row lives: its absolute end and its idle end are ahead (Control store tables, Sessions, cookies, and sign-in links). - The machine of the request holds its name, its target is not
deleted, and it is the machine of the token. - The account uses the machine, under the policy action
machine.open_url: it is the creator of a private machine, or a member of the org of a shared one (the API server). An org admin does not open the private machine of another member. - An instance admin did not suspend the org of the machine.
| Code | Message | Cause |
|---|---|---|
unauthenticated |
the sign-in of the machine URL is not valid: ... |
The code or the token is malformed, unknown, used, expired, replaced, or for another machine, or its console session ended. The machine can also be gone. The edge starts the sign-in again. |
permission_denied |
permission denied: ... |
The account has no access to the machine now. Another server than an edge server gets it too. |
failed_precondition |
failed precondition: org suspended: an instance admin suspended the org of the machine |
The org of the machine is suspended. |
invalid_argument |
invalid argument: ... |
The machine name is not a valid name (Domain rules). |
Forwarded requests
Section titled “Forwarded requests”The edge servers forward two kinds of requests to this listener: the requests of the domain of the install, and the requests of the Grafana host. They use the mutual TLS of their server certificates (the edge role). Each forwarded request carries the header Hopbox-Client-Addr with the address of the client, IP:port. The edge sets the header on each request, over any value that the client sent. A request of the Grafana host also carries the marker Hopbox-Forward-Target: grafana. The edge deletes any value of the marker that a client sent, on each host.
api.SplitForwarded splits the requests by these headers:
- A request without
Hopbox-Client-Addrreaches the cluster API, as in Callers. The marker alone changes nothing. - A request with
Hopbox-Client-AddrandHopbox-Forward-Target: grafanareaches the handler of the Grafana host (the edge role). The API listener does not serve this host. - Any other request with
Hopbox-Client-Addrreaches the public API and the admin API, as on the API listener (the API server). The plain HTTP routes under/auth/and the WebSocket of exec are there too. So a forwarded request never reaches the cluster API with the certificate of the edge server.
The listener takes the marker under the same proof as the address of the client, because the check below comes first. Before it serves a forwarded request, the listener checks the certificate of its connection. The certificate must pass the checks of Enrollment and the install PKI. It must also carry the role edge, under the policy action server.forward_requests. The listener keeps a passed check for 5 s, by the serial of the certificate. So each request does not cost a read of the control store. It keeps at most 1024 checks. So a decommission or a retired certificate stops the forwards within 5 s. Then the address of the header becomes the peer of the request, and both headers go. The request gate, the rate limits, and the logs see the address of the client. The credentials of the request, such as the session cookie or an API key, prove its caller. The certificate of the edge server proves no caller. Only this check trusts a client address: no listener reads X-Forwarded-For.
| Status | Body | Cause |
|---|---|---|
| 403 | only a server with the edge role forwards the requests of clients |
The connection has no TLS client certificate, or the certificate is refused, or its server has no edge role. The listener logs forwarded request refused at level warn, with peer and err. |
| 503 | the server failed to check the credential. Retry later |
The check of the certificate failed, for example on a failure of the control store. The listener logs forwarded request check failed at level error, with peer and err. |
| 400 | the header Hopbox-Client-Addr must hold one IP:port |
The header has more than one value, or a value that is not an IP address and a port. |
The forwarded requests get the label listener="edge" in the metrics of the API. Each forwarded call also gets the access log record api call (the API server). A request of the Grafana host is no API call. It counts only in hopbox_http_requests_total, with the same label (Metrics).
Examples
Section titled “Examples”Root on an enrolled server can call the listener with the identity of the server. identity.pem holds both the certificate and the key, and ca.pem holds the install CA (Enrollment and the install PKI). The control certificate names the IP address of the listener, so the usual host check of curl and grpcurl passes for that address.
A health check with curl and the Connect protocol:
cd /var/lib/hopbox/serversudo curl -s --cacert ca.pem --cert identity.pem --key identity.pem \ -H 'Content-Type: application/json' -d '{}' \ https://127.0.0.1:7443/grpc.health.v1.Health/Check{"status":"SERVING"}The same call without the certificate:
sudo curl -s --cacert /var/lib/hopbox/server/ca.pem \ -H 'Content-Type: application/json' -d '{}' \ https://127.0.0.1:7443/grpc.health.v1.Health/Check{"code":"unauthenticated","message":"this call needs a server certificate"}The services of the listener, with grpcurl:
cd /var/lib/hopbox/serversudo grpcurl -cacert ca.pem -cert identity.pem -key identity.pem 127.0.0.1:7443 listhopbox.cluster.v1.ControlServicehopbox.cluster.v1.EdgeServicehopbox.cluster.v1.EnrollmentServiceReflection lists only the services of the cluster API, as on the other listeners.
A control server that is not enrolled has no identity files. Use ca.pem of an enrolled server, or --insecure with curl only to see the error of a call without a certificate.