-
Notifications
You must be signed in to change notification settings - Fork 35
Fix 951 skip ca tls #1086
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
base: main
Are you sure you want to change the base?
Fix 951 skip ca tls #1086
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,14 +234,7 @@ func (ci *CertInfo) buildClientConfig(lg *zap.Logger) (*tls.Config, error) { | |
| lg.Warn("specified auto-certs in a client tls config, ignored") | ||
| } | ||
|
|
||
| if !cfg.HasCA() { | ||
| if cfg.SkipCA { | ||
| // still enable TLS without verify server certs | ||
| return &tls.Config{ | ||
| InsecureSkipVerify: true, | ||
| MinVersion: GetMinTLSVer(cfg.MinTLSVersion, lg), | ||
| }, nil | ||
| } | ||
| if !cfg.HasCA() && !cfg.SkipCA { | ||
| lg.Debug("no CA to verify server connections, disable TLS") | ||
| return nil, nil | ||
| } | ||
|
|
@@ -251,30 +244,32 @@ func (ci *CertInfo) buildClientConfig(lg *zap.Logger) (*tls.Config, error) { | |
| GetCertificate: ci.getCert, | ||
| GetClientCertificate: ci.getClientCert, | ||
| InsecureSkipVerify: true, | ||
| VerifyPeerCertificate: func(rawCerts [][]byte, _ [][]*x509.Certificate) error { | ||
| return ci.verifyCA(rawCerts) | ||
| }, | ||
| } | ||
|
|
||
| caPEM, err := os.ReadFile(cfg.CA) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| certPool := x509.NewCertPool() | ||
| if !certPool.AppendCertsFromPEM(caPEM) { | ||
| return nil, errors.New("failed to append ca certs") | ||
| if cfg.HasCA() { | ||
| tcfg.VerifyPeerCertificate = func(rawCerts [][]byte, _ [][]*x509.Certificate) error { | ||
| return ci.verifyCA(rawCerts) | ||
| } | ||
| caPEM, err := os.ReadFile(cfg.CA) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| certPool := x509.NewCertPool() | ||
| if !certPool.AppendCertsFromPEM(caPEM) { | ||
| return nil, errors.New("failed to append ca certs") | ||
| } | ||
| ci.ca.Store(certPool) | ||
| tcfg.RootCAs = certPool | ||
| } | ||
| ci.ca.Store(certPool) | ||
| tcfg.RootCAs = certPool | ||
|
|
||
| if !cfg.HasCert() { | ||
| if cfg.Cert == "" || cfg.Key == "" { | ||
| lg.Debug("no certificates, server may reject the connection") | ||
| return tcfg, nil | ||
|
Comment on lines
+265
to
267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This return path exits without resetting Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| cert, err := tls.LoadX509KeyPair(cfg.Cert, cfg.Key) | ||
| if err != nil { | ||
| return nil, errors.WithStack(err) | ||
| return nil, err | ||
| } | ||
| ci.cert.Store(&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.
Treating
cfg.Cert == "" || cfg.Key == ""as success silently accepts a half-configured client certificate. With CA configured, this changes fail-fast behavior into runtime handshake failures (no client cert is sent) and hides configuration mistakes during reload. Return an error when only one ofcertorkeyis set so misconfiguration is surfaced immediately.Useful? React with 👍 / 👎.