-
Notifications
You must be signed in to change notification settings - Fork 55
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 implementation of CertFetcher abstraction on top of Lego/ACME library. #345
Conversation
… modify the current flow to inject an instance of CertFetcher into CertCache to take care of the scheduled cert renewals.
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
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.
Nice progress! Haven't reviewed tests yet, but let me know if there's anything in particular there you want me to notice. :)
"strconv" | ||
|
||
"github.com/WICG/webpackage/go/signedexchange" | ||
"github.com/go-acme/lego/v3/certcrypto" |
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.
Please run dep ensure
and add the vendor/
files to this PR. (https://golang.github.io/dep/)
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.
Will do this in next commit.
return nil, err | ||
} | ||
|
||
// We specify an http port of `acmeChallengePort` |
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.
OK for this PR. I think for some future PR it'd be preferable if we can host the challenge URLs on the same port as the rest of amppkg. (Agree/disagree?)
Naive ideas:
- https://golang.org/pkg/net/http/httputil/#ReverseProxy
- implement a custom challenge.Provider (https://github.com/go-acme/lego/blob/a5a29187fea9f555ea43fae16ca65066c452d330/challenge/http01/http_challenge_server.go#L25)
We'd also talked about, instead of the reverse-proxy approach, adding a new config field with a path to a directory where we'd dump the challenge responses, to be served by a normal web server (e.g. /var/www/html/.well-known/acme-challenge
). Especially useful if having to coexist with certbot. If that's still your thinking, then I guess the custom ProviderServer seems like the way to go?
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.
My 2c based on what I know so far is that we should lean towards the reverse proxy if we're picking exactly one.
The idea here is that this may be running on some remote server in a Google Cloud, Amazon, etc installation where shared filesystem may be difficult. The publisher already needs to set up reverse proxy rules for the Packager anyway, so adding one new rule should be fairly easy in any configuration.
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.
Good point, and I think agreed. If most people are using some CDN for their TLS termination, then they're probably using ACME DNS-01 challenge type, which won't interfere. This is probably the more common use-case.
If people are going full DIY, running their own Apache/nginx with certbot to manage their own TLS certs, then they're using HTTP-01 challenge type (certbot doc), so it would have to share the /.well-known/acme-challenge/
URL path prefix. I'm not sure if there's a way to tell Apache/nginx to say "rev-proxy only if there isn't a file on disk".
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.
Sorry, twifkak@, forgot to give you a heads up about this and my decision to do the proxy method after discussions with gregable@. At this point, let's go the direction of the reverse proxy method and address the co-mingling of certbot/DIY method with the reverse proxy at a later time. It's possible that DevRel type folks may have encountered this in the field and have suitable suggestions.
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.
Sounds good. Still would lean towards it running on the same port (future PR OK), unless you see a problem with that.
if !shouldRegister { | ||
myUser.Registration = new(registration.Resource) | ||
} else { | ||
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) |
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.
Add a TODO to make sure we present the TOS URL to the user and prompt for confirmation. (The plan is to move this to some separate setup command outside the server?)
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.
Done.
return nil, err | ||
} | ||
|
||
// We specify an http port of `acmeChallengePort` |
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.
My 2c based on what I know so far is that we should lean towards the reverse proxy if we're picking exactly one.
The idea here is that this may be running on some remote server in a Google Cloud, Amazon, etc installation where shared filesystem may be difficult. The publisher already needs to set up reverse proxy rules for the Packager anyway, so adding one new rule should be fairly easy in any configuration.
jose "gopkg.in/square/go-jose.v2" | ||
) | ||
|
||
const CertResponseMock = `-----BEGIN CERTIFICATE----- |
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.
Maybe document what you did to generate these.
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.
Done.
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 nit fixes. LGTM once Travis is happy.
return nil, err | ||
} | ||
|
||
// We specify an http port of `acmeChallengePort` |
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.
Sounds good. Still would lean towards it running on the same port (future PR OK), unless you see a problem with that.
_, apiURL, tearDown := tester.SetupFakeAPI() | ||
defer tearDown() | ||
|
||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048) |
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.
Should this be ec.GenerateKey or something?
` | ||
|
||
func TestNewFetcher(t *testing.T) { | ||
_, apiURL, tearDown := tester.SetupFakeAPI() |
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.
Instead of doing this, you may be interested in https://godoc.org/github.com/stretchr/testify/suite which supports SetupTest() and TearDownTest() methods.
(Also, assert.X(t, ...)
becomes this.Assert().X(...)
which is neither better nor worse.)
|
||
cert, err := fetcher.FetchNewCert() | ||
assert.NotNil(t, err) | ||
assert.Nil(t, cert) |
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.
Maybe also assert the cert subject or something just to make sure it's been populated.
assert.Nil(t, cert) | ||
} | ||
|
||
func setupMux(mux *http.ServeMux, apiURL string, privateKey *rsa.PrivateKey) { |
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.
Add a quick comment to say what this does, e.g. "Builds a fake ACME server that supports /newOrder and /finalize; tests should add a custom implementation of /certificate."
Thanks for the approvals. Per an offline conversation with twifkak@, we will need to move the amppackager project from dep to go modules (issue #270) in order to resolve the travis failures for this PR. |
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.
LICENSE files LGTM for new vendored deps, and vendored deps outside golang.org/x seem fairly minimal, and changes for existing vendored deps seem harmless.
On of these days, I would love to understand the difference between the lists of deps in go.mod, go.sum, vendor, and vendor/modules.txt. All 4 are different... for good reasons I hope.
No description provided.