Repository navigation
Expand file tree
/
Copy pathvalidate-haproxy.sh
More file actions
executable file
·47 lines (44 loc) · 2.08 KB
/
Copy pathvalidate-haproxy.sh
File metadata and controls
executable file
·47 lines (44 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Runs HAProxy's own check, haproxy -c, on generated files with each HAProxy release proxyfile writes for. The tests
# prove that a file is the one written by hand; only HAProxy proves that it loads, on each version the file is written
# for, with no warning: -dW makes a warning fail the check as an error does.
#
# HAProxy's check reads the certificate, the key and the clients CA a tls key names, and refuses a missing one. So
# every file is checked with a throwaway certificate, its key and a CA bundle mounted at /etc/gateway/tls, the folder
# examples/tls names, made for this run by throwaway-tls.sh and removed after it; no key is ever committed. The file
# loads proxyfile.lua, which render writes beside it, from its own folder, so the folder of the configuration is
# mounted and holds both. The check sends nothing, but HAProxy connects a UDP socket to each name server of a resolvers
# section and warns when it has no route to it: with --network none HAProxy 3.2.26 and 3.4.7 refused a file whose name
# server was 10.0.0.2:53 ("can't connect socket for nameserver"), so the check runs on Docker's default network, where
# an IPv4 name server has a route.
set -euo pipefail
# Each file named is checked, so a run that names none would check nothing and exit 0, which reads as every file
# loading.
if (($# == 0)); then
echo "usage: validate-haproxy.sh <haproxy.cfg>..." >&2
exit 2
fi
source "$(dirname "$0")/pinned-images.sh"
pinned_images haproxy HAProxy
files=$(mktemp -d)
trap 'rm -rf "$files"' EXIT
"$(dirname "$0")/throwaway-tls.sh" "$files"
tls="$files/tls"
status=0
for file in "$@"; do
dir=$(cd "$(dirname "$file")" && pwd)
name=$(basename "$file")
for image in "${images[@]}"; do
tag=${image%%@*}
if out=$(docker run --rm --volume "${dir}:/config:ro" --volume "${tls}:/etc/gateway/tls:ro" \
"$image" haproxy -c -V -dW -f "/config/$name" 2>&1) &&
grep -qF "Configuration file is valid" <<<"$out"; then
echo "valid: $file on $tag"
else
printf '%s\n' "$out"
echo "refused: $file on $tag"
status=1
fi
done
done
exit "$status"