Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1797123: pkg/cvo: Fetch proxy CA certs from openshift-config-managed/trusted-ca-bundle #311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ type Operator struct {
// syncBackoff allows the tests to use a quicker backoff
syncBackoff wait.Backoff

cvLister configlistersv1.ClusterVersionLister
coLister configlistersv1.ClusterOperatorLister
cmConfigLister listerscorev1.ConfigMapNamespaceLister
proxyLister configlistersv1.ProxyLister
cacheSynced []cache.InformerSynced
cvLister configlistersv1.ClusterVersionLister
coLister configlistersv1.ClusterOperatorLister
cmConfigLister listerscorev1.ConfigMapNamespaceLister
cmConfigManagedLister listerscorev1.ConfigMapNamespaceLister
proxyLister configlistersv1.ProxyLister
cacheSynced []cache.InformerSynced

// queue tracks applying updates to a cluster.
queue workqueue.RateLimitingInterface
Expand Down Expand Up @@ -212,6 +213,7 @@ func New(

optr.proxyLister = proxyInformer.Lister()
optr.cmConfigLister = cmConfigInformer.Lister().ConfigMaps(internal.ConfigNamespace)
optr.cmConfigManagedLister = cmConfigInformer.Lister().ConfigMaps(internal.ConfigManagedNamespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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

var tlsConfig *tls.Config
if cmNameRef != "" {
tlsConfig, err = optr.getTLSConfig(cmNameRef)
if err != nil {
return nil, nil, err
}
tlsConfig, err = optr.getTLSConfig()
if err != nil {
return nil, nil, err
}
return proxyURL, tlsConfig, nil
}
1 change: 1 addition & 0 deletions pkg/cvo/cvo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,7 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
optr.proxyLister = &clientProxyLister{client: optr.client}
optr.coLister = &clientCOLister{client: optr.client}
optr.cvLister = &clientCVLister{client: optr.client}
optr.cmConfigManagedLister = &cmConfigLister{}
optr.eventRecorder = record.NewFakeRecorder(100)

if tt.handler != nil {
Expand Down
25 changes: 12 additions & 13 deletions pkg/cvo/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,38 @@ import (

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

if errors.IsNotFound(err) {
return nil, "", nil
return nil, nil
}
if err != nil {
return nil, "", err
return nil, err
}

if &proxy.Spec != nil {
if proxy.Spec.HTTPSProxy != "" {
proxyURL, err := url.Parse(proxy.Spec.HTTPSProxy)
if err != nil {
return nil, "", err
return nil, err
}
return proxyURL, proxy.Spec.TrustedCA.Name, nil
return proxyURL, nil
}
}
return nil, "", nil
return nil, nil
}

func (optr *Operator) getTLSConfig(cmNameRef string) (*tls.Config, error) {
cm, err := optr.cmConfigLister.Get(cmNameRef)

func (optr *Operator) getTLSConfig() (*tls.Config, error) {
cm, err := optr.cmConfigManagedLister.Get("trusted-ca-bundle")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are hard coding the name here i.e. "trusted-ca-bundle". Is there any way we can avoid it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of the adopted enhancement. I only use it in this one place, so it doesn't seem useful to create a local const for it. But I can if you want one.

if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, err
}

certPool, _ := x509.SystemCertPool()
if certPool == nil {
certPool = x509.NewCertPool()
}
certPool := x509.NewCertPool()

if cm.Data["ca-bundle.crt"] != "" {
if ok := certPool.AppendCertsFromPEM([]byte(cm.Data["ca-bundle.crt"])); !ok {
Expand Down
7 changes: 4 additions & 3 deletions pkg/internal/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package internal

const (
ConfigNamespace = "openshift-config"
InstallerConfigMap = "openshift-install"
ManifestsConfigMap = "openshift-install-manifests"
ConfigNamespace = "openshift-config"
ConfigManagedNamespace = "openshift-config-managed"
InstallerConfigMap = "openshift-install"
ManifestsConfigMap = "openshift-install-manifests"
)