|
1 | 1 | #!/bin/bash |
2 | | -# Copyright 2020-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# Copyright 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
3 | 3 | # |
4 | 4 | # Redistribution and use in source and binary forms, with or without |
5 | 5 | # modification, are permitted provided that the following conditions |
@@ -137,7 +137,10 @@ sleep 10 |
137 | 137 |
|
138 | 138 | # Test 1 Scenarios: |
139 | 139 | # 1. access blob using shared key in envs |
140 | | -# 2. adding more scenarios in future |
| 140 | +# 2. access blob using system-assigned managed identity |
| 141 | +# 3. access blob using user-assigned managed identity |
| 142 | +# 4. access blob using DefaultAzureCredential |
| 143 | +# 5. adding more scenarios in future |
141 | 144 | for ENV_VAR in "shared_key"; do |
142 | 145 | SERVER_LOG=$SERVER_LOG_BASE.$ENV_VAR.log |
143 | 146 | CLIENT_LOG=$CLIENT_LOG_BASE.$ENV_VAR.log |
@@ -169,6 +172,117 @@ for ENV_VAR in "shared_key"; do |
169 | 172 | wait $SERVER_PID |
170 | 173 | done |
171 | 174 |
|
| 175 | +# Test 2: Managed Identity authentication |
| 176 | +# Requires the test host (VM/AKS) to have a system-assigned managed identity |
| 177 | +# with Storage Blob Data Reader on the test storage account. |
| 178 | +# Skip if not running in an MI-capable environment. |
| 179 | +if [ ! -z "$TEST_AZURE_MANAGED_IDENTITY" ]; then |
| 180 | + echo -e "\n***\n*** Testing system-assigned Managed Identity\n***" |
| 181 | + |
| 182 | + # Save original key and clear it so it won't be used |
| 183 | + SAVED_AZURE_STORAGE_KEY=$AZURE_STORAGE_KEY |
| 184 | + unset AZURE_STORAGE_KEY |
| 185 | + export AZURE_STORAGE_AUTH_TYPE="managed_identity" |
| 186 | + |
| 187 | + SERVER_LOG=$SERVER_LOG_BASE.managed_identity_system.log |
| 188 | + CLIENT_LOG=$CLIENT_LOG_BASE.managed_identity_system.log |
| 189 | + MODEL_REPO="${AS_URL}/models" |
| 190 | + SERVER_ARGS="--model-repository=$MODEL_REPO --exit-timeout-secs=120" |
| 191 | + |
| 192 | + run_server |
| 193 | + if [ "$SERVER_PID" == "0" ]; then |
| 194 | + echo -e "\n***\n*** Failed to start $SERVER with system-assigned MI\n***" |
| 195 | + cat $SERVER_LOG |
| 196 | + RET=1 |
| 197 | + else |
| 198 | + set +e |
| 199 | + run_unit_tests |
| 200 | + set -e |
| 201 | + |
| 202 | + kill $SERVER_PID |
| 203 | + wait $SERVER_PID |
| 204 | + fi |
| 205 | + |
| 206 | + # Test 3: User-assigned Managed Identity (if client ID is provided) |
| 207 | + if [ ! -z "$AZURE_STORAGE_CLIENT_ID" ]; then |
| 208 | + echo -e "\n***\n*** Testing user-assigned Managed Identity\n***" |
| 209 | + |
| 210 | + SERVER_LOG=$SERVER_LOG_BASE.managed_identity_user.log |
| 211 | + CLIENT_LOG=$CLIENT_LOG_BASE.managed_identity_user.log |
| 212 | + SERVER_ARGS="--model-repository=$MODEL_REPO --exit-timeout-secs=120" |
| 213 | + |
| 214 | + run_server |
| 215 | + if [ "$SERVER_PID" == "0" ]; then |
| 216 | + echo -e "\n***\n*** Failed to start $SERVER with user-assigned MI\n***" |
| 217 | + cat $SERVER_LOG |
| 218 | + RET=1 |
| 219 | + else |
| 220 | + set +e |
| 221 | + run_unit_tests |
| 222 | + set -e |
| 223 | + |
| 224 | + kill $SERVER_PID |
| 225 | + wait $SERVER_PID |
| 226 | + fi |
| 227 | + else |
| 228 | + echo -e "\n***\n*** Skipping user-assigned MI test (AZURE_STORAGE_CLIENT_ID not set)\n***" |
| 229 | + fi |
| 230 | + |
| 231 | + # Test 4: DefaultAzureCredential chain |
| 232 | + echo -e "\n***\n*** Testing DefaultAzureCredential\n***" |
| 233 | + export AZURE_STORAGE_AUTH_TYPE="default" |
| 234 | + unset AZURE_STORAGE_CLIENT_ID |
| 235 | + |
| 236 | + SERVER_LOG=$SERVER_LOG_BASE.default_credential.log |
| 237 | + CLIENT_LOG=$CLIENT_LOG_BASE.default_credential.log |
| 238 | + SERVER_ARGS="--model-repository=$MODEL_REPO --exit-timeout-secs=120" |
| 239 | + |
| 240 | + run_server |
| 241 | + if [ "$SERVER_PID" == "0" ]; then |
| 242 | + echo -e "\n***\n*** Failed to start $SERVER with DefaultAzureCredential\n***" |
| 243 | + cat $SERVER_LOG |
| 244 | + RET=1 |
| 245 | + else |
| 246 | + set +e |
| 247 | + run_unit_tests |
| 248 | + set -e |
| 249 | + |
| 250 | + kill $SERVER_PID |
| 251 | + wait $SERVER_PID |
| 252 | + fi |
| 253 | + |
| 254 | + # Test: invalid auth_type should fail gracefully |
| 255 | + echo -e "\n***\n*** Testing invalid auth_type (expect failure)\n***" |
| 256 | + export AZURE_STORAGE_AUTH_TYPE="invalid_type" |
| 257 | + |
| 258 | + SERVER_LOG=$SERVER_LOG_BASE.invalid_auth_type.log |
| 259 | + SERVER_ARGS="--model-repository=$MODEL_REPO --exit-timeout-secs=120 --exit-on-error=false" |
| 260 | + |
| 261 | + run_server |
| 262 | + if [ "$SERVER_PID" != "0" ]; then |
| 263 | + # Server started — but model load should have failed. Verify the log |
| 264 | + # contains an authentication error rather than a successful load. |
| 265 | + if grep -q "Unable to create Azure filesystem client" $SERVER_LOG; then |
| 266 | + echo -e "*** invalid auth_type correctly rejected ***" |
| 267 | + else |
| 268 | + echo -e "\n***\n*** Expected auth failure with invalid auth_type\n***" |
| 269 | + cat $SERVER_LOG |
| 270 | + RET=1 |
| 271 | + fi |
| 272 | + kill $SERVER_PID |
| 273 | + wait $SERVER_PID |
| 274 | + else |
| 275 | + echo -e "*** Server correctly refused to start with invalid auth_type ***" |
| 276 | + fi |
| 277 | + |
| 278 | + # Restore environment for remaining tests |
| 279 | + unset AZURE_STORAGE_AUTH_TYPE |
| 280 | + unset AZURE_STORAGE_CLIENT_ID |
| 281 | + export AZURE_STORAGE_KEY=$SAVED_AZURE_STORAGE_KEY |
| 282 | +else |
| 283 | + echo -e "\n***\n*** Skipping Managed Identity tests (TEST_AZURE_MANAGED_IDENTITY not set)\n***" |
| 284 | +fi |
| 285 | + |
172 | 286 | # Test localization to a specified location |
173 | 287 | export TRITON_AZURE_MOUNT_DIRECTORY=`pwd`/azure_localization_test |
174 | 288 |
|
|
0 commit comments