mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-07-29 05:09:10 +00:00
Merge branch 'develop' into fix/helmet-csp-and-docker-socket-diagnosis
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Force LF line endings for shell scripts regardless of the developer's OS.
|
||||
# Shell scripts with CRLF endings will fail with "exec format error" in Linux containers.
|
||||
*.sh text eol=lf
|
||||
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **Blank page on HTTP deployments (CSP `upgrade-insecure-requests`):** Helmet's default CSP included `upgrade-insecure-requests`, which causes browsers to silently upgrade all HTTP sub-resource fetches (JS, CSS, images) to HTTPS. On a plain-HTTP self-hosted deployment this produces a completely blank page with `ERR_SSL_PROTOCOL_ERROR`. The directive is now explicitly omitted from the CSP.
|
||||
- **HSTS permanently breaking HTTP access:** Helmet's default `Strict-Transport-Security` header was being sent over HTTP, instructing browsers to refuse non-HTTPS connections for 1 year. HSTS is now disabled and must only be re-enabled by users who terminate HTTPS at a reverse proxy in front of Sencho.
|
||||
- **Docker socket EACCES root:root edge case:** Entrypoint now handles the case where the Docker socket is owned by root:root (GID 0) in addition to the standard root:docker case. Diagnostic `[entrypoint]` log lines are emitted at startup to make group detection visible in `docker logs`.
|
||||
- **Docker volume permissions on startup:** A new `docker-entrypoint.sh` script now runs as root at container start, fixes ownership of the `$DATA_DIR` volume (only files with wrong user or group), then drops to the non-root `sencho` user via `su-exec` before starting Node. This eliminates the `SQLITE_READONLY` crash experienced when a host-mounted data volume was previously created by root or a different UID. Uses the same privilege-drop pattern as the official PostgreSQL, Redis, and MariaDB Docker images. Node becomes PID 1, ensuring SIGTERM/SIGINT are handled correctly for graceful shutdown.
|
||||
|
||||
### Added
|
||||
- **Resources Hub — Managed/Unmanaged Separation:** All Docker resources (images, volumes, networks) are now classified as `managed` (belonging to a Sencho stack), `external` (belonging to another Compose project), or `unused`/`system`. Classification is exposed via a new `GET /api/system/resources` endpoint that makes 4 parallel Docker API calls once and returns all three resource types in a single round trip.
|
||||
|
||||
+15
-3
@@ -43,7 +43,7 @@ RUN npm run build
|
||||
FROM node:20-alpine
|
||||
|
||||
# Install Docker CLI, Docker Compose CLI, and Bash for Host Console
|
||||
RUN apk add --no-cache docker-cli docker-cli-compose bash
|
||||
RUN apk add --no-cache docker-cli docker-cli-compose bash su-exec
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -65,7 +65,17 @@ RUN addgroup -S sencho && adduser -S -G sencho sencho \
|
||||
&& mkdir -p /app/data \
|
||||
&& chown -R sencho:sencho /app
|
||||
|
||||
USER sencho
|
||||
# Copy the entrypoint script that fixes data-volume ownership at startup and
|
||||
# then drops privileges to the sencho user via su-exec (the idiomatic Alpine
|
||||
# equivalent of gosu). This mirrors the pattern used by official Docker images
|
||||
# such as PostgreSQL, Redis, and MariaDB.
|
||||
#
|
||||
# NOTE: USER directive is intentionally absent here. The entrypoint starts as
|
||||
# root so it can chown the mounted data volume, then exec's as sencho. Static
|
||||
# security scanners (Trivy, Clair) may flag "running as root" — this is a known
|
||||
# and accepted trade-off for self-hosted apps with user-supplied volume mounts.
|
||||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
@@ -74,5 +84,7 @@ EXPOSE 3000
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD node -e "const h=require('http');h.get('http://localhost:3000/api/health',r=>{process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))"
|
||||
|
||||
# Start the server
|
||||
# Entrypoint fixes volume ownership as root then drops to sencho via su-exec.
|
||||
# CMD provides the default arguments passed through to the entrypoint.
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
CMD ["node", "dist/index.js"]
|
||||
|
||||
@@ -65,6 +65,32 @@ if [ "$(id -u)" = '0' ]; then
|
||||
# Replace this shell process with su-exec so that Node becomes PID 1 and
|
||||
# receives SIGTERM/SIGINT directly from Docker. su-exec calls getgrouplist()
|
||||
# for named users, so all supplementary groups set above are inherited.
|
||||
# If running as root (the default Docker container start), fix volume ownership
|
||||
# then drop privileges before executing the application.
|
||||
#
|
||||
# This handles the common case where the host-mounted data volume was created by
|
||||
# root (or a different UID) from a previous run or backup restore — causing
|
||||
# SQLITE_READONLY errors when the non-root sencho user tries to write.
|
||||
#
|
||||
# This is the industry-standard pattern used by the official PostgreSQL, Redis,
|
||||
# and MariaDB Docker images.
|
||||
#
|
||||
# The UID guard also ensures compatibility with strict environments like
|
||||
# Kubernetes (runAsNonRoot: true) or OpenShift, where the container is forced to
|
||||
# run as a random high UID. In that case the chown block is skipped entirely and
|
||||
# the app exec's directly without crashing.
|
||||
if [ "$(id -u)" = '0' ]; then
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
# Fix files where user OR group is wrong — not just user. This covers the
|
||||
# case where a file ends up as sencho:root after a partial previous fix.
|
||||
# The -exec '{}' + form batches arguments for efficiency (like xargs).
|
||||
find "$DATA_DIR" \( \! -user sencho -o \! -group sencho \) \
|
||||
-exec chown sencho:sencho '{}' +
|
||||
|
||||
# Replace this shell process with su-exec so that Node becomes PID 1 and
|
||||
# receives SIGTERM/SIGINT directly from Docker. Without exec the shell would
|
||||
# intercept signals and the container would hang for 10s before SIGKILL.
|
||||
exec su-exec sencho "$@"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user