i196 r4: fix dbresult race, k8s error visibility

This commit is contained in:
2026-11-27 16:18:40 +00:00
parent 93c50c1cef
commit bb0cb4c986
+44 -33
View File
@@ -18,7 +18,7 @@ spec:
metadata: metadata:
labels: labels:
app: probe-reader app: probe-reader
probe-run: "r3" probe-run: "r4"
spec: spec:
securityContext: securityContext:
runAsNonRoot: true runAsNonRoot: true
@@ -62,36 +62,41 @@ spec:
R=/tmp/r.txt R=/tmp/r.txt
: > $R : > $R
say(){ echo "$@" >> $R; } say(){ echo "$@" >> $R; }
say 'I192-R3-START' kcall(){
say "--- $1"
: > /tmp/ka
code=$(curl -skS -m 15 -o /tmp/ka -w '%{http_code}' -H "Authorization: Bearer $TOKEN" "$2" 2>>$R)
say "HTTP=$code"
if [ -s /tmp/ka ]; then head -c 1500 /tmp/ka >> $R; echo >> $R; fi
}
say 'I196-R4-START'
date -u >> $R date -u >> $R
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
say "ns=$NS tokenlen=${#TOKEN}" say "ns=$NS tokenlen=${#TOKEN}"
say '--- [A] own-ns secrets' say '--- [Z] network diagnostics'
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets" >> $R 2>&1 cat /etc/resolv.conf >> $R 2>&1
echo >> $R nslookup kubernetes.default.svc >> $R 2>&1
say '--- [B] list namespaces' nslookup databases-cluster-rw.database.svc.cluster.local >> $R 2>&1
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces" >> $R 2>&1 nslookup openbao-active.openbao.svc.cluster.local >> $R 2>&1
echo >> $R kcall 'list namespaces' "https://kubernetes.default.svc/api/v1/namespaces"
say '--- [C] own secret probedb-db-credentials' kcall 'own-ns secrets' "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets"
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets/probedb-db-credentials" >> $R 2>&1 kcall 'own secret probedb-db-credentials' "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets/probedb-db-credentials"
echo >> $R kcall 'foreign ns secrets cottoncraft-demo-prod' "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-prod/secrets"
say '--- [D] foreign ns secrets cottoncraft-demo-prod' kcall 'foreign ns secrets cottoncraft-demo-dom1' "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-dom1/secrets"
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-prod/secrets" >> $R 2>&1 say '--- SelfSubjectRulesReview'
echo >> $R : > /tmp/ka
say '--- [D2] foreign ns secrets cottoncraft-demo-dom1' code=$(curl -skS -m 15 -o /tmp/ka -w '%{http_code}' -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d "{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"spec\":{\"namespace\":\"$NS\"}}" "https://kubernetes.default.svc/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" 2>>$R)
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-dom1/secrets" >> $R 2>&1 say "HTTP=$code"
echo >> $R if [ -s /tmp/ka ]; then head -c 2000 /tmp/ka >> $R; echo >> $R; fi
say '--- [E] SelfSubjectRulesReview' say 'I196-R4-K8S-END'
curl -sk -m 15 -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d "{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"spec\":{\"namespace\":\"$NS\"}}" "https://kubernetes.default.svc/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" >> $R 2>&1 pushr $R results-r4-k8s.txt 'i196 r4 k8s probe results'
echo >> $R cat $R
say 'I192-R3-K8S-END' sleep 10
pushr $R results-r3-k8s.txt 'i192 r3 k8s probe results'
sleep 20
R2=/tmp/r2.txt R2=/tmp/r2.txt
: > $R2 : > $R2
say2(){ echo "$@" >> $R2; } say2(){ echo "$@" >> $R2; }
say2 'I192-R3-BAO-START' say2 'I196-R4-BAO-START'
LB=$(curl -sk -m 20 -X POST -d "{\"role\":\"platchain-293213-dev-app-role\",\"jwt\":\"$TOKEN\"}" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/kubernetes-cf-lcj11-a/login) LB=$(curl -sk -m 20 -X POST -d "{\"role\":\"platchain-293213-dev-app-role\",\"jwt\":\"$TOKEN\"}" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/kubernetes-cf-lcj11-a/login)
echo "$LB" | head -c 400 >> $R2 echo "$LB" | head -c 400 >> $R2
echo >> $R2 echo >> $R2
@@ -108,21 +113,22 @@ spec:
say2 "user=$DU passlen=${#DP}" say2 "user=$DU passlen=${#DP}"
say2 '--- foreign static-creds checks' say2 '--- foreign static-creds checks'
for p in cottoncraft-demo-prod cottoncraft-demo-dev cottoncraft-demo-dom1; do for p in cottoncraft-demo-prod cottoncraft-demo-dev cottoncraft-demo-dom1; do
: > /tmp/fc
code=$(curl -sk -m 15 -o /tmp/fc -w '%{http_code}' -H "X-Vault-Token: $VT" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/$p") code=$(curl -sk -m 15 -o /tmp/fc -w '%{http_code}' -H "X-Vault-Token: $VT" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/$p")
say2 "path=$p HTTP=$code" say2 "path=$p HTTP=$code"
if [ "$code" = "200" ]; then head -c 1200 /tmp/fc >> $R2; echo >> $R2; fi if [ "$code" = "200" ]; then head -c 1200 /tmp/fc >> $R2; echo >> $R2; fi
done done
say2 'I192-R3-BAO-END' say2 'I196-R4-BAO-END'
pushr $R2 results-r3-bao.txt 'i192 r3 bao probe results' pushr $R2 results-r4-bao.txt 'i196 r4 bao probe results'
printf '%s\n%s\n' "$DU" "$DP" > /shared/dbcreds.txt printf '%s\n%s\n' "$DU" "$DP" > /shared/dbcreds.txt
echo "creds written $(wc -c < /shared/dbcreds.txt) bytes" >> $PL echo "creds written $(wc -c < /shared/dbcreds.txt) bytes" >> $PL
for i in $(seq 1 60); do for i in $(seq 1 90); do
if [ -s /shared/dbresult.txt ]; then echo "dbresult after $i polls" >> $PL; break; fi if grep -q 'I192-DB-END' /shared/dbresult.txt 2>/dev/null; then echo "dbresult after $i polls" >> $PL; break; fi
sleep 10 sleep 10
done done
pushr /shared/dbresult.txt results-r3-db.txt 'i192 r3 db probe results' pushr /shared/dbresult.txt results-r4-db.txt 'i196 r4 db probe results'
pushr $PL results-r3-pushlog.txt 'i192 r3 push log' pushr $PL results-r4-pushlog.txt 'i196 r4 push log'
echo DONE-R3 >> $PL echo DONE-R4 >> $PL
sleep 3600 sleep 3600
- name: dbprobe - name: dbprobe
image: postgres:18-alpine image: postgres:18-alpine
@@ -161,11 +167,16 @@ spec:
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select datname from pg_database order by datname;' >> $W 2>&1 psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select datname from pg_database order by datname;' >> $W 2>&1
say '--- pg_roles' say '--- pg_roles'
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select rolname from pg_roles order by rolname;' >> $W 2>&1 psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select rolname from pg_roles order by rolname;' >> $W 2>&1
say '--- connect probes (foreign tenant dbs + others, read-only current_database only)' say '--- connect probes (read-only, foreign tenant logical dbs)'
for d in $(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select datname from pg_database where datname not in ('postgres','template0','template1') order by datname limit 15;"); do for d in $(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select datname from pg_database where datname not in ('postgres','template0','template1') order by datname limit 15;"); do
say "CONNECT $d:" say "CONNECT $d:"
psql -h $DBH -U "$DU" -d "$d" -tAc 'select current_database();' >> $W 2>&1 if psql -h $DBH -U "$DU" -d "$d" -tAc 'select current_database();' >> $W 2>&1; then
say "catalog sample $d (information_schema.tables first 10):"
psql -h $DBH -U "$DU" -d "$d" -tAc "select table_schema||'.'||table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') limit 10;" >> $W 2>&1
fi
done done
say '--- own db tables' say '--- own db tables'
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select table_schema||'.'||table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') limit 20;" >> $W 2>&1 psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select table_schema||'.'||table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') limit 20;" >> $W 2>&1
say 'I192-DB-END' say 'I192-DB-END'
cat $W
sleep 30