Skip to content

Commit 1dca07b

Browse files
committed
test(e2e): configure sandbox JWT keys in harnesses
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 42289cf commit 1dca07b

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎e2e/support/gateway-common.sh‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,37 @@ EOF
9393
printf '%s' "${name}" >"${config_home}/openshell/active_gateway"
9494
}
9595

96+
e2e_toml_string() {
97+
local value="$1"
98+
value="${value//\\/\\\\}"
99+
value="${value//\"/\\\"}"
100+
printf '"%s"' "${value}"
101+
}
102+
103+
e2e_generate_gateway_jwt() {
104+
local jwt_dir=$1
105+
106+
mkdir -p "${jwt_dir}"
107+
(
108+
umask 077
109+
openssl genpkey -algorithm Ed25519 -out "${jwt_dir}/signing.pem" >/dev/null 2>&1
110+
)
111+
openssl pkey -in "${jwt_dir}/signing.pem" -pubout -out "${jwt_dir}/public.pem" >/dev/null 2>&1
112+
openssl rand -hex 16 >"${jwt_dir}/kid"
113+
}
114+
115+
e2e_write_gateway_jwt_config() {
116+
local jwt_dir=$1
117+
local gateway_id=$2
118+
119+
printf '[openshell.gateway.gateway_jwt]\n'
120+
printf 'signing_key_path = %s\n' "$(e2e_toml_string "${jwt_dir}/signing.pem")"
121+
printf 'public_key_path = %s\n' "$(e2e_toml_string "${jwt_dir}/public.pem")"
122+
printf 'kid_path = %s\n' "$(e2e_toml_string "${jwt_dir}/kid")"
123+
printf 'gateway_id = %s\n' "$(e2e_toml_string "${gateway_id}")"
124+
printf 'ttl_secs = 86400\n\n'
125+
}
126+
96127
e2e_build_gateway_binaries() {
97128
local root=$1
98129
local target_var=$2
@@ -176,4 +207,3 @@ e2e_print_gateway_log_on_failure() {
176207
echo "=== end gateway log ==="
177208
fi
178209
}
179-

‎e2e/with-docker-gateway.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ e2e_generate_pki "${GATEWAY_BIN}" "${PKI_DIR}"
391391
HOST_PORT=$(e2e_pick_port)
392392
STATE_DIR="${WORKDIR}/state"
393393
mkdir -p "${STATE_DIR}"
394+
JWT_DIR="${STATE_DIR}/jwt"
394395

395396
GATEWAY_ENDPOINT="https://host.openshell.internal:${HOST_PORT}"
396397
E2E_NAMESPACE="e2e-docker-$$-${HOST_PORT}"
@@ -410,6 +411,7 @@ else
410411
fi
411412

412413
echo "Starting openshell-gateway on port ${HOST_PORT} (namespace: ${E2E_NAMESPACE})..."
414+
e2e_generate_gateway_jwt "${JWT_DIR}"
413415

414416
# Driver-specific options moved from CLI flags into a TOML config table
415417
# (commit 560550d2). Synthesize a minimal config here and pass --config.
@@ -428,6 +430,7 @@ GATEWAY_CONFIG="${STATE_DIR}/gateway.toml"
428430
{
429431
printf '[openshell]\nversion = 1\n\n'
430432
printf '[openshell.gateway]\nlog_level = "info"\n\n'
433+
e2e_write_gateway_jwt_config "${JWT_DIR}" "openshell-e2e-docker-${HOST_PORT}"
431434
printf '[openshell.drivers.docker]\n'
432435
printf 'sandbox_namespace = %s\n' "$(toml_string "${E2E_NAMESPACE}")"
433436
printf 'network_name = %s\n' "$(toml_string "${DOCKER_NETWORK_NAME}")"

‎e2e/with-podman-gateway.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ HOST_PORT=$(e2e_pick_port)
335335
HEALTH_PORT=$(e2e_pick_port)
336336
STATE_DIR="${WORKDIR}/state"
337337
mkdir -p "${STATE_DIR}"
338+
JWT_DIR="${STATE_DIR}/jwt"
338339

339340
E2E_NAMESPACE="e2e-podman-$$-${HOST_PORT}"
340341
PODMAN_NETWORK_NAME="${E2E_NAMESPACE}"
@@ -346,6 +347,7 @@ export OPENSHELL_E2E_NETWORK_NAME="${PODMAN_NETWORK_NAME}"
346347
export OPENSHELL_E2E_SANDBOX_NAMESPACE="${E2E_NAMESPACE}"
347348

348349
echo "Starting openshell-gateway on port ${HOST_PORT} (namespace: ${E2E_NAMESPACE})..."
350+
e2e_generate_gateway_jwt "${JWT_DIR}"
349351

350352
# Driver-specific options moved from CLI flags into a TOML config table
351353
# (commit 560550d2). Synthesize a minimal config here and pass --config.
@@ -370,6 +372,7 @@ GATEWAY_CONFIG="${STATE_DIR}/gateway.toml"
370372
# (CLI > TOML in the merge precedence) so the test can use an ephemeral port.
371373
cp "${ROOT}/deploy/rpm/gateway.toml.default" "${GATEWAY_CONFIG}"
372374
{
375+
e2e_write_gateway_jwt_config "${JWT_DIR}" "openshell-e2e-podman-${HOST_PORT}"
373376
printf '\n[openshell.drivers.podman]\n'
374377
# The Podman driver scopes isolation by network rather than namespace.
375378
printf 'network_name = %s\n' "$(toml_string "${PODMAN_NETWORK_NAME}")"

0 commit comments

Comments
 (0)