Skip to content

Commit 90deaa8

Browse files
authored
Merge pull request #52579 from elezar/fix-cdi-additional-gids
daemon: preserve CDI additional GIDs
2 parents cc511e6 + 704210f commit 90deaa8

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎daemon/oci_linux.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c
10151015
withCgroups(daemon, &daemonCfg.Config, c),
10161016
WithResources(c),
10171017
WithSysctls(c),
1018+
// Set the user before CDI device injection, which may append supplementary groups.
1019+
WithUser(c),
10181020
WithDevices(daemon, c),
10191021
withRlimits(daemon, &daemonCfg.Config, c),
10201022
WithNamespaces(daemon, c),
@@ -1025,7 +1027,6 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c
10251027
WithSelinux(c),
10261028
WithOOMScore(&c.HostConfig.OomScoreAdj),
10271029
coci.WithAnnotations(c.HostConfig.Annotations),
1028-
WithUser(c),
10291030
)
10301031

10311032
if c.NoNewPrivileges {

‎daemon/oci_linux_test.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package daemon
22

33
import (
44
"context"
5+
"maps"
56
"os"
67
"path/filepath"
78
"slices"
@@ -76,6 +77,45 @@ func (i *fakeImageService) StorageDriver() string {
7677
return "overlay"
7778
}
7879

80+
func TestCreateSpecPreservesCDIAdditionalGIDs(t *testing.T) {
81+
cdiDir := t.TempDir()
82+
err := os.WriteFile(filepath.Join(cdiDir, "test-device.yaml"), []byte(`
83+
cdiVersion: "0.7.0"
84+
kind: "example.com/device"
85+
devices:
86+
- name: foo
87+
containerEdits:
88+
additionalGids:
89+
- 1234
90+
`), 0o644)
91+
assert.NilError(t, err)
92+
93+
origDeviceDrivers := maps.Clone(deviceDrivers)
94+
t.Cleanup(func() {
95+
deviceDrivers = origDeviceDrivers
96+
})
97+
RegisterCDIDriver(cdiDir)
98+
99+
c := &container.Container{
100+
Config: &containertypes.Config{},
101+
HostConfig: &containertypes.HostConfig{
102+
Resources: containertypes.Resources{
103+
DeviceRequests: []containertypes.DeviceRequest{
104+
{
105+
Driver: "cdi",
106+
DeviceIDs: []string{"example.com/device=foo"},
107+
},
108+
},
109+
},
110+
},
111+
}
112+
d := setupFakeDaemon(t, c)
113+
114+
s, err := d.createSpec(t.Context(), &configStore{}, c, nil)
115+
assert.NilError(t, err)
116+
assert.Assert(t, slices.Contains(s.Process.User.AdditionalGids, uint32(1234)), "CDI additional GID not present in OCI spec")
117+
}
118+
79119
// TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs
80120
// mount (as in "docker run --tmpfs /dev/shm:rw,size=NNN") does not result
81121
// in "Duplicate mount point" error from the engine.

0 commit comments

Comments
 (0)