Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64587679a4 |
@@ -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
|
- `CORS_ALLOWED_ORIGINS`, default empty: other origins whose pages may call
|
||||||
the API
|
the API
|
||||||
- `DEBUG`, default `false`: debug logging
|
- `DEBUG`, default `false`: debug logging
|
||||||
- `DATA_DIR`, default `/data/reports`: leave unset; reports kept outside
|
- `DATA_DIR`, default `/data/reports`: the directory the reports are kept
|
||||||
`/data` do not survive a redeploy
|
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
|
- `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
|
in front of the container connects from, as an IP address or CIDR; several
|
||||||
are separated by commas. nginx takes the client address from
|
are separated by commas. nginx takes the client address from
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ latest run passes.
|
|||||||
|
|
||||||
# Completed Steps
|
# 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):
|
- 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
|
`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
|
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
|
# 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
|
# 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
|
# uid. /data and everything in it are given to the netwatch user here,
|
||||||
# server gives a directory it creates, so the host directory needs no
|
# and /data and DATA_DIR get the mode the server gives a directory it
|
||||||
# preparing.
|
# creates, so the host directory needs no preparing.
|
||||||
#
|
#
|
||||||
# chown and chmod, run as root, change whatever a symbolic link on the
|
# This runs as root, so nothing is created or changed until DATA_DIR is
|
||||||
# path points to, anywhere in the container, and the netwatch user can
|
# known to be /data or a path below it, with no '.', '..' or empty
|
||||||
# put one in /data. So the start stops unless readlink -f, which
|
# part, and no part of it that exists, /data included, is a symbolic
|
||||||
# follows every link on a path, gives /data and DATA_DIR back as they
|
# link: the netwatch user can put one in /data, and root would follow
|
||||||
# are. It also writes a path in full, so a DATA_DIR with '.', '..' or
|
# it anywhere in the container. Nothing else runs in the container yet,
|
||||||
# an extra '/' in it is refused too.
|
# so no link can appear after the check.
|
||||||
export DATA_DIR="${DATA_DIR:-/data/reports}"
|
export DATA_DIR="${DATA_DIR:-/data/reports}"
|
||||||
mkdir -p "$DATA_DIR" || exit 1
|
data_dir_ok() {
|
||||||
if [ "$(readlink -f /data)" != /data ] ||
|
# With a / added at the end, a last part of '.' or '..', and a / at
|
||||||
[ "$(readlink -f "$DATA_DIR")" != "$DATA_DIR" ]; then
|
# the end, match these patterns too.
|
||||||
echo "entrypoint: DATA_DIR must be a full path with no '.', '..'," \
|
case "$DATA_DIR/" in
|
||||||
"extra '/' or symbolic link on it or on /data, not '$DATA_DIR'" >&2
|
*/./* | */../* | *//*) 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
|
exit 1
|
||||||
fi
|
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
|
chmod 750 /data "$DATA_DIR" || exit 1
|
||||||
|
|
||||||
# A stop signal is only noted here; the loop below acts on it.
|
# A stop signal is only noted here; the loop below acts on it.
|
||||||
|
|||||||
Reference in New Issue
Block a user