|
32 | 32 | # files, relative to the repository root or absolute, to layer additional chart |
33 | 33 | # configuration on top of ci/values-skaffold.yaml. |
34 | 34 | # |
| 35 | +# Set OPENSHELL_E2E_KUBE_POD_TLS=1 when the extra values turn gateway pod TLS |
| 36 | +# back on (for example ci/values-high-availability-tls.yaml). The harness then |
| 37 | +# port-forwards the gateway Service as usual but registers an mTLS CLI gateway |
| 38 | +# at https://localhost:<port> with the chart's openshell-client-tls material. |
| 39 | +# Envoy and the database scenarios still assume plaintext pods, so this mode |
| 40 | +# rejects them. |
| 41 | +# |
35 | 42 | # Image source: |
36 | 43 | # - Ephemeral k3d mode builds local |
37 | 44 | # `openshell/{gateway,sandbox,supervisor}:${IMAGE_TAG}` |
@@ -126,6 +133,8 @@ OPENSHIFT_ROUTE_HOST="" |
126 | 133 | # Temp dir holding the client mTLS material extracted from openshell-client-tls |
127 | 134 | # for the OpenShift Route transport. Removed by cleanup(). |
128 | 135 | OPENSHIFT_PKI_DIR="${WORKDIR}/openshift-pki" |
| 136 | +# Client mTLS material for OPENSHELL_E2E_KUBE_POD_TLS=1. Removed with WORKDIR. |
| 137 | +POD_TLS_PKI_DIR="${WORKDIR}/pod-tls-pki" |
129 | 138 |
|
130 | 139 | # Isolate CLI/SDK gateway metadata from the developer's real config. |
131 | 140 | export XDG_CONFIG_HOME="${WORKDIR}/config" |
@@ -825,6 +834,68 @@ openshift_register_route_gateway() { |
825 | 834 | "${pki_dir}" |
826 | 835 | } |
827 | 836 |
|
| 837 | +use_pod_tls() { |
| 838 | + case "${OPENSHELL_E2E_KUBE_POD_TLS:-0}" in |
| 839 | + 1 | true | TRUE | yes | YES) return 0 ;; |
| 840 | + *) return 1 ;; |
| 841 | + esac |
| 842 | +} |
| 843 | + |
| 844 | +# OPENSHELL_E2E_KUBE_POD_TLS=1 only: port-forward the gateway Service, wait for |
| 845 | +# an mTLS handshake with the chart's client material, and register an mTLS CLI |
| 846 | +# gateway at https://localhost:<port>. localhost is a server SAN in both chart |
| 847 | +# PKI modes. Sets LOCAL_PORT, PORTFORWARD_PID, GATEWAY_NAME, GATEWAY_ENDPOINT. |
| 848 | +kube_register_pod_tls_gateway() { |
| 849 | + local pki_dir="${POD_TLS_PKI_DIR}" |
| 850 | + local elapsed=0 timeout=60 |
| 851 | + |
| 852 | + rm -rf "${pki_dir}" |
| 853 | + mkdir -p "${pki_dir}/client" |
| 854 | + kctl -n "${NAMESPACE}" get secret openshell-client-tls \ |
| 855 | + -o jsonpath='{.data.ca\.crt}' | base64 -d >"${pki_dir}/ca.crt" |
| 856 | + kctl -n "${NAMESPACE}" get secret openshell-client-tls \ |
| 857 | + -o jsonpath='{.data.tls\.crt}' | base64 -d >"${pki_dir}/client/tls.crt" |
| 858 | + kctl -n "${NAMESPACE}" get secret openshell-client-tls \ |
| 859 | + -o jsonpath='{.data.tls\.key}' | base64 -d >"${pki_dir}/client/tls.key" |
| 860 | + |
| 861 | + LOCAL_PORT="$(e2e_pick_port)" |
| 862 | + echo "Starting kubectl port-forward svc/${RELEASE_NAME} ${LOCAL_PORT}:8080 (pod TLS)..." |
| 863 | + kctl -n "${NAMESPACE}" port-forward "svc/${RELEASE_NAME}" \ |
| 864 | + "${LOCAL_PORT}:8080" >"${PORTFORWARD_LOG}" 2>&1 & |
| 865 | + PORTFORWARD_PID=$! |
| 866 | + |
| 867 | + while [ "${elapsed}" -lt "${timeout}" ]; do |
| 868 | + if ! kill -0 "${PORTFORWARD_PID}" 2>/dev/null; then |
| 869 | + echo "ERROR: kubectl port-forward exited before becoming reachable" >&2 |
| 870 | + cat "${PORTFORWARD_LOG}" >&2 || true |
| 871 | + return 1 |
| 872 | + fi |
| 873 | + if curl -s -o /dev/null --max-time 5 \ |
| 874 | + --cacert "${pki_dir}/ca.crt" \ |
| 875 | + --cert "${pki_dir}/client/tls.crt" \ |
| 876 | + --key "${pki_dir}/client/tls.key" \ |
| 877 | + "https://localhost:${LOCAL_PORT}/"; then |
| 878 | + break |
| 879 | + fi |
| 880 | + sleep 1 |
| 881 | + elapsed=$((elapsed + 1)) |
| 882 | + done |
| 883 | + if [ "${elapsed}" -ge "${timeout}" ]; then |
| 884 | + echo "ERROR: gateway did not complete an mTLS handshake on https://localhost:${LOCAL_PORT} within ${timeout}s" >&2 |
| 885 | + cat "${PORTFORWARD_LOG}" >&2 || true |
| 886 | + return 1 |
| 887 | + fi |
| 888 | + |
| 889 | + GATEWAY_NAME="openshell-e2e-kube-${LOCAL_PORT}" |
| 890 | + GATEWAY_ENDPOINT="https://localhost:${LOCAL_PORT}" |
| 891 | + e2e_register_mtls_gateway \ |
| 892 | + "${XDG_CONFIG_HOME}" \ |
| 893 | + "${GATEWAY_NAME}" \ |
| 894 | + "${GATEWAY_ENDPOINT}" \ |
| 895 | + "${LOCAL_PORT}" \ |
| 896 | + "${pki_dir}" |
| 897 | +} |
| 898 | + |
828 | 899 | # Start `kubectl port-forward svc/openshell` for the gRPC endpoint and wait for |
829 | 900 | # it to accept TCP. Sets LOCAL_PORT and PORTFORWARD_PID. Prints the port-forward |
830 | 901 | # log and returns non-zero on failure. Used for the vanilla-Kubernetes transport |
@@ -891,6 +962,13 @@ require_cmd helm |
891 | 962 | require_cmd kubectl |
892 | 963 | require_cmd curl |
893 | 964 |
|
| 965 | +if use_pod_tls; then |
| 966 | + if use_envoy_gateway || [ "${OPENSHELL_E2E_KUBE_DB_SCENARIOS:-0}" = "1" ]; then |
| 967 | + echo "ERROR: OPENSHELL_E2E_KUBE_POD_TLS=1 does not support Envoy or the database scenarios" >&2 |
| 968 | + exit 2 |
| 969 | + fi |
| 970 | +fi |
| 971 | + |
894 | 972 | if [ -n "${OPENSHELL_E2E_KUBE_CONTEXT:-}" ]; then |
895 | 973 | KUBE_CONTEXT="${OPENSHELL_E2E_KUBE_CONTEXT}" |
896 | 974 | echo "Using existing kubectl context: ${KUBE_CONTEXT}" |
@@ -1407,6 +1485,9 @@ else |
1407 | 1485 | # OpenShift: reach the gateway over the passthrough Route with mTLS so the |
1408 | 1486 | # SSH-relay `sandbox connect` suites work (port-forward stalls them). |
1409 | 1487 | openshift_register_route_gateway || exit 1 |
| 1488 | + elif use_pod_tls; then |
| 1489 | + # Vanilla Kubernetes with pod TLS: mTLS over the Service port-forward. |
| 1490 | + kube_register_pod_tls_gateway || exit 1 |
1410 | 1491 | else |
1411 | 1492 | # Vanilla Kubernetes: reach the gateway in plaintext over port-forward. |
1412 | 1493 | start_gateway_portforward || exit 1 |
|
0 commit comments