Skip to content

fix(execd): apply owner/group to auto-created parent directories#1075

Open
Pangjiping wants to merge 3 commits into
mainfrom
fix/upload-parent-dir-ownership
Open

fix(execd): apply owner/group to auto-created parent directories#1075
Pangjiping wants to merge 3 commits into
mainfrom
fix/upload-parent-dir-ownership

Conversation

@Pangjiping

Copy link
Copy Markdown
Collaborator

Summary

  • Add MkdirAllWithOwnership helper that creates directories and applies owner/group only to newly created ones, leaving pre-existing directories untouched
  • Update resolveUploadTarget (file upload path) to propagate owner/group metadata to auto-created parent directories
  • Update MakeDir (create directories API) to use the same helper, fixing intermediate directory ownership for multi-level creation
  • Add tests for nested dir creation, pre-existing parent preservation, and all-exist no-op

Closes #1064

Test plan

  • TestMkdirAllWithOwnership_NewNestedDirs — multi-level dirs created correctly
  • TestMkdirAllWithOwnership_PreExistingParent — pre-existing parent permissions unchanged
  • TestMkdirAllWithOwnership_AllExist — all dirs exist, no-op
  • TestMakeDir_PreExistingDir — existing regression test still passes
  • TestMakeDir_NewDir — existing regression test still passes
  • Full go test ./pkg/web/controller/ passes

🤖 Generated with Claude Code

When uploading files or creating directories with nested paths, parent
directories created by os.MkdirAll inherited the execd process ownership
(typically root) instead of the requested owner/group. This caused
Permission denied errors when non-root workload users attempted cleanup.

Add MkdirAllWithOwnership helper that identifies newly created directories
and applies SetFileOwnership only to them, leaving pre-existing directories
untouched. Update resolveUploadTarget and MakeDir to use the new helper.

Closes #1064

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Pangjiping Pangjiping added bug Something isn't working component/execd labels Jun 15, 2026
…build

Mirror the unix MkdirAllWithOwnership helper and MakeDir changes in
utils_windows.go to fix the Windows cross-compilation failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1bf16f4c8f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread components/execd/pkg/web/controller/filesystem_upload.go
Comment thread components/execd/pkg/web/controller/utils.go Outdated
…ership

When targetDir itself already exists (e.g. uploading /file.txt where
targetDir is /), the walk-up loop exited without clearing firstNew,
causing SetFileOwnership to run on the pre-existing root directory.

Rewrite the loop to start firstNew as empty and only set it when a
non-existent directory is found, so pre-existing directories are
never touched.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working component/execd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

files.writeFiles owner/group metadata is not applied to auto-created parent directories

1 participant