daemon: rewrite git identity sync + file_sync on ext4 toolkit

ensureGitIdentityOnWorkDisk, writeGitIdentity, runFileSync, and
copyHostDir all dropped their mount + sudo install/mkdir/chmod/chown
scaffolding. Every write now goes through MkdirExt4,
WriteExt4FileOwned, ReadExt4File, and the new MkdirAllExt4 helper —
all sudoless against user-owned ext4 images.

Net effect with the prior two commits: ensureWorkDisk, authsync, image
seeding, git identity sync, and file_sync no longer mount the work
disk or spawn sudo mkdir/chmod/chown/cat/install. Only the
image-build path (which legitimately produces root-owned artifacts)
still touches MountTempDir.

The filesystemRunner test harness grew a small debugfs/e2cp/e2rm
emulator so the WorkspaceService tests keep exercising their real
code paths without a live ext4 image. The mock is deliberately
dumb — it only implements the subset runFileSync and writeGitIdentity
drive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-23 18:29:30 -03:00
parent f0685366ec
commit 6ab1a2b844
No known key found for this signature in database
GPG key ID: 33112E6833C34679
3 changed files with 253 additions and 74 deletions

View file

@ -49,6 +49,43 @@ func MkdirExt4(ctx context.Context, runner CommandRunner, imagePath, guestPath s
return debugfsScript(ctx, runner, imagePath, &script)
}
// MkdirAllExt4 creates each intermediate directory in guestPath that
// doesn't already exist, with the given mode/uid/gid. Mirrors
// os.MkdirAll's shape, not mkdir(1) -p: existing directories are left
// with their current metadata untouched (we don't reset mode/uid/gid
// on pre-existing parents, only on the final segment). Paths starting
// at "/" are allowed — the root is treated as pre-existing.
func MkdirAllExt4(ctx context.Context, runner CommandRunner, imagePath, guestPath string, mode os.FileMode, uid, gid int) error {
if err := rejectDebugfsUnsafePath(guestPath); err != nil {
return err
}
segments := strings.Split(strings.Trim(guestPath, "/"), "/")
cur := ""
for i, seg := range segments {
if seg == "" {
continue
}
cur = cur + "/" + seg
exists, err := Ext4PathExists(ctx, runner, imagePath, cur)
if err != nil {
return err
}
if exists {
continue
}
// Intermediate dirs inherit the requested mode/uid/gid too —
// callers that want a different mode on parents should create
// them explicitly. Matches the most common use (mkdir -p a
// config tree where every hop is root-owned).
if i < len(segments)-1 || !exists {
if err := MkdirExt4(ctx, runner, imagePath, cur, mode, uid, gid); err != nil {
return err
}
}
}
return nil
}
// WriteExt4FileOwned copies `data` into <imagePath>:<guestPath> and
// forces the inode's uid/gid/mode to the requested values. Unlike
// WriteExt4FileMode, this helper does NOT assume the image is a