feat(lab7): implement secure messenger infrastructure with TLS, OpenBao and observability
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PKI_DIR="${LAB7_PKI_DIR:-$HOME/.local/share/mtusi2026lab7/pki}"
|
||||
NETWORK="${COMPOSE_PROJECT_NAME:-mtusi2026lab7}_default"
|
||||
|
||||
for name in api1 api2; do
|
||||
echo
|
||||
echo "=== Testing $name mTLS ==="
|
||||
|
||||
run_curl() {
|
||||
docker run --rm \
|
||||
--network "$NETWORK" \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
-v "$PKI_DIR:/pki:ro" \
|
||||
curlimages/curl:8.16.0 \
|
||||
--silent --show-error \
|
||||
--max-time 10 \
|
||||
--cacert /pki/ca.crt \
|
||||
--resolve "$name:8443:$(docker inspect \
|
||||
-f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
|
||||
"mtusi2026lab7-$name-1")" \
|
||||
"$@" \
|
||||
"https://$name:8443/health/ready"
|
||||
}
|
||||
|
||||
echo "[1] Authorized LB certificate"
|
||||
response="$(run_curl \
|
||||
--cert /pki/lb-client.crt \
|
||||
--key /pki/lb-client.key)"
|
||||
echo "$response"
|
||||
[[ "$response" == *'"status":"ok"'* ]] || exit 1
|
||||
|
||||
echo "[2] No client certificate"
|
||||
if run_curl > /dev/null 2>&1; then
|
||||
echo "FAIL: connection accepted without client certificate"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: no certificate rejected"
|
||||
|
||||
echo "[3] Untrusted CA certificate"
|
||||
if run_curl \
|
||||
--cert /pki/rogue-client.crt \
|
||||
--key /pki/rogue-client.key \
|
||||
> /dev/null 2>&1; then
|
||||
echo "FAIL: rogue certificate accepted"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: rogue CA rejected"
|
||||
|
||||
echo "[4] Trusted CA, forbidden SAN"
|
||||
code="$(run_curl \
|
||||
--cert /pki/unauthorized-client.crt \
|
||||
--key /pki/unauthorized-client.key \
|
||||
-o /dev/null -w '%{http_code}')"
|
||||
|
||||
echo "HTTP $code"
|
||||
[[ "$code" == "403" ]] || {
|
||||
echo "FAIL: expected HTTP 403"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "PASS: $name mTLS identity enforcement"
|
||||
done
|
||||
|
||||
echo
|
||||
echo "PASS: all mTLS tests passed"
|
||||
Reference in New Issue
Block a user