Skip to content
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
20 changes: 20 additions & 0 deletions manifests/03_configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ data:
operator-config.yaml: |
apiVersion: operator.openshift.io/v1alpha1
kind: GenericOperatorConfig
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: openshift-authentication-operator
name: trusted-ca-bundle
annotations:
release.openshift.io/create-only: "true"
labels:
config.openshift.io/inject-trusted-cabundle: "true"
Copy link
Contributor

Choose a reason for hiding this comment

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

won't CVO stomp this configmap after network operator added the CA ?

Copy link
Contributor

Choose a reason for hiding this comment

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

same below of course

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

presumably not, because of the create-only annotation...

Copy link
Contributor

Choose a reason for hiding this comment

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

nvmd. The create-only label will make sure it is not overwritten.

---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: openshift-authentication
name: v4-0-config-system-trusted-ca-bundle
annotations:
release.openshift.io/create-only: "true"
labels:
config.openshift.io/inject-trusted-cabundle: "true"
7 changes: 7 additions & 0 deletions manifests/07_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ spec:
name: config
- mountPath: /var/run/secrets/serving-cert
name: serving-cert
- mountPath: /var/run/configmaps/trusted-ca-bundle
name: trusted-ca-bundle
readOnly: true
env:
- name: IMAGE
value: quay.io/openshift/origin-oauth-server:v4.2
Expand All @@ -53,6 +56,10 @@ spec:
configMap:
defaultMode: 440
name: authentication-operator-config
- name: trusted-ca-bundle
configMap:
name: trusted-ca-bundle
optional: true
- name: serving-cert
secret:
secretName: serving-cert
Expand Down
25 changes: 21 additions & 4 deletions pkg/operator2/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func defaultDeployment(
path: ocpBrandingSecretMount,
keys: []string{configv1.LoginTemplateKey, configv1.ProviderSelectionTemplateKey, configv1.ErrorsTemplateKey},
},
{
name: trustedCABundleName,
configmap: true,
path: trustedCABundleMountDir,
mappedKeys: map[string]string{
trustedCABundleKey: trustedCABundleMountFile,
},
},
} {
v, m := data.split()
volumes = append(volumes, v)
Expand Down Expand Up @@ -257,10 +265,11 @@ func appendEnvVar(envVars []corev1.EnvVar, envName, envVal string) []corev1.EnvV
}

type volume struct {
name string
configmap bool
path string
keys []string
name string
configmap bool
path string
keys []string
mappedKeys map[string]string
}

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

var items []corev1.KeyToPath
// maps' keys are random, we need to sort the output to prevent redeployment hotloops
for _, key := range sets.StringKeySet(v.mappedKeys).List() {
items = append(items, corev1.KeyToPath{
Key: key,
Path: v.mappedKeys[key],
})
}

for _, key := range v.keys {
items = append(items, corev1.KeyToPath{
Key: key,
Expand Down
14 changes: 13 additions & 1 deletion pkg/operator2/idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package operator2
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"

"k8s.io/klog"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -293,7 +296,7 @@ func (c *authOperator) discoverOpenIDURLs(issuer, key string, ca configv1.Config

func (c *authOperator) transportForCARef(ca configv1.ConfigMapNameReference, key string) (http.RoundTripper, error) {
if len(ca.Name) == 0 {
return transportFor("", nil, nil, nil)
return transportFor("", trustedCABytes(), nil, nil)
}
cm, err := c.configMaps.ConfigMaps(userConfigNamespace).Get(ca.Name, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -343,3 +346,12 @@ func encodeOrDie(obj runtime.Object) []byte {
}
return bytes
}

func trustedCABytes() []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

are these additional to the system trust store? The file only includes some CAs, not all. Especially not possibly required intermediate ones.

caData, err := ioutil.ReadFile(operatorTrustedCAFile)
if err != nil {
klog.Infof("could not read %s, it won't be used in transport", operatorTrustedCAFile)
return nil
}
return caData
}
12 changes: 10 additions & 2 deletions pkg/operator2/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const (
kasServiceAndEndpointName = "kubernetes"
kasServiceFullName = kasServiceAndEndpointName + "." + corev1.NamespaceDefault + ".svc"

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

systemConfigPath = "/var/config/system"
systemConfigPathConfigMaps = systemConfigPath + "/configmaps"
Expand Down Expand Up @@ -109,6 +110,12 @@ const (
consoleConfigMapLocalName = systemConfigPrefix + consoleConfigMapSharedName
consoleConfigKey = consoleConfigMapSharedName + ".yaml"

// trustedCABundleName part of manifests, if changing this, need to change that, too
trustedCABundleName = systemConfigPrefix + "trusted-ca-bundle"
trustedCABundleKey = "ca-bundle.crt"
trustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"
trustedCABundleMountFile = "tls-ca-bundle.pem"
Copy link
Contributor

Choose a reason for hiding this comment

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

a plain yaml text file would me much more readable than 35 constansts.


ocpBrandingSecretName = systemConfigPrefix + "ocp-branding-template"
ocpBrandingSecretMount = systemConfigPathSecrets + "/" + ocpBrandingSecretName
ocpBrandingLoginPath = ocpBrandingSecretMount + "/" + configv1.LoginTemplateKey
Expand Down Expand Up @@ -525,7 +532,8 @@ func (c *authOperator) checkDeploymentReady(deployment *appsv1.Deployment, opera
func (c *authOperator) checkRouteHealthy(route *routev1.Route, routerSecret *corev1.Secret, ingress *configv1.Ingress) (ready bool, msg, reason string, err error) {
caData := routerSecretToCA(route, routerSecret, ingress)

rt, err := transportFor("", caData, nil, nil)
// merge trustedCA data with router cert in case TLS intercept proxy is in place
rt, err := transportFor("", append(caData, trustedCABytes()...), nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

this reads the file on every request, not good.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure these bytes always append cleanly, i.e. that we have a trailing newline in caData? Looks fragile.

Copy link
Contributor

Choose a reason for hiding this comment

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

ic, we probably reread to get the latest version (which can change in the background).

if err != nil {
return false, "", "FailedTransport", fmt.Errorf("failed to build transport for route: %v", err)
}
Expand Down