Skip to content

Commit 5273b3d

Browse files
committed
Replace Linux.Device with more specific config
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
1 parent 7414f4d commit 5273b3d

File tree

2 files changed

+95
-12
lines changed

2 files changed

+95
-12
lines changed

config-linux.md

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,82 @@ within the container.
5555

5656
### Access to devices
5757

58-
Devices is an array specifying the list of devices from the host to make available in the container.
59-
By providing a device name within the list the runtime should look up the same device on the host's `/dev`
60-
and collect information about the device node so that it can be recreated for the container. The runtime
61-
should not only create the device inside the container but ensure that the root user inside
62-
the container has access rights for the device.
58+
Devices is an array specifying the list of devices to be created in the container.
59+
Next parameters can be specified:
60+
61+
* type - type of device: 'c', 'b', 'u' or 'p'. More info in `man mknod`
62+
* path - full path to device inside container
63+
* major, minor - major, minor numbers for device. More info in `man mknod`.
64+
There is special value: `-1`, which means `*` for `device`
65+
cgroup setup.
66+
* permissions - cgroup permissions for device. A composition of 'r'
67+
(read), 'w' (write), and 'm' (mknod).
68+
* fileMode - file mode for device file
69+
* uid - uid of device owner
70+
* gid - gid of device owner
6371

6472
```json
6573
"devices": [
66-
"null",
67-
"random",
68-
"full",
69-
"tty",
70-
"zero",
71-
"urandom"
74+
{
75+
"path": "/dev/random",
76+
"type": "c",
77+
"major": 1,
78+
"minor": 8,
79+
"permissions": "rwm",
80+
"fileMode": 0666,
81+
"uid": 0,
82+
"gid": 0
83+
},
84+
{
85+
"path": "/dev/urandom",
86+
"type": "c",
87+
"major": 1,
88+
"minor": 9,
89+
"permissions": "rwm",
90+
"fileMode": 0666,
91+
"uid": 0,
92+
"gid": 0
93+
},
94+
{
95+
"path": "/dev/null",
96+
"type": "c",
97+
"major": 1,
98+
"minor": 3,
99+
"permissions": "rwm",
100+
"fileMode": 0666,
101+
"uid": 0,
102+
"gid": 0
103+
},
104+
{
105+
"path": "/dev/zero",
106+
"type": "c",
107+
"major": 1,
108+
"minor": 5,
109+
"permissions": "rwm",
110+
"fileMode": 0666,
111+
"uid": 0,
112+
"gid": 0
113+
},
114+
{
115+
"path": "/dev/tty",
116+
"type": "c",
117+
"major": 5,
118+
"minor": 0,
119+
"permissions": "rwm",
120+
"fileMode": 0666,
121+
"uid": 0,
122+
"gid": 0
123+
},
124+
{
125+
"path": "/dev/full",
126+
"type": "c",
127+
"major": 1,
128+
"minor": 7,
129+
"permissions": "rwm",
130+
"fileMode": 0666,
131+
"uid": 0,
132+
"gid": 0
133+
}
72134
]
73135
```
74136

spec_linux.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package specs
44

5+
import "os"
6+
57
// LinuxSpec is the full specification for Linux containers
68
type LinuxSpec struct {
79
Spec
@@ -27,7 +29,7 @@ type Linux struct {
2729
// Capabilities are Linux capabilities that are kept for the container
2830
Capabilities []string `json:"capabilities"`
2931
// Devices are a list of device nodes that are created and enabled for the container
30-
Devices []string `json:"devices"`
32+
Devices []Device `json:"devices"`
3133
// RootfsPropagation is the rootfs mount propagation mode for the container
3234
RootfsPropagation string `json:"rootfsPropagation"`
3335
}
@@ -157,3 +159,22 @@ type Resources struct {
157159
// Network restriction configuration
158160
Network Network `json:"network"`
159161
}
162+
163+
type Device struct {
164+
// Device type, block, char, etc.
165+
Type rune `json:"type"`
166+
// Path to the device.
167+
Path string `json:"path"`
168+
// Major is the device's major number.
169+
Major int64 `json:"major"`
170+
// Minor is the device's minor number.
171+
Minor int64 `json:"minor"`
172+
// Cgroup permissions format, rwm.
173+
Permissions string `json:"permissions"`
174+
// FileMode permission bits for the device.
175+
FileMode os.FileMode `json:"fileMode"`
176+
// UID of the device.
177+
UID uint32 `json:"uid"`
178+
// Gid of the device.
179+
GID uint32 `json:"gid"`
180+
}

0 commit comments

Comments
 (0)