Should a Node 24 service terminate TLS itself with node:https or node:http2, or leave TLS to a proxy in front, and what does each choice commit the team to?
answer
- who owns the certificate
- rotation without a restart
- defaults that assume a proxy
- HTTP/2 to browsers needs TLS
- encrypted hop or plaintext hop
basics
~20 sTerminating in Node means owning certificates, rotation (server.setSecureContext), TLS settings and the slow-client limits. A proxy centralises those but leaves a plaintext hop unless it re-encrypts. Choose by who operates certificates and whether traffic must stay encrypted end to end.
solid answer
~50 sWith `https.createServer` or `http2.createSecureServer`, the Node process holds the key and certificate, so the team owns renewal and must reload them, either by restart or with `server.setSecureContext()`, which swaps the context without interrupting existing connections. It also owns TLS policy (`minVersion` defaults to `'TLSv1.2'`), `SNICallback` for several names, `requestCert` for client certificates, and the slow-client deadlines, which the http docs say must stay non-zero when no reverse proxy is in front. Handshake work then runs in the same process as the handlers. A proxy in front lets the service run plain `node:http`, centralises certificates and protocol upgrades such as HTTP/2 to browsers, and absorbs slow clients, at the cost of a plaintext hop unless the proxy re-encrypts to Node. There is no single right answer: the deciding facts are whether policy requires encryption to the process, who already operates certificates, and how many services would repeat the work.
go deeper
Know that node:https takes a key and certificate and serves HTTPS, and that many deployments let a proxy handle TLS instead.
Explain the main https options, key, cert, ca, minVersion and requestCert, and that setSecureContext swaps certificates on a running server.
Run the chosen model safely: certificate reload without dropped connections, mandatory slow-client deadlines when Node faces clients, and timeout agreement with any proxy.
Own the decision: weigh end-to-end encryption, client identity, certificate operations across services and the cost of a plaintext hop, then record who renews what.
## What the decision is **TLS termination** is the point where encrypted traffic is decrypted. Either the Node process does it, using `node:https` (or `node:http2` with `createSecureServer`), or a proxy or load balancer in front does it and forwards requests to Node, in plaintext or over a second TLS connection. Both are common, both work, and each leaves the team with different permanent chores. ## What terminating in Node commits you to `https.createServer(options, handler)` accepts the options of `tls.createServer()`, `tls.createSecureContext()` and `http.createServer()` together, so one call sets certificates, TLS policy and HTTP limits. 1. **Certificate custody.** `key` and `cert` (or `pfx`, plus `ca` for chains) are loaded into the process. The private key now lives wherever the service runs, and every instance needs it. 2. **Rotation.** A renewed certificate is not picked up automatically. Either restart instances, or call `server.setSecureContext({ key, cert })`, which replaces the secure context of a running server; the docs state existing connections are not interrupted. Someone has to build and monitor that reload path. 3. **TLS policy.** `minVersion` defaults to `tls.DEFAULT_MIN_VERSION`, which is `'TLSv1.2'` unless a flag such as `--tls-min-v1.3` changes it. Cipher choices, session resumption (`sessionTimeout`, 300 seconds by default) and `handshakeTimeout` (120000 ms) become application settings. 4. **Several hostnames.** `SNICallback(servername, callback)` picks a secure context per requested name, so one process can serve several certificates. 5. **Client certificates.** `requestCert: true` asks clients for a certificate, and `rejectUnauthorized` (default `true`, effective only with `requestCert`) refuses ones not signed by the configured `ca`. This is the strongest reason to terminate in Node: the service sees the verified client identity itself. 6. **Exposure to slow and abusive clients.** The http docs say `headersTimeout` and `requestTimeout` must be non-zero to protect against denial of service when the server is deployed without a reverse proxy in front. Every connection's handshake and encryption work is done by the Node process that also runs the handlers. 7. **HTTP/2 to browsers.** The http2 docs state that no browser is known to support unencrypted HTTP/2, so a Node service that wants to offer HTTP/2 to browsers itself must use `http2.createSecureServer`. ## What a proxy in front commits you to - The service runs plain `http.createServer`; certificates, renewal and TLS policy live in one place for many services. - The proxy can speak HTTP/2 or newer protocols to clients while forwarding HTTP/1.1 to Node, so the Node side stays simple. - The proxy absorbs slow clients and connection floods before they reach the event loop, though Node's own deadlines stay worth keeping as a second line. - The hop between proxy and Node is **plaintext** unless the proxy re-encrypts. Whether that is acceptable is a policy question about the network between them. - Node no longer sees the client's address or TLS details directly; they arrive in headers the proxy adds, and trusting those headers is a framework and proxy configuration concern. - A second component with its own idle and keep-alive timeouts now has to agree with Node's. ## Comparing the two | Concern | TLS in Node | TLS at a proxy | |---|---|---| | Certificate custody | every service instance | one place | | Rotation | restart or `setSecureContext` per service | the proxy's own mechanism | | Client certificates | verified in the service | forwarded as headers, if at all | | Encryption to the process | yes | only if the proxy re-encrypts | | Slow-client exposure | Node's limits are the defence | the proxy absorbs most of it | | HTTP/2 to browsers | `http2.createSecureServer` | the proxy speaks it | ## How a lead decides - If policy demands encryption all the way to the process, or the service must verify client certificates itself, terminate in Node, or have the proxy re-encrypt. - If many services share one edge, centralising certificates at the proxy removes the same rotation code from every one of them. - If Node terminates, write down who renews certificates, how reload works (`setSecureContext` or rolling restarts) and which deadlines are mandatory. - Revisit the choice when the topology changes; a service that moves behind a new edge often keeps a TLS setup nobody maintains any more.
- How can a Node https server pick up a renewed certificate without dropping traffic?Read the new key and certificate and call `server.setSecureContext({ key, cert })`. It replaces the server's secure context for new handshakes, and the docs state existing connections are not interrupted. Trigger it from a file watcher, a signal or a timer, and alert if the served certificate's expiry stops moving. The alternative is a rolling restart of instances.
- A Node service terminates TLS and must accept only clients presenting a certificate from an internal authority. Which https options do that?Set `requestCert: true` so the server asks for a client certificate, provide the internal authority in `ca`, and leave `rejectUnauthorized` at its default `true`, which refuses certificates that do not verify against that `ca`. Without `requestCert`, `rejectUnauthorized` has no effect on the server side.
- Thinks Node reloads a renewed certificate file automatically
- Believes a proxy makes Node's own timeouts pointless
- Assumes rejectUnauthorized alone enables client certificates
- Treats the proxy-to-Node hop as encrypted by default
- Claims one answer is right for every service