Skip to content

Commit

Permalink
Fix README custom plugin returns, fix prefix/registered order for aut…
Browse files Browse the repository at this point in the history
…h check, don return an error on enabled but unregistered superuser on valid prefix.
  • Loading branch information
iegomez committed Mar 10, 2021
1 parent 5cc6873 commit e4d6555
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1275,15 +1275,15 @@ func Init(authOpts map[string]string, logLevel log.Level) error {
}

func GetUser(username, password, clientid string) (bool, error) {
return false
return false, nil
}

func GetSuperuser(username string) (bool, error) {
return false
return false, nil
}

func CheckAcl(username, topic, clientid string, acc int) (bool, error) {
return false
return false, nil
}

func GetName() string {
Expand Down
28 changes: 17 additions & 11 deletions backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ func (b *Backends) setCheckers(authOpts map[string]string) error {
b.userCheckers = append(b.userCheckers, name)
log.Infof("registered user checker: %s", name)
case superuserCheck:
b.superuserCheckers = append(b.superuserCheckers, name)
log.Infof("registered superuser checker: %s", name)
if !b.disableSuperuser {
b.superuserCheckers = append(b.superuserCheckers, name)
log.Infof("registered superuser checker: %s", name)
}
default:
return fmt.Errorf("unsupported check %s found for backend %s", check, name)
}
Expand All @@ -230,8 +232,11 @@ func (b *Backends) setCheckers(authOpts map[string]string) error {
log.Infof("registered acl checker: %s", name)
b.userCheckers = append(b.userCheckers, name)
log.Infof("registered user checker: %s", name)
b.superuserCheckers = append(b.superuserCheckers, name)
log.Infof("registered superuser checker: %s", name)

if !b.disableSuperuser {
b.superuserCheckers = append(b.superuserCheckers, name)
log.Infof("registered superuser checker: %s", name)
}
}
}

Expand Down Expand Up @@ -319,14 +324,14 @@ func (b *Backends) AuthUnpwdCheck(username, password, clientid string) (bool, er

validPrefix, bename := b.lookupPrefix(username)

if !checkRegistered(bename, b.userCheckers) {
return false, fmt.Errorf("backend %s not registered to check users", bename)
}

if !validPrefix {
return b.checkAuth(username, password, clientid)
}

if !checkRegistered(bename, b.userCheckers) {
return false, fmt.Errorf("backend %s not registered to check users", bename)
}

// If the backend is JWT and the token was prefixed, then strip the token. If the token was passed without a prefix it will be handled in the common case.
if bename == jwtBackend {
prefix := b.getPrefixForBackend(bename)
Expand Down Expand Up @@ -395,11 +400,12 @@ func (b *Backends) AuthAclCheck(clientid, username, topic string, acc int) (bool

// Short circuit checks when superusers are disabled.
if !b.disableSuperuser {
log.Debugf("Superuser check with backend %s", backend.GetName())
if !checkRegistered(bename, b.superuserCheckers) {
return false, fmt.Errorf("backend %s not registered to check superusers", bename)
return false, nil
}

log.Debugf("Superuser check with backend %s", backend.GetName())

aclCheck, err = backend.GetSuperuser(username)

if aclCheck && err == nil {
Expand All @@ -409,7 +415,7 @@ func (b *Backends) AuthAclCheck(clientid, username, topic string, acc int) (bool
// If not superuser, check acl.
if !aclCheck {
if !checkRegistered(bename, b.aclCheckers) {
return false, fmt.Errorf("backend %s not registered to check superusers", bename)
return false, fmt.Errorf("backend %s not registered to check acls", bename)
}

log.Debugf("Acl check with backend %s", backend.GetName())
Expand Down

0 comments on commit e4d6555

Please sign in to comment.