2016-03-18 14:50:19 -04:00
|
|
|
package oci
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
2016-08-17 12:38:34 -04:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func iPtr(i int64) *int64 { return &i }
|
|
|
|
func u32Ptr(i int64) *uint32 { u := uint32(i); return &u }
|
|
|
|
func fmPtr(i int64) *os.FileMode { fm := os.FileMode(i); return &fm }
|
|
|
|
|
2017-04-27 17:52:47 -04:00
|
|
|
func defaultCapabilities() []string {
|
|
|
|
return []string{
|
|
|
|
"CAP_CHOWN",
|
|
|
|
"CAP_DAC_OVERRIDE",
|
|
|
|
"CAP_FSETID",
|
|
|
|
"CAP_FOWNER",
|
|
|
|
"CAP_MKNOD",
|
|
|
|
"CAP_NET_RAW",
|
|
|
|
"CAP_SETGID",
|
|
|
|
"CAP_SETUID",
|
|
|
|
"CAP_SETFCAP",
|
|
|
|
"CAP_SETPCAP",
|
|
|
|
"CAP_NET_BIND_SERVICE",
|
|
|
|
"CAP_SYS_CHROOT",
|
|
|
|
"CAP_KILL",
|
|
|
|
"CAP_AUDIT_WRITE",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
// DefaultSpec returns default oci spec used by docker.
|
|
|
|
func DefaultSpec() specs.Spec {
|
|
|
|
s := specs.Spec{
|
|
|
|
Version: specs.Version,
|
|
|
|
Platform: specs.Platform{
|
|
|
|
OS: runtime.GOOS,
|
|
|
|
Arch: runtime.GOARCH,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s.Mounts = []specs.Mount{
|
|
|
|
{
|
|
|
|
Destination: "/proc",
|
|
|
|
Type: "proc",
|
|
|
|
Source: "proc",
|
|
|
|
Options: []string{"nosuid", "noexec", "nodev"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/dev",
|
|
|
|
Type: "tmpfs",
|
|
|
|
Source: "tmpfs",
|
|
|
|
Options: []string{"nosuid", "strictatime", "mode=755"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/dev/pts",
|
|
|
|
Type: "devpts",
|
|
|
|
Source: "devpts",
|
|
|
|
Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/sys",
|
|
|
|
Type: "sysfs",
|
|
|
|
Source: "sysfs",
|
|
|
|
Options: []string{"nosuid", "noexec", "nodev", "ro"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/sys/fs/cgroup",
|
|
|
|
Type: "cgroup",
|
|
|
|
Source: "cgroup",
|
|
|
|
Options: []string{"ro", "nosuid", "noexec", "nodev"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/dev/mqueue",
|
|
|
|
Type: "mqueue",
|
|
|
|
Source: "mqueue",
|
|
|
|
Options: []string{"nosuid", "noexec", "nodev"},
|
|
|
|
},
|
|
|
|
}
|
2017-04-27 17:52:47 -04:00
|
|
|
s.Process.Capabilities = &specs.LinuxCapabilities{
|
|
|
|
Bounding: defaultCapabilities(),
|
|
|
|
Permitted: defaultCapabilities(),
|
|
|
|
Inheritable: defaultCapabilities(),
|
|
|
|
Effective: defaultCapabilities(),
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:26:59 -04:00
|
|
|
s.Linux = &specs.Linux{
|
2016-04-04 17:27:44 -04:00
|
|
|
MaskedPaths: []string{
|
|
|
|
"/proc/kcore",
|
|
|
|
"/proc/latency_stats",
|
Adding /proc/timer_list to the masked paths list
/proc/timer_list seems to leak information about the host. Here is
an example from a busybox container running on docker+kubernetes.
# cat /proc/timer_list | grep -i -e kube
<ffff8800b8cc3db0>, hrtimer_wakeup, S:01, futex_wait_queue_me, kubelet/2497
<ffff880129ac3db0>, hrtimer_wakeup, S:01, futex_wait_queue_me, kube-proxy/3478
<ffff8800b1b77db0>, hrtimer_wakeup, S:01, futex_wait_queue_me, kube-proxy/3470
<ffff8800bb6abdb0>, hrtimer_wakeup, S:01, futex_wait_queue_me, kubelet/2499
Signed-Off-By: Davanum Srinivas <davanum@gmail.com>
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2016-08-11 15:12:35 -04:00
|
|
|
"/proc/timer_list",
|
2016-04-04 17:27:44 -04:00
|
|
|
"/proc/timer_stats",
|
|
|
|
"/proc/sched_debug",
|
2016-10-12 02:07:13 -04:00
|
|
|
"/sys/firmware",
|
2016-04-04 17:27:44 -04:00
|
|
|
},
|
|
|
|
ReadonlyPaths: []string{
|
|
|
|
"/proc/asound",
|
|
|
|
"/proc/bus",
|
|
|
|
"/proc/fs",
|
|
|
|
"/proc/irq",
|
|
|
|
"/proc/sys",
|
|
|
|
"/proc/sysrq-trigger",
|
|
|
|
},
|
2017-04-27 17:52:47 -04:00
|
|
|
Namespaces: []specs.LinuxNamespace{
|
2016-03-18 14:50:19 -04:00
|
|
|
{Type: "mount"},
|
|
|
|
{Type: "network"},
|
|
|
|
{Type: "uts"},
|
|
|
|
{Type: "pid"},
|
|
|
|
{Type: "ipc"},
|
|
|
|
},
|
2016-04-08 01:28:37 -04:00
|
|
|
// Devices implicitly contains the following devices:
|
|
|
|
// null, zero, full, random, urandom, tty, console, and ptmx.
|
|
|
|
// ptmx is a bind-mount or symlink of the container's ptmx.
|
|
|
|
// See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices
|
2017-04-27 17:52:47 -04:00
|
|
|
Devices: []specs.LinuxDevice{},
|
|
|
|
Resources: &specs.LinuxResources{
|
|
|
|
Devices: []specs.LinuxDeviceCgroup{
|
2016-03-18 14:50:19 -04:00
|
|
|
{
|
|
|
|
Allow: false,
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(5),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(3),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(9),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(8),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(5),
|
|
|
|
Minor: iPtr(0),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(5),
|
|
|
|
Minor: iPtr(1),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: false,
|
2017-04-27 17:52:47 -04:00
|
|
|
Type: "c",
|
2016-03-18 14:50:19 -04:00
|
|
|
Major: iPtr(10),
|
|
|
|
Minor: iPtr(229),
|
2017-04-27 17:52:47 -04:00
|
|
|
Access: "rwm",
|
2016-03-18 14:50:19 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|