Skip to content

Commit

Permalink
Merge pull request #1460 from Neon-White/backport-ocp-ca-injection
Browse files Browse the repository at this point in the history
[Backport to 5.15] Modify the handling of injected OCP CA bundles
  • Loading branch information
liranmauda authored Oct 8, 2024
2 parents 50b40ed + fbb0f0d commit 9344feb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 68 deletions.
2 changes: 1 addition & 1 deletion deploy/internal/configmap-ca-inject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ kind: ConfigMap
metadata:
labels:
config.openshift.io/inject-trusted-cabundle: "true"
name: noobaa-ca-inject
name: ocp-injected-ca-bundle
data: {}
10 changes: 5 additions & 5 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ spec:
# SHOULD BE RETURNED ONCE COSI IS BACK
# - name: socket
# emptyDir: {}
- name: noobaa-ca-inject
- name: ocp-injected-ca-bundle
configMap:
name: noobaa-ca-inject
name: ocp-injected-ca-bundle
items:
- key: ca-bundle.crt
path: tls-ca-bundle.pem
path: ca-bundle.crt
optional: true
containers:
- name: noobaa-operator
Expand All @@ -44,8 +44,8 @@ spec:
- name: bound-sa-token
mountPath: /var/run/secrets/openshift/serviceaccount
readOnly: true
- name: noobaa-ca-inject
mountPath: /etc/pki/ca-trust/extracted/pem
- name: ocp-injected-ca-bundle
mountPath: /etc/ocp-injected-ca-bundle
# SHOULD BE RETURNED ONCE COSI IS BACK
# - name: socket
# mountPath: /var/lib/cosi
Expand Down
16 changes: 8 additions & 8 deletions pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3599,14 +3599,14 @@ spec:
skipServiceCheck: true
`

const Sha256_deploy_internal_configmap_ca_inject_yaml = "75f8ab503a683bcebd2ed6a2c9f8da0a4c174a62b4e6ca7e97ebc3da847ca866"
const Sha256_deploy_internal_configmap_ca_inject_yaml = "fac2305a04146c6b553398b1cb69b3ee2f32c5735359f5102590d43d33ccecba"

const File_deploy_internal_configmap_ca_inject_yaml = `apiVersion: v1
kind: ConfigMap
metadata:
labels:
config.openshift.io/inject-trusted-cabundle: "true"
name: noobaa-ca-inject
name: ocp-injected-ca-bundle
data: {}
`

Expand Down Expand Up @@ -5947,7 +5947,7 @@ spec:
sourceNamespace: default
`

const Sha256_deploy_operator_yaml = "1a2c110adc6763047d158e9021ea716e8d16ce734c0302c569b02e114189dff8"
const Sha256_deploy_operator_yaml = "f1d3f744af5e55b5476c085c10425f93837cf0bdf39d206f3857d3c5e9bc6c78"

const File_deploy_operator_yaml = `apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -5981,12 +5981,12 @@ spec:
# SHOULD BE RETURNED ONCE COSI IS BACK
# - name: socket
# emptyDir: {}
- name: noobaa-ca-inject
- name: ocp-injected-ca-bundle
configMap:
name: noobaa-ca-inject
name: ocp-injected-ca-bundle
items:
- key: ca-bundle.crt
path: tls-ca-bundle.pem
path: ca-bundle.crt
optional: true
containers:
- name: noobaa-operator
Expand All @@ -5995,8 +5995,8 @@ spec:
- name: bound-sa-token
mountPath: /var/run/secrets/openshift/serviceaccount
readOnly: true
- name: noobaa-ca-inject
mountPath: /etc/pki/ca-trust/extracted/pem
- name: ocp-injected-ca-bundle
mountPath: /etc/ocp-injected-ca-bundle
# SHOULD BE RETURNED ONCE COSI IS BACK
# - name: socket
# mountPath: /var/lib/cosi
Expand Down
4 changes: 4 additions & 0 deletions pkg/olm/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func RunCatalog(cmd *cobra.Command, args []string) {
util.Panic(os.WriteFile(dir+"noobaa-operator.package.yaml", pkgBytes, 0644))
}
util.Panic(util.WriteYamlFile(csvFileName, GenerateCSV(opConf, csvParams)))
// The CA configmap is needed prior to the operator startup to prevent a certificate injection race condition
util.Panic(util.WriteYamlFile(
versionDir+"noobaa-operator.ca-bundle-configmap.yaml",
util.KubeObject(bundle.File_deploy_internal_configmap_ca_inject_yaml)))
crd.ForEachCRD(func(c *crd.CRD) {
if c.Spec.Group == nbv1.SchemeGroupVersion.Group || (csvParams.OBCMode == OBCOwned && c.Spec.Group == obAPI.Domain) {
util.Panic(util.WriteYamlFile(versionDir+c.Name+".crd.yaml", c))
Expand Down
20 changes: 0 additions & 20 deletions pkg/system/azure_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,20 @@ package system
import (
"fmt"
"log"
"net/http"
"net/url"
"time"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"

"github.com/noobaa/noobaa-operator/v5/pkg/util"
)

func (r *Reconciler) getStorageAccountsClient() storage.AccountsClient {
storageAccountsClient := storage.NewAccountsClient(r.AzureContainerCreds.StringData["azure_subscription_id"])
auth, _ := r.GetResourceManagementAuthorizer()
storageAccountsClient.Authorizer = auth
// Inject the global refreshing CA pool into the one used by the Azure client
var httpClient = &http.Client{
Transport: util.GlobalCARefreshingTransport,
Timeout: 10 * time.Second,
}
underlyingHTTPClient, ok := storageAccountsClient.Sender.(*http.Client)
if !ok {
log.Fatalf("failed to cast underlyingHTTPClient to *http.Client")
}
underlyingHTTPClient.Transport = httpClient.Transport
underlyingTransport, ok := underlyingHTTPClient.Transport.(*http.Transport)
if !ok {
log.Fatalf("failed to cast underlyingTransport to *http.Transport")
}
underlyingTransport.TLSClientConfig.RootCAs = util.GlobalCARefreshingTransport.TLSClientConfig.RootCAs

err := storageAccountsClient.AddToUserAgent("Go-http-client/1.1")
if err != nil {
log.Fatalf("got error on storageAccountsClient.AddToUserAgent %v", err)
Expand Down
24 changes: 2 additions & 22 deletions pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ func (r *Reconciler) ReconcilePhaseCreating() error {
r.NooBaaMongoDB.Name, r.NooBaaMongoDB.Spec.ServiceName)
}

if err := r.ReconcileCAInject(); err != nil {
return err
}
if err := r.ReconcileObject(r.ServiceAccount, r.SetDesiredServiceAccount); err != nil {
return err
}
Expand Down Expand Up @@ -541,7 +538,7 @@ func (r *Reconciler) SetDesiredCoreApp() error {
if util.KubeCheckQuiet(r.CaBundleConf) {
configMapVolumeMounts := []corev1.VolumeMount{{
Name: r.CaBundleConf.Name,
MountPath: "/etc/pki/ca-trust/extracted/pem",
MountPath: "/etc/ocp-injected-ca-bundle.crt",
ReadOnly: true,
}}
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
Expand Down Expand Up @@ -610,7 +607,7 @@ func (r *Reconciler) SetDesiredCoreApp() error {
},
Items: []corev1.KeyToPath{{
Key: "ca-bundle.crt",
Path: "tls-ca-bundle.pem",
Path: "ca-bundle.crt",
}},
},
},
Expand Down Expand Up @@ -855,23 +852,6 @@ func (r *Reconciler) ReconcileIBMCredentials() error {
return nil
}

// ReconcileCAInject checks if a namespace called openshift-config exist (OCP)
// if so creates a cofig map for OCP to inject supported CAs to
func (r *Reconciler) ReconcileCAInject() error {
ocpConfigNamespace := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{Kind: "Namespace"},
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-config",
},
}
if util.KubeCheckQuiet(ocpConfigNamespace) {
r.Logger.Infof("Found openshift-config ns - will reconcile CA inject configmap: %q", r.CaBundleConf.Name)
if err := r.ReconcileObject(r.CaBundleConf, nil); err != nil {
return err
}
}
return nil
}

// SetDesiredAgentProfile updates the value of the AGENT_PROFILE env
func (r *Reconciler) SetDesiredAgentProfile(profileString string) string {
Expand Down
12 changes: 2 additions & 10 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,15 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
},
Items: []corev1.KeyToPath{{
Key: "ca-bundle.crt",
Path: "tls-ca-bundle.pem",
Path: "ca-bundle.crt",
}},
},
},
}}
util.MergeVolumeList(&podSpec.Volumes, &configMapVolumes)
configMapVolumeMounts := []corev1.VolumeMount{{
Name: r.CaBundleConf.Name,
MountPath: "/etc/pki/ca-trust/extracted/pem",
MountPath: "/etc/ocp-injected-ca-bundle.crt",
ReadOnly: true,
}}
util.MergeVolumeMountList(&container.VolumeMounts, &configMapVolumeMounts)
Expand Down Expand Up @@ -861,10 +861,6 @@ func (r *Reconciler) prepareAWSBackingStore() error {
*result.Credentials.SecretAccessKey,
*result.Credentials.SessionToken,
),
HTTPClient: &http.Client{
Transport: util.GlobalCARefreshingTransport,
Timeout: 10 * time.Second,
},
Region: &region,
}
} else { // handle AWS long-lived credentials (not STS)
Expand All @@ -874,10 +870,6 @@ func (r *Reconciler) prepareAWSBackingStore() error {
cloudCredsSecret.StringData["aws_secret_access_key"],
"",
),
HTTPClient: &http.Client{
Transport: util.GlobalCARefreshingTransport,
Timeout: 10 * time.Second,
},
Region: &region,
}
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ var (

// AddToRootCAs adds a local cert file to Our GlobalCARefreshingTransport
func AddToRootCAs(localCertFile string) error {
rootCAs := x509.NewCertPool()
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}

var certFiles = []string{
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
"/etc/ocp-injected-ca-bundle.crt",
localCertFile,
}

Expand Down

0 comments on commit 9344feb

Please sign in to comment.