Skip to content
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 http-01 support to the Let's Encrypt mechanism. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

knightsc
Copy link

Since the autocert.Manager is always created regardless of whether
Let's Encrypt is being used or not I opted to always wrap the HTTP
redirect handler with the autocert.Manager HTTPHandler. This means
that port 80 will always be available to handle a Let's Encrypt challenge
as well as do the redirect. This should get Let's Encrypt support
functioning again since tls-sni-02 and tls-sni-01 were deprecated.

Fixes micromdm/micromdm#408

Testing this was a little bit of a pain but here's the process I followed.

  • Spun up a new EC2 instance (or really anything with a public IP would work)
  • Put a build of micromdm with these changes on the server
  • Created a public DNS entry to point to the public EC2 server
  • Ran micromdm as follows sudo ./build/darwin/micromdm serve --server-url https://mydomain
  • Tried accessing https://mydomain in a web browser

The result was no errors like mentioned in micromdm/micromdm#408 and I could view the certificate from the http response and it was indeed one issued by lets encrypt.

Since the autocert.Manager is always created regardless of whether
Let's Encrypt is being used or not I opted to always wrap the HTTP
redirect handler with the autocert.Manager HTTPHandler. This means
that port 80 will always be available to handle a Let's Encrypt challenge
as well as do the redirect. This should get Let's Encrypt support
functioning again since tls-sni-02 and tls-sni-01 were deprecated.
url := "https://" + req.Host + req.URL.String()
http.Redirect(w, req, url, http.StatusMovedPermanently)
}),
Handler: m.HTTPHandler(http.HandlerFunc(redirect)),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll need to refactor this a little since currently this code will only run if redirectHTTPS is true and we might be using Let's Encrypt but not doing redirects in that case these changes wouldn't work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fixup in 178158e. If redirectHTTPS is true or we've set the GetCertificate config which indicates we're using Let's Encrypt then we will start the http listener. Using the redirect methods in both cases should be fine because the autocert.HTTPHandler will do a redirect anyway if nil is passed in which is the other option we could do. I think this should correctly work now in all cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant