mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AuthN: Register flags for grpc_server_authentication
configuration (#97063)
* AuthZServer: Add authenticator * Add flags
This commit is contained in:
parent
722af820a5
commit
6e2d3cae5e
@ -3,6 +3,8 @@ package grpcutils
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +28,11 @@ type GrpcServerConfig struct {
|
|||||||
AllowedAudiences []string
|
AllowedAudiences []string
|
||||||
Mode Mode
|
Mode Mode
|
||||||
LegacyFallback bool
|
LegacyFallback bool
|
||||||
|
AllowInsecure bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GrpcServerConfig) AddFlags(fs *pflag.FlagSet) {
|
||||||
|
fs.StringVar(&c.SigningKeysURL, "grpc-server-authentication.signing-keys-url", "", "gRPC server authentication signing keys URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadGrpcServerConfig(cfg *setting.Cfg) (*GrpcServerConfig, error) {
|
func ReadGrpcServerConfig(cfg *setting.Cfg) (*GrpcServerConfig, error) {
|
||||||
@ -41,6 +48,7 @@ func ReadGrpcServerConfig(cfg *setting.Cfg) (*GrpcServerConfig, error) {
|
|||||||
AllowedAudiences: section.Key("allowed_audiences").Strings(","),
|
AllowedAudiences: section.Key("allowed_audiences").Strings(","),
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
LegacyFallback: section.Key("legacy_fallback").MustBool(true),
|
LegacyFallback: section.Key("legacy_fallback").MustBool(true),
|
||||||
|
AllowInsecure: cfg.Env == setting.Dev,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,7 @@ func NewInProcGrpcAuthenticator() *authnlib.GrpcAuthenticator {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcAuthenticator(cfg *setting.Cfg, tracer tracing.Tracer) (*authnlib.GrpcAuthenticator, error) {
|
func NewGrpcAuthenticator(authCfg *GrpcServerConfig, tracer tracing.Tracer) (*authnlib.GrpcAuthenticator, error) {
|
||||||
authCfg, err := ReadGrpcServerConfig(cfg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
grpcAuthCfg := authnlib.GrpcAuthenticatorConfig{
|
grpcAuthCfg := authnlib.GrpcAuthenticatorConfig{
|
||||||
KeyRetrieverConfig: authnlib.KeyRetrieverConfig{
|
KeyRetrieverConfig: authnlib.KeyRetrieverConfig{
|
||||||
SigningKeysURL: authCfg.SigningKeysURL,
|
SigningKeysURL: authCfg.SigningKeysURL,
|
||||||
@ -42,7 +38,7 @@ func NewGrpcAuthenticator(cfg *setting.Cfg, tracer tracing.Tracer) (*authnlib.Gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := http.DefaultClient
|
client := http.DefaultClient
|
||||||
if cfg.Env == setting.Dev {
|
if authCfg.AllowInsecure {
|
||||||
// allow insecure connections in development mode to facilitate testing
|
// allow insecure connections in development mode to facilitate testing
|
||||||
client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
|
client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
|
||||||
}
|
}
|
||||||
@ -87,7 +83,7 @@ func NewGrpcAuthenticatorWithFallback(cfg *setting.Cfg, reg prometheus.Registere
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticator, err := NewGrpcAuthenticator(cfg, tracer)
|
authenticator, err := NewGrpcAuthenticator(authCfg, tracer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user