-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
return auto_encrypt cert for listeners #6489
Conversation
return c.manual.cert, nil | ||
cert := c.manual.cert | ||
if cert == nil { | ||
cert = c.autoEncrypt.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.
can c.autoEncrypt
ever be nil? If it is this will panic.
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.
NewConfigurator initializes it:
Lines 169 to 176 in ef52147
func NewConfigurator(config Config, logger *log.Logger) (*Configurator, error) { | |
c := &Configurator{logger: logger, manual: &manual{}, autoEncrypt: &autoEncrypt{}} | |
err := c.Update(config) | |
if err != nil { | |
return nil, err | |
} | |
return c, nil | |
} |
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.
Couple of points in tests but the code looks good.
One inline but a meta one: the significant behaviour change here is in GetCertificate
yet the tests have no diff that mentions that method? How are we testing the actual change here that GetCertificate
now returns auto TLS?
tlsutil/config_test.go
Outdated
require.NoError(t, err) | ||
require.Equal(t, c.autoEncrypt.cert, cert) | ||
|
||
c.manual.cert = &tls.Certificate{Certificate: [][]byte{}} |
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 we add some actual payload to this Certificate that means it can't accidentally compare equal to the auto one above due to deep-equals rather than exact pointer checking?
I'm actually not sure this assertion prooves anything currently because I think it would still pass even if we were returning the auto cert not the manual cert after this since they both have equivalent values and require.Equal
does a deep equality not a pointer match IIRC.
Making them obviously different would make the intent of this test clearer too.
Thanks for the review @banks! I addressed your points and made the tests more meaningful. And improved the code as well. |
@@ -351,7 +351,7 @@ func (c *Config) baseVerifyIncoming() bool { | |||
|
|||
func loadKeyPair(certFile, keyFile string) (*tls.Certificate, error) { | |||
if certFile == "" || keyFile == "" { | |||
return &tls.Certificate{}, nil | |||
return nil, nil |
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.
Returning an empty cert here led to all kinds of strange things. This is gone now for good.
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.
Changes look good to me. I realise @i0rek is not likely to be around to make the small comment tweak suggested here or merge but we can find someone else who can hopefully!
require.NoError(t, err) | ||
require.Equal(t, c.autoEncrypt.cert, cert) | ||
|
||
c2, err := loadKeyPair("../test/key/ourdomain.cer", "../test/key/ourdomain.key") |
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.
nit: this test looks good now but it might not be obvious to future us exactly what the signficance f this behaviour is.
Maybe add comments that adding one cert as the auto_encrypt one gets returned as the regular server cert above and then that loading a different one as well as the "manual" cert means we still server the manual one not the auto-encrypt one.
4ce1363
to
d28773e
Compare
for empty string certFile or keyFile arg
9528c02
to
9f18bc4
Compare
* fix cert check * fix lock * add tests * test: add comments describing expected behavior for auto-encrypt and manual certificates * test: expect nil *tls.Certificate for empty string certFile or keyFile arg
Hey there, This issue has been automatically locked because it is closed and there hasn't been any activity for at least 30 days. If you are still experiencing problems, or still have questions, feel free to open a new one 👍. |
Fixes #6403