Repository navigation
fix(cli): keep /app readable for any runtime uid - #86
Merged
Zhiyue-Wang merged 1 commit intoOct 31, 2026
Merged
Conversation
`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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Images built from the Dockerfile that
agentartsgenerates fail to start on EulerOSwith
Permission deniedon/app. The container is launched with a runtime UID thatis 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 themto a default. So the modes inside the image are inherited from the build host's umask:
002206440755002706400750The generated Dockerfile then ran only
chown -R appuser:appuser /app.chownfixesownership but leaves the mode bits alone, so
0640stays0640. With umask0027there are no "other" permission bits at all, and any UID outside the owner group is
locked out of
/app. Under Ubuntu's0022theo+rbits mask the problem, because0644is world-readable.Fix
Run
chmod -R a+rX /appin the same layer as thechown:RUN chown -R appuser:appuser /app && \ chmod -R a+rX /appa+rXis deliberate rather thana+rx: the capitalXonly sets the execute bit ondirectories, and on files that already have some execute bit set. Directories get
0755, plain.pyfiles stay0644and are not turned into executables, and anyshell 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(files0640, directories0750), then ran both images asUID 1234, i.e. not
appuser:cat /app/agent.pyas UID 1234Permission deniedls /app/pkgas UID 1234Permission deniedopen()on a module filePermissionErrorappuser(UID 1000).pymode after the fix0644(no stray+x)Worth noting: checking this with
import pkggives a false positive — a namespacepackage resolves with
__file__ is Noneand never actually reads the file, so theimport succeeds even when nothing is readable.
cat/ls/open()on a real path isthe honest check.
Unit tests: added
tests/unit/toolkit/utils/test_docker_template.py, which asserts therendered Dockerfile carries the
chmod(it fails on the old template). Targeted run:Scope
One line of generated Dockerfile plus its test. No API change, no behaviour change for
builds that were already readable.
Refs #77