Enrollment and the install PKI
Enrollment makes a new server a part of an install. This page covers the certificates of an install and the enrollment token. It also covers the command hopboxd enroll, the call EnrollmentService.Enroll, and the check of a server certificate on each call. The code is in internal/pki, internal/node, internal/service, and cmd/hopboxd.
After the enrollment, the server keeps a control channel to the control role (the control channel). The server enrolls and talks to the control role on the internal listener (the internal listener).
Overview
Section titled “Overview”- Root on a control server makes an enrollment token:
sudo hopboxd admin enrollment-token create(hopboxd). - Root on the new server runs
sudo hopboxd enroll --token <token>. The command runs the preflight check (the preflight check), makes a key, and callsEnroll. - The control role checks the token, records the server in the registry, and signs a certificate for the key of the server.
- The new server saves its identity in
<data_dir>/server.hopboxd runwith a role other thancontrolthen opens the control channel with it.
The server never sends its private key. First it checks the CA of the control role against the CA hash in the token. Until that check passes, it sends nothing, not even the token.
Certificates
Section titled “Certificates”Every key of an install is an ECDSA key on the curve P-256. Every certificate starts 5 minutes before the time of its issue, so a server with a clock that runs a little behind still accepts it.
Install CA
Section titled “Install CA”| Item | Value |
|---|---|
| Key | ECDSA P-256 |
| Subject | CN=hopbox install CA |
| Lifetime | 10 years from its creation |
| Basic constraints | CA, path length 0 |
| Key usage | certificate sign, CRL sign, digital signature |
| Hash | the SHA-256 of the DER certificate, in lowercase hex (64 characters). An enrollment token holds it. |
| Storage | the table install_ca of the control store (Control store tables). The certificate is plain. The key, in PKCS #8 DER, is sealed with the place InstallSecret{Name: "install_ca.key"} (Sealing). |
The install has one CA. The first control process that needs it makes it: the first CreateEnrollmentToken, or the start of the internal listener. To seal the key, the keyring must have a key-encryption key. hopboxd install makes the first one (hopboxd). On a server without it, root makes one with sudo hopboxd admin kek rotate (hopboxd). Until then, each call that needs the CA fails with failed_precondition and the message 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.
Two control processes that make a CA at the same time both insert it. Only the first insert counts, and both read that one. Each control process keeps the CA in memory after its first read. A new CA makes the record created the install CA with the field ca_hash and component=service.
Server certificate
Section titled “Server certificate”The CA signs one certificate for each enrolled server, and a new one at each renewal (the control channel).
| Item | Value |
|---|---|
| Key | ECDSA P-256. The server makes it. The request must prove that the server holds the private key. |
| Subject | CN=<server ID> |
| Lifetime | 30 days, and never past the end of the CA |
| Key usage | digital signature |
| Extended key usage | client auth only. A server certificate never works as the certificate of a listener. |
| URI SAN | hopbox://server/<server ID>?roles=<roles>, for example hopbox://server/01a14403-6bd1-7522-9ab0-b3ab4517e0e4?roles=node. The roles are lowercase words joined by plain commas, for example ?roles=node,dns. |
| Serial number | 128 random bits. The control store keeps it in lowercase hex, without leading zeros. |
A certificate names exactly one server URI, with 1 to 8 roles. The roles of the certificate are the roles of the server in the registry.
Control certificate
Section titled “Control certificate”The internal listener presents a certificate of the same CA (the internal listener). A control process also sends it as its client certificate to the internal listener of another control process.
| Item | Value |
|---|---|
| Key | ECDSA P-256, new for each certificate. It stays in the memory of the control process. |
| Subject | CN=hopbox control |
| Lifetime | 30 days, and never past the end of the CA |
| Extended key usage | server auth and client auth. Client auth lets a control process send the certificate when it calls another one (the control channel). |
| URI SAN | hopbox://control |
| IP SAN | the IP address of control.internal_listen, such as 127.0.0.1. For an address such as 0.0.0.0, which listens on every address, the certificate has no IP SAN. |
| Chain | the certificate, then the CA certificate |
Each control process makes its own control certificate. It makes it at the start of its internal listener, or at the first handshake after the CA exists. At the first handshake after the certificate is 20 days old, it makes a new one.
A server checks three things about the control certificate. It must chain to the install CA. It must have the extended key usage server auth. It must name hopbox://control. If a check fails, the server refuses the control role. The server does not check a host name.
Enrollment token
Section titled “Enrollment token”An enrollment token lets one server enroll into one pool.
| Item | Value |
|---|---|
| Form | hbxe_<id>_<secret>_<cahash>, 167 characters |
<id> |
the ID of the token, a UUIDv7 as 32 lowercase hex digits without hyphens |
<secret> |
32 random bytes as 64 lowercase hex digits |
<cahash> |
the hash of the install CA, 64 lowercase hex digits |
| Lifetime | 1 hour from its creation by default. The call that makes it can set another ttl, at most 24 hours. |
| Use | once. The first enrollment that uses the token spends it. A retry of that enrollment with the same key gets the same certificate again, until the token expires (Retry after a lost answer). A token that names a server can also resync that server (Resync after the end of the token). |
| Scope | one pool, by default the pool default |
| Peer address | none by default. A token can name the peer address of its server. The enrollment must then come from that address (Peer addresses). |
| Storage | the table enrollment_tokens (Control store tables). It keeps the SHA-256 of the secret, never the secret. |
The text of a token is a secret. Keep it out of logs and shell history. hopboxd enroll also takes it from the environment variable HOPBOX_ENROLLMENT_TOKEN. The secret scan of the commits refuses the form of a token.
A token for another install CA never works: the new server refuses the control role in the TLS handshake, and the control role refuses the token too. A wrong secret does not spend a token. A failed check of the request, such as a bad key, does not spend it either.
The leader deletes the tokens that expired more than 1 day ago, every 10 minutes (hopboxd).
Make a token
Section titled “Make a token”The admin call ServerService.CreateEnrollmentToken makes a token (the admin API). On a control server, run:
sudo hopboxd admin enrollment-token create [--pool NAME] [--roles ROLE,...] [--peer-address ADDRESS] [--ttl DURATION] [--json]The command prints the token on one line, so a script can keep it in a variable. With --peer-address, the server must enroll from that address. --ttl sets the lifetime of the token, such as 2h, at most 24h. The token allows only its roles: node, dns, edge, or more than one, by default node. The row of the token keeps them. The response holds the only copy of the token. The call takes an idempotency key, but the control store keeps no copy of its response, so a retry with the same key fails with already_exists and makes no second token (the admin API). A lost token costs only a new token.
Peer addresses
Section titled “Peer addresses”The peer address of a server is the public address at which the other servers reach it (plan question Q91). It is one public unicast IPv4 address on the uplink of the server, with no NAT. The install refuses a private, loopback, link-local, multicast, or reserved address. It also refuses an address in the shared address space 100.64.0.0/10 of carrier NAT, the mesh range 10.239.0.0/16, or the machine range 10.240.0.0/12. The table servers keeps it (Control store tables). A peer address belongs to one server until the server is decommissioned, because the Terraform provider imports a server by its peer address (plan question Q96).
A token can name the peer address of the server that enrolls with it (plan question Q92). The enrollment must then come from that address. The install makes no such token while a control process of a release before migration 0054 is live, because that release enrolls from any address (the admin API). The new server keeps the address as its peer address. A heartbeat never changes a peer address. Only these three paths set it:
- The enrollment with a token that names one. For a server that adds roles to itself, such a token sets the peer address only when the server has none (Add roles to an enrolled server).
hopboxd install --peer-addresson the first server, which enrolls with a token from its own control role (hopboxd).hopboxd admin server set-peer-address, such as on a server from before peer addresses (the admin API).
A token without a peer address enrolls as before, and its server gets no peer address. Such a token enrolls from these addresses:
| The install | A token without a peer address enrolls from |
|---|---|
| No server of the install ever had a peer address. | Any address that reaches the internal listener. |
| A server of the install has or had a peer address, also a decommissioned one. | The control server itself only, such as the node role of a one-server install: loopback, or the address of the internal listener on which the call came. After the move of the internal listener to the peer address of the first server, its roles dial the listener from that address (the internal listener). |
So once the servers of an install have peer addresses, a token that leaks is no use from another host. A connection that comes from the address of the control server itself comes from that host: TCP refuses a forged source, and a packet of a machine to an address of its host takes no source NAT. The host firewall also keeps the egress of the machines away from every peer address (the host firewall). The rule of the address of the control server itself is a build default of N28, not an owner decision. The rule stays for good: the decommission of the last server with a peer address does not end it. This is a build default that follows from Q91 and Q92, not an owner decision. The rule also holds when an enrolled server adds roles to itself (Add roles to an enrolled server). The control role checks the address under the lock of the server registry, which SetServerPeerAddress also takes. So the first peer address of an install and an enrollment never overlap.
A control process of a release before migration 0054 ignores both rules. So while such a process is live, CreateEnrollmentToken refuses a peer_address, and SetServerPeerAddress refuses every call (the admin API). A rollback of a control server to such a release still lets that process ignore both rules. It enrolls each live token from any address, until the token expires, at most 24 hours later. Wait for the live tokens to expire before a rollback across migration 0054, or roll forward again.
While a token with a peer address is not used and not expired, its address is in the set registered (Control store tables). The host firewall of each control server opens the public port of the internal listener to the addresses of that set, so that a new server can enroll (the host firewall). A new token reaches the firewall of each control server within 2 s, so start the enrollment 2 s after the make of the token. After the enrollment, the address of the server is in the set peers, which keeps the listener open to its control channel. A long ttl keeps the listener open to that address for that time. So the default lifetime is 1 hour, and the longest is 24 hours.
hopboxd enroll
Section titled “hopboxd enroll”hopboxd enroll --token=TOKEN [--config=PATH] [--json]enroll makes this server a part of an install. Run it as root on the new server.
| Flag | Type | Default | Description |
|---|---|---|---|
--token |
string | the variable HOPBOX_ENROLLMENT_TOKEN |
The enrollment token. Required. |
--config |
path | /etc/hopbox/hopboxd.toml |
The bootstrap config (the bootstrap config of hopboxd). enroll reads roles, data_dir, and channel.control_urls. |
--json |
bool | false |
Prints the identity as one JSON object instead of the server ID. |
enroll takes these steps, and stops at the first that fails:
- It reads the bootstrap config. The roles that enroll are every role of the config but
control. Today these roles arenode,dns, andedge. - It checks the form of the token.
- Only with the node role, it runs the preflight check (the preflight check) and prints one line for each check to standard error. A failed check of severity
failstops the enrollment. - It checks that
<data_dir>/serverholds no identity yet. - It reads the hardware of the server (Hardware of a pool).
- It makes a new ECDSA P-256 key and a certificate request for it. The request names nothing: the control role sets every name. Before the call, it saves the key and the request with the token and the roles in
<data_dir>/server/pending.pem. If that file holds a pending enrollment for the same token and the same roles, it sends that request again instead (Retry after a lost answer). - It dials the first URL of
channel.control_urlsover TLS 1.3 with HTTP/2. If the dial fails, it goes on to the next URL. A call that reached a control server can have used the token, so the next URL never gets it. In the handshake, it finds the CA certificate with the CA hash of the token in the chain of the control role. The certificate of the control role must chain to that CA and namehopbox://control. If a check fails, it ends the handshake and sends nothing. - It calls
EnrollmentService.Enrollwith the token, the request, the host name of the server, the roles, and the hardware. - It checks the answer. The CA certificate must have the hash of the token. The signature of the server certificate must be from the CA. The certificate must hold the new key and name the server ID and the roles of the answer.
- It saves the identity in
<data_dir>/server, and removespending.pem.
The whole command has at most 60 seconds. After a failed first try, enroll removes pending.pem again, and the dir <data_dir>/server when it made it, in two cases. In the first case, no call left the server, because each dial failed or each control listener failed the check of the CA. In the second case, the control role refused the call with an error of its own, after a rollback of the call. So a refused token does not stay on the disk, and a later hopboxd install without a token does not send it again. An error that a lost answer can give keeps pending.pem for a retry: unavailable, deadline_exceeded, canceled, unknown, internal, aborted, resource_exhausted, and data_loss. A failed commit of the control role can give internal, and a conflict can give aborted, so the server keeps its key after these codes too. A refused retry keeps pending.pem until its token surely expired (Retry after a lost answer).
On success, enroll prints the server ID on standard output, and this line on standard error:
hopboxd: enrolled as the server <server ID>. hopboxd run connects it to the control plane.With --json, it prints one object:
| Key | Value |
|---|---|
server_id |
The ID of the server. |
roles |
The roles of the server, such as ["node"] or ["dns"]. |
ca_hash |
The hash of the install CA. |
certificate_expire_time |
The end of the server certificate, in UTC. |
dir |
The dir of the identity, <data_dir>/server. |
Example:
$ sudo hopboxd enroll --token "$TOKEN"preflight kvm okpreflight cgroup2 okpreflight tun okpreflight nftables okpreflight reflink okpreflight e2fsck okpreflight kernel okhopboxd: enrolled as the server 01a14403-6bd1-7522-9ab0-b3ab4517e0e4. hopboxd run connects it to the control plane.01a14403-6bd1-7522-9ab0-b3ab4517e0e4A server that is enrolled already, and whose config lists a role beyond those of its identity, adds the new roles in place (Enrollment and the install PKI). The token must allow each new role. A server whose config leaves out a role of its identity ends the removal of that role instead (Enrollment and the install PKI). The token must allow each role that stays. The server keeps its ID. enroll then prints hopboxd: the server <id> has the roles <roles> now. Restart hopboxd to use them: systemctl restart hopboxd. hopboxd install restarts it on its own. On the installed server, enroll takes the lock of the install, and writes the marker /opt/hopbox/.restart-pending before the call to the control role. It keeps the marker once the identity on disk changed. If an install, an upgrade, or another enroll holds the lock, enroll stops before the call with another hopboxd install, upgrade, or enroll runs on this server. Wait for it to end. So if you forget the restart, or enroll stops after the save, the next hopboxd install restarts hopboxd. A restart by hand leaves the marker, so that install restarts hopboxd once more. The installed server is the one whose config /etc/hopbox/hopboxd.toml names the same data_dir as --config.
enroll does not start anything. The channel unit of hopboxd run waits for the identity and opens the control channel once it exists, so hopboxd run can run before enroll (the control channel).
Add roles to an enrolled server
Section titled “Add roles to an enrolled server”A role that a removal took from a running server comes back in place (the admin API). An example is the role node of an edge server after the removal of its node role. The server keeps its ID and its other roles.
- An operator makes a token for the roles that come back alone, that names the server, such as
hopboxd admin enrollment-token create --server <id> --roles node --peer-address <peer address>. Only that server takes the token, so a token that leaks adds no role to another server. No new server enrolls with it. - The server calls
EnrollmentService.Enrollwith the token, a new CSR, and every role that enrolls, the old ones and the new ones. It calls with its current certificate as the client certificate, so the control role knows which server asks. - The control role checks that the token names the server, and allows each new role. It checks the address of the call as for a new server (Peer addresses). A token that names a peer address other than the peer address of the server fails with
unauthenticated. A token that names a peer address gives that address to a server without one. - The control role adds only a role that a removal took from the server. The list
removed_rolesof the server row must hold each new role. The gate has no exception, on the first server too. The add of a role that the server never lost fails withfailed_precondition, and waits for the owner. A trigger of the store refuses such an add from a control process of an older release too (Control store tables). The call also refuses an add while a removal of roles is pending on the server. - The control role sets the roles of the server in the registry, and issues a certificate with every role. It takes the new roles out of
removed_roles, and uses the token. So a later add of the same role needs a new removal first. The audit entry isserver.add_roles, withold_roles,roles,token_id, andserial, andpeer_addresswhen the token gave the server its peer address. - The server saves the new identity. Its old certificate stops at once, because its roles no longer match the registry. So hopboxd must restart to use the new one.
hopboxd installcallsEnrollafter its checks and before it writes the config. Its restart runs the new roles with the new identity, also when a later step of the install fails. A refusal of the control role changes nothing on the server: the config and the identity stay (hopboxd).hopboxd enrollsays to restart.
A node that comes back takes its old subnet again, because the server kept its row in node_subnets (the node network).
A server keeps one peer address. So CreateEnrollmentToken refuses a token with server_id and a peer_address other than the peer address of that server. A token without peer_address works for any server. These rules are build defaults that follow from Q91 and Q92, not owner decisions.
Until N32, a role that a new release brought, such as edge, came to a first server that lacked it through this path. Every install has the roles edge and dns since, so no current release brings a role. The next release that adds a role defines its own rule for it.
Remove roles from an enrolled server
Section titled “Remove roles from an enrolled server”An enrollment also ends the removal of roles from a running server, the reverse of Add roles to an enrolled server. RemoveServerRoles starts the removal, and its checks run first (the admin API). The role control never enrolls, and no token or certificate holds it. So the token and the call carry only the roles that enroll and stay. Examples are node on a first server with control and node, and edge and dns on an edge server.
- Once the removal is ready (
removal.readyof the server), an operator or the Terraform provider makes a token. The token names the server, the enrolling roles that stay, and the peer address of the server. An example ishopboxd admin enrollment-token create --server <id> --roles node --peer-address <peer address>. With the peer address, the rule of Peer addresses lets the call in. - The operator runs
hopboxd install --roles <every role that stays>on the server with that token,controlincluded on a control server, such as--roles control,node(hopboxd). - The server calls
Enrollwith the token, a new CSR, and the enrolling roles that stay, with its current certificate. - The control role checks the token, the address of the call, and the pool, as for an add. Then it checks that a removal of exactly the missing roles is pending for the server, and that the removal is ready. It also checks that the checks of
RemoveServerRolesstill hold. The check of another ready node for the machines runs only at the start, because the machines moved already. Each refusal comes before the use of the token, so the token stays unused. - The control role sets the roles that stay in the registry, issues a certificate with them, and uses the token. It adds the roles that went to
removed_roles, and ends the removal with its stranded machines. It lifts the cordon that a removal ofnodeset. The audit entry isserver.remove_roles, withold_roles,roles,token_id, andserial, andpeer_addresswhen the token gave the server its peer address. The old certificate of the server fails at once, because its roles no longer match the registry. The control process also ends the channel of that certificate. - The server saves the new identity, and
hopboxd installrestarts it with the new config. The restart stops the services of the server for some seconds. Then the server drops the data of the roles that went (hopboxd).
The log record of the end is removed roles from a server, with component=service and the fields server, removed, and roles.
Retry after a lost answer
Section titled “Retry after a lost answer”The answer of Enroll can get lost after the control role used the token, for example when the connection breaks. The server then has no new identity, but the registry holds the new server or its new roles. After an add or the end of a removal, the old certificate of the server fails at once, because its roles no longer match the registry. So a used token works again in one case: a retry with the same key. The owner decided this on 2026-10-29 (plan question Q101). The rule holds for a new server, for an add of roles, and for the end of a removal. For a new server, the retry needs the same token: run hopboxd enroll again with it. The Terraform provider makes a new token on each run of a first enrollment, so a rerun of the provider after a lost answer enrolls a second server, and the first one stays in the registry as unresponsive. The provider retries only the add of a role and the end of a removal (hopbox Terraform provider).
- Before the call, the server saves its new key and its certificate request in
<data_dir>/server/pending.pem, with the token and the roles (Identity files). - A later enrollment with the same token and the same roles sends the same request again.
hopboxd enrolldoes it when it gets the same token.hopboxd installwithout--enroll-tokentakes the token ofpending.pemwhen its roles are the enrolling roles that the install asks for (hopboxd). So a run of the Terraform provider that gives no token, because the registry holds the new roles already, ends the change. After a lost answer, run the enrollment again without a token or with the same token. Do not give a new token: an enrollment with another token replacespending.pemwith a new key before its call, so the key of the used token is gone. - A server with an identity calls with its current certificate first. If the internal listener refuses that certificate with
unauthenticatedand the messagethe credential is not valid, the server calls once more without a client certificate. A refusal of the token, with another message, gets no second call. - The control role finds the token used. It looks for a certificate of the server of the token that holds the key of the request, and that is not retired and not expired. The request must parse, and its signature must be valid. Its roles must be the roles of that certificate, in any order. The registry must hold the same roles, and the server must not be decommissioned. A caller with a server certificate must be that server. The address of the call must pass the rule of Peer addresses.
- The token must not be expired. So the retry works for the lifetime of the token: 1 hour by default, and at most 24 hours.
- The control role answers with the same certificate, the server ID, the CA, and the pool. It changes nothing in the registry and issues no certificate. It writes the audit entry
server.enroll_retry. - The server saves the identity and removes
pending.pem.hopboxd installthen restartshopboxdwith it.
A retry that fails a check of step 4, other than the address, gets the error of a used token, the enrollment token is not valid: it was used already. Make a new token, and changes nothing. A retry from another address fails with permission_denied, as in Peer addresses. A retry after the end of the token gets the enrollment token is not valid: it expired at <time>. Make a new token. So a thief of a token without the private key of the server gets nothing: a request for another key gets the error of a used token. The certificate itself is not a secret, and it works only with the private key.
The audit entry server.enroll_retry has the actor of the caller, most often anonymous. Its target is the server: the target kind server and the server ID. Its details are pool, token_id, roles, and serial, the serial of the certificate that the retry sent again. The log record is sent the certificate of an enrollment again, with component=service and the fields server, serial, and roles.
A control process of a release before this rule refuses each retry as a used token. During an upgrade of the control servers, a retry that reaches such a process fails. So the server keeps pending.pem after a refused retry, and a later retry at a control process of this release succeeds within the lifetime of the token. The server does not know the end of its token. It writes the header Not-After in pending.pem: the time that the server saved pending.pem, before its first call, plus 24 hours, the longest lifetime of a token. A refused retry after that time removes pending.pem. Until then, a run of hopboxd install without a token after a lost answer sends the token again and fails with each refusal. The rule needs no migration.
These rules are build defaults of Q101, not owner decisions: the window of the lifetime of the token, the second call without a client certificate, and the token of pending.pem for hopboxd install. After the end of the token, no retry gives the server its new identity, and the registry keeps refusing the old certificate. Then a resync with a new token gives it a certificate (Resync after the end of the token).
Resync after the end of the token
Section titled “Resync after the end of the token”A server that lost the answer of an add or of the end of a removal, and whose token then expired, has no retry. The registry refuses its old certificate, because its roles differ from the registry. A resync gives such a server a new certificate with the roles of the registry. The server proves the key of its old certificate, and calls with a new token that an admin made for it. The owner decided this on 2026-10-29 (plan question Q105).
To resync a server:
- On a control server, read the roles of the server in the registry:
sudo hopboxd admin server get <id>. - Make a token that names the server and allows each of those roles, such as
sudo hopboxd admin enrollment-token create --server <id> --roles node,dns --peer-address <peer address>. - On the server, run the install of the change again with that token, such as
sudo hopboxd install --roles node,dns --enroll-token <token>. The roles that enroll must be the roles of the registry.
hopboxd enroll --token <token> also resyncs, and then you restart hopboxd. The resync takes these steps:
- The server calls
Enrollwith its old certificate first, as for a change of its roles. The internal listener refuses that certificate withthe credential is not valid. - If
pending.pemholds a pending enrollment for the same token and the same roles, the server sends that request again without a client certificate (Retry after a lost answer). - If the control role refuses that call too, or no such pending enrollment exists, the server calls again without a client certificate. Its request is for the key of its old identity. An enrolled server sends no hardware on any call. So a token that names no server fails as a new server without hardware, and never enrolls a second server. The server then adds to the error:
A resync of the server <id> needs a token that names it, such as from hopboxd admin enrollment-token create --server <id>, and a control process of this release. If the answer of the call of step 2 got lost, the server makes no call of step 3, and keepspending.pemfor the next run. - The control role finds the token unused, so the call is no retry. The caller has no client certificate, and the token names a server, so the call is a resync. The token must be live, and it must allow each role of the request.
- It takes the lock of the server registry, and checks the address of the call (Peer addresses). It locks the row of the server, and checks the peer address and the pool of the token, as for an add. A token that names a peer address gives that address to a server without one. A token whose peer address another server holds fails with
already_exists. - Under the lock of the row, the control role looks for a certificate of the server of the token that holds the key of the request, and that is not retired and not expired. The request must parse, and its signature must be valid. The first use of another certificate retires the old one under the same lock, so a retirement cannot come between this check and the issue.
- The server must not be decommissioned. The roles of the request must be the roles of the server in the registry, in any order.
hopboxd installsends the roles in its own order, so the order does not count. - The control role issues a certificate for the key with the roles in the order of the registry, and uses the token. It changes nothing else in the registry, other than the peer address of step 5. It writes the audit entry
server.enroll_resync. - The server saves the new certificate with its old key, and removes
pending.pem.hopboxd installthen restartshopboxdwith it.
Each refusal comes before the use of the token, so the token stays unused, and nothing changes. If the answer of the resync gets lost, run the same command again with the same token within its lifetime. That call is a retry of the resync: its request is for the old key, and the control role sends the certificate of the resync again. The old certificate and the certificate of the resync hold the same key, so a retry takes the newest live certificate of that key. So a retry of the token of the lost add with the old key, within the lifetime of that token, also gets the certificate of the resync. Its audit entry server.enroll_retry then names the token of the add. The caller proves the key in both cases, so it gets no more than the resync gave.
A thief needs the private key of a live certificate of the server, and a token that an admin made for that server. With both, the thief gets the certificate that the server gets: the roles of the registry, with a new lifetime of 30 days.
A server whose old certificate expired has no resync. The internal listener checks the validity period of a client certificate in the TLS handshake, so the first call fails before Enroll, and the server never gets the credential is not valid. Such a server needs a decommission and a new enrollment. A server whose old certificate a renewal retired gets the refusal of its key at step 6. Its first call also writes the alarm of a retired certificate (Client certificates on each call).
The audit entry server.enroll_resync has the actor of the caller, most often anonymous. Its target is the server: the target kind server and the server ID. Its details are pool, token_id, roles, serial, the serial of the new certificate, and old_serial, the serial of the certificate whose key the request holds. It also has peer_address when the token gave the server its peer address. The log record is resynced a server, with component=service and the fields server, serial, and roles.
A control process of a release before this rule refuses a resync with invalid argument: the server reports no hardware. Update hopboxd on the server. During an upgrade of the control servers, run the resync again once each control process runs this release. The rule needs no migration.
These rules are build defaults of Q105, not owner decisions: the key of the old identity as the proof, the token of hopboxd admin enrollment-token create --server for every role of the registry, the call without a client certificate after the refusal of the old certificate, and the retry of a resync with the same token. A resync needs an identity, so it does not cover the first enrollment of a new server. The Terraform provider makes no token when the registry holds the roles of its plan, so it never resyncs. Run the resync by hand.
Hardware of a pool
Section titled “Hardware of a pool”All servers of a pool have identical hardware. So the first server that enrolls into a pool records its hardware in the pool, and the enrollment of a new server with other hardware fails (plan question Q61). The pool shows the hardware in the field hardware (the admin API).
hopboxd enroll reads these facts on a new server. A server that adds roles to itself (Add roles to an enrolled server) reads and sends none, because the control role checks the hardware only of a new server.
| Fact | Source |
|---|---|
| CPU model | model name of the first processor in /proc/cpuinfo |
| CPU threads | The CPUs in /sys/devices/system/cpu/online, the same count as in the heartbeats (the control channel) |
| RAM | MemTotal of /proc/meminfo |
| Disks | The size of each whole disk under /sys/block. A whole disk has a device entry and removable 0, so loop devices, RAID and device-mapper volumes, zram, and optical drives do not count. A disk of size 0 does not count either. |
On Linux, hopboxd enroll refuses a new server whose CPU is not amd64, before it reads these facts. In v1, every server has an Intel or AMD CPU. Also, only the /proc/cpuinfo of amd64 names the vendor, the family, and the model of the CPU fingerprint (the control channel).
On a Mac, which enrolls only the dns and the edge roles in development (Serve the domain of an install with the DNS role), hopboxd enroll reads the CPU model, the CPU threads, and the RAM with sysctl: machdep.cpu.brand_string, hw.logicalcpu, and hw.memsize. It reports no disk.
The control role compares a new server with the hardware of its pool:
| Fact | Rule |
|---|---|
| CPU model | The same text |
| CPU threads | The same count |
| RAM | At most 2% apart, because the firmware of two servers of one model can keep a few MiB more or less (domain.HardwareTolerance) |
| Disks | The same count, and each disk at most 2% apart from the disk of the same rank, in the order of size |
The pool default and each pool from before this rule have no hardware yet. The next server that enrolls into such a pool records it, not the servers that the pool holds already. An install from before this rule can enroll a server of another model beside its old server in the pool default. The pool records no hardware of the old server, so it takes that new server.
A pool whose servers are all decommissioned takes the hardware of its next server. So an instance admin who wants another model in a pool decommissions every server of the pool first. Only an enrollment adds a server, and each enrollment holds the lock of the server registry and the lock of the pool, so no server joins between the count of the live servers and the record of the hardware. The same hardware again leaves the pool and its version as they are.
Errors of enroll
Section titled “Errors of enroll”| Error | Cause |
|---|---|
the config <path> lists no role that enrolls. Add "node", "dns", "edge", or more than one to roles |
The config lists only control. |
the token does not have the form hbxe_<id>_<secret>_<cahash>. Make one with hopboxd admin enrollment-token create |
The token is not a token. |
the preflight check failed, so this server cannot run machines: and one line for each failed check |
A check of severity fail failed (the preflight check). |
this server is enrolled already as the server <id> with the roles <roles>. To enroll it again, remove <dir> first |
<data_dir>/server holds an identity with the roles of the config. |
enroll at <url>: invalid_argument: invalid argument: the roles drop <roles>, and the server <id> has no removal of them. Start one with hopboxd admin server remove-role |
The config lists fewer roles than the identity, and no removal of the missing roles is pending (the admin API). |
enroll at <url>: unavailable: ...pki: the peer is not the control plane of this install: no certificate of its chain has the CA hash of the enrollment token |
The control role at the URL has another CA than the token names, or the peer is not a control role. |
enroll at <url>: unavailable: ... with a TLS or a connection error |
No control role listens at this URL of channel.control_urls, or the install has no CA yet, so its handshakes fail. With several URLs, the error holds one such line for each URL. |
enroll at <url>: unauthenticated: the enrollment token is not valid... |
The control role refused the token (Errors of Enroll). |
enroll at <url>: invalid_argument: ... |
The control role refused the request, for example a role that it does not know. |
enroll at <url>: permission_denied: permission denied: the enrollment comes from <address>... |
The server enrolled from another address than the peer address of the token, or from an address other than loopback with a token without one (Peer addresses). |
read the hardware of the server: hostinfo: a server of hopbox needs an amd64 CPU from Intel or AMD, and this host runs <arch> |
A new server on Linux, with a CPU that is not amd64, such as arm64 (Hardware of a pool). |
read the hardware of the server: ... |
enroll cannot read /proc/cpuinfo, /proc/meminfo, or /sys/block. Off Linux, the message ends with the CPU and memory facts need Linux. |
enroll at <url>: failed_precondition: the hardware of this server differs from the pool <pool>: ... |
The server has other hardware than the first server of its pool (Hardware of a pool). |
node: the control plane sent another CA than the token names |
The answer holds another CA certificate. |
node: the certificate does not hold the key of this server |
The answer holds a certificate for another key. |
node: <path> must hold one PRIVATE KEY block and one CERTIFICATE REQUEST block with the token, the roles, and the end. Remove it to enroll with a new key |
<data_dir>/server/pending.pem does not load (Retry after a lost answer). |
Identity files
Section titled “Identity files”| Path | Mode | Contents |
|---|---|---|
<data_dir>/server |
0700 |
The dir of the identity. enroll makes it. |
<data_dir>/server/identity.pem |
0600 |
One CERTIFICATE block, the server certificate, and one PRIVATE KEY block, the PKCS #8 key of the server. |
<data_dir>/server/ca.pem |
0644 |
One CERTIFICATE block, the install CA. |
<data_dir>/server/pending.pem |
0600 |
The key and the request of an enrollment whose answer the server has not saved yet: one PRIVATE KEY block, and one CERTIFICATE REQUEST block with the headers Token, Roles, and Not-After. The enrollment writes it before its first call. It removes it after the save of the identity, after a first call that the control role refused or that never left the server, and after a refused retry once Not-After passed (Retry after a lost answer). |
The default data_dir is /var/lib/hopbox, so the default dir is /var/lib/hopbox/server.
Each write goes to a temp file .<name>.<random>.tmp in the same dir, which hopboxd syncs and then renames. The CA file goes first and the identity file last. So a crash leaves the old identity or the new one, never a half. A renewal rewrites identity.pem in the same way.
hopboxd checks pending.pem as it checks identity.pem: the mode, the owner, and that the request holds the key of the file. hopboxd checks the identity each time that it reads it. It refuses an identity.pem that is not a regular file. It refuses one that group or others can read, with node: <path> has mode <mode>, which lets group or others read the key of the server. Use mode 0600. It refuses one that belongs to another user than the user of hopboxd. It also refuses a certificate that the CA of ca.pem did not sign, and a certificate that does not hold the key of the file.
Enroll again
Section titled “Enroll again”You can enroll a server again, for example after its install starts from nothing. Stop hopboxd, remove <data_dir>/server, and run hopboxd enroll with a new token. The removal of the dir also removes pending.pem, so the server makes a new key. The server then gets a new server ID. The old server stays in the registry, unresponsive.
EnrollmentService
Section titled “EnrollmentService”hopbox.cluster.v1.EnrollmentService runs only on the internal listener (the internal listener). It is not part of the public API, and the SDKs do not include it.
Enroll
Section titled “Enroll”| Item | Value |
|---|---|
| Procedure | /hopbox.cluster.v1.EnrollmentService/Enroll |
| Credential | the enrollment token in the request. The call needs no client certificate. A retry with a used token also needs the private key of the certificate that the use issued (Retry after a lost answer). A resync also needs the private key of a live certificate of the server that the token names (Resync after the end of the token). |
| Policy action | server.enroll, every caller (the API server) |
| Idempotent option | no |
| Audit entry | server.enroll, server.enroll_retry for a retry, or server.enroll_resync for a resync |
EnrollRequest:
| Field | Type | Description |
|---|---|---|
token |
string | The enrollment token. |
csr |
bytes | A DER certificate request for an ECDSA P-256 key of the server. |
hostname |
string | The host name of the server, for the operator only. At most 253 bytes of printable ASCII without spaces. It can be empty. |
roles |
repeated string | The roles of the server: node, dns, edge, or more than one. |
hardware |
Hardware |
The hardware of the server (Hardware of a pool). A new server must send it. |
Hardware:
| Field | Type | Description |
|---|---|---|
cpu_model |
string | The model name of the CPU, such as AMD EPYC 4244P 6-Core Processor. Required. |
cpu_threads |
uint32 | The count of CPU threads. Required. |
memory_bytes |
uint64 | The RAM that the kernel sees, in bytes. Required. |
disk_bytes |
repeated uint64 | The sizes of the whole disks, in bytes, in any order. It can be empty, but a disk of 0 bytes fails. |
EnrollResponse:
| Field | Type | Description |
|---|---|---|
server_id |
string | The ID of the new server, a UUIDv7. |
certificate |
bytes | The DER server certificate. |
ca_certificate |
bytes | The DER certificate of the install CA. |
pool |
string | The name of the pool that the server joined. |
The control role checks the request in this order:
- The policy check, which allows every caller.
- The form of the token.
- The roles: at least one, each one a role that a server can enroll with, none twice.
- The host name.
- The install CA exists, or the control role makes it.
- The CA hash of the token is the hash of the install CA.
- In one transaction, it locks the token row. The token must exist, and its secret must match. A token that an enrollment used already makes the call a retry, for every caller. The retry goes on as Retry after a lost answer says, and the steps below do not run. For an unused token, the transaction ends without a change.
- A caller without a client certificate whose token names a server makes the call a resync. The resync goes on as Resync after the end of the token says, and the steps below do not run. For a new server, the hardware: a CPU model, CPU threads, RAM, and no disk of 0 bytes. A server that changes its roles skips this check, and goes on as Add roles to an enrolled server and Remove roles from an enrolled server say.
- In one transaction, it locks the token row. The token must exist, its secret must match, it must not be used, and it must not be expired. Each role of the request must be a role of the token. Otherwise the call fails with
unauthenticatedand the messagethe enrollment token is not valid: it allows only the roles <roles>, not <role>. Make a token with --roles, and the token stays unused. - In the same transaction, the certificate request must parse, its signature must be valid, and its key must be ECDSA P-256. Then the CA signs the certificate. So the CA signs only for a caller that holds a live token, and a bad request leaves the token unused.
- In the same transaction, it takes the lock of the server registry. Then it checks the address from which the call came (Peer addresses). A token with a peer address needs that address. A token without one needs loopback once a server of the install has or had a peer address. Otherwise the call fails with
permission_denied. The certificate of step 10 then goes nowhere, and the token stays unused. - In the same transaction, it locks the row of the pool of the token. A pool that an instance admin deleted after the make of the token fails with
failed_precondition, and the token stays unused (the admin API). - A pool without hardware records the hardware of the request. A pool with hardware compares it with the request (Hardware of a pool). Other hardware fails with
failed_precondition, and the token stays unused. The lock of the pool makes two first enrollments at the same time record the hardware once. - A token with a peer address that another server holds fails with
already_exists, and the token stays unused. The transaction inserts the server with the peer address of the token, its certificate, and the use of the token, and writes the audit entry.
Two enrollments with one token wait for each other on the row lock, so only one of them uses the token. The other one is a retry: it gets the same certificate only with the same key.
The new server has the state unresponsive until its first heartbeat. The heartbeat makes it ready (the control channel).
The audit entry server.enroll has the actor of the caller, most often anonymous. Its target is the new server: the target kind server and the server ID. It has these details:
| Detail | Value |
|---|---|
pool |
The name of the pool. |
token_id |
The ID of the token. |
hostname |
The host name from the request. |
roles |
The roles, joined by commas. |
serial |
The serial number of the certificate, in hex. |
hardware |
The hardware of the server, as text, such as AMD EPYC 4244P 6-Core Processor, 12 CPU threads, 62.5 GiB of RAM, disks 960 GB, 960 GB. |
peer_address |
The peer address of the token, such as 203.0.113.12. Only an enrollment with a token that names one has it. |
The service also writes the log record enrolled a server with component=service and the fields server, pool, hostname, and roles. The first server of a pool also writes recorded the hardware of a pool, with the fields pool and hardware.
Errors of Enroll
Section titled “Errors of Enroll”| Code | Message | Cause |
|---|---|---|
unauthenticated |
the enrollment token is not valid: it does not have the form hbxe_<id>_<secret>_<cahash> |
The token is not a token. |
unauthenticated |
the enrollment token is not valid: it was made for another install CA |
The CA hash of the token is not the hash of the install CA. |
unauthenticated |
the enrollment token is not valid |
No token has the ID, or the secret does not match. |
unauthenticated |
the enrollment token is not valid: it was used already. Make a new token |
A server enrolled with the token already, and the call is no retry with the same key (Retry after a lost answer). |
unauthenticated |
the enrollment token is not valid: it expired at <time>. Make a new token |
The lifetime of the token is over. The time is in RFC 3339, in UTC. |
permission_denied |
permission denied: the enrollment comes from <address>, but the token allows only the peer address <peer address> |
The token names a peer address, and the call came from another address. <address> is an unknown address when the call has no network address. |
permission_denied |
permission denied: the enrollment comes from <address>, and a token without a peer address enrolls only from this control server once a server of the install has a peer address. Make a token with --peer-address |
The token names no peer address, a server of the install has or had one, and the call came neither from loopback nor from the address of the control server on which it came. |
invalid_argument |
invalid argument: unknown server role: the server names no role |
The request has no role. |
invalid_argument |
invalid argument: unknown server role: "<role>". A server enrolls with the roles: node, dns, edge |
A role that a server cannot enroll with, such as control. |
invalid_argument |
invalid argument: unknown server role: the role "<role>" appears twice |
A role appears twice. |
unauthenticated |
the enrollment token is not valid: it names the peer address <address>, but the server has the peer address <server address>. Make a token with --peer-address <server address> |
A server that adds roles to itself with a token whose peer address is not its own, such as after SetServerPeerAddress changed it. |
already_exists |
already exists: the server <id> has the peer address <address>. A peer address belongs to one server until its decommission |
Another server that is not decommissioned took the peer address of the token after its make. This also holds for an add and a resync. |
invalid_argument |
invalid argument: the host name has <n> bytes, more than 253 |
The host name is too long. |
invalid_argument |
invalid argument: the host name "<name>" holds a character that is not printable ASCII |
The host name holds a space, a control character, or a character that is not ASCII. |
invalid_argument |
invalid argument: pki: the certificate request is not valid: ... |
The request does not parse, its signature is wrong, or its key is not ECDSA P-256. |
failed_precondition |
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 |
The install has no CA and no key-encryption key. In practice, the TLS handshake fails before the call. |
failed_precondition |
failed precondition: the pool <pool> was deleted. Make a token for a live pool |
An instance admin deleted the pool of the token after its make. |
failed_precondition |
failed precondition: the hardware of this server differs from the pool <pool>: it has <differences>. All servers of a pool have identical hardware, so enroll it into a pool of its server model |
A new server whose hardware differs from the hardware of its pool. <differences> names each fact that differs, such as 16 CPU threads, not 12. |
invalid_argument |
invalid argument: the server reports no hardware. Update hopboxd on the server |
A new server from a release of hopboxd that does not send its hardware. |
invalid_argument |
invalid argument: invalid hardware: ... |
The hardware has no CPU model, no CPU thread, no RAM, or a disk of 0 bytes. |
invalid_argument |
invalid argument: the roles drop <roles>, and the server <id> has no removal of them. Start one with hopboxd admin server remove-role |
A server that names fewer roles than it has, without a pending removal of exactly the missing roles. The token stays unused. |
failed_precondition |
failed precondition: the removal of the roles <roles> from the server <id> is not ready: <n> machines are still on it |
The end of a removal of node before its machines moved, such as a provider that ended the removal too early. Another thing that the server still holds, such as an old copy of a moved machine, gives its own reason after is not ready:. The token stays unused. |
failed_precondition |
failed precondition: the removal of the roles <roles> from the server <id> no longer passes its checks: <reason>. Fix the reason, or cancel the removal with hopboxd admin server cancel-remove-role |
A check of RemoveServerRoles failed after the start, such as public addresses of the install that name the server again. The token stays unused. |
failed_precondition |
failed precondition: the server <id> never lost the role <role>, so a token cannot add it. The add of a new role to a running server waits for the owner |
A token that adds a role that no removal took from the server, on the first server too. The token stays unused. |
failed_precondition |
failed precondition: the server <id> has a pending removal of the roles <roles>. Let it end, or cancel it with hopboxd admin server cancel-remove-role <id>, before a token adds a role |
A token that adds a role while a removal is pending. The token stays unused. |
invalid_argument |
invalid argument: the roles add <roles> and drop <roles> of the server <id>. A change of the roles adds roles or drops them, one change at a time |
A list that adds a role and drops another. The token stays unused. |
invalid_argument |
invalid argument: the server <id> has the roles <roles> already |
A server that names the roles that it has. |
unauthenticated |
the enrollment token is not valid: it names the enrolled server <id>, and enrolls no new server. A resync needs a request for the key of a live certificate of that server |
A call without a client certificate with a token that names a server, and a request for another key, such as a new server. It is also the refusal of a resync whose old certificate was retired. A resync whose old certificate expired fails earlier, in the TLS handshake. The token stays unused. |
invalid_argument |
invalid argument: the request names the roles <roles>, but the server <id> has the roles <roles> in the registry. A resync asks for the roles of the registry |
A resync with other roles than the registry. The token stays unused. |
failed_precondition |
failed precondition: the server <id> is decommissioned |
A resync of a decommissioned server. The token stays unused. |
Client certificates on each call
Section titled “Client certificates on each call”The internal listener verifies a client certificate against the install CA in the TLS handshake: its chain, its validity period, and the extended key usage client auth. A certificate of another CA fails the handshake. Then the request gate asks the server-certificate resolver for the caller (the internal listener). The resolver ties the certificate to a server of the registry with these checks, in order:
| Check | Refusal |
|---|---|
The certificate names exactly one hopbox://server/<id> URI with valid roles. |
the server certificate is not valid: pki: the certificate names no server: ... |
The table server_certificates has its serial. |
the server certificate is not valid: the CA never issued the serial <serial> to a server |
| That row names the server of the URI. | the server certificate is not valid: the serial <serial> belongs to the server <id>, not <id> |
| The certificate has not expired. | the server certificate is not valid: the certificate <serial> expired |
| No renewal retired the certificate. | the server certificate is not valid: a renewal retired the certificate <serial> |
| The roles of the URI are the roles of the server in the registry. | the server certificate is not valid: the certificate <serial> names the roles [<roles>], and the registry [<roles>] |
| The server is not decommissioned. | the server certificate is not valid: the server <id> is decommissioned |
A certificate that passes proves the caller server with the ID of the server. A refused certificate ends the call with unauthenticated and the message the credential is not valid. The cause goes to the log record api credential refused (the API server).
The first call with a certificate records its first use. That call also retires every other certificate of the server, older or never used, and logs retired other server certificates with component=service and the fields server, serial, and retired. Then the control role ends a channel that a retired certificate holds open (the control channel). So after a renewal, the old certificate works only until the server uses the new one, which it does at once. A stolen copy of the old certificate then stops working. A server gets at most one new certificate an hour.
The caller server carries the serial of its certificate. A heartbeat or a renewal on a channel whose certificate a renewal retired fails with unauthenticated and the message the server is decommissioned or unknown: a renewal retired the certificate of this channel, which ends the channel.
A call with a retired certificate is a sign that another party holds a copy of it, because the server holds a newer one. So the refusal also logs a retired server certificate called. Another party can hold a copy of it at level error with component=service and the fields server, serial, peer, and suppressed, and writes the audit entry server.retired_certificate_used. The entry has the actor server, the server as target, and the details serial, peer (the address of the caller), and suppressed. A copy that keeps dialing gets this alarm at most once an hour for each certificate, so it cannot flood the audit log. The calls in between are only refused and counted, and suppressed in the next alarm gives their count. The count lives in the control store, so it holds across control processes. In maintenance mode, the alarm writes nothing: each call logs the error without suppressed, and gets the refusal of maintenance mode (the API server). The first use of a certificate writes too, so maintenance mode refuses it the same way.
The leader deletes a certificate more than 1 day after it expired, except the newest certificate of each server (hopboxd).