When no_auth_user is set, do not require a CONNECT proto.

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2022-01-21 09:41:45 -08:00
parent 7aba8a8e9e
commit dcadf6643a
2 changed files with 64 additions and 3 deletions

View File

@@ -147,8 +147,7 @@ func (c *client) parse(buf []byte) error {
// proper CONNECT if needed.
authSet := c.awaitingAuth()
// Snapshot max control line as well.
mcl := c.mcl
trace := c.trace
s, mcl, trace := c.srv, c.mcl, c.trace
c.mu.Unlock()
// Move to loop instead of range syntax to allow jumping of i
@@ -160,7 +159,24 @@ func (c *client) parse(buf []byte) error {
c.op = b
if b != 'C' && b != 'c' {
if authSet {
goto authErr
if s == nil {
goto authErr
}
var ok bool
// Check here for NoAuthUser. If this is set allow non CONNECT protos as our first.
// E.g. telnet proto demos.
if noAuthUser := s.getOpts().NoAuthUser; noAuthUser != _EMPTY_ {
s.mu.Lock()
user, exists := s.users[noAuthUser]
s.mu.Unlock()
if exists {
c.RegisterUser(user)
ok = true
}
}
if !ok {
goto authErr
}
}
// If the connection is a gateway connection, make sure that
// if this is an inbound, it starts with a CONNECT.