-
Notifications
You must be signed in to change notification settings - Fork 35
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.
return &cert, nil | ||
} | ||
|
||
err = os.Mkdir(s.config.StoragePath, 0750) |
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.
We'll need to MkdirAll
here, as StoragePath
may be more than one level deep.
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.
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.
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
.
Fixed #34 so that it cleanly applies to the current HEAD.
In addition, here is how to test it:
Then you can test it: