Skip to content

Commit 833e6d7

Browse files
committed
*: flatten platform dependent source
This introduces verbiage of fields that may occur in json (technically optional), but is required on certain platforms (e.g. Linux). The JSON document will look the same as it presently does, but now the reference source compiles regardless of platform. Not adding a "name" string to the user sturct, as that is not a requirement yet. In the event a windows runtime shows up, I could imagine an `sid` on the user struct, but we'll get to that when it happens. Closes #135 Related to #166 Signed-off-by: Vincent Batts <[email protected]>
1 parent 3b7c15d commit 833e6d7

File tree

2 files changed

+325
-329
lines changed

2 files changed

+325
-329
lines changed

config.go

Lines changed: 325 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package specs
22

3+
import "os"
4+
35
// Spec is the base configuration for the container. It specifies platform
46
// independent configuration. This information must be included when the
57
// bundle is packaged for distribution.
@@ -18,6 +20,9 @@ type Spec struct {
1820
Mounts []Mount `json:"mounts"`
1921
// Hooks are the commands run at various lifecycle events of the container.
2022
Hooks Hooks `json:"hooks"`
23+
24+
// Linux is platform specific configuration for Linux based containers.
25+
Linux Linux `json:"linux" platform:"linux"`
2126
}
2227

2328
// Process contains information to start a specific application inside the container.
@@ -33,14 +38,26 @@ type Process struct {
3338
// Cwd is the current working directory for the process and must be
3439
// relative to the container's root.
3540
Cwd string `json:"cwd"`
36-
// Capabilities are linux capabilities that are kept for the container.
37-
Capabilities []string `json:"capabilities,omitempty"`
38-
// ApparmorProfile specified the apparmor profile for the container.
39-
ApparmorProfile string `json:"apparmorProfile,omitempty"`
40-
// SelinuxProcessLabel specifies the selinux context that the container process is run as.
41-
SelinuxLabel string `json:"selinuxLabel,omitempty"`
41+
// Capabilities are Linux capabilities that are kept for the container.
42+
Capabilities []string `json:"capabilities,omitempty" platform:"linux"`
4243
// NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
4344
NoNewPrivileges bool `json:"noNewPrivileges,omitempty"`
45+
46+
// ApparmorProfile specified the apparmor profile for the container. (this field is platform dependent)
47+
ApparmorProfile string `json:"apparmorProfile,omitempty" platform:"linux"`
48+
// SelinuxProcessLabel specifies the selinux context that the container process is run as. (this field is platform dependent)
49+
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
50+
}
51+
52+
// User specifies Linux specific user and group information for the container's
53+
// main process.
54+
type User struct {
55+
// UID is the user id. (this field is platform dependent)
56+
UID uint32 `json:"uid,omitempty" platform:"linux"`
57+
// GID is the group id. (this field is platform dependent)
58+
GID uint32 `json:"gid,omitempty" platform:"linux"`
59+
// AdditionalGids are additional group ids set for the container's process. (this field is platform dependent)
60+
AdditionalGids []uint32 `json:"additionalGids,omitempty" platform:"linux"`
4461
}
4562

4663
// Root contains information about the container's root filesystem on the host.
@@ -67,7 +84,7 @@ type Mount struct {
6784
// Type specifies the mount kind.
6885
Type string `json:"type"`
6986
// Source specifies the source path of the mount. In the case of bind mounts on
70-
// linux based systems this would be the file on the host.
87+
// Linux based systems this would be the file on the host.
7188
Source string `json:"source"`
7289
// Options are fstab style mount options.
7390
Options []string `json:"options,omitempty"`
@@ -90,3 +107,304 @@ type Hooks struct {
90107
// Poststop is a list of hooks to be run after the container process exits.
91108
Poststop []Hook `json:"poststop,omitempty"`
92109
}
110+
111+
// Linux contains platform specific configuration for Linux based containers.
112+
type Linux struct {
113+
// UIDMapping specifies user mappings for supporting user namespaces on Linux.
114+
UIDMappings []IDMapping `json:"uidMappings,omitempty"`
115+
// GIDMapping specifies group mappings for supporting user namespaces on Linux.
116+
GIDMappings []IDMapping `json:"gidMappings,omitempty"`
117+
// Rlimits specifies rlimit options to apply to the container's process.
118+
Rlimits []Rlimit `json:"rlimits,omitempty"`
119+
// Sysctl are a set of key value pairs that are set for the container on start
120+
Sysctl map[string]string `json:"sysctl,omitempty"`
121+
// Resources contain cgroup information for handling resource constraints
122+
// for the container
123+
Resources *Resources `json:"resources,omitempty"`
124+
// CgroupsPath specifies the path to cgroups that are created and/or joined by the container.
125+
// The path is expected to be relative to the cgroups mountpoint.
126+
// If resources are specified, the cgroups at CgroupsPath will be updated based on resources.
127+
CgroupsPath *string `json:"cgroupsPath,omitempty"`
128+
// Namespaces contains the namespaces that are created and/or joined by the container
129+
Namespaces []Namespace `json:"namespaces"`
130+
// Devices are a list of device nodes that are created for the container
131+
Devices []Device `json:"devices"`
132+
// Seccomp specifies the seccomp security settings for the container.
133+
Seccomp *Seccomp `json:"seccomp,omitempty"`
134+
// RootfsPropagation is the rootfs mount propagation mode for the container.
135+
RootfsPropagation string `json:"rootfsPropagation,omitempty"`
136+
}
137+
138+
// Namespace is the configuration for a Linux namespace
139+
type Namespace struct {
140+
// Type is the type of Linux namespace
141+
Type NamespaceType `json:"type"`
142+
// Path is a path to an existing namespace persisted on disk that can be joined
143+
// and is of the same type
144+
Path string `json:"path,omitempty"`
145+
}
146+
147+
// NamespaceType is one of the Linux namespaces
148+
type NamespaceType string
149+
150+
const (
151+
// PIDNamespace for isolating process IDs
152+
PIDNamespace NamespaceType = "pid"
153+
// NetworkNamespace for isolating network devices, stacks, ports, etc
154+
NetworkNamespace = "network"
155+
// MountNamespace for isolating mount points
156+
MountNamespace = "mount"
157+
// IPCNamespace for isolating System V IPC, POSIX message queues
158+
IPCNamespace = "ipc"
159+
// UTSNamespace for isolating hostname and NIS domain name
160+
UTSNamespace = "uts"
161+
// UserNamespace for isolating user and group IDs
162+
UserNamespace = "user"
163+
)
164+
165+
// IDMapping specifies UID/GID mappings
166+
type IDMapping struct {
167+
// HostID is the UID/GID of the host user or group
168+
HostID uint32 `json:"hostID"`
169+
// ContainerID is the UID/GID of the container's user or group
170+
ContainerID uint32 `json:"containerID"`
171+
// Size is the length of the range of IDs mapped between the two namespaces
172+
Size uint32 `json:"size"`
173+
}
174+
175+
// Rlimit type and restrictions
176+
type Rlimit struct {
177+
// Type of the rlimit to set
178+
Type string `json:"type"`
179+
// Hard is the hard limit for the specified type
180+
Hard uint64 `json:"hard"`
181+
// Soft is the soft limit for the specified type
182+
Soft uint64 `json:"soft"`
183+
}
184+
185+
// HugepageLimit structure corresponds to limiting kernel hugepages
186+
type HugepageLimit struct {
187+
// Pagesize is the hugepage size
188+
Pagesize *string `json:"pageSize,omitempty"`
189+
// Limit is the limit of "hugepagesize" hugetlb usage
190+
Limit *uint64 `json:"limit,omitempty"`
191+
}
192+
193+
// InterfacePriority for network interfaces
194+
type InterfacePriority struct {
195+
// Name is the name of the network interface
196+
Name string `json:"name"`
197+
// Priority for the interface
198+
Priority uint32 `json:"priority"`
199+
}
200+
201+
// blockIODevice holds major:minor format supported in blkio cgroup
202+
type blockIODevice struct {
203+
// Major is the device's major number.
204+
Major int64 `json:"major"`
205+
// Minor is the device's minor number.
206+
Minor int64 `json:"minor"`
207+
}
208+
209+
// WeightDevice struct holds a `major:minor weight` pair for blkioWeightDevice
210+
type WeightDevice struct {
211+
blockIODevice
212+
// Weight is the bandwidth rate for the device, range is from 10 to 1000
213+
Weight *uint16 `json:"weight,omitempty"`
214+
// LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, CFQ scheduler only
215+
LeafWeight *uint16 `json:"leafWeight,omitempty"`
216+
}
217+
218+
// ThrottleDevice struct holds a `major:minor rate_per_second` pair
219+
type ThrottleDevice struct {
220+
blockIODevice
221+
// Rate is the IO rate limit per cgroup per device
222+
Rate *uint64 `json:"rate,omitempty"`
223+
}
224+
225+
// BlockIO for Linux cgroup 'blkio' resource management
226+
type BlockIO struct {
227+
// Specifies per cgroup weight, range is from 10 to 1000
228+
Weight *uint16 `json:"blkioWeight,omitempty"`
229+
// Specifies tasks' weight in the given cgroup while competing with the cgroup's child cgroups, range is from 10 to 1000, CFQ scheduler only
230+
LeafWeight *uint16 `json:"blkioLeafWeight,omitempty"`
231+
// Weight per cgroup per device, can override BlkioWeight
232+
WeightDevice []WeightDevice `json:"blkioWeightDevice,omitempty"`
233+
// IO read rate limit per cgroup per device, bytes per second
234+
ThrottleReadBpsDevice []ThrottleDevice `json:"blkioThrottleReadBpsDevice,omitempty"`
235+
// IO write rate limit per cgroup per device, bytes per second
236+
ThrottleWriteBpsDevice []ThrottleDevice `json:"blkioThrottleWriteBpsDevice,omitempty"`
237+
// IO read rate limit per cgroup per device, IO per second
238+
ThrottleReadIOPSDevice []ThrottleDevice `json:"blkioThrottleReadIOPSDevice,omitempty"`
239+
// IO write rate limit per cgroup per device, IO per second
240+
ThrottleWriteIOPSDevice []ThrottleDevice `json:"blkioThrottleWriteIOPSDevice,omitempty"`
241+
}
242+
243+
// Memory for Linux cgroup 'memory' resource management
244+
type Memory struct {
245+
// Memory limit (in bytes).
246+
Limit *uint64 `json:"limit,omitempty"`
247+
// Memory reservation or soft_limit (in bytes).
248+
Reservation *uint64 `json:"reservation,omitempty"`
249+
// Total memory limit (memory + swap).
250+
Swap *uint64 `json:"swap,omitempty"`
251+
// Kernel memory limit (in bytes).
252+
Kernel *uint64 `json:"kernel,omitempty"`
253+
// Kernel memory limit for tcp (in bytes)
254+
KernelTCP *uint64 `json:"kernelTCP"`
255+
// How aggressive the kernel will swap memory pages. Range from 0 to 100.
256+
Swappiness *uint64 `json:"swappiness,omitempty"`
257+
}
258+
259+
// CPU for Linux cgroup 'cpu' resource management
260+
type CPU struct {
261+
// CPU shares (relative weight (ratio) vs. other cgroups with cpu shares).
262+
Shares *uint64 `json:"shares,omitempty"`
263+
// CPU hardcap limit (in usecs). Allowed cpu time in a given period.
264+
Quota *uint64 `json:"quota,omitempty"`
265+
// CPU period to be used for hardcapping (in usecs).
266+
Period *uint64 `json:"period,omitempty"`
267+
// How much time realtime scheduling may use (in usecs).
268+
RealtimeRuntime *uint64 `json:"realtimeRuntime,omitempty"`
269+
// CPU period to be used for realtime scheduling (in usecs).
270+
RealtimePeriod *uint64 `json:"realtimePeriod,omitempty"`
271+
// CPUs to use within the cpuset. Default is to use any CPU available.
272+
Cpus *string `json:"cpus,omitempty"`
273+
// List of memory nodes in the cpuset. Default is to use any available memory node.
274+
Mems *string `json:"mems,omitempty"`
275+
}
276+
277+
// Pids for Linux cgroup 'pids' resource management (Linux 4.3)
278+
type Pids struct {
279+
// Maximum number of PIDs. Default is "no limit".
280+
Limit *int64 `json:"limit,omitempty"`
281+
}
282+
283+
// Network identification and priority configuration
284+
type Network struct {
285+
// Set class identifier for container's network packets
286+
ClassID *uint32 `json:"classID"`
287+
// Set priority of network traffic for container
288+
Priorities []InterfacePriority `json:"priorities,omitempty"`
289+
}
290+
291+
// Resources has container runtime resource constraints
292+
type Resources struct {
293+
// Devices are a list of device rules for the whitelist controller
294+
Devices []DeviceCgroup `json:"devices"`
295+
// DisableOOMKiller disables the OOM killer for out of memory conditions
296+
DisableOOMKiller *bool `json:"disableOOMKiller,omitempty"`
297+
// Specify an oom_score_adj for the container.
298+
OOMScoreAdj *int `json:"oomScoreAdj,omitempty"`
299+
// Memory restriction configuration
300+
Memory *Memory `json:"memory,omitempty"`
301+
// CPU resource restriction configuration
302+
CPU *CPU `json:"cpu,omitempty"`
303+
// Task resource restriction configuration.
304+
Pids *Pids `json:"pids,omitempty"`
305+
// BlockIO restriction configuration
306+
BlockIO *BlockIO `json:"blockIO,omitempty"`
307+
// Hugetlb limit (in bytes)
308+
HugepageLimits []HugepageLimit `json:"hugepageLimits,omitempty"`
309+
// Network restriction configuration
310+
Network *Network `json:"network,omitempty"`
311+
}
312+
313+
// Device represents the mknod information for a Linux special device file
314+
type Device struct {
315+
// Path to the device.
316+
Path string `json:"path"`
317+
// Device type, block, char, etc.
318+
Type string `json:"type"`
319+
// Major is the device's major number.
320+
Major int64 `json:"major"`
321+
// Minor is the device's minor number.
322+
Minor int64 `json:"minor"`
323+
// FileMode permission bits for the device.
324+
FileMode *os.FileMode `json:"fileMode,omitempty"`
325+
// UID of the device.
326+
UID *uint32 `json:"uid,omitempty"`
327+
// Gid of the device.
328+
GID *uint32 `json:"gid,omitempty"`
329+
}
330+
331+
// DeviceCgroup represents a device rule for the whitelist controller
332+
type DeviceCgroup struct {
333+
// Allow or deny
334+
Allow bool `json:"allow"`
335+
// Device type, block, char, etc.
336+
Type *string `json:"type,omitempty"`
337+
// Major is the device's major number.
338+
Major *int64 `json:"major,omitempty"`
339+
// Minor is the device's minor number.
340+
Minor *int64 `json:"minor,omitempty"`
341+
// Cgroup access permissions format, rwm.
342+
Access *string `json:"access,omitempty"`
343+
}
344+
345+
// Seccomp represents syscall restrictions
346+
type Seccomp struct {
347+
DefaultAction Action `json:"defaultAction"`
348+
Architectures []Arch `json:"architectures"`
349+
Syscalls []Syscall `json:"syscalls,omitempty"`
350+
}
351+
352+
// Arch used for additional architectures
353+
type Arch string
354+
355+
// Additional architectures permitted to be used for system calls
356+
// By default only the native architecture of the kernel is permitted
357+
const (
358+
ArchX86 Arch = "SCMP_ARCH_X86"
359+
ArchX86_64 Arch = "SCMP_ARCH_X86_64"
360+
ArchX32 Arch = "SCMP_ARCH_X32"
361+
ArchARM Arch = "SCMP_ARCH_ARM"
362+
ArchAARCH64 Arch = "SCMP_ARCH_AARCH64"
363+
ArchMIPS Arch = "SCMP_ARCH_MIPS"
364+
ArchMIPS64 Arch = "SCMP_ARCH_MIPS64"
365+
ArchMIPS64N32 Arch = "SCMP_ARCH_MIPS64N32"
366+
ArchMIPSEL Arch = "SCMP_ARCH_MIPSEL"
367+
ArchMIPSEL64 Arch = "SCMP_ARCH_MIPSEL64"
368+
ArchMIPSEL64N32 Arch = "SCMP_ARCH_MIPSEL64N32"
369+
)
370+
371+
// Action taken upon Seccomp rule match
372+
type Action string
373+
374+
// Define actions for Seccomp rules
375+
const (
376+
ActKill Action = "SCMP_ACT_KILL"
377+
ActTrap Action = "SCMP_ACT_TRAP"
378+
ActErrno Action = "SCMP_ACT_ERRNO"
379+
ActTrace Action = "SCMP_ACT_TRACE"
380+
ActAllow Action = "SCMP_ACT_ALLOW"
381+
)
382+
383+
// Operator used to match syscall arguments in Seccomp
384+
type Operator string
385+
386+
// Define operators for syscall arguments in Seccomp
387+
const (
388+
OpNotEqual Operator = "SCMP_CMP_NE"
389+
OpLessThan Operator = "SCMP_CMP_LT"
390+
OpLessEqual Operator = "SCMP_CMP_LE"
391+
OpEqualTo Operator = "SCMP_CMP_EQ"
392+
OpGreaterEqual Operator = "SCMP_CMP_GE"
393+
OpGreaterThan Operator = "SCMP_CMP_GT"
394+
OpMaskedEqual Operator = "SCMP_CMP_MASKED_EQ"
395+
)
396+
397+
// Arg used for matching specific syscall arguments in Seccomp
398+
type Arg struct {
399+
Index uint `json:"index"`
400+
Value uint64 `json:"value"`
401+
ValueTwo uint64 `json:"valueTwo"`
402+
Op Operator `json:"op"`
403+
}
404+
405+
// Syscall is used to match a syscall in Seccomp
406+
type Syscall struct {
407+
Name string `json:"name"`
408+
Action Action `json:"action"`
409+
Args []Arg `json:"args,omitempty"`
410+
}

0 commit comments

Comments
 (0)