Skip to content

Commit e923f70

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

File tree

2 files changed

+93
-12
lines changed

2 files changed

+93
-12
lines changed

config-linux.md

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,80 @@ 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+
* permissions - cgroup permissions for device. A composition of 'r'
65+
(read), 'w' (write), and 'm' (mknod).
66+
* fileMode - file mode for device file
67+
* uid - uid of device owner
68+
* gid - gid of device owner
6369

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

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)