66 lines
2.5 KiB
Bash
Executable File
66 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
project_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$project_root"
|
|
|
|
curl_from_test() {
|
|
docker compose --profile tests run --rm --no-deps --entrypoint curl security-test "$@"
|
|
}
|
|
|
|
expect_tls_rejection() {
|
|
name=$1
|
|
shift
|
|
if curl_from_test --silent --show-error --fail --cacert /run/secrets/ca.crt \
|
|
"$@" https://api:8444/health/live >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: $name was accepted" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: $name rejected"
|
|
}
|
|
|
|
expect_tls_rejection "missing client certificate"
|
|
expect_tls_rejection "client certificate from foreign CA" \
|
|
--cert /run/secrets/foreign-client.crt --key /run/secrets/foreign-client.key
|
|
expect_tls_rejection "trusted certificate with forbidden identity" \
|
|
--cert /run/secrets/wrong-client.crt --key /run/secrets/wrong-client.key
|
|
|
|
curl_from_test --silent --show-error --fail --cacert /run/secrets/ca.crt \
|
|
--cert /run/secrets/lb-client.crt --key /run/secrets/lb-client.key \
|
|
https://api:8444/health/live >/dev/null
|
|
printf '%s\n' "PASS: allowed LB identity accepted"
|
|
|
|
# `docker compose port` in Compose v5 reports `invalid IP:0` even for an
|
|
# unbound EXPOSE port, so verify the effective runtime bindings directly.
|
|
for container_id in $(docker compose ps -q api); do
|
|
bindings=$(docker inspect "$container_id" --format '{{json .NetworkSettings.Ports}}')
|
|
case "$bindings" in
|
|
*'"HostPort"'*)
|
|
printf '%s\n' "FAIL: API port is published and bypasses ingress" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
printf '%s\n' "PASS: API replicas have no published bypass port"
|
|
|
|
prometheus_url="https://127.0.0.1:${PROMETHEUS_PORT:-19090}/-/ready"
|
|
if curl --silent --show-error --fail --cacert secrets/pki/ca.crt \
|
|
"$prometheus_url" >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: telemetry backend accepted a client without identity" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: telemetry backend rejects a missing client identity"
|
|
|
|
if curl --silent --show-error --fail --cacert secrets/pki/ca.crt \
|
|
--cert secrets/pki/lb-client.crt --key secrets/pki/lb-client.key \
|
|
"$prometheus_url" >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: telemetry backend accepted the LB identity" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: telemetry backend rejects a trusted but unauthorized identity"
|
|
|
|
curl --silent --show-error --fail --cacert secrets/pki/ca.crt \
|
|
--cert secrets/pki/grafana-client.crt --key secrets/pki/grafana-client.key \
|
|
"$prometheus_url" >/dev/null
|
|
printf '%s\n' "PASS: telemetry backend accepts the scoped Grafana identity"
|