Read every setting through viper and rename the settings (closes #211)
check / check (push) Waiting to run

Every setting of waf and rproxy is read through viper, in place of the
os.LookupEnv function Main passed down. NewViper turns AutomaticEnv and
AllowEmptyEnv on, so a setting that is set but empty reads as set. A
setting may also be given as a file, the _FILE form, which rproxy's
settings now have too; rproxy still writes nothing to disk.

The settings are renamed: waf's take the prefix SWW_WAF_, rproxy's take
SWW_RPROXY_, and the shared SWW_COMMAND keeps SWW_. The Core Rule Set's
settings take SWW_WAF_CORE_RULE_SET_ rather than SWW_WAF_WAF_.

Model: deepseek-v4-pro (first version); opus-5-5 (rework)
This commit is contained in:
sneak committed 2026-11-11 10:15:12 +00:00
1 parent b93bad5842
commit c516e34145
122 files changed
+2288 -2170

No files matched your search

+16 -16
View File
@@ -17,10 +17,10 @@
# - that a new waf container on the same volume still refuses the banned
# client;
# - that a waf container with its state files on a new volume mounted at
# the directory SWW_STATE_DIR_FILE names becomes healthy;
# - that one whose SWW_STATE_DIR does not exist logs waf's message
# the directory SWW_WAF_STATE_DIR_FILE names becomes healthy;
# - that one whose SWW_WAF_STATE_DIR does not exist logs waf's message
# about it.
# waf runs with SWW_LOOKUP_SOURCE=off, so that no address is sent to
# waf runs with SWW_WAF_LOOKUP_SOURCE=off, so that no address is sent to
# GeoJS. The containers, the network, the volumes and both images are removed
# however the script ends. Building the app needs network access, for nixpkgs'
# binary cache. script/check does not run this.
@@ -38,7 +38,7 @@ NETWORK="$NAME"
APP="$NAME-app-container"
WAF="$NAME-waf"
VOLUME="$NAME-state"
# The volumes of the container whose state directory SWW_STATE_DIR_FILE
# The volumes of the container whose state directory SWW_WAF_STATE_DIR_FILE
# names: its state files, and the file that names their directory.
MOVED_VOLUME="$NAME-moved-state"
SETTINGS_VOLUME="$NAME-settings"
@@ -95,8 +95,8 @@ start_waf() {
docker run --detach --name "$WAF" --network "$NETWORK" \
--volume "$VOLUME:/var/lib/sww" \
--env SWW_COMMAND=waf \
--env SWW_RATE_LIMIT_PER_MINUTE=1 \
--env SWW_LOOKUP_SOURCE=off \
--env SWW_WAF_RATE_LIMIT_PER_MINUTE=1 \
--env SWW_WAF_LOOKUP_SOURCE=off \
"$IMAGE" >/dev/null
wait_for "waf's health check did not pass" healthy "$WAF"
}
@@ -105,14 +105,14 @@ start_waf() {
# healthy.
start_app() {
docker run --detach --name "$APP" --network "$NETWORK" --publish 127.0.0.1::8080 \
--env SWRP_WAF_BACKEND="http://$WAF:8080" \
--env SWW_RPROXY_WAF_BACKEND="http://$WAF:8080" \
"$APP_IMAGE" >/dev/null
wait_for "the app's health check did not pass" healthy "$APP"
address="$(docker port "$APP" 8080/tcp)"
}
# start_moved_waf: run waf with the state files on a new volume at
# /srv/state, which SWW_STATE_DIR_FILE names in a file only the sww
# /srv/state, which SWW_WAF_STATE_DIR_FILE names in a file only the sww
# user can read, as under "Settings given as files" in docs/settings.md, and
# wait until it is healthy. waf can write the new volume only once the run
# script has given it to that user.
@@ -127,8 +127,8 @@ start_moved_waf() {
--volume "$MOVED_VOLUME:/srv/state" \
--volume "$SETTINGS_VOLUME:/etc/sww/settings:ro" \
--env SWW_COMMAND=waf \
--env SWW_STATE_DIR_FILE=/etc/sww/settings/state-dir \
--env SWW_LOOKUP_SOURCE=off \
--env SWW_WAF_STATE_DIR_FILE=/etc/sww/settings/state-dir \
--env SWW_WAF_LOOKUP_SOURCE=off \
"$IMAGE" >/dev/null
wait_for "waf's health check did not pass" healthy "$WAF"
}
@@ -141,7 +141,7 @@ status_from() {
--max-time 10 --header "X-Forwarded-For: $1" "http://$address$2" || true
}
# refused: a request to the container gets 403, SWW_BAN_RESPONSE's
# refused: a request to the container gets 403, SWW_WAF_BAN_RESPONSE's
# default.
refused() {
code="$(curl --silent --output /dev/null --write-out '%{http_code}' \
@@ -208,7 +208,7 @@ main() {
wait_for "waf did not stop in order" logged "$WAF" '"msg":"stopped"'
[ "$(status_from 203.0.113.9 /)" = 200 ] ||
fail "with waf stopped, the app did not answer through rproxy"
wait_for "rproxy logged no request SWRP_DEFAULT_DISPOSITION decided" \
wait_for "rproxy logged no request SWW_RPROXY_DEFAULT_DISPOSITION decided" \
logged "$APP" '"default_disposition":true'
docker exec "$APP" /usr/local/bin/sww healthcheck ||
fail "with waf stopped, the app's health check failed"
@@ -243,16 +243,16 @@ main() {
docker rm --force "$WAF" >/dev/null
start_moved_waf
echo "example-app: the run script gives the state files' directory named" \
"by SWW_STATE_DIR_FILE to the sww user"
"by SWW_WAF_STATE_DIR_FILE to the sww user"
docker rm --force "$WAF" >/dev/null
docker run --detach --name "$WAF" --network "$NETWORK" \
--env SWW_COMMAND=waf \
--env SWW_STATE_DIR=/srv/missing \
--env SWW_LOOKUP_SOURCE=off \
--env SWW_WAF_STATE_DIR=/srv/missing \
--env SWW_WAF_LOOKUP_SOURCE=off \
"$IMAGE" >/dev/null
wait_for "waf did not report the missing state directory" \
logged "$WAF" "SWW_STATE_DIR cannot be written"
logged "$WAF" "SWW_WAF_STATE_DIR cannot be written"
echo "example-app: waf reports a state directory that does not exist"
}