updated libs

This commit is contained in:
ston1th 2021-10-16 19:13:57 +02:00
commit f305f96195
11 changed files with 79 additions and 265 deletions

View file

@ -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,
},

View file

@ -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)

View file

@ -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
}

View file

@ -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)
}

View file

@ -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 {

View file

@ -6,7 +6,8 @@ import (
"net/http"
"runtime"
"github.com/iand/logfmtr"
//"github.com/iand/logfmtr"
"git.giftfish.de/ston1th/logfmtr"
)
var (