Skip to content

Commit aac3772

Browse files
committed
test(smoke-tests): add tenant auth to tests
- Implement get_tenant_auth function - Fetch tenant credentials from K8s secret - Apply auth to Loki push and query requests
1 parent 09932c7 commit aac3772

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

.github/scripts/smoke-tests.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ get_endpoint() {
7676
fi
7777
}
7878

79+
# Get authentication arguments for a tenant
80+
get_tenant_auth() {
81+
local tenant="${1:-default}"
82+
if [[ "$tenant" == "default" ]]; then
83+
echo "" # No auth for default tenant (infrastructure)
84+
return
85+
fi
86+
87+
# Fetch password from the K8s Secret created by the sync script
88+
local pass
89+
pass=$(kubectl get secret grafana-tenant-passwords -n "$NAMESPACE" -o jsonpath="{.data.$tenant}" 2>/dev/null | base64 -d 2>/dev/null || echo "")
90+
91+
if [[ -n "$pass" ]]; then
92+
echo "-u $tenant:$pass"
93+
else
94+
echo "" # Fallback to no auth if secret/tenant not found
95+
fi
96+
}
97+
7998
cleanup_port_forwards() {
8099
for service in "${!PF_PIDS[@]}"; do
81100
local pid="${PF_PIDS[$service]}"
@@ -101,7 +120,9 @@ echo " 📤 Pushing test logs..."
101120
TIMESTAMP=$(date +%s)000000000
102121
TRACE_ID=$(uuidgen | tr -d '-')
103122

123+
LOKI_AUTH=$(get_tenant_auth "default")
104124
LOKI_PUSH_RESPONSE=$(curl -s -X POST "$LOKI_ENDPOINT/loki/api/v1/push" \
125+
$LOKI_AUTH \
105126
-H "X-Scope-OrgID: default" \
106127
-H "Content-Type: application/json" \
107128
-d '{
@@ -140,7 +161,9 @@ START_TIME_LOKI=$(($(date +%s) - 300))
140161
# Try for up to 30 seconds
141162
for i in {1..6}; do
142163
sleep 5
164+
LOKI_AUTH=$(get_tenant_auth "default")
143165
LOKI_QUERY_RESPONSE=$(curl -s -G "$LOKI_ENDPOINT/loki/api/v1/query_range" \
166+
$LOKI_AUTH \
144167
-H "X-Scope-OrgID: default" \
145168
--data-urlencode 'query={job="smoke-test"}' \
146169
--data-urlencode "start=$START_TIME_LOKI" \
@@ -417,7 +440,9 @@ echo " 📝 [Loki] Pushing a secret log to 'webank' tenant..."
417440
ISOLATION_TIMESTAMP=$(date +%s)000000000
418441
WEBANK_SECRET="WEBANK-ONLY-SECRET-$(uuidgen)"
419442

443+
WEBANK_AUTH=$(get_tenant_auth "webank")
420444
curl -s -X POST "$LOKI_ENDPOINT/loki/api/v1/push" \
445+
$WEBANK_AUTH \
421446
-H "X-Scope-OrgID: webank" \
422447
-H "Content-Type: application/json" \
423448
-d "{\"streams\":[{\"stream\":{\"job\":\"isolation-test\"},\"values\":[[\"$ISOLATION_TIMESTAMP\",\"$WEBANK_SECRET\"]]}" \
@@ -442,7 +467,9 @@ else
442467
fi
443468

444469
# Query as 'webank' — MUST see its own secret
470+
WEBANK_AUTH=$(get_tenant_auth "webank")
445471
ISOLATION_AS_WEBANK=$(curl -s -G "$LOKI_ENDPOINT/loki/api/v1/query_range" \
472+
$WEBANK_AUTH \
446473
-H "X-Scope-OrgID: webank" \
447474
--data-urlencode 'query={job="isolation-test"}' \
448475
--data-urlencode "start=$(($(date +%s) - 60))" \
@@ -453,7 +480,7 @@ if echo "$ISOLATION_AS_WEBANK" | grep -q "$WEBANK_SECRET"; then
453480
echo " ✅ Loki: webank tenant can read its own logs"
454481
else
455482
record_test "isolation" "loki_tenant_reads_own" "FAIL" "webank tenant cannot read its own logs"
456-
echo " ❌ Loki: webank tenant cannot read its own logs"
483+
echo " ❌ Loki: webank tenant cannot read its own logs (Response: $(echo $ISOLATION_AS_WEBANK | cut -c1-50)...)"
457484
ISOLATION_OK=false
458485
fi
459486

0 commit comments

Comments
 (0)