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

Add server TLS key and cert into Che configmap if a separate namespace for Che workspaces is configured #421

Merged
merged 1 commit into from
Aug 31, 2020
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
40 changes: 27 additions & 13 deletions pkg/deploy/che_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ type CheConfigMap struct {
}

func SyncCheConfigMapToCluster(deployContext *DeployContext) (*corev1.ConfigMap, error) {
data := GetCheConfigMapData(deployContext)
data, err := GetCheConfigMapData(deployContext)
if err != nil {
return nil, err
}
specConfigMap, err := GetSpecConfigMap(deployContext, CheConfigMapName, data)
if err != nil {
return nil, err
Expand All @@ -86,9 +89,9 @@ func SyncCheConfigMapToCluster(deployContext *DeployContext) (*corev1.ConfigMap,
return SyncConfigMapToCluster(deployContext, specConfigMap)
}

// GetConfigMapData gets env values from CR spec and returns a map with key:value
// GetCheConfigMapData gets env values from CR spec and returns a map with key:value
// which is used in CheCluster ConfigMap to configure CheCluster master behavior
func GetCheConfigMapData(deployContext *DeployContext) (cheEnv map[string]string) {
func GetCheConfigMapData(deployContext *DeployContext) (cheEnv map[string]string, err error) {
cheHost := deployContext.CheCluster.Spec.Server.CheHost
keycloakURL := deployContext.CheCluster.Spec.Auth.IdentityProviderURL
isOpenShift, isOpenshift4, err := util.DetectOpenShift()
Expand Down Expand Up @@ -227,19 +230,30 @@ func GetCheConfigMapData(deployContext *DeployContext) (cheEnv map[string]string
err = json.Unmarshal(out, &cheEnv)

// k8s specific envs
k8sCheEnv := map[string]string{
"CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_FS__GROUP": securityContextFsGroup,
"CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_RUN__AS__USER": securityContextRunAsUser,
"CHE_INFRA_KUBERNETES_INGRESS_DOMAIN": ingressDomain,
"CHE_INFRA_KUBERNETES_SERVER__STRATEGY": ingressStrategy,
"CHE_INFRA_KUBERNETES_TLS__SECRET": tlsSecretName,
"CHE_INFRA_KUBERNETES_INGRESS_ANNOTATIONS__JSON": "{\"kubernetes.io/ingress.class\": " + ingressClass + ", \"nginx.ingress.kubernetes.io/rewrite-target\": \"/$1\",\"nginx.ingress.kubernetes.io/ssl-redirect\": " + tls + ",\"nginx.ingress.kubernetes.io/proxy-connect-timeout\": \"3600\",\"nginx.ingress.kubernetes.io/proxy-read-timeout\": \"3600\"}",
"CHE_INFRA_KUBERNETES_INGRESS_PATH__TRANSFORM": "%s(.*)",
}
if !isOpenShift {
k8sCheEnv := map[string]string{
"CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_FS__GROUP": securityContextFsGroup,
"CHE_INFRA_KUBERNETES_POD_SECURITY__CONTEXT_RUN__AS__USER": securityContextRunAsUser,
"CHE_INFRA_KUBERNETES_INGRESS_DOMAIN": ingressDomain,
"CHE_INFRA_KUBERNETES_SERVER__STRATEGY": ingressStrategy,
"CHE_INFRA_KUBERNETES_TLS__SECRET": tlsSecretName,
"CHE_INFRA_KUBERNETES_INGRESS_ANNOTATIONS__JSON": "{\"kubernetes.io/ingress.class\": " + ingressClass + ", \"nginx.ingress.kubernetes.io/rewrite-target\": \"/$1\",\"nginx.ingress.kubernetes.io/ssl-redirect\": " + tls + ",\"nginx.ingress.kubernetes.io/proxy-connect-timeout\": \"3600\",\"nginx.ingress.kubernetes.io/proxy-read-timeout\": \"3600\"}",
"CHE_INFRA_KUBERNETES_INGRESS_PATH__TRANSFORM": "%s(.*)",
}
// Add TLS key and server certificate to properties when user workspaces should be created in another
// than Che server namespace, from where the Che TLS secret is not accesible.
if _, keyExists := deployContext.CheCluster.Spec.Server.CustomCheProperties["CHE_INFRA_KUBERNETES_NAMESPACE_DEFAULT"]; keyExists {
cheTLSSecret, err := GetClusterSecret(deployContext.CheCluster.Spec.K8s.TlsSecretName, deployContext.CheCluster.ObjectMeta.Namespace, deployContext.ClusterAPI)
if err != nil {
return nil, err
}
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__KEY"] = string(cheTLSSecret.Data["tls.key"])
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__CERT"] = string(cheTLSSecret.Data["tls.crt"])
}

addMap(cheEnv, k8sCheEnv)
}

addMap(cheEnv, deployContext.CheCluster.Spec.Server.CustomCheProperties)
return cheEnv
return cheEnv, nil
}
8 changes: 4 additions & 4 deletions pkg/deploy/che_configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestNewCheConfigMap(t *testing.T) {
cr.Spec.Auth.OpenShiftoAuth = true
deployContext := &DeployContext{
CheCluster: cr,
Proxy: &Proxy{},
Proxy: &Proxy{},
ClusterAPI: ClusterAPI{},
}
cheEnv := GetCheConfigMapData(deployContext)
cheEnv, _ := GetCheConfigMapData(deployContext)
testCm, _ := GetSpecConfigMap(deployContext, CheConfigMapName, cheEnv)
identityProvider := testCm.Data["CHE_INFRA_OPENSHIFT_OAUTH__IDENTITY__PROVIDER"]
_, isOpenshiftv4, _ := util.DetectOpenShift()
Expand All @@ -60,10 +60,10 @@ func TestConfigMapOverride(t *testing.T) {
cr.Spec.Auth.OpenShiftoAuth = true
deployContext := &DeployContext{
CheCluster: cr,
Proxy: &Proxy{},
Proxy: &Proxy{},
ClusterAPI: ClusterAPI{},
}
cheEnv := GetCheConfigMapData(deployContext)
cheEnv, _ := GetCheConfigMapData(deployContext)
testCm, _ := GetSpecConfigMap(deployContext, CheConfigMapName, cheEnv)
if testCm.Data["CHE_WORKSPACE_NO_PROXY"] != "myproxy.myhostname.com" {
t.Errorf("Test failed. Expected myproxy.myhostname.com but was %s", testCm.Data["CHE_WORKSPACE_NO_PROXY"])
Expand Down