fix(conpot): use honeynet/conpot:latest base, run as conpot user
The BASE_IMAGE build arg was being unconditionally overwritten by composer.py with the decky's distro build_base (debian:bookworm-slim), turning the conpot container into a bare Debian image with no conpot installation — hence the silent restart loop. Two fixes: 1. composer.py: use args.setdefault() so services that pre-declare BASE_IMAGE in their compose_fragment() win over the distro default. 2. conpot.py: pre-declare BASE_IMAGE=honeynet/conpot:latest in build args so it always uses the upstream image regardless of decky distro. Also removed the USER decnet switch from the conpot Dockerfile. The upstream image already runs as the non-root 'conpot' user; switching to 'decnet' broke pkg_resources because conpot's eggs live under /home/conpot/.local and are only on sys.path for that user.
This commit is contained in:
@@ -69,8 +69,11 @@ def generate_compose(config: DecnetConfig) -> dict:
|
|||||||
|
|
||||||
# Inject the per-decky base image into build services so containers
|
# Inject the per-decky base image into build services so containers
|
||||||
# vary by distro and don't all fingerprint as debian:bookworm-slim.
|
# vary by distro and don't all fingerprint as debian:bookworm-slim.
|
||||||
|
# Services that need a fixed upstream image (e.g. conpot) can pre-set
|
||||||
|
# build.args.BASE_IMAGE in their compose_fragment() to opt out.
|
||||||
if "build" in fragment:
|
if "build" in fragment:
|
||||||
fragment["build"].setdefault("args", {})["BASE_IMAGE"] = decky.build_base
|
args = fragment["build"].setdefault("args", {})
|
||||||
|
args.setdefault("BASE_IMAGE", decky.build_base)
|
||||||
|
|
||||||
fragment.setdefault("environment", {})
|
fragment.setdefault("environment", {})
|
||||||
fragment["environment"]["HOSTNAME"] = decky.hostname
|
fragment["environment"]["HOSTNAME"] = decky.hostname
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from decnet.services.base import BaseService
|
from decnet.services.base import BaseService
|
||||||
|
|
||||||
@@ -24,7 +23,8 @@ class ConpotService(BaseService):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"build": {
|
"build": {
|
||||||
"context": str(self.dockerfile_context())
|
"context": str(self.dockerfile_context()),
|
||||||
|
"args": {"BASE_IMAGE": "honeynet/conpot:latest"},
|
||||||
},
|
},
|
||||||
"container_name": f"{decky_name}-conpot",
|
"container_name": f"{decky_name}-conpot",
|
||||||
"restart": "unless-stopped",
|
"restart": "unless-stopped",
|
||||||
|
|||||||
@@ -3,21 +3,16 @@ FROM ${BASE_IMAGE}
|
|||||||
|
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
# Replace 5020 with 502 in all templates
|
# Replace 5020 with 502 in all templates so Modbus binds on the standard port
|
||||||
RUN find /opt /usr /etc /home -name "*.xml" -exec sed -i 's/<port>5020<\/port>/<port>502<\/port>/g' {} + 2>/dev/null || true
|
RUN find /opt /usr /etc /home -name "*.xml" -exec sed -i 's/<port>5020<\/port>/<port>502<\/port>/g' {} + 2>/dev/null || true
|
||||||
RUN find /opt /usr /etc /home -name "*.xml" -exec sed -i 's/port="5020"/port="502"/g' {} + 2>/dev/null || true
|
RUN find /opt /usr /etc /home -name "*.xml" -exec sed -i 's/port="5020"/port="502"/g' {} + 2>/dev/null || true
|
||||||
|
|
||||||
# Install libcap to allow binding to 502
|
# Install libcap and give the Python interpreter permission to bind ports < 1024
|
||||||
RUN (apt-get update && apt-get install -y --no-install-recommends libcap2-bin 2>/dev/null) || (apk add --no-cache libcap 2>/dev/null) || true
|
RUN (apt-get update && apt-get install -y --no-install-recommends libcap2-bin 2>/dev/null) || (apk add --no-cache libcap 2>/dev/null) || true
|
||||||
|
RUN find /home/conpot/.local/bin /usr /opt -type f -name 'python*' -exec setcap 'cap_net_bind_service+eip' {} \; 2>/dev/null || true
|
||||||
|
|
||||||
# Apply setcap to python binaries
|
# The upstream image already runs as the non-root 'conpot' user.
|
||||||
RUN find /usr /opt -type f -name 'python*' -exec setcap 'cap_net_bind_service+eip' {} \; 2>/dev/null || true
|
# We do NOT switch to a 'decnet' user here — doing so breaks pkg_resources
|
||||||
|
# because conpot's eggs live under /home/conpot/.local and are only on the
|
||||||
# Create the decnet user following repository conventions
|
# Python path when the interpreter runs as 'conpot'.
|
||||||
RUN (addgroup -S decnet && adduser -S decnet -G decnet 2>/dev/null) || useradd -r -s /bin/false decnet 2>/dev/null || true
|
USER conpot
|
||||||
|
|
||||||
# Make sure all conpot-related directories are owned by decnet so it can run it
|
|
||||||
RUN chown -R decnet:decnet /var/log/conpot /opt/conpot /home/conpot /usr/local/lib/python*/site-packages/conpot/tests/data /tmp 2>/dev/null || true
|
|
||||||
|
|
||||||
# Run as decnet user, avoiding the root-check failure and 777 hacks
|
|
||||||
USER decnet
|
|
||||||
|
|||||||
Reference in New Issue
Block a user