updated libs
This commit is contained in:
parent
8104009bdc
commit
f305f96195
11 changed files with 79 additions and 265 deletions
|
|
@ -141,8 +141,14 @@ func NewClient(options ...ClientOption) *Client {
|
|||
if client.httpClient == nil {
|
||||
client.httpClient = &http.Client{Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
ForceAttemptHTTP2: true,
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: client.insecure,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -60,7 +60,10 @@ func NewServer(c *config.Config, log logr.Logger) (*Server, error) {
|
|||
prefix: c.VIP.Prefix,
|
||||
store: c.VIP.Store,
|
||||
}
|
||||
s.Data.Auth = types.NewAuth(c.APIServer.BasicAuth)
|
||||
s.Data.AuthDisabled = c.APIServer.DisableAuth
|
||||
if !s.Data.AuthDisabled {
|
||||
s.Data.Auth = types.NewAuth(c.APIServer.BasicAuth)
|
||||
}
|
||||
|
||||
if c.APIServer.TLS != nil {
|
||||
cert, err := tls.LoadX509KeyPair(c.APIServer.TLS.Cert, c.APIServer.TLS.Key)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,12 @@ import (
|
|||
)
|
||||
|
||||
type ContextData struct {
|
||||
Net netalloc.Allocator
|
||||
DB *db.DB
|
||||
Auth *Auth
|
||||
Net netalloc.Allocator
|
||||
DB *db.DB
|
||||
|
||||
Auth *Auth
|
||||
AuthDisabled bool
|
||||
|
||||
Leader bool
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,16 @@ var errFollower = errors.New("follower write")
|
|||
|
||||
func authHandler(h types.CtxHandler) types.CtxHandler {
|
||||
return func(ctx *types.Context) {
|
||||
user, pass, ok := ctx.Request.BasicAuth()
|
||||
if !ok {
|
||||
ctx.Err(types.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
if !ctx.Data.Auth.Login(user, pass, ctx.Path()) {
|
||||
ctx.Err(types.ErrForbidden)
|
||||
return
|
||||
if !ctx.Data.AuthDisabled {
|
||||
user, pass, ok := ctx.Request.BasicAuth()
|
||||
if !ok {
|
||||
ctx.Err(types.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
if !ctx.Data.Auth.Login(user, pass, ctx.Path()) {
|
||||
ctx.Err(types.ErrForbidden)
|
||||
return
|
||||
}
|
||||
}
|
||||
h(ctx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,16 +152,18 @@ func Validate(c *Config) error {
|
|||
if raft != nil && etcd != nil {
|
||||
return errors.New("only one cluster config allowed: raft or etcd")
|
||||
}
|
||||
if len(c.APIServer.BasicAuth) == 0 {
|
||||
return errors.New("missing basic auth configuration for api users")
|
||||
}
|
||||
for _, u := range c.APIServer.BasicAuth {
|
||||
if u.User == "" {
|
||||
return errors.New("basic auth username can not be empty")
|
||||
if !c.APIServer.DisableAuth {
|
||||
if len(c.APIServer.BasicAuth) == 0 {
|
||||
return errors.New("missing basic auth configuration for api users")
|
||||
}
|
||||
_, err := bcrypt.Cost([]byte(u.Hash))
|
||||
if u.Hash == "" {
|
||||
return fmt.Errorf("invalid basic auth hash for user %s: %w", u.User, err)
|
||||
for _, u := range c.APIServer.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
|
||||
|
|
@ -239,9 +241,10 @@ type Etcd struct {
|
|||
}
|
||||
|
||||
type APIServer struct {
|
||||
Listen string `yaml:"listen"`
|
||||
TLS *TLS `yaml:"tls"`
|
||||
BasicAuth []BasicAuth `yaml:"basicAuth"`
|
||||
Listen string `yaml:"listen"`
|
||||
TLS *TLS `yaml:"tls"`
|
||||
DisableAuth bool `yaml:"disableAuth"`
|
||||
BasicAuth []BasicAuth `yaml:"basicAuth"`
|
||||
}
|
||||
|
||||
type BasicAuth struct {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ import (
|
|||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"github.com/iand/logfmtr"
|
||||
//"github.com/iand/logfmtr"
|
||||
"git.giftfish.de/ston1th/logfmtr"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue