Skip to content

Commit eea2a6c

Browse files
committed
Merge pull request #310 from vbatts/multi-platform
config: platform dependent reference source
2 parents 9f909ab + 820131d commit eea2a6c

File tree

2 files changed

+325
-329
lines changed

2 files changed

+325
-329
lines changed

specs-go/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.
@@ -20,6 +22,9 @@ type Spec struct {
2022
Hooks Hooks `json:"hooks"`
2123
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
2224
Annotations map[string]string `json:"annotations,omitempty"`
25+
26+
// Linux is platform specific configuration for Linux based containers.
27+
Linux Linux `json:"linux" platform:"linux"`
2328
}
2429

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

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

0 commit comments

Comments
 (0)