1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # -------------------------------------------------------------------
5+ # Configuration
6+ # -------------------------------------------------------------------
7+ CHE_NAMESPACE=" eclipse-che"
8+ DW_NAMESPACE=" kubeadmin-che"
9+ DW_NAME=" code-latest"
10+
11+ CERT_COUNT=500
12+ BUNDLE_FILE=" custom-ca-certificates.pem"
13+
14+ # -------------------------------------------------------------------
15+ # Logging helpers
16+ # -------------------------------------------------------------------
17+ log_info () { echo -e " ℹ️ $* " ; }
18+ log_success () { echo -e " ✅ $* " ; }
19+ log_error () { echo -e " ❌ $* " >&2 ; }
20+
21+ # -------------------------------------------------------------------
22+ # Preconditions
23+ # -------------------------------------------------------------------
24+ log_info " Checking namespaces..."
25+ kubectl get ns " ${CHE_NAMESPACE} " > /dev/null
26+ kubectl get ns " ${DW_NAMESPACE} " > /dev/null
27+
28+ # -------------------------------------------------------------------
29+ # Generate dummy certificates (~1MB bundle)
30+ # -------------------------------------------------------------------
31+ log_info " Generating ${CERT_COUNT} dummy CA certificates..."
32+ rm -f " ${BUNDLE_FILE} "
33+
34+ for i in $( seq 1 " ${CERT_COUNT} " ) ; do
35+ openssl req -x509 -newkey rsa:2048 -nodes -days 1 \
36+ -subj " /CN=dummy-ca-${i} " \
37+ -keyout " dummy-ca-${i} .key" \
38+ -out " dummy-ca-${i} .pem" \
39+ > /dev/null 2>&1
40+
41+ cat " dummy-ca-${i} .pem" >> " ${BUNDLE_FILE} "
42+ done
43+
44+ BUNDLE_SIZE=$( stat -c%s " ${BUNDLE_FILE} " )
45+ log_success " Created CA bundle: $( du -h ${BUNDLE_FILE} | cut -f1) "
46+
47+ # -------------------------------------------------------------------
48+ # Create / update Che CA bundle ConfigMap
49+ # -------------------------------------------------------------------
50+ log_info " Creating Che CA bundle ConfigMap..."
51+
52+ kubectl create configmap custom-ca-certificates \
53+ --from-file=custom-ca-certificates.pem=" ${BUNDLE_FILE} " \
54+ -n " ${CHE_NAMESPACE} " \
55+ --dry-run=client -o yaml \
56+ | kubectl apply --server-side -f -
57+
58+
59+ kubectl label configmap custom-ca-certificates \
60+ app.kubernetes.io/component=ca-bundle \
61+ app.kubernetes.io/part-of=che.eclipse.org \
62+ -n " ${CHE_NAMESPACE} " \
63+ --overwrite
64+
65+ # -------------------------------------------------------------------
66+ # Configure CheCluster (disable /etc/pki mount)
67+ # -------------------------------------------------------------------
68+ log_info " Configuring CheCluster..."
69+
70+ CHECLUSTER_NAME=$( kubectl get checluster -n " ${CHE_NAMESPACE} " -o jsonpath=' {.items[0].metadata.name}' )
71+
72+ kubectl patch checluster " ${CHECLUSTER_NAME} " \
73+ -n " ${CHE_NAMESPACE} " \
74+ --type=merge \
75+ -p ' {
76+ "spec": {
77+ "devEnvironments": {
78+ "trustedCerts": {
79+ "disableWorkspaceCaBundleMount": true
80+ }
81+ }
82+ }
83+ }'
84+
85+ # -------------------------------------------------------------------
86+ # Restart Che to apply configuration
87+ # -------------------------------------------------------------------
88+ log_info " Restarting Che..."
89+ kubectl rollout status deploy/che -n " ${CHE_NAMESPACE} " --timeout=5m
90+ kubectl wait pod -n " ${CHE_NAMESPACE} " -l app=che --for=condition=Ready --timeout=5m
91+
92+ log_success " Che restarted with updated CA settings"
93+
94+ # -------------------------------------------------------------------
95+ # Create DevWorkspace
96+ # -------------------------------------------------------------------
97+ log_info " Creating DevWorkspace '${DW_NAME} '..."
98+ curl -sL https://gist.githubusercontent.com/rohanKanojia/f755717e3fac6a1f45921c3c2883c6d2/raw/1a256c6f7b9d6dcd8650135ecc492d9f08010a80/che-owned-code-latest.yaml \
99+ | sed " s/name: code-latest/name: ${DW_NAME} /" \
100+ | kubectl apply -n " ${DW_NAMESPACE} " -f -
101+
102+ # -------------------------------------------------------------------
103+ # Wait for DevWorkspace
104+ # -------------------------------------------------------------------
105+ log_info " Waiting for DevWorkspace to be Ready..."
106+ kubectl wait devworkspace/" ${DW_NAME} " \
107+ -n " ${DW_NAMESPACE} " \
108+ --for=condition=Ready \
109+ --timeout=5m
110+
111+ # -------------------------------------------------------------------
112+ # Wait for workspace pod
113+ # -------------------------------------------------------------------
114+ log_info " Waiting for workspace pod..."
115+ kubectl wait pod \
116+ -n " ${DW_NAMESPACE} " \
117+ -l controller.devfile.io/devworkspace_name=" ${DW_NAME} " \
118+ --for=condition=Ready \
119+ --timeout=5m
120+
121+ POD_NAME=$( kubectl get pod \
122+ -n " ${DW_NAMESPACE} " \
123+ -l controller.devfile.io/devworkspace_name=" ${DW_NAME} " \
124+ -o jsonpath=' {.items[0].metadata.name}' )
125+
126+ log_success " Workspace pod '${POD_NAME} ' is Ready"
127+
128+ # -------------------------------------------------------------------
129+ # Verify CA bundle certificate count
130+ # -------------------------------------------------------------------
131+ log_info " Verifying CA bundle certificate count inside workspace..."
132+
133+ CERT_PATH_PUBLIC=" /public-certs/tls-ca-bundle.pem"
134+
135+ if ! kubectl exec " ${POD_NAME} " -n " ${DW_NAMESPACE} " -- test -f " ${CERT_PATH_PUBLIC} " ; then
136+ log_error " CA bundle not found at ${CERT_PATH_PUBLIC} "
137+ exit 1
138+ fi
139+
140+ MOUNTED_CERT_COUNT=$( kubectl exec " ${POD_NAME} " -n " ${DW_NAMESPACE} " -- \
141+ sh -c " grep -c 'BEGIN CERTIFICATE' ${CERT_PATH_PUBLIC} " )
142+
143+ log_info " Generated certificates : ${CERT_COUNT} "
144+ log_info " Mounted certificates : ${MOUNTED_CERT_COUNT} "
145+
146+ if [ " ${MOUNTED_CERT_COUNT} " -gt " ${CERT_COUNT} " ]; then
147+ log_success " Mounted certificate count is greater than generated count ✅"
148+ else
149+ log_error " Mounted certificate count is NOT greater than generated count ❌"
150+ exit 1
151+ fi
152+
153+
154+ # -------------------------------------------------------------------
155+ # Debug: mounted volumes
156+ # -------------------------------------------------------------------
157+ log_info " Mounted volumes:"
158+ kubectl get pod " ${POD_NAME} " \
159+ -n " ${DW_NAMESPACE} " \
160+ -o jsonpath=' {.spec.volumes[*].name}'
161+
162+ # -------------------------------------------------------------------
163+ # Done
164+ # -------------------------------------------------------------------
165+ kubectl delete dw ${DW_NAME} ${DW_NAMESPACE}
166+ rm * .pem
167+ rm * .key
168+ log_success " END-TO-END verification complete (1MB CA bundle) 🎉"
0 commit comments