feat(server): support optional HTTPS via TLS cert/key env vars#165
feat(server): support optional HTTPS via TLS cert/key env vars#165
Conversation
- Add TLS_CERT_FILE and TLS_KEY_FILE config options - Serve HTTPS via ListenAndServeTLS when both are set - Reject partial TLS config in Validate to avoid silent HTTP fallback - Document the new env vars in .env.example and CONFIGURATION.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds first-class support for serving AuthGate over HTTPS directly (optional), controlled by TLS cert/key environment variables, while keeping the default HTTP behavior unchanged.
Changes:
- Introduces
TLS_CERT_FILE/TLS_KEY_FILEconfig fields,Config.TLSEnabled(), and validation to reject partial TLS configuration. - Updates server startup to call
ListenAndServeTLSwhen TLS is enabled and improve startup logging. - Adds config tests and documents the new TLS configuration in
.env.exampleanddocs/CONFIGURATION.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/config.go | Adds TLS cert/key fields, TLSEnabled(), env loading, and validation for partial TLS config. |
| internal/bootstrap/server.go | Switches server run loop between HTTP and HTTPS based on config. |
| internal/bootstrap/bootstrap.go | Updates call site to pass config into addServerRunningJob. |
| internal/config/config_test.go | Adds tests for TLSEnabled() and validation behavior for partial TLS config. |
| docs/CONFIGURATION.md | Documents TLS/HTTPS configuration and local self-signed testing steps. |
| .env.example | Provides example TLS env vars and notes for enabling HTTPS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Update TLS/HTTPS docs to state that partial cert/key config is rejected by Validate, not silently downgraded to HTTP - Store cfg.TLSEnabled() in a local bool in addServerRunningJob to avoid calling twice Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
TLS_CERT_FILEandTLS_KEY_FILEand AuthGate listens onSERVER_ADDRwith TLS; otherwise plain HTTP as before.Config.Validate()— mirrors the existing JWT-key validation pattern — to prevent silent HTTP fallback..env.exampleand added a TLS / HTTPS subsection indocs/CONFIGURATION.mdwith rationale (full chain,BASE_URLscheme update, no hot reload) and a self-signed quick-test snippet.Implementation notes
addServerRunningJobnow branches oncfg.TLSEnabled()and callssrv.ListenAndServeTLS/srv.ListenAndServe. Graceful shutdown is unchanged —srv.Shutdown()handles both identically.crypto/tlsdefaults (TLS 1.2+, modern ciphers). No manual tuning.Test plan
TestTLSEnabled— covers all four cert/key combinationsTestValidate_TLSPartialConfig— covers four cases incl. error pathsmake fmt,make lint(0 issues),go test ./internal/config/... ./internal/bootstrap/...TLS_CERT_FILE/TLS_KEY_FILE, confirmcurl -k https://localhost:8080/healthreturns 200Validate()error🤖 Generated with Claude Code