tls: allow a certificate for names other than localhost (extra_sans, cert_file, key_file)
Problem
Native TLS (tls.enabled: true) can only serve a certificate that is valid for localhost, 127.0.0.1 and ::1. A client that reaches mcpproxy by any other name (a Docker service name, a VM host name, a tailnet name, a Kubernetes service) cannot verify it. sbx and most MCP clients verify certificates, so for these setups native TLS is unusable and people put a reverse proxy in front just to change the certificate.
What the code does today
In internal/tlslocal/localca.go, EnsureServerTLSConfig:
- It creates
ca.pem/ca.keyandlocalhost.pem/localhost.keyintls.certs_dir(default~/.mcpproxy/certs) if they are missing. - The generated server certificate has
DNSNames: ["localhost"]andIPAddresses: [127.0.0.1, ::1]. There is no setting to add to that list. - If
localhost.pemandlocalhost.keyalready exist they are loaded as they are. So the only way to serve another name today is to leave a hand-made certificate under the file namelocalhost.pemincerts_dir, which is not documented and is easy to overwrite or lose. TLSConfighasenabled,require_client_cert,certs_dirandhsts; nothing else.
Proposal
Smallest change first:
tls.extra_sans: a list of DNS names and IP addresses added to the generated server certificate. The certificate is regenerated, signed by the same local CA, when the list differs from what the existing certificate carries.mcpproxy trust-certkeeps working because the CA does not change.tls.cert_fileandtls.key_file: use a certificate the operator supplies (from a real CA, an internal CA,certbot, or a Kubernetes secret mount). Both or neither; a startup error that names the setting if only one is set or a file cannot be read. When set, nothing is generated.- Optionally
tls.client_ca_fileforrequire_client_cert, since with an external server certificate the client CA is otherwise still the generated localca.pem.
Either 1 or 2 alone solves the hostname problem. 2 is the one that fits container and Kubernetes secret mounts, and it composes with MCPPROXY_API_KEY_FILE (#1706).
Not asking for
ACME, automatic renewal, or any change to the default behaviour: with none of the new settings, startup is byte-for-byte what it is now.
I can send a PR for 1, 2 or both. Which would you take, and should the key file follow the same read rules as the secret file reader (absolute path, regular file, size cap)?