Skip to content

Commit b25dd02

Browse files
committed
fix(e2e): load the OIDC token and trust the gateway when seeding profiles
Addresses the carried finding GATOR-c1bd9867-03. e2e_register_oidc_admin_session established a session the CLI never used. The CLI decides whether to load a stored bearer token by matching on the auth_mode field of the gateway metadata alone; the helper omitted that field, so the metadata fell through to the default arm and oidc_token.json stayed on disk unread. The profile import went out unauthenticated exactly as it had before the helper existed. The helper also installed no trust anchor, leaving the CLI unable to verify the gateway's self-signed serving certificate. Write auth_mode = "oidc" so the stored token is loaded, and install the CA at <gateway>/mtls/ca.crt. Only the CA is installed: with no client certificate or key on disk the CLI falls back to CA-only server verification and authenticates with the bearer token, which is what these lanes need because they start the gateway without --tls-client-ca. Certificate verification stays on; no insecure transport override is introduced. Assert the session before anything depends on it. ListProviderProfiles is annotated auth_mode: "bearer", so it cannot succeed unless the token was loaded and accepted. The helper now fails at that point, naming the gateway config directory and echoing the CLI output, rather than letting the defect surface later as an opaque profile import error. Both affected wrappers pass the PKI directory and CLI binary the helper needs; the mTLS lanes are untouched. Signed-off-by: Philippe Martin <[email protected]>
1 parent f90150b commit b25dd02

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎e2e/support/gateway-common.sh‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ e2e_register_oidc_admin_session() {
177177
local issuer=$5
178178
local username=$6
179179
local password=$7
180-
local client_id="${8:-openshell-cli}"
180+
local pki_dir=$8
181+
local cli_bin=$9
182+
local client_id="${10:-openshell-cli}"
181183
local gateway_config_dir="${config_home}/openshell/gateways/${name}"
182184

183185
local token
@@ -194,13 +196,27 @@ e2e_register_oidc_admin_session() {
194196
fi
195197

196198
mkdir -p "${gateway_config_dir}"
199+
200+
# Trust the gateway's self-signed serving certificate. Only the CA is
201+
# installed: these lanes start the gateway without --tls-client-ca, and with
202+
# no client cert/key on disk the CLI falls back to CA-only server
203+
# verification and authenticates with the bearer token instead of an mTLS
204+
# identity.
205+
mkdir -p "${gateway_config_dir}/mtls"
206+
cp "${pki_dir}/ca.crt" "${gateway_config_dir}/mtls/ca.crt"
207+
208+
# auth_mode must be "oidc": the CLI dispatches on this field alone when
209+
# deciding to load a stored bearer token, so omitting it leaves
210+
# oidc_token.json on disk and unread, and the request goes unauthenticated.
197211
cat >"${gateway_config_dir}/metadata.json" <<EOF
198212
{
199213
"name": "${name}",
200214
"gateway_endpoint": "${endpoint}",
201215
"is_remote": false,
202216
"gateway_port": ${port},
203-
"oidc_issuer": "${issuer}"
217+
"auth_mode": "oidc",
218+
"oidc_issuer": "${issuer}",
219+
"oidc_client_id": "${client_id}"
204220
}
205221
EOF
206222
cat >"${gateway_config_dir}/oidc_token.json" <<EOF
@@ -212,6 +228,21 @@ EOF
212228
EOF
213229
chmod 600 "${gateway_config_dir}/oidc_token.json"
214230
printf '%s' "${name}" >"${config_home}/openshell/active_gateway"
231+
232+
# Assert the CLI reaches the gateway as an authenticated administrator before
233+
# anything depends on it. ListProviderProfiles is annotated
234+
# auth_mode: "bearer", so it cannot succeed unless the stored token was
235+
# loaded and accepted -- this fails here, with the cause named, rather than
236+
# surfacing later as an opaque profile import error.
237+
if ! "${cli_bin}" provider list-profiles --global --output json >/dev/null 2>&1; then
238+
echo "ERROR: the CLI could not make an authenticated call as the OIDC administrator" >&2
239+
echo " gateway config: ${gateway_config_dir}" >&2
240+
echo " CLI output follows:" >&2
241+
"${cli_bin}" provider list-profiles --global --output json >&2 || true
242+
return 1
243+
fi
244+
245+
echo "Established an authenticated OIDC administrator session for '${name}'."
215246
}
216247

217248
e2e_toml_string() {

‎e2e/with-docker-gateway.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,9 @@ if [ "${OIDC_MODE}" = "1" ]; then
718718
"${HOST_PORT}" \
719719
"${OIDC_ISSUER}" \
720720
"${OPENSHELL_E2E_OIDC_USERNAME:-admin@test}" \
721-
"${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" || exit 1
721+
"${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" \
722+
"${PKI_DIR}" \
723+
"${CLI_BIN}" || exit 1
722724
fi
723725
e2e_import_example_provider_profiles "${CLI_BIN}" "${ROOT}" || exit 1
724726

‎e2e/with-podman-gateway.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,9 @@ if [ "${OIDC_MODE}" = "1" ]; then
922922
"${HOST_PORT}" \
923923
"${OIDC_ISSUER}" \
924924
"${OPENSHELL_E2E_OIDC_USERNAME:-admin@test}" \
925-
"${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" || exit 1
925+
"${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" \
926+
"${PKI_DIR}" \
927+
"${CLI_BIN}" || exit 1
926928
fi
927929
e2e_import_example_provider_profiles "${CLI_BIN}" "${ROOT}" || exit 1
928930

0 commit comments

Comments
 (0)