From 2f11a8c9049a950619986708dbfcf5c09654b0b7 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 24 Oct 2026 14:32:16 +0800 Subject: [PATCH] fix: make update container scripts readable after restrictive ZIP extraction --- server/updates/Dockerfile | 6 +++++- server/updates/README.md | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/updates/Dockerfile b/server/updates/Dockerfile index 7e8e060..31cf128 100644 --- a/server/updates/Dockerfile +++ b/server/updates/Dockerfile @@ -4,7 +4,11 @@ WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY main.py update_service.py manage.py ./ -RUN useradd --system --uid 10001 --create-home updates \ +# Uploaded ZIP files may have owner-only permissions. Keep code root-owned +# while making it readable to the unprivileged runtime user. +RUN chmod 0755 /app \ + && chmod 0644 /app/requirements.txt /app/main.py /app/update_service.py /app/manage.py \ + && useradd --system --uid 10001 --create-home updates \ && mkdir -p /app/data && chown updates:updates /app/data USER updates EXPOSE 8000 diff --git a/server/updates/README.md b/server/updates/README.md index 84ed001..71e1e87 100644 --- a/server/updates/README.md +++ b/server/updates/README.md @@ -32,6 +32,16 @@ docker compose run --rm --no-deps updates python manage.py 按提示输入至少12位后台密码并再次确认。工具会输出 `ADMIN_PASSWORD_HASH='…'` 和 `SESSION_SECRET='…'` 两行。只在服务器将这两行填入 `.env` 的对应位置,保留单引号,避免Docker把密码哈希中的 `$` 当作变量。不要把输出或密码发到聊天中。 +如果旧部署包在这一步报`python: can't open file '/app/manage.py': [Errno 13] Permission denied`,原因是旧压缩包的程序文件权限为600,而容器使用普通用户运行。只需将本次修正包的`Dockerfile`覆盖到原部署目录(保留`.env`和数据卷),然后执行: + +```sh +cd /opt/tpschedule-updates +docker compose build updates +docker compose run --rm --no-deps updates python manage.py +``` + +修正的Dockerfile在切换普通用户前将`/app`设为755、四个程序/依赖清单文件设为644,不改变`.env`权限。无需把容器改为root,也无需给整个目录设置777。若服务已启动,完成配置后执行`docker compose up -d`,使其使用新镜像。 + `.env`其他项目: ```dotenv