-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for local TLS. #40
base: main
Are you sure you want to change the base?
Conversation
Incredible, thanks - should I close #34 in favor of this? |
@reesericci I basically just squashed your PR and made a few fixes. You are welcome to close #34 in favour of this if you think that makes sense. You already solved all the tricky problems like constructing the local CA etc. |
@kevinmcconnell can you please review this PR? |
Hey there! Is there any chance this PR is going to get merged? It would greatly help in local debugging production-like environments |
@dhh any chance we can get a review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the nudges on this one @ioquatix, and sorry for the slow review, it had fallen off my radar 😬
I think this is a great idea, and I can see how it would be useful. Would definitely like to get this merged. Nice work figuring out the details of creating the authority and certs, it seems to work really well.
I've left a couple suggestions about the implementation. They're mostly minor, but I think it's worth extracting the logic of providing TLS certificates out from Server
. I think it'll clarify the logic a bit, but will also separate the responsibilities a bit more, and introduce a seam for testing. Let me know what you think.
s.httpsServer.TLSConfig = manager.TLSConfig() | ||
|
||
if s.config.TLSLocal { | ||
s.httpsServer.TLSConfig = s.localTLSConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing this, we won't need to create the manager
above. It's likely harmless, but it would be clearer to separate the ACME TLS and local TLS support more fully.
Rather than branch on the specific differences, how about introducing an interface that both the local TLS provider, and the autocert Manager implement, maybe something like:
type TLSProvider interface {
HTTPHandler(h http.Handler) http.Handler
TLSConfig() *tls.Config
}
Then we can create either a local provider or an autocert manager (depending on the config), and wire it up the same way in either case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but I don't know enough about Go to implement this without significant help, so maybe it's better if you either add commits to this PR to do what you want or merge it as is and then refactor it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this sounds great @kevinmcconnell. Unfortunately I don't have the bandwidth to implement this at the moment but a +1 from me on the common interface as a nice abstraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries @reesericci, I'll try to wrap this up when I have a bit of spare time. Thanks for getting this work started.
NextProtos: []string{ | ||
"h2", "http/1.1", // enable HTTP/2 | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be specified, as HTTP/2 support should be enabled automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, it needs to be specified for ALPN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary because the HTTP server includes h2
in its available protocols by default.
return cert, nil | ||
} | ||
|
||
func (s *Server) getLocalAuthority() (*tls.Certificate, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, I think it's worth introducing a common interface for the two types of TLS provider. At which point, we can move the work of getLocalAuthority
/getLocalCertificate
into its own type that implements that interface.
That would also give us a handy place to add some test coverage for GetCertificate
.
ec51dba
to
747c24e
Compare
Fixed #34 so that it cleanly applies to the current HEAD.
In addition, here is how to test it:
Then you can test it: