diff --git a/pkg/services/authn/grpcutils/config.go b/pkg/services/authn/grpcutils/config.go index 91929a0d1c5..8ffacacd134 100644 --- a/pkg/services/authn/grpcutils/config.go +++ b/pkg/services/authn/grpcutils/config.go @@ -3,6 +3,8 @@ package grpcutils import ( "fmt" + "github.com/spf13/pflag" + "github.com/grafana/grafana/pkg/setting" ) @@ -26,6 +28,11 @@ type GrpcServerConfig struct { AllowedAudiences []string Mode Mode 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) { @@ -41,6 +48,7 @@ func ReadGrpcServerConfig(cfg *setting.Cfg) (*GrpcServerConfig, error) { AllowedAudiences: section.Key("allowed_audiences").Strings(","), Mode: mode, LegacyFallback: section.Key("legacy_fallback").MustBool(true), + AllowInsecure: cfg.Env == setting.Dev, }, nil } diff --git a/pkg/services/authn/grpcutils/grpc_authenticator.go b/pkg/services/authn/grpcutils/grpc_authenticator.go index 8b4086f1205..8014a62beac 100644 --- a/pkg/services/authn/grpcutils/grpc_authenticator.go +++ b/pkg/services/authn/grpcutils/grpc_authenticator.go @@ -27,11 +27,7 @@ func NewInProcGrpcAuthenticator() *authnlib.GrpcAuthenticator { ) } -func NewGrpcAuthenticator(cfg *setting.Cfg, tracer tracing.Tracer) (*authnlib.GrpcAuthenticator, error) { - authCfg, err := ReadGrpcServerConfig(cfg) - if err != nil { - return nil, err - } +func NewGrpcAuthenticator(authCfg *GrpcServerConfig, tracer tracing.Tracer) (*authnlib.GrpcAuthenticator, error) { grpcAuthCfg := authnlib.GrpcAuthenticatorConfig{ KeyRetrieverConfig: authnlib.KeyRetrieverConfig{ SigningKeysURL: authCfg.SigningKeysURL, @@ -42,7 +38,7 @@ func NewGrpcAuthenticator(cfg *setting.Cfg, tracer tracing.Tracer) (*authnlib.Gr } client := http.DefaultClient - if cfg.Env == setting.Dev { + if authCfg.AllowInsecure { // allow insecure connections in development mode to facilitate testing 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 } - authenticator, err := NewGrpcAuthenticator(cfg, tracer) + authenticator, err := NewGrpcAuthenticator(authCfg, tracer) if err != nil { return nil, err }