Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64587679a4 | ||
|
|
7dfb3b8c32 | ||
|
|
a5ca73c585 | ||
|
|
bd08e901ee |
@@ -216,8 +216,10 @@ What the [upaas](https://git.eeqj.de/sneak/upaas) app for netwatch needs:
|
||||
- `CORS_ALLOWED_ORIGINS`, default empty: other origins whose pages may call
|
||||
the API
|
||||
- `DEBUG`, default `false`: debug logging
|
||||
- `DATA_DIR`, default `/data/reports`: leave unset; reports kept outside
|
||||
`/data` do not survive a redeploy
|
||||
- `DATA_DIR`, default `/data/reports`: the directory the reports are kept
|
||||
in: `/data` or a path below it, with no `.` or `..` part and no extra `/`.
|
||||
The container also stops if a part of the path that exists, `/data`
|
||||
included, is a symbolic link
|
||||
- `TRUSTED_PROXIES`, default empty: set it to the address the reverse proxy
|
||||
in front of the container connects from, as an IP address or CIDR; several
|
||||
are separated by commas. nginx takes the client address from
|
||||
|
||||
@@ -23,6 +23,14 @@ latest run passes.
|
||||
|
||||
# Completed Steps
|
||||
|
||||
- 2026-09-29: `bin/entrypoint.sh` checks `DATA_DIR` in full before it acts on it
|
||||
as root (issue #80): `DATA_DIR` must be `/data` or a path below it with no
|
||||
`.`, `..` or empty part, and no part of it that exists, `/data` included, may
|
||||
be a symbolic link; anything else stops the start with a message naming
|
||||
`DATA_DIR`. Only then is `DATA_DIR` created and `/data` given to `netwatch`,
|
||||
so a refused start no longer creates directories outside `/data`, and
|
||||
`DATA_DIR=/etc` no longer gives `/etc` to `netwatch`. The `README.md` section
|
||||
"Running under upaas" says which values are accepted
|
||||
- 2026-09-29: the container sets up its own data directory (issue #75):
|
||||
`bin/entrypoint.sh`, still as root, creates `DATA_DIR` if missing and gives it
|
||||
and `/data` to the `netwatch` user with mode 750 before starting the backend
|
||||
|
||||
+33
-15
@@ -63,25 +63,43 @@ done > /etc/nginx/trusted-proxies.conf
|
||||
|
||||
# netwatch-server keeps its report files in DATA_DIR, on the /data
|
||||
# volume, which may be a host directory owned by root or by another
|
||||
# uid. Both are given to the netwatch user here, with the mode the
|
||||
# server gives a directory it creates, so the host directory needs no
|
||||
# preparing.
|
||||
# uid. /data and everything in it are given to the netwatch user here,
|
||||
# and /data and DATA_DIR get the mode the server gives a directory it
|
||||
# creates, so the host directory needs no preparing.
|
||||
#
|
||||
# chown and chmod, run as root, change whatever a symbolic link on the
|
||||
# path points to, anywhere in the container, and the netwatch user can
|
||||
# put one in /data. So the start stops unless readlink -f, which
|
||||
# follows every link on a path, gives /data and DATA_DIR back as they
|
||||
# are. It also writes a path in full, so a DATA_DIR with '.', '..' or
|
||||
# an extra '/' in it is refused too.
|
||||
# This runs as root, so nothing is created or changed until DATA_DIR is
|
||||
# known to be /data or a path below it, with no '.', '..' or empty
|
||||
# part, and no part of it that exists, /data included, is a symbolic
|
||||
# link: the netwatch user can put one in /data, and root would follow
|
||||
# it anywhere in the container. Nothing else runs in the container yet,
|
||||
# so no link can appear after the check.
|
||||
export DATA_DIR="${DATA_DIR:-/data/reports}"
|
||||
mkdir -p "$DATA_DIR" || exit 1
|
||||
if [ "$(readlink -f /data)" != /data ] ||
|
||||
[ "$(readlink -f "$DATA_DIR")" != "$DATA_DIR" ]; then
|
||||
echo "entrypoint: DATA_DIR must be a full path with no '.', '..'," \
|
||||
"extra '/' or symbolic link on it or on /data, not '$DATA_DIR'" >&2
|
||||
data_dir_ok() {
|
||||
# With a / added at the end, a last part of '.' or '..', and a / at
|
||||
# the end, match these patterns too.
|
||||
case "$DATA_DIR/" in
|
||||
*/./* | */../* | *//*) return 1 ;;
|
||||
/data/*) ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
# Each part from DATA_DIR up to /data. [ -L ] is false for a part
|
||||
# that does not exist.
|
||||
dir="$DATA_DIR"
|
||||
while [ "$dir" != /data ]; do
|
||||
[ -L "$dir" ] && return 1
|
||||
dir="${dir%/*}"
|
||||
done
|
||||
[ ! -L /data ]
|
||||
}
|
||||
if ! data_dir_ok; then
|
||||
echo "entrypoint: DATA_DIR must be /data or a path below it, with no" \
|
||||
"'.', '..', extra '/' or symbolic link on it, not '$DATA_DIR'" >&2
|
||||
exit 1
|
||||
fi
|
||||
chown -R netwatch:netwatch /data "$DATA_DIR" || exit 1
|
||||
mkdir -p "$DATA_DIR" || exit 1
|
||||
# -h: a symbolic link in /data is itself given to netwatch, not what it
|
||||
# points to.
|
||||
chown -R -h netwatch:netwatch /data || exit 1
|
||||
chmod 750 /data "$DATA_DIR" || exit 1
|
||||
|
||||
# A stop signal is only noted here; the loop below acts on it.
|
||||
|
||||
Reference in New Issue
Block a user