2018-02-05 21:05:59 +00:00
|
|
|
package oci // import "github.com/docker/docker/oci"
|
2016-03-18 18:50:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
2019-11-14 17:53:52 +00:00
|
|
|
"github.com/docker/docker/oci/caps"
|
2019-08-05 14:37:47 +00:00
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
|
|
|
|
2021-12-01 15:08:03 +00:00
|
|
|
func iPtr(i int64) *int64 { return &i }
|
2016-03-18 18:50:19 +00:00
|
|
|
|
2022-10-07 21:57:09 +00:00
|
|
|
const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
|
|
|
// DefaultPathEnv is unix style list of directories to search for
|
|
|
|
// executables. Each directory is separated from the next by a colon
|
|
|
|
// ':' character .
|
|
|
|
// For Windows containers, an empty string is returned as the default
|
|
|
|
// path will be set by the container, and Docker has no context of what the
|
|
|
|
// default path should be.
|
|
|
|
//
|
|
|
|
// TODO(thaJeztah) align Windows default with BuildKit; see https://github.com/moby/buildkit/pull/1747
|
|
|
|
// TODO(thaJeztah) use defaults from containerd (but align it with BuildKit; see https://github.com/moby/buildkit/pull/1747)
|
|
|
|
func DefaultPathEnv(os string) string {
|
|
|
|
if os == "windows" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return defaultUnixPathEnv
|
|
|
|
}
|
|
|
|
|
2017-05-26 23:14:18 +00:00
|
|
|
// DefaultSpec returns the default spec used by docker for the current Platform
|
2016-03-18 18:50:19 +00:00
|
|
|
func DefaultSpec() specs.Spec {
|
2021-07-27 10:12:11 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
2017-05-26 23:14:18 +00:00
|
|
|
return DefaultWindowsSpec()
|
|
|
|
}
|
2017-10-24 18:32:52 +00:00
|
|
|
return DefaultLinuxSpec()
|
2017-05-26 23:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultWindowsSpec create a default spec for running Windows containers
|
|
|
|
func DefaultWindowsSpec() specs.Spec {
|
|
|
|
return specs.Spec{
|
2016-03-18 18:50:19 +00:00
|
|
|
Version: specs.Version,
|
2017-05-26 23:14:18 +00:00
|
|
|
Windows: &specs.Windows{},
|
2017-08-01 17:00:38 +00:00
|
|
|
Process: &specs.Process{},
|
|
|
|
Root: &specs.Root{},
|
2017-05-26 23:14:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultLinuxSpec create a default spec for running Linux containers
|
|
|
|
func DefaultLinuxSpec() specs.Spec {
|
2021-07-27 10:12:11 +00:00
|
|
|
return specs.Spec{
|
2017-05-26 23:14:18 +00:00
|
|
|
Version: specs.Version,
|
2017-09-22 13:52:41 +00:00
|
|
|
Process: &specs.Process{
|
|
|
|
Capabilities: &specs.LinuxCapabilities{
|
2022-01-31 20:08:01 +00:00
|
|
|
Bounding: caps.DefaultCapabilities(),
|
|
|
|
Permitted: caps.DefaultCapabilities(),
|
|
|
|
Effective: caps.DefaultCapabilities(),
|
2017-09-22 13:52:41 +00:00
|
|
|
},
|
|
|
|
},
|
2017-10-26 21:16:43 +00:00
|
|
|
Root: &specs.Root{},
|
2021-07-27 10:12:11 +00:00
|
|
|
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", "size=65536k"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Destination: "/dev/shm",
|
|
|
|
Type: "tmpfs",
|
|
|
|
Source: "shm",
|
|
|
|
Options: []string{"nosuid", "noexec", "nodev", "mode=1777"},
|
|
|
|
},
|
2016-03-18 18:50:19 +00:00
|
|
|
},
|
2021-07-27 10:12:11 +00:00
|
|
|
Linux: &specs.Linux{
|
|
|
|
MaskedPaths: []string{
|
|
|
|
"/proc/asound",
|
|
|
|
"/proc/acpi",
|
|
|
|
"/proc/kcore",
|
|
|
|
"/proc/keys",
|
|
|
|
"/proc/latency_stats",
|
|
|
|
"/proc/timer_list",
|
|
|
|
"/proc/timer_stats",
|
|
|
|
"/proc/sched_debug",
|
|
|
|
"/proc/scsi",
|
|
|
|
"/sys/firmware",
|
|
|
|
},
|
|
|
|
ReadonlyPaths: []string{
|
|
|
|
"/proc/bus",
|
|
|
|
"/proc/fs",
|
|
|
|
"/proc/irq",
|
|
|
|
"/proc/sys",
|
|
|
|
"/proc/sysrq-trigger",
|
|
|
|
},
|
|
|
|
Namespaces: []specs.LinuxNamespace{
|
|
|
|
{Type: "mount"},
|
|
|
|
{Type: "network"},
|
|
|
|
{Type: "uts"},
|
|
|
|
{Type: "pid"},
|
|
|
|
{Type: "ipc"},
|
|
|
|
},
|
|
|
|
// 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
|
|
|
|
Devices: []specs.LinuxDevice{},
|
|
|
|
Resources: &specs.LinuxResources{
|
|
|
|
Devices: []specs.LinuxDeviceCgroup{
|
|
|
|
{
|
|
|
|
Allow: false,
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(5),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(3),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(9),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(1),
|
|
|
|
Minor: iPtr(8),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(5),
|
|
|
|
Minor: iPtr(0),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: true,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(5),
|
|
|
|
Minor: iPtr(1),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Allow: false,
|
|
|
|
Type: "c",
|
|
|
|
Major: iPtr(10),
|
|
|
|
Minor: iPtr(229),
|
|
|
|
Access: "rwm",
|
|
|
|
},
|
2016-03-18 18:50:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|