fix(proxy): guard external TLS misconfig and suppress G402 for skip-verify
Address PR review: - Reject external config that supplies TLS material (CA/cert/key/server-name/ skip-verify) without TLSRequired, which would otherwise silently connect in plaintext despite the user providing TLS settings. - Annotate the intentional InsecureSkipVerify assignment (TLSSkipVerify opt-in testing flag) with //nolint:gosec G402. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8c779d3aa5
commit
e8c6e04d6f
2 changed files with 27 additions and 2 deletions
|
|
@ -77,6 +77,19 @@ func (c ExternalDoltConfig) Validate() error {
|
|||
return fmt.Errorf("ExternalDoltConfig: TLSCACert %q is not absolute", c.TLSCACert)
|
||||
}
|
||||
|
||||
if !c.TLSRequired {
|
||||
switch {
|
||||
case c.TLSCACert != "":
|
||||
return errors.New("ExternalDoltConfig: TLSCACert set without TLSRequired")
|
||||
case c.TLSCert != "" || c.TLSKey != "":
|
||||
return errors.New("ExternalDoltConfig: TLSCert/TLSKey set without TLSRequired")
|
||||
case c.TLSServerName != "":
|
||||
return errors.New("ExternalDoltConfig: TLSServerName set without TLSRequired")
|
||||
case c.TLSSkipVerify:
|
||||
return errors.New("ExternalDoltConfig: TLSSkipVerify set without TLSRequired")
|
||||
}
|
||||
}
|
||||
|
||||
if c.TLSRequired && hasSocket && c.TLSServerName == "" && !c.TLSSkipVerify {
|
||||
return errors.New("ExternalDoltConfig: TLSRequired over Socket needs TLSServerName or TLSSkipVerify")
|
||||
}
|
||||
|
|
@ -96,7 +109,7 @@ func (c ExternalDoltConfig) TLSClientConfig() (*tls.Config, error) {
|
|||
cfg := &tls.Config{MinVersion: tls.VersionTLS12}
|
||||
|
||||
if c.TLSSkipVerify {
|
||||
cfg.InsecureSkipVerify = true
|
||||
cfg.InsecureSkipVerify = true //nolint:gosec // G402: opt-in insecure transport via the TLSSkipVerify testing flag
|
||||
} else {
|
||||
name := c.TLSServerName
|
||||
if name == "" {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,19 @@ func TestExternalDoltConfig_Validate_TLS(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
_ = keyPath
|
||||
t.Run("tls material without tls required is rejected", func(t *testing.T) {
|
||||
cases := []ExternalDoltConfig{
|
||||
{Host: "db", Port: 3306, TLSCACert: certPath},
|
||||
{Host: "db", Port: 3306, TLSCert: certPath, TLSKey: keyPath},
|
||||
{Host: "db", Port: 3306, TLSServerName: "db"},
|
||||
{Host: "db", Port: 3306, TLSSkipVerify: true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if err := c.Validate(); err == nil {
|
||||
t.Fatalf("expected error for TLS material without TLSRequired: %+v", c)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestExternalDoltConfig_TLSClientConfig(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue