Skip to content

Commit ced1054

Browse files
committed
Separate CA configuration for pulls vs catalogd services
Rename the flags that provide CAs to image pulling to indicate the use. Keep the old flag around (for backward compatibility), but prefer the new flag(s). Signed-off-by: Todd Short <[email protected]>
1 parent 10e2754 commit ced1054

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

catalogd/cmd/catalogd/main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func main() {
9898
keyFile string
9999
webhookPort int
100100
caCertDir string
101+
pullCertDir string
101102
globalPullSecret string
102103
)
103104
flag.StringVar(&metricsAddr, "metrics-bind-address", "", "The address for the metrics endpoint. Requires tls-cert and tls-key. (Default: ':7443')")
@@ -115,7 +116,8 @@ func main() {
115116
flag.StringVar(&certFile, "tls-cert", "", "The certificate file used for serving catalog and metrics. Required to enable the metrics server. Requires tls-key.")
116117
flag.StringVar(&keyFile, "tls-key", "", "The key file used for serving catalog contents and metrics. Required to enable the metrics server. Requires tls-cert.")
117118
flag.IntVar(&webhookPort, "webhook-server-port", 9443, "The port that the mutating webhook server serves at.")
118-
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of CA certificate to use for verifying HTTPS connections to image registries.")
119+
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of CA certificates to use for verifying HTTPS connections to image registries (deprecated).")
120+
flag.StringVar(&pullCertDir, "pull-certs-dir", "", "The directory of CA certificates to use for verifying HTTPS connections to image registries.")
119121
flag.StringVar(&globalPullSecret, "global-pull-secret", "", "The <namespace>/<name> of the global pull secret that is going to be used to pull bundle images.")
120122

121123
klog.InitFlags(flag.CommandLine)
@@ -132,6 +134,17 @@ func main() {
132134

133135
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
134136

137+
// if the old flag is specified, but not the new flag
138+
// use the old flag
139+
if caCertDir != "" {
140+
if pullCertDir == "" {
141+
pullCertDir = caCertDir
142+
setupLog.Info("using deprecated --ca-certs-dir flag as --pull-certs-dir flag is not specified")
143+
} else {
144+
setupLog.Info("deprecated --ca-certs-dir flag ignored due to use of --pull-certs-dir flag")
145+
}
146+
}
147+
135148
authFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s.json", authFilePrefix, apimachineryrand.String(8)))
136149
var globalPullSecretKey *k8stypes.NamespacedName
137150
if globalPullSecret != "" {
@@ -271,8 +284,8 @@ func main() {
271284
BaseCachePath: unpackCacheBasePath,
272285
SourceContextFunc: func(logger logr.Logger) (*types.SystemContext, error) {
273286
srcContext := &types.SystemContext{
274-
DockerCertPath: caCertDir,
275-
OCICertPath: caCertDir,
287+
DockerCertPath: pullCertDir,
288+
OCICertPath: pullCertDir,
276289
}
277290
if _, err := os.Stat(authFilePath); err == nil && globalPullSecretKey != nil {
278291
logger.Info("using available authentication information for pulling image")

catalogd/config/components/ca/patches/manager_deployment_cacerts.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
value: {"name":"olmv1-certificate", "readOnly": true, "mountPath":"/var/ca-certs/"}
77
- op: add
88
path: /spec/template/spec/containers/0/args/-
9-
value: "--ca-certs-dir=/var/ca-certs"
9+
value: "--pull-certs-dir=/var/ca-certs"

cmd/operator-controller/main.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ func main() {
102102
operatorControllerVersion bool
103103
systemNamespace string
104104
caCertDir string
105+
catalogdCertDir string
106+
pullCertDir string
105107
globalPullSecret string
106108
)
107109
flag.StringVar(&metricsAddr, "metrics-bind-address", "", "The address for the metrics endpoint. Requires tls-cert and tls-key. (Default: ':8443')")
108110
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
109-
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of TLS certificate to use for verifying HTTPS connections to the Catalogd and docker-registry web servers.")
111+
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of TLS certificates to use for verifying HTTPS connections to the Catalogd and docker-registry web servers (deprecated).")
112+
flag.StringVar(&catalogdCertDir, "catalogd-certs-dir", "", "The directory of TLS certificates to use for verifying HTTPS connections to the Catalogd web service.")
113+
flag.StringVar(&pullCertDir, "pull-certs-dir", "", "The directory of TLS certificates to use for verifying HTTPS connections to image registries.")
110114
flag.StringVar(&certFile, "tls-cert", "", "The certificate file used for the metrics server. Required to enable the metrics server. Requires tls-key.")
111115
flag.StringVar(&keyFile, "tls-key", "", "The key file used for the metrics server. Required to enable the metrics server. Requires tls-cert")
112116
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -128,6 +132,19 @@ func main() {
128132
os.Exit(0)
129133
}
130134

135+
// if the old flag is specified, but neither of the new flags
136+
// use the old flag
137+
if caCertDir != "" {
138+
if catalogdCertDir == "" && pullCertDir == "" {
139+
catalogdCertDir = caCertDir
140+
pullCertDir = caCertDir
141+
setupLog.Info("using deprecated --ca-certs-dir flag as --catalogd-certs-dir or --pull-certs-dir flags are not specified")
142+
} else {
143+
setupLog.Info("deprecated --ca-certs-dir flag ignored due to use of --catalogd-certs-dir or --pull-certs-dir flags")
144+
}
145+
146+
}
147+
131148
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
132149
setupLog.Error(nil, "unable to configure TLS certificates: tls-cert and tls-key flags must be used together")
133150
os.Exit(1)
@@ -283,7 +300,7 @@ func main() {
283300
os.Exit(1)
284301
}
285302

286-
certPoolWatcher, err := httputil.NewCertPoolWatcher(caCertDir, ctrl.Log.WithName("cert-pool"))
303+
certPoolWatcher, err := httputil.NewCertPoolWatcher(catalogdCertDir, ctrl.Log.WithName("cert-pool"))
287304
if err != nil {
288305
setupLog.Error(err, "unable to create CA certificate pool")
289306
os.Exit(1)
@@ -301,8 +318,8 @@ func main() {
301318
BaseCachePath: filepath.Join(cachePath, "unpack"),
302319
SourceContextFunc: func(logger logr.Logger) (*types.SystemContext, error) {
303320
srcContext := &types.SystemContext{
304-
DockerCertPath: caCertDir,
305-
OCICertPath: caCertDir,
321+
DockerCertPath: pullCertDir,
322+
OCICertPath: pullCertDir,
306323
}
307324
if _, err := os.Stat(authFilePath); err == nil && globalPullSecretKey != nil {
308325
logger.Info("using available authentication information for pulling image")

config/components/tls/patches/manager_deployment_cert.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
value: {"name":"olmv1-certificate", "readOnly": true, "mountPath":"/var/certs/"}
77
- op: add
88
path: /spec/template/spec/containers/0/args/-
9-
value: "--ca-certs-dir=/var/certs"
9+
value: "--catalogd-certs-dir=/var/certs"
10+
- op: add
11+
path: /spec/template/spec/containers/0/args/-
12+
value: "--pull-certs-dir=/var/certs"
1013
- op: add
1114
path: /spec/template/spec/containers/0/args/-
1215
value: "--tls-cert=/var/certs/tls.cert"

0 commit comments

Comments
 (0)