Skip to content
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

If no_auth_user is set, clear auth required from server info to client. #3659

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2019 The NATS Authors
// Copyright 2012-2022 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
24 changes: 23 additions & 1 deletion server/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2020 The NATS Authors
// Copyright 2012-2022 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -2583,3 +2583,25 @@ func TestClientDenySysGroupSub(t *testing.T) {
require_Error(t, err)
require_Contains(t, err.Error(), "Permissions Violation")
}

func TestClientAuthRequiredNoAuthUser(t *testing.T) {
conf := createConfFile(t, []byte(`
listen: 127.0.0.1:-1
accounts: {
A: { users: [ { user: user, password: pass } ] }
}
no_auth_user: user
`))
defer removeFile(t, conf)

s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

nc, err := nats.Connect(s.ClientURL())
require_NoError(t, err)
defer nc.Close()

if nc.AuthRequired() {
t.Fatalf("Expected AuthRequired to be false due to 'no_auth_user'")
}
}
6 changes: 6 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,12 @@ func (s *Server) createClient(conn net.Conn) *client {
c.nonce = []byte(info.Nonce)
authRequired = info.AuthRequired

// Check to see if we have auth_required set but we also have a no_auth_user.
// If so set back to false.
if info.AuthRequired && opts.NoAuthUser != _EMPTY_ {
info.AuthRequired = false
}

s.totalClients++
s.mu.Unlock()

Expand Down