Skip to content

Commit 546aca0

Browse files
Merge pull request #172 from stlaz/mount_proxy_ca
Inject payload's system store with proxy CA when specified
2 parents 77dfe7e + df55535 commit 546aca0

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

manifests/03_configmap.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@ data:
77
operator-config.yaml: |
88
apiVersion: operator.openshift.io/v1alpha1
99
kind: GenericOperatorConfig
10+
---
11+
apiVersion: v1
12+
kind: ConfigMap
13+
metadata:
14+
namespace: openshift-authentication-operator
15+
name: trusted-ca-bundle
16+
annotations:
17+
release.openshift.io/create-only: "true"
18+
labels:
19+
config.openshift.io/inject-trusted-cabundle: "true"
20+
---
21+
apiVersion: v1
22+
kind: ConfigMap
23+
metadata:
24+
namespace: openshift-authentication
25+
name: v4-0-config-system-trusted-ca-bundle
26+
annotations:
27+
release.openshift.io/create-only: "true"
28+
labels:
29+
config.openshift.io/inject-trusted-cabundle: "true"

manifests/07_deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ spec:
3636
name: config
3737
- mountPath: /var/run/secrets/serving-cert
3838
name: serving-cert
39+
- mountPath: /var/run/configmaps/trusted-ca-bundle
40+
name: trusted-ca-bundle
41+
readOnly: true
3942
env:
4043
- name: IMAGE
4144
value: quay.io/openshift/origin-oauth-server:v4.2
@@ -53,6 +56,10 @@ spec:
5356
configMap:
5457
defaultMode: 440
5558
name: authentication-operator-config
59+
- name: trusted-ca-bundle
60+
configMap:
61+
name: trusted-ca-bundle
62+
optional: true
5663
- name: serving-cert
5764
secret:
5865
secretName: serving-cert

pkg/operator2/deployment.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ func defaultDeployment(
7171
path: ocpBrandingSecretMount,
7272
keys: []string{configv1.LoginTemplateKey, configv1.ProviderSelectionTemplateKey, configv1.ErrorsTemplateKey},
7373
},
74+
{
75+
name: trustedCABundleName,
76+
configmap: true,
77+
path: trustedCABundleMountDir,
78+
mappedKeys: map[string]string{
79+
trustedCABundleKey: trustedCABundleMountFile,
80+
},
81+
},
7482
} {
7583
v, m := data.split()
7684
volumes = append(volumes, v)
@@ -257,10 +265,11 @@ func appendEnvVar(envVars []corev1.EnvVar, envName, envVal string) []corev1.EnvV
257265
}
258266

259267
type volume struct {
260-
name string
261-
configmap bool
262-
path string
263-
keys []string
268+
name string
269+
configmap bool
270+
path string
271+
keys []string
272+
mappedKeys map[string]string
264273
}
265274

266275
func (v *volume) split() (corev1.Volume, corev1.VolumeMount) {
@@ -269,6 +278,14 @@ func (v *volume) split() (corev1.Volume, corev1.VolumeMount) {
269278
}
270279

271280
var items []corev1.KeyToPath
281+
// maps' keys are random, we need to sort the output to prevent redeployment hotloops
282+
for _, key := range sets.StringKeySet(v.mappedKeys).List() {
283+
items = append(items, corev1.KeyToPath{
284+
Key: key,
285+
Path: v.mappedKeys[key],
286+
})
287+
}
288+
272289
for _, key := range v.keys {
273290
items = append(items, corev1.KeyToPath{
274291
Key: key,

pkg/operator2/idp.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package operator2
33
import (
44
"encoding/json"
55
"fmt"
6+
"io/ioutil"
67
"net/http"
78
"net/url"
89
"strings"
910

11+
"k8s.io/klog"
12+
1013
corev1 "k8s.io/api/core/v1"
1114
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1215
"k8s.io/apimachinery/pkg/runtime"
@@ -293,7 +296,7 @@ func (c *authOperator) discoverOpenIDURLs(issuer, key string, ca configv1.Config
293296

294297
func (c *authOperator) transportForCARef(ca configv1.ConfigMapNameReference, key string) (http.RoundTripper, error) {
295298
if len(ca.Name) == 0 {
296-
return transportFor("", nil, nil, nil)
299+
return transportFor("", trustedCABytes(), nil, nil)
297300
}
298301
cm, err := c.configMaps.ConfigMaps(userConfigNamespace).Get(ca.Name, metav1.GetOptions{})
299302
if err != nil {
@@ -343,3 +346,12 @@ func encodeOrDie(obj runtime.Object) []byte {
343346
}
344347
return bytes
345348
}
349+
350+
func trustedCABytes() []byte {
351+
caData, err := ioutil.ReadFile(operatorTrustedCAFile)
352+
if err != nil {
353+
klog.Infof("could not read %s, it won't be used in transport", operatorTrustedCAFile)
354+
return nil
355+
}
356+
return caData
357+
}

pkg/operator2/operator.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ const (
6262
kasServiceAndEndpointName = "kubernetes"
6363
kasServiceFullName = kasServiceAndEndpointName + "." + corev1.NamespaceDefault + ".svc"
6464

65-
rootCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
65+
rootCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
66+
operatorTrustedCAFile = "/var/run/configmaps/trusted-ca-bundle/ca-bundle.crt"
6667

6768
systemConfigPath = "/var/config/system"
6869
systemConfigPathConfigMaps = systemConfigPath + "/configmaps"
@@ -109,6 +110,12 @@ const (
109110
consoleConfigMapLocalName = systemConfigPrefix + consoleConfigMapSharedName
110111
consoleConfigKey = consoleConfigMapSharedName + ".yaml"
111112

113+
// trustedCABundleName part of manifests, if changing this, need to change that, too
114+
trustedCABundleName = systemConfigPrefix + "trusted-ca-bundle"
115+
trustedCABundleKey = "ca-bundle.crt"
116+
trustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"
117+
trustedCABundleMountFile = "tls-ca-bundle.pem"
118+
112119
ocpBrandingSecretName = systemConfigPrefix + "ocp-branding-template"
113120
ocpBrandingSecretMount = systemConfigPathSecrets + "/" + ocpBrandingSecretName
114121
ocpBrandingLoginPath = ocpBrandingSecretMount + "/" + configv1.LoginTemplateKey
@@ -525,7 +532,8 @@ func (c *authOperator) checkDeploymentReady(deployment *appsv1.Deployment, opera
525532
func (c *authOperator) checkRouteHealthy(route *routev1.Route, routerSecret *corev1.Secret, ingress *configv1.Ingress) (ready bool, msg, reason string, err error) {
526533
caData := routerSecretToCA(route, routerSecret, ingress)
527534

528-
rt, err := transportFor("", caData, nil, nil)
535+
// merge trustedCA data with router cert in case TLS intercept proxy is in place
536+
rt, err := transportFor("", append(caData, trustedCABytes()...), nil, nil)
529537
if err != nil {
530538
return false, "", "FailedTransport", fmt.Errorf("failed to build transport for route: %v", err)
531539
}

0 commit comments

Comments
 (0)