server/auth: enable tokenProvider if recoved store enables auth

we found a lease leak issue:
if a new member(by member add) is recovered by snapshot, and then
become leader, the lease will never expire afterwards. leader will
log the revoke failure caused by "invalid auth token", since the
token provider is not functional, and drops all generated token
from upper layer, which in this case, is the lease revoking
routine.
This commit is contained in:
cfz 2021-07-02 13:06:28 +08:00
parent 8453b10e58
commit cceb25d758
No known key found for this signature in database
GPG Key ID: 557D9FD4346B1312
2 changed files with 8 additions and 0 deletions

View File

@ -156,6 +156,11 @@ func (t *tokenSimple) invalidateUser(username string) {
}
func (t *tokenSimple) enable() {
t.simpleTokensMu.Lock()
defer t.simpleTokensMu.Unlock()
if t.simpleTokenKeeper != nil { // already enabled
return
}
if t.simpleTokenTTL <= 0 {
t.simpleTokenTTL = simpleTokenTTLDefault
}

View File

@ -368,6 +368,9 @@ func (as *authStore) Recover(be backend.Backend) {
as.enabledMu.Lock()
as.enabled = enabled
if enabled {
as.tokenProvider.enable()
}
as.enabledMu.Unlock()
}