InfluxDB: Fix Unable to use self-signed CA for adding influxdb data source (#105586)
* Fix Unable to use self-signed CA for verification when adding influxdb data source (#105585) * Update pkg/tsdb/influxdb/fsql/fsql.go --------- Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com>
This commit is contained in:
co-authored by
Andrew Hackmann
parent
fbef31b2e0
commit
43ac5b52f9
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/apache/arrow-go/v18/arrow/flight/flightsql"
|
||||
"github.com/apache/arrow-go/v18/arrow/ipc"
|
||||
"github.com/apache/arrow-go/v18/arrow/memory"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
@@ -28,8 +29,8 @@ func (c *client) FlightClient() flight.Client {
|
||||
return c.Client.Client
|
||||
}
|
||||
|
||||
func newFlightSQLClient(addr string, metadata metadata.MD, secure bool, proxyClient proxy.Client) (*client, error) {
|
||||
dialOptions, err := grpcDialOptions(secure, proxyClient)
|
||||
func newFlightSQLClient(addr string, metadata metadata.MD, secure bool, tlsConfig *httpclient.TLSOptions, proxyClient proxy.Client) (*client, error) {
|
||||
dialOptions, err := grpcDialOptions(secure, tlsConfig, proxyClient)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("grpc dial options: %s", err)
|
||||
}
|
||||
@@ -46,7 +47,7 @@ func newFlightSQLClient(addr string, metadata metadata.MD, secure bool, proxyCli
|
||||
return &client{Client: fsqlClient, md: metadata}, nil
|
||||
}
|
||||
|
||||
func grpcDialOptions(secure bool, proxyClient proxy.Client) ([]grpc.DialOption, error) {
|
||||
func grpcDialOptions(secure bool, tlsConfig *httpclient.TLSOptions, proxyClient proxy.Client) ([]grpc.DialOption, error) {
|
||||
dialOptions := []grpc.DialOption{}
|
||||
secureDialOpt := grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||
|
||||
@@ -55,6 +56,9 @@ func grpcDialOptions(secure bool, proxyClient proxy.Client) ([]grpc.DialOption,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("x509: %s", err)
|
||||
}
|
||||
if tlsConfig != nil && len(tlsConfig.CACertificate) > 0 {
|
||||
pool.AppendCertsFromPEM([]byte(tlsConfig.CACertificate))
|
||||
}
|
||||
secureDialOpt = grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(pool, ""))
|
||||
}
|
||||
dialOptions = append(dialOptions, secureDialOpt)
|
||||
|
||||
@@ -143,7 +143,7 @@ func runnerFromDataSource(dsInfo *models.DatasourceInfo) (*runner, error) {
|
||||
md.Set("Authorization", fmt.Sprintf("Bearer %s", dsInfo.Token))
|
||||
}
|
||||
|
||||
fsqlClient, err := newFlightSQLClient(u, md, !dsInfo.InsecureGrpc, dsInfo.ProxyClient)
|
||||
fsqlClient, err := newFlightSQLClient(u, md, !dsInfo.InsecureGrpc, dsInfo.TLSConfig, dsInfo.ProxyClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ func newInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
|
||||
Token: settings.DecryptedSecureJSONData["token"],
|
||||
Timeout: opts.Timeouts.Timeout,
|
||||
ProxyClient: proxyClient,
|
||||
TLSConfig: opts.TLS,
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
|
||||
)
|
||||
|
||||
@@ -25,5 +26,7 @@ type DatasourceInfo struct {
|
||||
// FlightSQL grpc connection
|
||||
InsecureGrpc bool `json:"insecureGrpc"`
|
||||
|
||||
TLSConfig *httpclient.TLSOptions
|
||||
|
||||
ProxyClient proxy.Client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user