Skip to content

Commit 672c6c8

Browse files
Merge pull request #23133 from Luap99/device-validation
specgen: parse devices even with privileged set
2 parents 94ebb12 + 9814ed4 commit 672c6c8

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

docs/source/markdown/options/network.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Valid _mode_ values are:
1717

1818
For example, to set a static ipv4 address and a static mac address, use `--network bridge:ip=10.88.0.10,mac=44:33:22:11:00:99`.
1919

20-
- _\<network name or ID\>_**[:OPTIONS,...]**: Connect to a user-defined network; this is the network name or ID from a network created by **[podman network create](podman-network-create.1.md)**. Using the network name implies the bridge network mode. It is possible to specify the same options described under the bridge mode above. Use the **--network** option multiple times to specify additional networks. \
20+
- _\<network name or ID\>_**[:OPTIONS,...]**: Connect to a user-defined network; this is the network name or ID from a network created by **[podman network create](podman-network-create.1.md)**. It is possible to specify the same options described under the bridge mode above. Use the **--network** option multiple times to specify additional networks. \
2121
For backwards compatibility it is also possible to specify comma-separated networks on the first **--network** argument, however this prevents you from using the options described under the bridge section above.
2222

2323
- **none**: Create a network namespace for the container but do not configure network interfaces for it, thus the container has no network connectivity.

pkg/specgen/generate/oci_linux.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,21 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
254254
}
255255

256256
var userDevices []spec.LinuxDevice
257-
258-
if !s.IsPrivileged() {
259-
// add default devices from containers.conf
260-
for _, device := range rtc.Containers.Devices.Get() {
261-
if err = DevicesFromPath(&g, device); err != nil {
262-
return nil, err
263-
}
264-
}
265-
if len(compatibleOptions.HostDeviceList) > 0 && len(s.Devices) == 0 {
266-
userDevices = compatibleOptions.HostDeviceList
267-
} else {
268-
userDevices = s.Devices
257+
// add default devices from containers.conf
258+
for _, device := range rtc.Containers.Devices.Get() {
259+
if err = DevicesFromPath(&g, device); err != nil {
260+
return nil, err
269261
}
270-
// add default devices specified by caller
271-
for _, device := range userDevices {
272-
if err = DevicesFromPath(&g, device.Path); err != nil {
273-
return nil, err
274-
}
262+
}
263+
if len(compatibleOptions.HostDeviceList) > 0 && len(s.Devices) == 0 {
264+
userDevices = compatibleOptions.HostDeviceList
265+
} else {
266+
userDevices = s.Devices
267+
}
268+
// add default devices specified by caller
269+
for _, device := range userDevices {
270+
if err = DevicesFromPath(&g, device.Path); err != nil {
271+
return nil, err
275272
}
276273
}
277274
s.HostDeviceList = userDevices

pkg/util/utils_linux.go

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func AddPrivilegedDevices(g *generate.Generator, systemdMode bool) error {
106106
if err != nil {
107107
return err
108108
}
109-
g.ClearLinuxDevices()
110109

111110
if rootless.IsRootless() {
112111
mounts := make(map[string]interface{})

test/e2e/run_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,19 @@ VOLUME %s`, ALPINE, volPath, volPath)
16871687
Expect(session).Should(ExitCleanly())
16881688
})
16891689

1690+
It("podman run --device and --privileged", func() {
1691+
session := podmanTest.Podman([]string{"run", "--device", "/dev/null:/dev/testdevice", "--privileged", ALPINE, "ls", "/dev"})
1692+
session.WaitWithDefaultTimeout()
1693+
Expect(session).Should(ExitCleanly())
1694+
Expect(session.OutputToString()).To(ContainSubstring(" testdevice "), "our custom device")
1695+
// assumes that /dev/mem always exists
1696+
Expect(session.OutputToString()).To(ContainSubstring(" mem "), "privileged device")
1697+
1698+
session = podmanTest.Podman([]string{"run", "--device", "invalid-device", "--privileged", ALPINE, "ls", "/dev"})
1699+
session.WaitWithDefaultTimeout()
1700+
Expect(session).Should(ExitWithError(125, "stat invalid-device: no such file or directory"))
1701+
})
1702+
16901703
It("podman run --replace", func() {
16911704
// Make sure we error out with --name.
16921705
session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"})

0 commit comments

Comments
 (0)