daemon/graphdriver: Avoid recursive driver home ownership changes

The daemon root exists before graphdriver initialization, so
recursively creating driver homes can apply the driver's ownership and
mode to missing parent directories.

Create each driver-owned directory directly during initialization,
including the VFS layer parent.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Paweł Gronowski
2026-07-24 14:48:35 +02:00
committed by Sebastiaan van Stijn
parent 7a4a06cc89
commit 4d64f0249d
6 changed files with 11 additions and 8 deletions

View File

@@ -78,7 +78,7 @@ func Init(home string, options []string, idMap user.IdentityMapping) (graphdrive
}
_, gid := idMap.RootPair()
if err := user.MkdirAllAndChown(home, 0o710, os.Getuid(), gid); err != nil {
if err := user.MkdirAndChown(home, 0o710, os.Getuid(), gid); err != nil {
return nil, err
}

View File

@@ -84,10 +84,10 @@ func Init(home string, options []string, idMap user.IdentityMapping) (graphdrive
cuid := os.Getuid()
_, gid := idMap.RootPair()
if err := user.MkdirAllAndChown(home, 0o710, cuid, gid); err != nil {
if err := user.MkdirAndChown(home, 0o710, cuid, gid); err != nil {
return nil, err
}
if err := user.MkdirAllAndChown(path.Join(home, linkDir), 0o700, cuid, os.Getegid()); err != nil {
if err := user.MkdirAndChown(path.Join(home, linkDir), 0o700, cuid, os.Getegid()); err != nil {
return nil, err
}

View File

@@ -167,10 +167,10 @@ func Init(home string, options []string, idMap user.IdentityMapping) (graphdrive
cuid := os.Getuid()
_, gid := idMap.RootPair()
if err := user.MkdirAllAndChown(home, 0o710, cuid, gid); err != nil {
if err := user.MkdirAndChown(home, 0o710, cuid, gid); err != nil {
return nil, err
}
if err := user.MkdirAllAndChown(path.Join(home, linkDir), 0o700, cuid, os.Getegid()); err != nil {
if err := user.MkdirAndChown(path.Join(home, linkDir), 0o700, cuid, os.Getegid()); err != nil {
return nil, err
}

View File

@@ -40,7 +40,10 @@ func Init(home string, options []string, idMap user.IdentityMapping) (graphdrive
}
_, gid := d.idMapping.RootPair()
if err := user.MkdirAllAndChown(home, 0o710, os.Getuid(), gid); err != nil {
if err := user.MkdirAndChown(home, 0o710, os.Getuid(), gid); err != nil {
return nil, err
}
if err := user.MkdirAndChown(filepath.Join(home, "dir"), 0o710, os.Getuid(), gid); err != nil {
return nil, err
}

View File

@@ -106,7 +106,7 @@ func Init(base string, opt []string, idMap user.IdentityMapping) (graphdriver.Dr
}
_, gid := idMap.RootPair()
if err := user.MkdirAllAndChown(base, 0o710, os.Getuid(), gid); err != nil {
if err := user.MkdirAndChown(base, 0o710, os.Getuid(), gid); err != nil {
return nil, fmt.Errorf("Failed to create '%s': %v", base, err)
}

View File

@@ -49,7 +49,7 @@ func TestLayerMigrationNoTarsplit(t *testing.T) {
newTestFile("/root/.bashrc", []byte("# Updated configuration"), 0o644),
}
graph, err := newVFSGraphDriver(filepath.Join(tempDir, "graphdriver-"))
graph, err := newVFSGraphDriver(tempDir)
if err != nil {
t.Fatal(err)
}