mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
Validated launch on runner & hardend
This commit is contained in:
@@ -79,27 +79,19 @@ RUN apk add --no-cache bash libbsd zip lsblk gettext-envsubst sudo mtr tzdata cu
|
||||
rm -rf /var/cache/apk/* && \
|
||||
rm -f /etc/nginx/http.d/default.conf
|
||||
|
||||
# Install from previous build stage
|
||||
|
||||
|
||||
# Install application, copy files, set permissions
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
COPY --from=builder /usr/sbin/usermod /usr/sbin/groupmod /usr/sbin/
|
||||
|
||||
# Simple copy of directory structure instead of individual files or complicated directory structure with RUN mkdir
|
||||
COPY --chown=netalertx:netalertx install/alpine-docker/ /
|
||||
|
||||
RUN chmod -R a+x ${SYSTEM_SERVICES} /build/ /entrypoint.sh && \
|
||||
sh -c "find ${NETALERTX_APP} -type d -exec chmod 750 {} \;" && \
|
||||
sh -c "find ${NETALERTX_APP} -type f -exec chmod 640 {} \;" && \
|
||||
sh -c "find ${NETALERTX_APP} -type f \( -name '*.sh' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
|
||||
|
||||
# Copy source
|
||||
COPY --chown=netalertx:netalertx --chmod=755 back ${NETALERTX_BACK}
|
||||
COPY --chown=netalertx:netalertx --chmod=755 front ${NETALERTX_FRONT}
|
||||
COPY --chown=netalertx:netalertx --chmod=755 server ${NETALERTX_SERVER}
|
||||
# create folders with netalertx user ownership and 755 permissions
|
||||
RUN install -d -o netalertx -g netalertx -m 755 ${NETALERTX_API}
|
||||
|
||||
# Install runtime dependencies
|
||||
|
||||
RUN install -d -o netalertx -g netalertx -m 755 ${NETALERTX_API} && \
|
||||
install -d -o netalertx -g netalertx -m 755 ${NETALERTX_LOG} && \
|
||||
sh -c "find ${NETALERTX_APP} -type f \( -name '*.sh' -o -name 'speedtest-cli' \) \
|
||||
-exec chmod 750 {} \;"
|
||||
|
||||
|
||||
#initialize each service with the dockerfiles/init-*.sh scripts, once.
|
||||
@@ -113,9 +105,7 @@ RUN sh /build/init-nginx.sh && \
|
||||
# set netalertx to allow sudoers for any command, no password
|
||||
RUN echo "netalertx ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
|
||||
|
||||
|
||||
|
||||
ENTRYPOINT ["/bin/sh","-c","sleep infinity"]
|
||||
# Final hardened stage to improve security by setting correct permissions and removing sudo access
|
||||
# When complete, if the image is compromised, there's not much that can be done with it.
|
||||
FROM runner AS hardened
|
||||
@@ -163,13 +153,16 @@ ENTRYPOINT ["/entrypoint.sh"]
|
||||
# Prefer to place dev-only setup here; use setup.sh only for runtime fixes.
|
||||
|
||||
FROM runner AS netalertx-devcontainer
|
||||
USER root
|
||||
ENV INSTALL_DIR=/app
|
||||
ENV PYTHONPATH=/workspaces/NetAlertX/test:/workspaces/NetAlertX/server:/app:/app/server:/opt/venv/lib/python3.12/site-packages
|
||||
ENV HOME=/workspaces
|
||||
|
||||
COPY .devcontainer/resources/99-xdebug.ini /etc/php83/conf.d/99-xdebug.ini
|
||||
|
||||
# Install common tools, create user, and set up sudo
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov shadow
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov shadow github-cli fish
|
||||
|
||||
|
||||
# Install debugpy in the virtualenv if present, otherwise into system python3
|
||||
RUN /bin/sh -c '(/opt/venv/bin/python3 -m pip install --no-cache-dir debugpy) || (python3 -m pip install --no-cache-dir debugpy) || true'
|
||||
@@ -177,7 +170,8 @@ RUN /opt/venv/bin/python -m pip install -U pytest pytest-cov
|
||||
|
||||
USER netalertx
|
||||
|
||||
WORKDIR /workspaces/NetAlertX
|
||||
WORKDIR /workspaces/
|
||||
RUN mkdir -p /workspaces && \
|
||||
sudo chmod 777 /workspaces
|
||||
|
||||
|
||||
ENTRYPOINT ["/bin/sh","-c","sleep infinity"]
|
||||
USER netalertx
|
||||
|
||||
@@ -11,15 +11,11 @@ ENV PYTHONPATH=/workspaces/NetAlertX/test:/workspaces/NetAlertX/server:/app:/app
|
||||
COPY .devcontainer/resources/99-xdebug.ini /etc/php83/conf.d/99-xdebug.ini
|
||||
|
||||
# Install common tools, create user, and set up sudo
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov shadow github-cli
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov
|
||||
|
||||
# Install debugpy in the virtualenv if present, otherwise into system python3
|
||||
RUN /bin/sh -c '(/opt/venv/bin/python3 -m pip install --no-cache-dir debugpy) || (python3 -m pip install --no-cache-dir debugpy) || true'
|
||||
RUN /opt/venv/bin/python -m pip install -U pytest pytest-cov
|
||||
RUN sudo /env/bin/python -m pip install -U pytest pytest-cov
|
||||
|
||||
USER netalertx
|
||||
|
||||
WORKDIR /workspaces/NetAlertX
|
||||
|
||||
|
||||
ENTRYPOINT ["/bin/sh","-c","sleep infinity"]
|
||||
RUN ["/bin/sh","-c","sleep infinity"]
|
||||
|
||||
@@ -10,7 +10,7 @@ id
|
||||
export APP_DIR="/app"
|
||||
export APP_COMMAND="/workspaces/NetAlertX/.devcontainer/scripts/restart-backend.sh"
|
||||
export PHP_FPM_BIN="/usr/sbin/php-fpm83"
|
||||
export NGINX_BIN="/usr/sbin/nginx"
|
||||
export NGINX_BIN="/workspaces/NetAlertX/.devcontainer/scripts/start-nginx.sh"
|
||||
export CROND_BIN="/usr/sbin/crond -f"
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ export SOURCE_DIR="/workspaces/NetAlertX"
|
||||
main() {
|
||||
echo "=== NetAlertX Development Container Setup ==="
|
||||
echo "Setting up ${SOURCE_DIR}..."
|
||||
sudo chown $(id -u):$(id -g) /workspaces
|
||||
sudo chown 755 /workspaces
|
||||
configure_source
|
||||
|
||||
echo "--- Starting Development Services ---"
|
||||
@@ -75,8 +77,10 @@ configure_source() {
|
||||
sudo cp -R ${SOURCE_DIR}/log/ /tmp/log/ || true
|
||||
sudo cp -R ${SOURCE_DIR}/api/ /tmp/api/ || true
|
||||
sudo mkdir -p ${NETALERTX_API} ${NETALERTX_LOG}
|
||||
sudo mount -t tmpfs -o size=256M tmpfs "${INSTALL_DIR}/log"
|
||||
sudo mount -t tmpfs -o size=512M tmpfs "${INSTALL_DIR}/api"
|
||||
# mount tmpfs with netalertx:netalertx ownership and 775 permissions
|
||||
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_LOG}"
|
||||
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_API}"
|
||||
# mount tmpfs with root:root ownership and 755 permissions
|
||||
sudo cp -R /tmp/log/* ${NETALERTX_LOG} 2>/dev/null || true
|
||||
sudo cp -R /tmp/api/* ${NETALERTX_API} 2>/dev/null || true
|
||||
sudo rm -Rf /tmp/log /tmp/api || true
|
||||
@@ -86,6 +90,7 @@ configure_source() {
|
||||
|
||||
|
||||
echo " -> Setting ownership and permissions"
|
||||
chmod +x /workspaces/NetAlertX/.devcontainer/scripts/start-nginx.sh
|
||||
sudo date +%s > "${INSTALL_DIR}/front/buildtimestamp.txt"
|
||||
|
||||
|
||||
@@ -96,6 +101,8 @@ configure_source() {
|
||||
touch ${INSTALL_DIR}/log/stderr.log \
|
||||
${INSTALL_DIR}/log/execution_queue.log
|
||||
echo 0>${INSTALL_DIR}/log/db_is_locked.log
|
||||
mkdir -p /app/log/plugins
|
||||
sudo chown -R netalertx:www-data ${INSTALL_DIR}
|
||||
|
||||
date +%s > /app/front/buildtimestamp.txt
|
||||
|
||||
@@ -141,10 +148,11 @@ start_services() {
|
||||
configure_php() {
|
||||
echo "[2/3] Configuring PHP-FPM..."
|
||||
sudo killall php-fpm83 &>/dev/null || true
|
||||
install -d -o nginx -g www-data /run/php/ &>/dev/null
|
||||
install -d -o netalertx -g www-data /run/php/ &>/dev/null
|
||||
sudo sed -i "/^;pid/c\pid = /run/php/php8.3-fpm.pid" /etc/php83/php-fpm.conf
|
||||
sudo sed -i 's|^listen = .*|listen = 127.0.0.1:9000|' /etc/php83/php-fpm.d/www.conf
|
||||
sudo sed -i 's|fastcgi_pass .*|fastcgi_pass 127.0.0.1:9000;|' /etc/nginx/http.d/*.conf
|
||||
|
||||
|
||||
#increase max child process count to 10
|
||||
sudo sed -i -e 's/pm.max_children = 5/pm.max_children = 10/' /etc/php83/php-fpm.d/www.conf
|
||||
@@ -155,7 +163,7 @@ configure_php() {
|
||||
if ! grep -q '^error_log\s*=' /etc/php83/php-fpm.conf; then
|
||||
echo 'error_log = /app/log/app.php_errors.log' | sudo tee -a /etc/php83/php-fpm.conf
|
||||
fi
|
||||
|
||||
|
||||
sudo mkdir -p /etc/php83/conf.d
|
||||
sudo cp /workspaces/NetAlertX/.devcontainer/resources/99-xdebug.ini /etc/php83/conf.d/99-xdebug.ini
|
||||
|
||||
@@ -163,6 +171,12 @@ configure_php() {
|
||||
install -d -o netalertx -g www-data -m 755 var/log/php83;
|
||||
|
||||
sudo chmod 644 /etc/php83/conf.d/99-xdebug.ini || true
|
||||
sudo install -d -o netalertx -g www-data -m 775 /run/php
|
||||
|
||||
sudo rm /var/lib/nginx/logs/ && sudo install -d -o netalertx -g www-data /var/lib/nginx/logs/
|
||||
sudo rm /var/log/nginx && sudo install -d -o netalertx -g www-data /var/log/nginx
|
||||
sudo chown -R netalertx:www-data /var/log/nginx
|
||||
sudo chown -R netalertx:www-data /run/nginx
|
||||
|
||||
}
|
||||
|
||||
|
||||
11
.devcontainer/scripts/start-nginx.sh
Executable file
11
.devcontainer/scripts/start-nginx.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
|
||||
#create /services/nginx directory for nginx system files
|
||||
sudo install -d /services/nginx -m 755 -o netalertx -g netalertx
|
||||
sudo install -d /services/nginx -m 755 -o netalertx -g netalertx
|
||||
sudo chown -R netalertx:netalertx /var/lib/nginx
|
||||
|
||||
cp /workspaces/NetAlertX/install/alpine-docker/app/services/nginx/nginx.conf /services/nginx/nginx.conf
|
||||
sed -i 's|/app/services/nginx/netalertx.conf|/services/nginx/netalertx.conf|' /services/nginx/nginx.conf
|
||||
cp /workspaces/NetAlertX/install/alpine-docker/app/services/nginx/netalertx.conf /services/nginx/netalertx.conf
|
||||
cp /workspaces/NetAlertX/install/alpine-docker/app/services/nginx/fastcgi_params /services/nginx/fastcgi_params
|
||||
nginx -c "/services/nginx/nginx.conf" -g "daemon off;" 2>&1 >/app/log/app_front.log
|
||||
Reference in New Issue
Block a user