Skip to content

Commit f77f2b3

Browse files
authored
fix: migrate verify script from removed /v1/tokens to /v1/api-keys (opendatahub-io#546)
The verify-models-and-limits.sh script was broken because it called the removed /maas-api/v1/tokens endpoint. This migrates it to the current /v1/api-keys flow. Model discovery stays on the /v1/models API (no kubectl calls). Changes: Use POST /maas-api/v1/api-keys with named keys instead of removed /v1/tokens Parse .key and .id from API key response Clean up temporary API key on exit via DELETE /v1/api-keys/{id} Remove unused USER_NAME and stale JWT decoding logic Prerequisite: The maas-api-auth-policy must support API key authentication (see deployment/base/maas-api/policies/auth-policy.yaml). The ODH operator currently deploys a stale version without API key support. How Has This Been Tested? Ran the script end-to-end on a live cluster (maas.apps.giteltal.dev.datahub.redhat.com) API key creation, model discovery, inference, rate limiting, and cleanup all passed Merge criteria: The commits are squashed in a cohesive manner and have meaningful messages. Testing instructions have been added in the PR body. The developer has manually tested the changes and verified that the changes work. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Switched verification scripts from token-based to API key-based authentication and updated related messaging. * Added creation and guaranteed cleanup (revocation) of temporary API keys, with improved success/error reporting. * Removed JWT decoding and related user-extraction steps; updated model discovery and inference calls to use API key authorization. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1cbba6f commit f77f2b3

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

scripts/verify-models-and-limits.sh

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22

3-
# Source helper functions for JWT decoding
3+
# Verifies model inference and rate limiting through the MaaS API gateway.
4+
# Requires the maas-api-auth-policy to support API key authentication
5+
# (deployment/base/maas-api/policies/auth-policy.yaml).
6+
7+
# Source shared helper functions
48
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
59
source "$SCRIPT_DIR/deployment-helpers.sh"
610

@@ -73,7 +77,7 @@ echo ""
7377
echo -e "${BLUE}Gateway URL:${NC} ${GATEWAY_URL}"
7478
echo ""
7579

76-
echo -e "${BLUE}Obtaining token from MaaS API...${NC}"
80+
echo -e "${BLUE}Obtaining API key from MaaS API...${NC}"
7781

7882
OC_TOKEN=$(oc whoami -t 2>/dev/null)
7983
if [ -z "$OC_TOKEN" ]; then
@@ -82,40 +86,44 @@ if [ -z "$OC_TOKEN" ]; then
8286
exit 1
8387
fi
8488

89+
KEY_NAME="verify-test-$(date +%s)"
90+
8591
TOKEN_RESPONSE=$(curl -sSk \
8692
-H "Authorization: Bearer $OC_TOKEN" \
8793
-H "Content-Type: application/json" \
8894
-X POST \
89-
-d '{"expiration": "1h"}' \
95+
-d "{\"expiresIn\": \"1h\", \"name\": \"$KEY_NAME\"}" \
9096
-w "\nHTTP_STATUS:%{http_code}\n" \
91-
"${API_BASE}/maas-api/v1/tokens" 2>&1)
97+
"${API_BASE}/maas-api/v1/api-keys" 2>&1)
9298

9399
http_status=$(echo "$TOKEN_RESPONSE" | grep "HTTP_STATUS:" | cut -d':' -f2)
94100
response_body=$(echo "$TOKEN_RESPONSE" | sed '/HTTP_STATUS:/d')
95101

96102
if [ "$http_status" != "201" ]; then
97-
echo -e "${RED}Failed to obtain token from MaaS API!${NC}"
103+
echo -e "${RED}Failed to create API key from MaaS API!${NC}"
98104
echo -e "${RED}HTTP Status: $http_status${NC}"
99105
echo -e "${RED}Response: $response_body${NC}"
100106
exit 1
101107
fi
102108

103-
TOKEN=$(echo "$response_body" | jq -r '.token' 2>/dev/null)
104-
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
105-
echo -e "${RED}Failed to parse token from response!${NC}"
109+
TOKEN=$(echo "$response_body" | jq -r '.key' 2>/dev/null)
110+
KEY_ID=$(echo "$response_body" | jq -r '.id' 2>/dev/null)
111+
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ] || [ -z "$KEY_ID" ] || [ "$KEY_ID" = "null" ]; then
112+
echo -e "${RED}Failed to parse API key from response!${NC}"
106113
exit 1
107114
fi
108115

109-
echo -e "${GREEN}✓ Token obtained successfully from MaaS API${NC}"
116+
cleanup_api_key() {
117+
if [ -n "${KEY_ID:-}" ] && [ "${KEY_ID}" != "null" ]; then
118+
curl -sSk -o /dev/null -w "" \
119+
-H "Authorization: Bearer $OC_TOKEN" \
120+
-X DELETE \
121+
"${API_BASE}/maas-api/v1/api-keys/${KEY_ID}" 2>/dev/null || true
122+
fi
123+
}
124+
trap cleanup_api_key EXIT INT TERM
110125

111-
# Use helper function to decode JWT payload
112-
TOKEN_PAYLOAD=$(decode_jwt_payload "$TOKEN")
113-
if [ -z "$TOKEN_PAYLOAD" ]; then
114-
echo -e "${YELLOW}Warning:${NC} Failed to decode MaaS token payload"
115-
USER_NAME="unknown"
116-
else
117-
USER_NAME=$(echo "$TOKEN_PAYLOAD" | jq -r '.sub // "unknown"' 2>/dev/null)
118-
fi
126+
echo -e "${GREEN}✓ API key created successfully (name: $KEY_NAME)${NC}"
119127

120128
echo -e "${BLUE}Discovering available models...${NC}"
121129
MODELS_RESPONSE=$(curl -sSk \
@@ -316,8 +324,8 @@ echo -e "${CYAN}======================================${NC}"
316324
echo ""
317325

318326
echo -e "${BLUE}Authentication:${NC}"
319-
echo -e " ${GREEN}${NC} MaaS API token endpoint is working"
320-
echo -e " ${GREEN}${NC} Token authentication successful"
327+
echo -e " ${GREEN}${NC} MaaS API key endpoint is working"
328+
echo -e " ${GREEN}${NC} API key authentication successful"
321329
echo ""
322330

323331
echo -e "${BLUE}Model Discovery:${NC}"
@@ -347,7 +355,6 @@ fi
347355
echo ""
348356

349357
echo -e "${BLUE}Gateway URL:${NC} ${GATEWAY_URL}"
350-
echo -e "${BLUE}User:${NC} $USER_NAME"
351358
echo ""
352359

353360
if [ "$MODEL_COUNT" -gt 0 ]; then
@@ -357,3 +364,4 @@ if [ "$MODEL_COUNT" -gt 0 ]; then
357364
done
358365
echo ""
359366
fi
367+

0 commit comments

Comments
 (0)