@@ -17,6 +17,7 @@ package utils
1717import (
1818 "context"
1919 "crypto/tls"
20+ "crypto/x509"
2021 "encoding/json"
2122 "fmt"
2223 "net/http"
@@ -38,24 +39,37 @@ import (
3839)
3940
4041const (
41- mlflowEndpointEnv = "MLFLOW_TRACKING_URI"
42- mlflowInsecureTLSEnv = "MLFLOW_TRACKING_INSECURE_TLS "
43- mlflowBearerTokenEnv = "MLFLOW_BEARER_TOKEN"
44- mlflowWorkspaceEnv = "MLFLOW_WORKSPACE"
45- mlflowPluginKey = "MLflow"
42+ mlflowEndpointEnv = "MLFLOW_TRACKING_URI"
43+ mlflowCABundlePathEnv = "MLFLOW_CA_BUNDLE_PATH "
44+ mlflowBearerTokenEnv = "MLFLOW_BEARER_TOKEN"
45+ mlflowWorkspaceEnv = "MLFLOW_WORKSPACE"
46+ mlflowPluginKey = "MLflow"
4647)
4748
4849func getMLflowClient (endpoint string ) (* mlflowclient.Client , error ) {
49- insecure := strings .EqualFold (os .Getenv (mlflowInsecureTLSEnv ), "true" )
5050 workspace := os .Getenv (mlflowWorkspaceEnv )
5151 bearerToken := os .Getenv (mlflowBearerTokenEnv )
52+
53+ tlsConfig := & tls.Config {}
54+ if caBundlePath := os .Getenv (mlflowCABundlePathEnv ); caBundlePath != "" {
55+ caCert , err := os .ReadFile (caBundlePath )
56+ if err != nil {
57+ return nil , fmt .Errorf ("failed to read CA bundle from %s: %w" , caBundlePath , err )
58+ }
59+ pool , err := x509 .SystemCertPool ()
60+ if err != nil {
61+ pool = x509 .NewCertPool ()
62+ }
63+ if ! pool .AppendCertsFromPEM (caCert ) {
64+ return nil , fmt .Errorf ("failed to parse CA certificate from %s" , caBundlePath )
65+ }
66+ tlsConfig .RootCAs = pool
67+ logger .Log ("MLflow client initialized with CA bundle from %s" , caBundlePath )
68+ }
69+
5270 httpClient := & http.Client {
53- Timeout : 30 * time .Second ,
54- Transport : & http.Transport {
55- TLSClientConfig : & tls.Config {
56- InsecureSkipVerify : insecure , //nolint:gosec
57- },
58- },
71+ Timeout : 30 * time .Second ,
72+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
5973 }
6074 client , err := mlflowclient .NewClient (mlflowclient.Config {
6175 Endpoint : endpoint ,
@@ -73,9 +87,6 @@ func getMLflowClient(endpoint string) (*mlflowclient.Client, error) {
7387 if workspace != "" {
7488 logger .Log ("MLflow client initialized with workspace header: %s" , workspace )
7589 }
76- if insecure {
77- logger .Log ("MLflow client initialized with InsecureSkipVerify=true" )
78- }
7990 return client , nil
8091}
8192
0 commit comments