2019-04-26 17:49:28 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/consul/authmethod"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
|
2020-05-12 01:59:29 +00:00
|
|
|
// register these as a builtin auth method
|
2022-03-31 15:18:48 +00:00
|
|
|
_ "github.com/hashicorp/consul/agent/consul/authmethod/awsauth"
|
2019-04-26 17:49:28 +00:00
|
|
|
_ "github.com/hashicorp/consul/agent/consul/authmethod/kubeauth"
|
2020-05-12 01:59:29 +00:00
|
|
|
_ "github.com/hashicorp/consul/agent/consul/authmethod/ssoauth"
|
2019-04-26 17:49:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type authMethodValidatorEntry struct {
|
|
|
|
Validator authmethod.Validator
|
|
|
|
ModifyIndex uint64 // the raft index when this last changed
|
|
|
|
}
|
|
|
|
|
|
|
|
// loadAuthMethodValidator returns an authmethod.Validator for the given auth
|
|
|
|
// method configuration. If the cache is up to date as-of the provided index
|
|
|
|
// then the cached version is returned, otherwise a new validator is created
|
|
|
|
// and cached.
|
|
|
|
func (s *Server) loadAuthMethodValidator(idx uint64, method *structs.ACLAuthMethod) (authmethod.Validator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
if prevIdx, v, ok := s.aclAuthMethodValidators.GetValidator(method); ok && idx <= prevIdx {
|
2019-04-26 17:49:28 +00:00
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
2020-05-01 20:55:26 +00:00
|
|
|
v, err := authmethod.NewValidator(s.logger, method)
|
2019-04-26 17:49:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("auth method validator for %q could not be initialized: %v", method.Name, err)
|
|
|
|
}
|
|
|
|
|
2019-10-24 18:38:09 +00:00
|
|
|
v = s.aclAuthMethodValidators.PutValidatorIfNewer(method, v, idx)
|
2019-04-26 17:49:28 +00:00
|
|
|
|
|
|
|
return v, nil
|
|
|
|
}
|