added auth method
This commit is contained in:
parent
7715fcf373
commit
a735b9cc5e
8 changed files with 270 additions and 12 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
|
|
@ -109,16 +110,35 @@ func Validate(c *Config) error {
|
|||
if raft != nil && etcd != nil {
|
||||
return errors.New("only one cluster config allowed: raft or etcd")
|
||||
}
|
||||
if len(c.BasicAuth) == 0 {
|
||||
return errors.New("missing basic auth configuration for api users")
|
||||
}
|
||||
for _, u := range c.BasicAuth {
|
||||
if u.User == "" {
|
||||
return errors.New("basic auth username can not be empty")
|
||||
}
|
||||
_, err := bcrypt.Cost([]byte(u.Hash))
|
||||
if u.Hash == "" {
|
||||
return fmt.Errorf("invalid basic auth hash for user %s: %w", u.User, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
VirtualIPs []string `yaml:"virtualIPs"`
|
||||
Interface string `yaml:"interface,omitempty"`
|
||||
Label string `yaml:"label,omitempty"`
|
||||
LeaderHook string `yaml:"leaderHook,omitempty"`
|
||||
FollowerHook string `yaml:"followerHook,omitempty"`
|
||||
Cluster Cluster `yaml:"cluster"`
|
||||
VirtualIPs []string `yaml:"virtualIPs"`
|
||||
Interface string `yaml:"interface,omitempty"`
|
||||
Label string `yaml:"label,omitempty"`
|
||||
LeaderHook string `yaml:"leaderHook,omitempty"`
|
||||
FollowerHook string `yaml:"followerHook,omitempty"`
|
||||
Cluster Cluster `yaml:"cluster"`
|
||||
BasicAuth []BasicAuth `yaml:"basicAuth"`
|
||||
}
|
||||
|
||||
type BasicAuth struct {
|
||||
User string `yaml:"user"`
|
||||
Hash string `yaml:"hash"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue