Skip to content

fix(cli): keep /app readable for any runtime uid - #86

Merged
Zhiyue-Wang merged 1 commit into
huaweicloud:mainfrom
xjc961125:fix/dockerfile-umask-permissions
Oct 31, 2026
Merged

Zhiyue-Wang merged 1 commit into
huaweicloud:mainfrom
xjc961125:fix/dockerfile-umask-permissions

Conversation

@xjc961125

Copy link
Copy Markdown
Collaborator

Problem

Images built from the Dockerfile that agentarts generates fail to start on EulerOS
with Permission denied on /app. The container is launched with a runtime UID that
is not the image's appuser, and that UID cannot read the application files.

This is the failure reported in #77. It does not reproduce on an Ubuntu build host,
which is why it stayed hidden.

Root cause

COPY . . preserves the permission bits of the build context; it does not rewrite them
to a default. So the modes inside the image are inherited from the build host's umask:

build host umask files directories
Ubuntu (default) 0022 0644 0755
EulerOS (default) 0027 0640 0750

The generated Dockerfile then ran only chown -R appuser:appuser /app. chown fixes
ownership but leaves the mode bits alone, so 0640 stays 0640. With umask 0027
there are no "other" permission bits at all, and any UID outside the owner group is
locked out of /app. Under Ubuntu's 0022 the o+r bits mask the problem, because
0644 is world-readable.

Fix

Run chmod -R a+rX /app in the same layer as the chown:

RUN chown -R appuser:appuser /app && \
    chmod -R a+rX /app

a+rX is deliberate rather than a+rx: the capital X only sets the execute bit on
directories, and on files that already have some execute bit set. Directories get
0755, plain .py files stay 0644 and are not turned into executables, and any
shell script in the user's context that is executable keeps working.

Verification

Built the same build context twice — once with the pre-fix template, once with this
branch — under umask 0027 (files 0640, directories 0750), then ran both images as
UID 1234, i.e. not appuser:

before after
cat /app/agent.py as UID 1234 Permission denied reads the file
ls /app/pkg as UID 1234 Permission denied lists
open() on a module file PermissionError succeeds
appuser (UID 1000) works works (no regression)
.py mode after the fix — 0644 (no stray +x)

Worth noting: checking this with import pkg gives a false positive — a namespace
package resolves with __file__ is None and never actually reads the file, so the
import succeeds even when nothing is readable. cat / ls / open() on a real path is
the honest check.

Unit tests: added tests/unit/toolkit/utils/test_docker_template.py, which asserts the
rendered Dockerfile carries the chmod (it fails on the old template). Targeted run:

uv run --frozen pytest tests/unit/toolkit/utils/test_docker_template.py \
    tests/unit/toolkit/operations/runtime/test_init.py -q
# 27 passed

Scope

One line of generated Dockerfile plus its test. No API change, no behaviour change for
builds that were already readable.

Refs #77

`COPY . .` preserves the build context's permission bits, so the modes
come from the build host's umask: EulerOS defaults to 0027, which lands
files at 0640 and directories at 0750. The generated Dockerfile only ran
`chown -R`, which fixes ownership but leaves the modes untouched — a
container started with any uid other than appuser then cannot read /app
and never boots. Ubuntu's 0022 masked this because 0644 is world-readable.

Widen the modes after the copy with `chmod -R a+rX /app`. `X` only adds
execute to directories and files that already have it, so plain .py files
stay non-executable.

Verified by building the same umask-0027 context with the old and new
templates and reading /app as uid 1234: Permission denied before, works
after, appuser unaffected either way.

Refs huaweicloud#77
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.93%. Comparing base (9d62fce) to head (0e51805).
⚠️ Report is 26 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   59.41%   59.93%   +0.52%     
==========================================
  Files         115      116       +1     
  Lines       10570    10646      +76     
  Branches     1695     1707      +12     
==========================================
+ Hits         6280     6381     +101     
+ Misses       3752     3705      -47     
- Partials      538      560      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Zhiyue-Wang
Zhiyue-Wang merged commit 02b6fc8 into huaweicloud:main Oct 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants