Skip to content

Commit 137bab7

Browse files
committed
Implement tlsEnabled options for driver and launcher.
Signed-off-by: agoins <alyssacgoins@gmail.com>
1 parent f67e36e commit 137bab7

16 files changed

Lines changed: 134 additions & 81 deletions

File tree

backend/src/apiserver/common/config.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
KubeflowUserIDPrefix string = "KUBEFLOW_USERID_PREFIX"
3333
UpdatePipelineVersionByDefault string = "AUTO_UPDATE_PIPELINE_DEFAULT_VERSION"
3434
TokenReviewAudience string = "TOKEN_REVIEW_AUDIENCE"
35-
MLPipelineTLSEnabled string = "ML_PIPELINE_TLS_ENABLED"
35+
MetadataTLSEnabled string = "METADATA_TLS_ENABLED"
3636
CaBundleSecretName string = "CABUNDLE_SECRET_NAME"
3737
)
3838

@@ -130,12 +130,8 @@ func GetTokenReviewAudience() string {
130130
return GetStringConfigWithDefault(TokenReviewAudience, DefaultTokenReviewAudience)
131131
}
132132

133-
func SetMLPipelineServiceTLSEnabled(enabled bool) {
134-
viper.Set(MLPipelineTLSEnabled, enabled)
135-
}
136-
137-
func GetMLPipelineServiceTLSEnabled() bool {
138-
return GetBoolConfigWithDefault(MLPipelineTLSEnabled, DefaultMLPipelineTLSEnabled)
133+
func GetMetadataTLSEnabled() bool {
134+
return GetBoolConfigWithDefault(MetadataTLSEnabled, DefaultMetadataTLSEnabled)
139135
}
140136

141137
func GetCaBundleSecretName() string {

backend/src/apiserver/common/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353

5454
const DefaultTokenReviewAudience string = "pipelines.kubeflow.org"
5555

56-
const DefaultMLPipelineTLSEnabled = false
56+
const DefaultMetadataTLSEnabled = false
5757

5858
const (
5959
DefaultPipelineRunnerServiceAccount = "pipeline-runner"

backend/src/apiserver/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ func initCerts() (*tls.Config, error) {
9999
config := &tls.Config{
100100
Certificates: []tls.Certificate{serverCert},
101101
}
102-
// Update MLPipelineServiceTLSEnabled global variable to true once tls Config is initialized.
103-
common.SetMLPipelineServiceTLSEnabled(true)
104102
glog.Info("TLS cert key/pair loaded.")
105103
return config, err
106104
}

backend/src/v2/client_manager/client_manager.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Options struct {
3333
MLMDServerPort string
3434
CacheDisabled bool
3535
CaCertPath string
36+
MLMDTLSEnabled bool
3637
}
3738

3839
// NewClientManager creates and Init a new instance of ClientManager.
@@ -59,9 +60,13 @@ func (cm *ClientManager) CacheClient() cacheutils.Client {
5960
}
6061

6162
func (cm *ClientManager) init(opts *Options) error {
62-
tlsCfg, err := util.GetTLSConfig(opts.CaCertPath)
63-
if err != nil {
64-
return err
63+
var tlsCfg *tls.Config
64+
var err error
65+
if opts.MLMDTLSEnabled {
66+
tlsCfg, err = util.GetTLSConfig(opts.CaCertPath)
67+
if err != nil {
68+
return err
69+
}
6570
}
6671
k8sClient, err := initK8sClient()
6772
if err != nil {

backend/src/v2/cmd/driver/main.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616
import (
1717
"bytes"
1818
"context"
19+
"crypto/tls"
1920
"encoding/json"
2021
"flag"
2122
"fmt"
@@ -86,8 +87,10 @@ var (
8687
noProxy = flag.String(noProxyArg, unsetProxyArgValue, "Addresses that should ignore the proxy.")
8788
publishLogs = flag.String("publish_logs", "true", "Whether to publish component logs to the object store")
8889
cacheDisabledFlag = flag.Bool("cache_disabled", false, "Disable cache globally.")
89-
90-
caCertPath = flag.String("ca_cert_path", "", "The path to the CA certificate to trust on connections to the ML pipeline API server and metadata server.")
90+
//todo: retrieve exact wording
91+
mlPipelineServiceTLSEnabled = flag.Bool("ml_pipeline_tls_enabled", false, "add wording here")
92+
metadataTLSEnabled = flag.Bool("metadata_tls_enabled", false, " add wording")
93+
caCertPath = flag.String("ca_cert_path", "", "The path to the CA certificate to trust on connections to the ML pipeline API server and metadata server.")
9194
)
9295

9396
// func RootDAG(pipelineName string, runID string, component *pipelinespec.ComponentSpec, task *pipelinespec.PipelineTaskSpec, mlmd *metadata.Client) (*Execution, error) {
@@ -177,11 +180,14 @@ func drive() (err error) {
177180
if err != nil {
178181
return err
179182
}
180-
client, err := newMlmdClient()
181-
if err != nil {
182-
return err
183+
var tlsCfg *tls.Config
184+
if *metadataTLSEnabled {
185+
tlsCfg, err = util.GetTLSConfig(*caCertPath)
186+
if err != nil {
187+
return err
188+
}
183189
}
184-
tlsCfg, err := util.GetTLSConfig(*caCertPath)
190+
client, err := newMlmdClient(tlsCfg)
185191
if err != nil {
186192
return err
187193
}
@@ -190,23 +196,25 @@ func drive() (err error) {
190196
return err
191197
}
192198
options := driver.Options{
193-
PipelineName: *pipelineName,
194-
RunID: *runID,
195-
RunName: *runName,
196-
RunDisplayName: *runDisplayName,
197-
Namespace: namespace,
198-
Component: componentSpec,
199-
Task: taskSpec,
200-
DAGExecutionID: *dagExecutionID,
201-
IterationIndex: *iterationIndex,
202-
PipelineLogLevel: *logLevel,
203-
PublishLogs: *publishLogs,
204-
CacheDisabled: *cacheDisabledFlag,
205-
DriverType: *driverType,
206-
TaskName: *taskName,
207-
MLMDServerAddress: *mlmdServerAddress,
208-
MLMDServerPort: *mlmdServerPort,
209-
CaCertPath: *caCertPath,
199+
PipelineName: *pipelineName,
200+
RunID: *runID,
201+
RunName: *runName,
202+
RunDisplayName: *runDisplayName,
203+
Namespace: namespace,
204+
Component: componentSpec,
205+
Task: taskSpec,
206+
DAGExecutionID: *dagExecutionID,
207+
IterationIndex: *iterationIndex,
208+
PipelineLogLevel: *logLevel,
209+
PublishLogs: *publishLogs,
210+
CacheDisabled: *cacheDisabledFlag,
211+
DriverType: *driverType,
212+
TaskName: *taskName,
213+
MLMDServerAddress: *mlmdServerAddress,
214+
MLMDServerPort: *mlmdServerPort,
215+
MLPipelineTLSEnabled: *mlPipelineServiceTLSEnabled,
216+
MLMDTLSEnabled: *metadataTLSEnabled,
217+
CaCertPath: *caCertPath,
210218
}
211219
var execution *driver.Execution
212220
var driverErr error
@@ -339,15 +347,11 @@ func writeFile(path string, data []byte) (err error) {
339347
return os.WriteFile(path, data, 0o644)
340348
}
341349

342-
func newMlmdClient() (*metadata.Client, error) {
350+
func newMlmdClient(tlsCfg *tls.Config) (*metadata.Client, error) {
343351
mlmdConfig := metadata.DefaultConfig()
344352
if *mlmdServerAddress != "" && *mlmdServerPort != "" {
345353
mlmdConfig.Address = *mlmdServerAddress
346354
mlmdConfig.Port = *mlmdServerPort
347355
}
348-
tlsConfig, err := util.GetTLSConfig(*caCertPath)
349-
if err != nil {
350-
return nil, err
351-
}
352-
return metadata.NewClient(mlmdConfig.Address, mlmdConfig.Port, tlsConfig)
356+
return metadata.NewClient(mlmdConfig.Address, mlmdConfig.Port, tlsCfg)
353357
}

backend/src/v2/cmd/launcher-v2/main.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ var (
4646
publishLogs = flag.String("publish_logs", "true", "Whether to publish component logs to the object store")
4747
cacheDisabledFlag = flag.Bool("cache_disabled", false, "Disable cache globally.")
4848
caCertPath = flag.String("ca_cert_path", "", "The path to the CA certificate to trust on connections to the ML pipeline API server and metadata server.")
49+
//todo: retrieve exact wording
50+
mlPipelineServiceTLSEnabled = flag.Bool("ml_pipeline_tls_enabled", false, "add wording here")
51+
metadataTLSEnabled = flag.Bool("metadata_tls_enabled", false, " add wording")
4952
)
5053

5154
func main() {
@@ -77,16 +80,18 @@ func run() error {
7780
}
7881

7982
launcherV2Opts := &component.LauncherV2Options{
80-
Namespace: namespace,
81-
PodName: *podName,
82-
PodUID: *podUID,
83-
MLMDServerAddress: *mlmdServerAddress,
84-
MLMDServerPort: *mlmdServerPort,
85-
PipelineName: *pipelineName,
86-
RunID: *runID,
87-
PublishLogs: *publishLogs,
88-
CacheDisabled: *cacheDisabledFlag,
89-
CaCertPath: *caCertPath,
83+
Namespace: namespace,
84+
PodName: *podName,
85+
PodUID: *podUID,
86+
MLMDServerAddress: *mlmdServerAddress,
87+
MLMDServerPort: *mlmdServerPort,
88+
PipelineName: *pipelineName,
89+
RunID: *runID,
90+
PublishLogs: *publishLogs,
91+
CacheDisabled: *cacheDisabledFlag,
92+
MLPipelineTLSEnabled: *mlPipelineServiceTLSEnabled,
93+
MetadataTLSEnabled: *metadataTLSEnabled,
94+
CaCertPath: *caCertPath,
9095
}
9196

9297
switch *executorType {
@@ -109,6 +114,7 @@ func run() error {
109114
MLMDServerAddress: launcherV2Opts.MLMDServerAddress,
110115
MLMDServerPort: launcherV2Opts.MLMDServerPort,
111116
CacheDisabled: launcherV2Opts.CacheDisabled,
117+
MLMDTLSEnabled: launcherV2Opts.MetadataTLSEnabled,
112118
CaCertPath: launcherV2Opts.CaCertPath,
113119
}
114120
clientManager, err := client_manager.NewClientManager(clientOptions)

backend/src/v2/compiler/argocompiler/argo.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func Compile(jobArg *pipelinespec.PipelineJob, kubernetesSpecArg *pipelinespec.S
171171
if opts != nil {
172172
c.cacheDisabled = opts.CacheDisabled
173173
c.defaultWorkspace = opts.DefaultWorkspace
174+
c.mlPipelineTLSEnabled = opts.TLSEnabled
174175
if opts.DriverImage != "" {
175176
c.driverImage = opts.DriverImage
176177
}
@@ -199,14 +200,15 @@ type workflowCompiler struct {
199200
spec *pipelinespec.PipelineSpec
200201
executors map[string]*pipelinespec.PipelineDeploymentConfig_ExecutorSpec
201202
// state
202-
wf *wfapi.Workflow
203-
templates map[string]*wfapi.Template
204-
driverImage string
205-
driverCommand []string
206-
launcherImage string
207-
launcherCommand []string
208-
cacheDisabled bool
209-
defaultWorkspace *k8score.PersistentVolumeClaimSpec
203+
wf *wfapi.Workflow
204+
templates map[string]*wfapi.Template
205+
driverImage string
206+
driverCommand []string
207+
launcherImage string
208+
launcherCommand []string
209+
cacheDisabled bool
210+
defaultWorkspace *k8score.PersistentVolumeClaimSpec
211+
mlPipelineTLSEnabled bool
210212
}
211213

212214
func (c *workflowCompiler) Resolver(name string, component *pipelinespec.ComponentSpec, resolver *pipelinespec.PipelineDeploymentConfig_ResolverSpec) error {

backend/src/v2/compiler/argocompiler/common.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ func ConfigureCustomCABundle(tmpl *wfapi.Template) {
6161
glog.Error("Env var CABUNDLE_SECRET_NAME is blank or empty. Failed to configure custom CA bundle.")
6262
return
6363
}
64-
// OpenSSL default cert file env variable.
65-
// Similar to AWS_CA_BUNDLE, the SSL_CERT_DIR equivalent for paths had unyielding
66-
// results, even after rehashing.
67-
// https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_default_verify_paths.html
68-
tmpl.Container.Env = append(tmpl.Container.Env, k8score.EnvVar{
69-
Name: "SSL_CERT_FILE",
70-
Value: common.TLSCertCAPath,
71-
})
72-
tmpl.Container.Env = append(tmpl.Container.Env, k8score.EnvVar{
73-
Name: "SSL_CERT_DIR",
74-
Value: common.TLSCertCAPath,
75-
})
7664
volume := k8score.Volume{
7765
Name: "ca-secret",
7866
VolumeSource: k8score.VolumeSource{

backend/src/v2/compiler/argocompiler/container.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ func (c *workflowCompiler) addContainerDriverTemplate() string {
210210
if c.cacheDisabled {
211211
args = append(args, "--cache_disabled")
212212
}
213-
if common.GetMLPipelineServiceTLSEnabled() {
213+
if c.mlPipelineTLSEnabled {
214+
args = append(args, "--ml_pipeline_tls_enabled")
215+
}
216+
if common.GetMetadataTLSEnabled() {
217+
args = append(args, "--metadata_tls_enabled")
218+
}
219+
if c.mlPipelineTLSEnabled || common.GetMetadataTLSEnabled() {
214220
args = append(args, "--ca_cert_path", common.TLSCertCAPath)
215221
}
216222
if value, ok := os.LookupEnv(PipelineLogLevelEnvVar); ok {
@@ -249,7 +255,7 @@ func (c *workflowCompiler) addContainerDriverTemplate() string {
249255
},
250256
}
251257
// If the apiserver is TLS-enabled, add the custom CA bundle to the container driver template.
252-
if common.GetMLPipelineServiceTLSEnabled() {
258+
if c.mlPipelineTLSEnabled {
253259
ConfigureCustomCABundle(t)
254260
}
255261
c.templates[name] = t
@@ -535,7 +541,7 @@ func (c *workflowCompiler) addContainerExecutorTemplate(task *pipelinespec.Pipel
535541
},
536542
}
537543
// If the apiserver is TLS-enabled, add the custom CA bundle to the executor.
538-
if common.GetMLPipelineServiceTLSEnabled() {
544+
if c.mlPipelineTLSEnabled {
539545
ConfigureCustomCABundle(executor)
540546
}
541547

backend/src/v2/compiler/argocompiler/dag.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,13 @@ func (c *workflowCompiler) addDAGDriverTemplate() string {
575575
if c.cacheDisabled {
576576
args = append(args, "--cache_disabled")
577577
}
578-
if common.GetMLPipelineServiceTLSEnabled() {
578+
if c.mlPipelineTLSEnabled {
579+
args = append(args, "--ml_pipeline_tls_enabled")
580+
}
581+
if common.GetMetadataTLSEnabled() {
582+
args = append(args, "--metadata_tls_enabled")
583+
}
584+
if c.mlPipelineTLSEnabled || common.GetMetadataTLSEnabled() {
579585
args = append(args, "--ca_cert_path", common.TLSCertCAPath)
580586
}
581587
if value, ok := os.LookupEnv(PipelineLogLevelEnvVar); ok {
@@ -614,7 +620,7 @@ func (c *workflowCompiler) addDAGDriverTemplate() string {
614620
},
615621
}
616622
// If the apiserver is TLS-enabled, add the custom CA bundle to the DAG driver template.
617-
if common.GetMLPipelineServiceTLSEnabled() {
623+
if c.mlPipelineTLSEnabled {
618624
ConfigureCustomCABundle(t)
619625
}
620626
c.templates[name] = t

0 commit comments

Comments
 (0)