Skip to content

chore: implement non-root execution for Docker - #1214

Merged
ZhuLinsen merged 1 commit into
ZhuLinsen:mainfrom
RinZ27:fix/docker-non-root
May 7, 2026
Merged

chore: implement non-root execution for Docker#1214
ZhuLinsen merged 1 commit into
ZhuLinsen:mainfrom
RinZ27:fix/docker-non-root

Conversation

@RinZ27

@RinZ27 RinZ27 commented May 6, 2026

Copy link
Copy Markdown
Contributor

PR Type

  • chore
  • docs

Background And Problem

Docker containers running as root pose a security risk. Implementing a non-root user adheres to security best practices and reduces the potential attack surface.

Scope Of Change

  • Modified docker/Dockerfile to add a dsa user (UID 1000).
  • Configured ownership of the /app directory and subdirectories (data, logs, reports).
  • Switched execution context to the non-root user using the USER instruction.
  • Updated docs/DEPLOY.md with instructions for handling host directory permissions.
  • Added a [Unreleased] entry to docs/CHANGELOG.md.

Issue Link

Refs #1157 (Follow-up focused PR as requested by maintainer).

Verification Commands And Results

Verified that the Dockerfile builds successfully and the dsa user is correctly identified at runtime.

docker build -f docker/Dockerfile -t dsa-test .
docker run --rm dsa-test id

Key output & conclusion:
uid=1000(dsa) gid=1000(dsa) groups=1000(dsa)

Compatibility And Risk

Minimal risk. Existing volume mounts might require a chown on the host side if they were previously created by root, which is addressed in the updated DEPLOY.md.

Rollback Plan

Revert this PR to return to root-based execution.

Checklist

  • 本 PR 有明确动机和业务价值 / This PR has a clear motivation and value
  • 已提供可复现的验证命令与结果 / Reproducible verification commands and results are included
  • 已评估兼容性与风险 / Compatibility and risk have been assessed
  • 已提供回滚方案 / A rollback plan is provided
  • 已同步更新相关文档与 docs/CHANGELOG.md / Relevant docs and docs/CHANGELOG.md are updated

@RinZ27
RinZ27 requested a review from ZhuLinsen as a code owner May 6, 2026 14:29
@github-actions github-actions Bot added documentation Improvements or additions to documentation size/S labels May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

🤖 自动审查报告

项目 结果
📊 变更文件 3 个
➕ 新增行数 20 行
➖ 删除行数 2 行
🔍 静态检查 ✅ 通过
🧠 AI 审查 ✅ 已完成

📁 修改的文件

  • 📝 docker/Dockerfile (+10/-2)
  • 📝 docs/CHANGELOG.md (+1/-0)
  • 📝 docs/DEPLOY.md (+9/-0)

💡 提示: 请确保代码已通过本地测试,并遵循项目代码规范。

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

  • 必要性:通过 + Docker 容器非 root 运行符合安全加固目标,且改动范围集中在镜像运行用户与部署说明。
  • 是否有对应 issue:有,Refs #1157
  • PR 类型:chore + docs,运行时镜像用户切换属于部署/安全维护改动,并同步更新了部署文档与 changelog。
  • description 完整性:完整 + 已说明背景、改动范围、验证命令与结果、兼容风险和 rollback。
  • 是否可直接合入:可 + CI 已通过;mergeable_state=blocked 按当前规则更像分支保护/权限状态,不构成本次代码审查阻断。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

  • 必要性:通过 + Docker 镜像改为非 root 运行符合安全加固目标,且改动范围集中在镜像与部署说明。
  • 是否有对应 issue:有,Refs #1157
  • PR 类型:chore + docs,属于部署安全维护改动,并同步更新了部署文档与 docs/CHANGELOG.md
  • description 完整性:完整 + 已说明背景、范围、验证命令、兼容风险和回滚方式。
  • 是否可直接合入:可 + 当前 CI 成功,mergeable_state=blocked 更像分支保护/权限状态;未发现需要阻断合入的代码或文档风险。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@massif-01 massif-01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhuLinsen ready to merge

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跟进结论

  • 结论:接受,当前补充的 “ready to merge” 判断成立;本地最新 diff 与 CI 结果未显示新的代码或文档阻断风险。
  • 是否仍有阻断:无,CI 已全部通过,mergeable_state=blocked 更符合分支保护/权限状态,不应单独视为代码审查阻断。

说明

  1. docker/Dockerfile:已创建 dsa 用户并在 USER dsa 前对 /appdatalogsreports 完成授权,非 root 执行路径与 PR 描述一致。
  2. docs/DEPLOY.md:已补充宿主机挂载目录遇到 Permission denied 时的 chown 1000:1000 处理方式,覆盖主要兼容风险。
  3. docs/CHANGELOG.md:新增条目位于 [Unreleased] 扁平列表中,格式符合仓库规则。
  4. 当前 CI 摘要显示 ai-governancebackend-gatedocker-build 均为 success,且 web-gate 因无前端改动跳过,验证证据足够支撑合入。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@ZhuLinsen
ZhuLinsen merged commit 34cdf5b into ZhuLinsen:main May 7, 2026
10 checks passed
@RinZ27
RinZ27 deleted the fix/docker-non-root branch May 8, 2026 13:52
cwjyu pushed a commit to cwjyu/daily_stock_analysis that referenced this pull request May 10, 2026
zbl-96 pushed a commit to zbl-96/daily_stock_analysis that referenced this pull request May 10, 2026
EchoingFootsteps pushed a commit to EchoingFootsteps/daily_stock_analysis that referenced this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants