-
-
Couldn't load subscription status.
- Fork 63
Implement rootless Docker container with enhanced security and preserved TFTP logging #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Git and version control | ||
| .git | ||
| .gitignore | ||
| .gitattributes | ||
|
|
||
| # Documentation | ||
| README.md | ||
| *.md | ||
| docs/ | ||
|
|
||
| # CI/CD | ||
| .github/ | ||
| .gitlab-ci.yml | ||
| .travis.yml | ||
|
|
||
| # Docker files | ||
| Dockerfile* | ||
| docker-compose* | ||
| .dockerignore | ||
|
|
||
| # Node.js | ||
| node_modules/ | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # Logs | ||
| *.log | ||
| logs/ | ||
|
|
||
| # Temporary files | ||
| tmp/ | ||
| temp/ | ||
| .tmp | ||
|
|
||
| # IDE and editor files | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS generated files | ||
| .DS_Store | ||
| .DS_Store? | ||
| ._* | ||
| .Spotlight-V100 | ||
| .Trashes | ||
| ehthumbs.db | ||
| Thumbs.db | ||
|
|
||
| # Testing | ||
| coverage/ | ||
| .nyc_output/ | ||
| test-results/ | ||
|
|
||
| # Build artifacts | ||
| dist/ | ||
| build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,106 @@ | ||
| # Build stage - Download and prepare webapp | ||
| FROM alpine:3.22.0 AS build | ||
|
|
||
| # set version label | ||
| # Set version label | ||
| ARG WEBAPP_VERSION | ||
|
|
||
| RUN apk add --no-cache \ | ||
| # Install build dependencies with virtual package for easy cleanup | ||
| RUN apk add --no-cache --virtual .build-deps \ | ||
| bash \ | ||
| busybox \ | ||
| curl \ | ||
| git \ | ||
| jq \ | ||
| npm && \ | ||
| mkdir /app && \ | ||
| if [ -z ${WEBAPP_VERSION+x} ]; then \ | ||
| npm \ | ||
| && mkdir /app \ | ||
| # Determine webapp version if not provided | ||
| && if [ -z ${WEBAPP_VERSION+x} ]; then \ | ||
| WEBAPP_VERSION=$(curl -sX GET "https://api.github.com/repos/netbootxyz/webapp/releases/latest" \ | ||
| | awk '/tag_name/{print $4;exit}' FS='[""]'); \ | ||
| fi && \ | ||
| curl -o /tmp/webapp.tar.gz -L \ | ||
| "https://github.com/netbootxyz/webapp/archive/${WEBAPP_VERSION}.tar.gz" && \ | ||
| tar xf /tmp/webapp.tar.gz -C /app/ --strip-components=1 && \ | ||
| npm install --prefix /app && \ | ||
| rm -rf /tmp/* | ||
| fi \ | ||
| # Download and extract webapp | ||
| && curl -o /tmp/webapp.tar.gz -L \ | ||
| "https://github.com/netbootxyz/webapp/archive/${WEBAPP_VERSION}.tar.gz" \ | ||
| && tar xf /tmp/webapp.tar.gz -C /app/ --strip-components=1 \ | ||
| # Install only production dependencies | ||
| && cd /app \ | ||
| && npm install --omit=dev --no-audit --no-fund \ | ||
| # Clean up build artifacts and cache | ||
| && npm cache clean --force \ | ||
| && rm -rf /tmp/* \ | ||
| && apk del .build-deps | ||
|
|
||
| # Production stage - Final container | ||
| FROM alpine:3.22.0 | ||
|
|
||
| # set version label | ||
| # Build arguments for labels | ||
| ARG BUILD_DATE | ||
| ARG VERSION | ||
| ARG VCS_REF | ||
|
|
||
| LABEL build_version="netboot.xyz version: ${VERSION} Build-date: ${BUILD_DATE}" | ||
| LABEL maintainer="antonym" | ||
| LABEL org.opencontainers.image.description="netboot.xyz official docker container - Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE." | ||
| # Enhanced container labels following OCI spec | ||
| LABEL org.opencontainers.image.title="netboot.xyz" \ | ||
| org.opencontainers.image.description="Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE." \ | ||
| org.opencontainers.image.version="${VERSION}" \ | ||
| org.opencontainers.image.created="${BUILD_DATE}" \ | ||
| org.opencontainers.image.revision="${VCS_REF}" \ | ||
| org.opencontainers.image.vendor="netboot.xyz" \ | ||
| org.opencontainers.image.url="https://netboot.xyz" \ | ||
| org.opencontainers.image.source="https://github.com/netbootxyz/docker-netbootxyz" \ | ||
| org.opencontainers.image.licenses="Apache-2.0" \ | ||
| maintainer="antonym" | ||
|
|
||
| # Install runtime dependencies and configure system in a single layer | ||
| RUN apk add --no-cache \ | ||
| # Core utilities | ||
| bash \ | ||
| busybox \ | ||
| curl \ | ||
| dnsmasq \ | ||
| envsubst \ | ||
| git \ | ||
| jq \ | ||
| nghttp2-dev \ | ||
| tar \ | ||
| # Network services | ||
| dnsmasq \ | ||
| nginx \ | ||
| nodejs \ | ||
| # System services | ||
| shadow \ | ||
| sudo \ | ||
| supervisor \ | ||
| syslog-ng \ | ||
| tar && \ | ||
| groupmod -g 1000 users && \ | ||
| useradd -u 911 -U -d /config -s /bin/false nbxyz && \ | ||
| usermod -G users nbxyz && \ | ||
| mkdir /app /config /defaults | ||
| # Security tools | ||
| gosu \ | ||
| # Runtime libraries | ||
| nghttp2-dev \ | ||
| # Create required directories | ||
| && mkdir -p /app /config /defaults \ | ||
| # Remove unnecessary packages to reduce size | ||
| && rm -rf /var/cache/apk/* | ||
|
|
||
| # Copy webapp from build stage | ||
| COPY --from=build /app /app | ||
|
|
||
| ENV TFTPD_OPTS='' | ||
| ENV NGINX_PORT='80' | ||
| ENV WEB_APP_PORT='3000' | ||
| # Environment variables with defaults | ||
| ENV TFTPD_OPTS='' \ | ||
| NGINX_PORT='80' \ | ||
| WEB_APP_PORT='3000' \ | ||
| NODE_ENV='production' \ | ||
| NPM_CONFIG_CACHE='/tmp/.npm' \ | ||
| PUID='1000' \ | ||
| PGID='1000' | ||
|
|
||
| EXPOSE 69/udp | ||
| EXPOSE 80 | ||
| EXPOSE 3000 | ||
|
|
||
| COPY root/ / | ||
| # Copy configuration files and scripts | ||
| COPY --chown=root:root root/ / | ||
|
|
||
| # Make scripts executable | ||
| RUN chmod +x /start.sh /init.sh /healthcheck.sh /usr/local/bin/dnsmasq-wrapper.sh | ||
|
|
||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD /healthcheck.sh | ||
| # Enhanced health check with better timing for slow systems | ||
| HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 \ | ||
| CMD /healthcheck.sh | ||
|
|
||
| CMD ["sh","/start.sh"] | ||
| # Use exec form for better signal handling | ||
| CMD ["/start.sh"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,29 @@ | ||
| [supervisord] | ||
| nodaemon=true | ||
| user=root | ||
|
|
||
| [program:syslog-ng] | ||
| command=/usr/sbin/syslog-ng --foreground --no-caps | ||
| stdout_syslog=true | ||
| stdout_capture_maxbytes=1MB | ||
| priority = 1 | ||
| silent=false | ||
| logfile=/tmp/supervisord.log | ||
| pidfile=/run/supervisord.pid | ||
|
|
||
| [program:nginx] | ||
| command = /usr/sbin/nginx -c /config/nginx/nginx.conf | ||
| command = gosu nbxyz /usr/sbin/nginx -c /config/nginx/nginx.conf | ||
| startretries = 2 | ||
| daemon=off | ||
| priority = 2 | ||
| stdout_logfile=/dev/null | ||
| stderr_logfile=/dev/null | ||
|
|
||
| [program:webapp] | ||
| environment=NODE_ENV="production",PORT=%(ENV_WEB_APP_PORT)s | ||
| command=/usr/bin/node app.js | ||
| user=nbxyz | ||
| command=gosu nbxyz /usr/bin/node app.js | ||
| directory=/app | ||
| priority = 3 | ||
| stdout_logfile=/dev/null | ||
| stderr_logfile=/dev/null | ||
|
|
||
| [program:dnsmasq] | ||
| command=/usr/sbin/dnsmasq --port=0 --keep-in-foreground --enable-tftp --user=nbxyz --tftp-secure --tftp-root=/config/menus %(ENV_TFTPD_OPTS)s | ||
| stdout_logfile=/config/tftpd.log | ||
| command=/usr/local/bin/dnsmasq-wrapper.sh %(ENV_TFTPD_OPTS)s | ||
| priority = 3 | ||
| redirect_stderr=true | ||
| priority = 4 | ||
|
|
||
| [program:messages-log] | ||
| command=tail -f /var/log/messages | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile=/dev/fd/1 | ||
| stdout_logfile_maxbytes=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Wrapper script for dnsmasq to ensure TFTP logs are visible in docker logs | ||
| echo "[dnsmasq] Starting TFTP server on port 69" | ||
| echo "[dnsmasq] TFTP root: /config/menus" | ||
| echo "[dnsmasq] TFTP security: enabled" | ||
| echo "[dnsmasq] Logging: enabled (dhcp and queries)" | ||
|
|
||
| # Start dnsmasq via gosu with logging to stderr (which supervisord can capture) | ||
| exec gosu nbxyz /usr/sbin/dnsmasq --port=0 --keep-in-foreground --enable-tftp --user=nbxyz --tftp-secure --tftp-root=/config/menus --log-facility=- --log-dhcp --log-queries "$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.