Add TLS/HTTPS support with Let's Encrypt and BYO certificates#246
Open
patrickdappollonio wants to merge 4 commits intomasterfrom
Open
Add TLS/HTTPS support with Let's Encrypt and BYO certificates#246patrickdappollonio wants to merge 4 commits intomasterfrom
patrickdappollonio wants to merge 4 commits intomasterfrom
Conversation
Serve content over HTTPS using your own certificate and key pair. When TLS is active, the server runs dual listeners: HTTPS for content and HTTP for automatic redirects. Certificates can be reloaded at runtime via SIGHUP or the /_/tls/reload API endpoint. New flags: --tls-cert, --tls-key, --hostname, --https-port, --http-port. All CLI flags are now organized into logical groups in --help output.
Pass --hostname without --tls-cert/--tls-key and http-server provisions a free TLS certificate from Let's Encrypt automatically. Handles HTTP-01 challenges on port 80, automatic renewal, and local certificate storage via certmagic. New flag: --tls-email for Let's Encrypt account notifications.
When --hostname is passed without --tls-cert/--tls-key, http-server provisions a free TLS certificate from Let's Encrypt automatically via certmagic. Handles HTTP-01 challenges, automatic renewal, and filesystem-based cert storage for multi-instance safety. New flags: --tls-email Let's Encrypt account notifications --tls-cache-dir certificate storage path (default: .certmagic/ in served dir) The cache directory is hidden from listings and blocked from direct access only when auto-TLS is active with that specific path. Users serving .certmagic directories without auto-TLS are not affected. The HTTP listener is mandatory in auto-TLS mode since it handles ACME HTTP-01 challenges (--http-port 0 is rejected).
Config file and environment variable values were not detected by cmd.Flags().Changed(), so port conflicts were silently ignored when set via .http-server.yaml or env vars. Now compares against default values (5000 for --port, 80/443 for --http-port/--https-port) which works regardless of how the value was configured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds native HTTPS support to
http-serverin two modes:Automatic certificates (Let's Encrypt): pass
--hostname example.comand a free TLS certificate is provisioned automatically via certmagic. Handles HTTP-01 challenges, automatic renewal, and filesystem-based certificate storage.Bring your own certificate: pass
--tls-certand--tls-keywith your own cert and key files.Both modes include:
SIGHUP(Unix) orPOST /_/tls/reloadGET /_/tlsreturns JSON with subject, SANs, issuer, and expiry--help: all CLI flags organized into logical sectionsNew flags
--hostname--tls-cert/--tls-key= BYO cert.--tls-cert--tls-key--tls-email--tls-cache-dir.certmagic/in served dir--https-port443--http-port800to disable in BYO mode)Usage
Multi-instance / Kubernetes
Certificates are stored on the filesystem (default
.certmagic/in the served directory). Multiple instances sharing the same volume reuse the same certificates. certmagic uses file locking to prevent ACME races. Use--tls-cache-dirto point at a shared persistent volume.Cache directory hiding is scoped to the active auto-TLS cache path only. Users serving
.certmagicdirectories without auto-TLS are not affected.Closes
Test plan
golangci-lintclean