Skip to content

Commit c9fab43

Browse files
committed
pkg/cvo: Fetch proxy CA certs from openshift-config-managed/trusted-ca-bundle
The API docs [1] recommend avoiding trustedCA (unless you happen to be the "proxy validator") and instead pulling the trust bundle from this managed namespace. The docs also explain that the trusted-ca-bundle ConfigMap has already been merged with the system certificates, so we don't need to inject those locally. If trusted-ca-bundle doesn't exist, we'll fall back to our local system store. Our logic was touched most recently in 5968cdf (pkg: switch to openshift-config for proxy CA, 2019-08-07, #231), which resolved the "looking in the wrong place" issue by looking at the trustedCA source (which feeds the proxy validator). With this commit we switch that around and look at the proxy validator's output. [1]: https://github.com/openshift/api/blob/f2a771e1a90ceb4e65f1ca2c8b11fc1ac6a66da8/config/v1/types_proxy.go#L44-L52
1 parent a49fef5 commit c9fab43

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

pkg/cvo/cvo.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ type Operator struct {
115115
// syncBackoff allows the tests to use a quicker backoff
116116
syncBackoff wait.Backoff
117117

118-
cvLister configlistersv1.ClusterVersionLister
119-
coLister configlistersv1.ClusterOperatorLister
120-
cmConfigLister listerscorev1.ConfigMapNamespaceLister
121-
proxyLister configlistersv1.ProxyLister
122-
cacheSynced []cache.InformerSynced
118+
cvLister configlistersv1.ClusterVersionLister
119+
coLister configlistersv1.ClusterOperatorLister
120+
cmConfigLister listerscorev1.ConfigMapNamespaceLister
121+
cmConfigManagedLister listerscorev1.ConfigMapNamespaceLister
122+
proxyLister configlistersv1.ProxyLister
123+
cacheSynced []cache.InformerSynced
123124

124125
// queue tracks applying updates to a cluster.
125126
queue workqueue.RateLimitingInterface
@@ -212,6 +213,7 @@ func New(
212213

213214
optr.proxyLister = proxyInformer.Lister()
214215
optr.cmConfigLister = cmConfigInformer.Lister().ConfigMaps(internal.ConfigNamespace)
216+
optr.cmConfigManagedLister = cmConfigInformer.Lister().ConfigMaps(internal.ConfigManagedNamespace)
215217

216218
// make sure this is initialized after all the listers are initialized
217219
optr.upgradeableChecks = optr.defaultUpgradeableChecks()
@@ -743,17 +745,15 @@ func (optr *Operator) HTTPClient() (*http.Client, error) {
743745
// getTransportOpts retrieves the URL of the cluster proxy and the CA
744746
// trust, if they exist.
745747
func (optr *Operator) getTransportOpts() (*url.URL, *tls.Config, error) {
746-
proxyURL, cmNameRef, err := optr.getHTTPSProxyURL()
748+
proxyURL, err := optr.getHTTPSProxyURL()
747749
if err != nil {
748750
return nil, nil, err
749751
}
750752

751753
var tlsConfig *tls.Config
752-
if cmNameRef != "" {
753-
tlsConfig, err = optr.getTLSConfig(cmNameRef)
754-
if err != nil {
755-
return nil, nil, err
756-
}
754+
tlsConfig, err = optr.getTLSConfig()
755+
if err != nil {
756+
return nil, nil, err
757757
}
758758
return proxyURL, tlsConfig, nil
759759
}

pkg/cvo/cvo_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,7 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
26282628
optr.proxyLister = &clientProxyLister{client: optr.client}
26292629
optr.coLister = &clientCOLister{client: optr.client}
26302630
optr.cvLister = &clientCVLister{client: optr.client}
2631+
optr.cmConfigManagedLister = &cmConfigLister{}
26312632
optr.eventRecorder = record.NewFakeRecorder(100)
26322633

26332634
if tt.handler != nil {

pkg/cvo/egress.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,38 @@ import (
1111

1212
// getHTTPSProxyURL returns a url.URL object for the configured
1313
// https proxy only. It can be nil if does not exist or there is an error.
14-
func (optr *Operator) getHTTPSProxyURL() (*url.URL, string, error) {
14+
func (optr *Operator) getHTTPSProxyURL() (*url.URL, error) {
1515
proxy, err := optr.proxyLister.Get("cluster")
1616

1717
if errors.IsNotFound(err) {
18-
return nil, "", nil
18+
return nil, nil
1919
}
2020
if err != nil {
21-
return nil, "", err
21+
return nil, err
2222
}
2323

2424
if &proxy.Spec != nil {
2525
if proxy.Spec.HTTPSProxy != "" {
2626
proxyURL, err := url.Parse(proxy.Spec.HTTPSProxy)
2727
if err != nil {
28-
return nil, "", err
28+
return nil, err
2929
}
30-
return proxyURL, proxy.Spec.TrustedCA.Name, nil
30+
return proxyURL, nil
3131
}
3232
}
33-
return nil, "", nil
33+
return nil, nil
3434
}
3535

36-
func (optr *Operator) getTLSConfig(cmNameRef string) (*tls.Config, error) {
37-
cm, err := optr.cmConfigLister.Get(cmNameRef)
38-
36+
func (optr *Operator) getTLSConfig() (*tls.Config, error) {
37+
cm, err := optr.cmConfigManagedLister.Get("trusted-ca-bundle")
38+
if errors.IsNotFound(err) {
39+
return nil, nil
40+
}
3941
if err != nil {
4042
return nil, err
4143
}
4244

43-
certPool, _ := x509.SystemCertPool()
44-
if certPool == nil {
45-
certPool = x509.NewCertPool()
46-
}
45+
certPool := x509.NewCertPool()
4746

4847
if cm.Data["ca-bundle.crt"] != "" {
4948
if ok := certPool.AppendCertsFromPEM([]byte(cm.Data["ca-bundle.crt"])); !ok {

pkg/internal/constants.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package internal
22

33
const (
4-
ConfigNamespace = "openshift-config"
5-
InstallerConfigMap = "openshift-install"
6-
ManifestsConfigMap = "openshift-install-manifests"
4+
ConfigNamespace = "openshift-config"
5+
ConfigManagedNamespace = "openshift-config-managed"
6+
InstallerConfigMap = "openshift-install"
7+
ManifestsConfigMap = "openshift-install-manifests"
78
)

0 commit comments

Comments
 (0)