mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
[FIXED] allow_non_tls is lost after server reload
The server would reset its INFO's TLSRequired to the presence of a TLS configuration without checking for the allow_non_tls option. Resolves #3581 Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -206,7 +206,7 @@ type tlsOption struct {
|
||||
func (t *tlsOption) Apply(server *Server) {
|
||||
server.mu.Lock()
|
||||
tlsRequired := t.newValue != nil
|
||||
server.info.TLSRequired = tlsRequired
|
||||
server.info.TLSRequired = tlsRequired && !server.getOpts().AllowNonTLS
|
||||
message := "disabled"
|
||||
if tlsRequired {
|
||||
server.info.TLSVerify = (t.newValue.ClientAuth == tls.RequireAndVerifyClientCert)
|
||||
|
||||
@@ -1973,3 +1973,40 @@ func TestTLSPinnedCertsRoute(t *testing.T) {
|
||||
checkNumRoutes(t, srvSeed, 0)
|
||||
checkNumRoutes(t, srv, 0)
|
||||
}
|
||||
|
||||
func TestAllowNonTLSReload(t *testing.T) {
|
||||
tmpl := `
|
||||
listen: "127.0.0.1:-1"
|
||||
ping_interval: "%s"
|
||||
tls {
|
||||
ca_file: "configs/certs/ca.pem"
|
||||
cert_file: "configs/certs/server-cert.pem"
|
||||
key_file: "configs/certs/server-key.pem"
|
||||
}
|
||||
allow_non_tls: true
|
||||
`
|
||||
conf := createConfFile(t, []byte(fmt.Sprintf(tmpl, "10s")))
|
||||
defer removeFile(t, conf)
|
||||
s, o := RunServerWithConfig(conf)
|
||||
defer s.Shutdown()
|
||||
|
||||
check := func() {
|
||||
t.Helper()
|
||||
nc := createClientConn(t, "127.0.0.1", o.Port)
|
||||
defer nc.Close()
|
||||
info := checkInfoMsg(t, nc)
|
||||
if !info.TLSAvailable {
|
||||
t.Fatal("TLSAvailable should be true, was false")
|
||||
}
|
||||
if info.TLSRequired {
|
||||
t.Fatal("TLSRequired should be false, was true")
|
||||
}
|
||||
}
|
||||
check()
|
||||
|
||||
os.WriteFile(conf, []byte(fmt.Sprintf(tmpl, "20s")), 0660)
|
||||
if err := s.Reload(); err != nil {
|
||||
t.Fatalf("Error on reload: %v", err)
|
||||
}
|
||||
check()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user