smallwebwaf starts with SWWAF_STATE_DIR given as a file on a new volume (closes #137)
check / check (push) Canceled after 0s

The run script gave ${SWWAF_STATE_DIR:-/var/lib/smallwebwaf} to the
smallwebwaf user and never read SWWAF_STATE_DIR_FILE, so a new volume
at the directory that file names stayed root's and smallwebwaf could
not write it. The run script now reads the setting as smallwebwaf does:
the variable, or what is in the file. When both are set or the file
cannot be read, it leaves the owner alone, and smallwebwaf stops with
its message naming the setting. script/example-app checks that a
container with its state files on a new volume at /srv/state, named in
a file only the smallwebwaf user can read, becomes healthy.

Model: opus-5-5
This commit is contained in:
2026-10-20 09:20:08 +00:00
parent 7a9471df28
commit 95cfbdc03b
2 changed files with 58 additions and 8 deletions
+18 -1
View File
@@ -9,8 +9,25 @@ set -euo pipefail
# reaches smallwebwaf itself.
main() {
sleep 1
chown -R smallwebwaf:smallwebwaf "${SWWAF_STATE_DIR:-/var/lib/smallwebwaf}"
local dir
if dir="$(state_dir)"; then
chown -R smallwebwaf:smallwebwaf "${dir:-/var/lib/smallwebwaf}"
fi
exec chpst -u smallwebwaf:smallwebwaf /usr/local/bin/smallwebwaf
}
# state_dir prints SWWAF_STATE_DIR as smallwebwaf reads it: the variable,
# or what is in the file SWWAF_STATE_DIR_FILE names. It fails when both
# are set or the file cannot be read; the state directory then keeps its
# owner, and smallwebwaf stops with a message naming the setting.
state_dir() {
if [[ ! -v SWWAF_STATE_DIR_FILE ]]; then
printf '%s\n' "${SWWAF_STATE_DIR:-}"
elif [[ ! -v SWWAF_STATE_DIR ]]; then
cat -- "$SWWAF_STATE_DIR_FILE" 2>/dev/null
else
return 1
fi
}
main "$@"