Custom authentication extension for message system nats (gnatsd)

Because of the simple research on the source code of the mqtt server mosquitto, I feel that its performance has bottlenecks in many places. For example, the network layer does not use epoll, and the topic uses the tree (doesn't it have to traverse to death when there are a large number of topics) There are still many..., so I went online again. I searched for information on other messaging systems, and found that gnatsd's performance is very powerful. Although its function is weaker than mqtt, it may also fit my project to some extent.
First of all, I want to learn about the authentication system of gnatsd. At first, I found that it is written in the configuration file, so that it is possible for a small number of users or a large number of users to share passwords and permissions, but if you want to use different passwords for all users And permission control will not work.

Custom Authentication Solutions


I haven't started to use it officially, I haven't downloaded the code, I just checked the code on github and finally found a solution:

server/auth.go:
// Authentication is an interface for implementing authentication
type Authentication interface {
    // Check if a client is authorized to connect
    Check(c ClientAuthentication) bool
}
server/auth.go
if s.opts.CustomRouterAuthentication != nil {
        return s.opts.CustomRouterAuthentication.Check(c)
    }
server/opts.go:
CustomClientAuthentication Authentication `json:"-"`

Authentication is performed in auto.go, and each time it is judged that if it CustomRouterAuthenticationis not empty, the CustomRouterAuthentication.Checkauthentication is performed.

CustomRouterAuthenticationThe methods that implement Authenticationthe interface Check.


So when the server is initialized, you can pass in a custom one CustomClientAuthentication, for example:

opts := DefaultOptions()
opts.CustomClientAuthentication = &clientAuth
s := RunServer(opts)

The custom authentication class can imitate the mosquitto auth plugin plugin to use the query database for authentication, such as querying Redis.


Attached is the discussion on authentication in Issues:
Enable external Authentication (authn) and Authorization (authz) via Extensible Auth Provider. #434

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325671560&siteId=291194637