130
vendor/github.com/opencontainers/runtime-tools/README.md
generated
vendored
130
vendor/github.com/opencontainers/runtime-tools/README.md
generated
vendored
@@ -8,7 +8,7 @@ To build from source code, runtime-tools requires Go 1.7.x or above.
|
||||
[`oci-runtime-tool generate`][generate.1] generates [configuration JSON][config.json] for an [OCI bundle][bundle].
|
||||
[OCI-compatible runtimes][runtime-spec] like [runC][] expect to read the configuration from `config.json`.
|
||||
|
||||
```sh
|
||||
```console
|
||||
$ oci-runtime-tool generate --output config.json
|
||||
$ cat config.json
|
||||
{
|
||||
@@ -22,7 +22,7 @@ $ cat config.json
|
||||
[`oci-runtime-tool validate`][validate.1] validates an OCI bundle.
|
||||
The error message will be printed if the OCI bundle failed the validation procedure.
|
||||
|
||||
```sh
|
||||
```console
|
||||
$ oci-runtime-tool generate
|
||||
$ oci-runtime-tool validate
|
||||
INFO[0000] Bundle validation succeeded.
|
||||
@@ -30,55 +30,99 @@ INFO[0000] Bundle validation succeeded.
|
||||
|
||||
## Testing OCI runtimes
|
||||
|
||||
```sh
|
||||
The runtime validation suite uses [node-tap][], which is packaged for some distributions (for example, it is in [Debian's `node-tap` package][debian-node-tap]).
|
||||
If your distribution does not package node-tap, you can install [npm][] (for example, from [Gentoo's `nodejs` package][gentoo-nodejs]) and use it:
|
||||
|
||||
```console
|
||||
$ npm install tap
|
||||
```
|
||||
|
||||
Build the validation executables:
|
||||
|
||||
```console
|
||||
$ make runtimetest validation-executables
|
||||
```
|
||||
|
||||
Runtime validation currently [only supports](docs/runtime-compliance-testing.md) the [OCI Runtime Command Line Interface](doc/command-line-interface.md).
|
||||
If we add support for alternative APIs in the future, runtime validation will gain an option to select the desired runtime API.
|
||||
For the command line interface, the `RUNTIME` option selects the runtime command (`funC` in the [OCI Runtime Command Line Interface](doc/command-line-interface.md)).
|
||||
|
||||
```
|
||||
$ sudo make RUNTIME=runc localvalidation
|
||||
RUNTIME=runc go test -tags "" -v github.com/opencontainers/runtime-tools/validation
|
||||
=== RUN TestValidateBasic
|
||||
RUNTIME=runc tap validation/pidfile.t validation/linux_cgroups_hugetlb.t validation/linux_cgroups_memory.t validation/linux_rootfs_propagation_shared.t validation/kill.t validation/create.t validation/poststart.t validation/linux_cgroups_network.t validation/poststop_fail.t validation/linux_readonly_paths.t validation/prestart_fail.t validation/hooks_stdin.t validation/default.t validation/linux_masked_paths.t validation/poststop.t validation/misc_props.t validation/prestart.t validation/poststart_fail.t validation/mounts.t validation/linux_cgroups_relative_pids.t validation/process_user.t validation/process.t validation/hooks.t validation/process_capabilities_fail.t validation/process_rlimits_fail.t validation/linux_cgroups_relative_cpus.t validation/process_rlimits.t validation/linux_cgroups_relative_blkio.t validation/linux_sysctl.t validation/linux_seccomp.t validation/linux_devices.t validation/start.t validation/linux_cgroups_pids.t validation/process_capabilities.t validation/process_oom_score_adj.t validation/linux_cgroups_relative_hugetlb.t validation/linux_cgroups_cpus.t validation/linux_cgroups_relative_memory.t validation/state.t validation/root_readonly_true.t validation/linux_cgroups_blkio.t validation/linux_rootfs_propagation_unbindable.t validation/delete.t validation/linux_cgroups_relative_network.t validation/hostname.t validation/killsig.t validation/linux_uid_mappings.t
|
||||
validation/pidfile.t .failed to create the container
|
||||
container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"process_linux.go:367: setting cgroup config for procHooks process caused \\\"failed to write 56892210544640 to hugetlb.1GB.limit_in_bytes: open /sys/fs/cgroup/hugetlb/cgrouptest/hugetlb.1GB.limit_in_bytes: permission denied\\\"\""
|
||||
exit status 1
|
||||
validation/pidfile.t .................................. 1/1 315ms
|
||||
validation/linux_cgroups_hugetlb.t .................... 0/1
|
||||
not ok validation/linux_cgroups_hugetlb.t
|
||||
timeout: 30000
|
||||
file: validation/linux_cgroups_hugetlb.t
|
||||
command: validation/linux_cgroups_hugetlb.t
|
||||
args: []
|
||||
stdio:
|
||||
- 0
|
||||
- pipe
|
||||
- 2
|
||||
cwd: /…/go/src/github.com/opencontainers/runtime-tools
|
||||
exitCode: 1
|
||||
|
||||
validation/linux_cgroups_memory.t ..................... 9/9
|
||||
validation/linux_rootfs_propagation_shared.t ...... 252/282
|
||||
not ok shared root propogation exposes "/target348456609/mount892511628/example376408222"
|
||||
|
||||
Skipped: 29
|
||||
/dev/null (default device) has unconfigured permissions
|
||||
…
|
||||
total ........................................... 4381/4962
|
||||
|
||||
|
||||
4381 passing (1m)
|
||||
567 pending
|
||||
14 failing
|
||||
|
||||
make: *** [Makefile:44: localvalidation] Error 1
|
||||
```
|
||||
|
||||
You can also run an individual test executable directly:
|
||||
|
||||
```console
|
||||
$ RUNTIME=runc validation/default.t
|
||||
TAP version 13
|
||||
ok 1 - root filesystem
|
||||
ok 2 - hostname
|
||||
ok 3 - mounts
|
||||
ok 4 - capabilities
|
||||
ok 5 - default symlinks
|
||||
ok 6 - default devices
|
||||
ok 7 - linux devices
|
||||
ok 8 - linux process
|
||||
ok 9 - masked paths
|
||||
ok 10 - oom score adj
|
||||
ok 11 - read only paths
|
||||
ok 12 - rlimits
|
||||
ok 13 - sysctls
|
||||
ok 14 - uid mappings
|
||||
ok 15 - gid mappings
|
||||
1..15
|
||||
--- PASS: TestValidateBasic (0.08s)
|
||||
=== RUN TestValidateSysctls
|
||||
TAP version 13
|
||||
ok 1 - root filesystem
|
||||
ok 2 - hostname
|
||||
ok 3 - mounts
|
||||
ok 4 - capabilities
|
||||
ok 5 - default symlinks
|
||||
ok 6 - default devices
|
||||
ok 7 - linux devices
|
||||
ok 8 - linux process
|
||||
ok 9 - masked paths
|
||||
ok 10 - oom score adj
|
||||
ok 11 - read only paths
|
||||
ok 12 - rlimits
|
||||
ok 13 - sysctls
|
||||
ok 14 - uid mappings
|
||||
ok 15 - gid mappings
|
||||
1..15
|
||||
--- PASS: TestValidateSysctls (0.20s)
|
||||
PASS
|
||||
ok github.com/opencontainers/runtime-tools/validation 0.281s
|
||||
ok 1 - has expected hostname
|
||||
---
|
||||
{
|
||||
"actual": "mrsdalloway",
|
||||
"expected": "mrsdalloway"
|
||||
}
|
||||
...
|
||||
…
|
||||
ok 287 # SKIP linux.gidMappings not set
|
||||
1..287
|
||||
```
|
||||
|
||||
If you cannot install node-tap, you can probably run the test suite with another [TAP consumer][tap-consumers].
|
||||
For example, with [`prove`][prove]:
|
||||
|
||||
```console
|
||||
$ sudo make TAP='prove -Q -j9' RUNTIME=runc VALIDATION_TESTS=validation/pidfile.t localvalidation
|
||||
RUNTIME=runc prove -Q -j9 validation/pidfile.t
|
||||
All tests successful.
|
||||
Files=1, Tests=1, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.03 cusr 0.03 csys = 0.08 CPU)
|
||||
Result: PASS
|
||||
```
|
||||
|
||||
[bundle]: https://github.com/opencontainers/runtime-spec/blob/master/bundle.md
|
||||
[config.json]: https://github.com/opencontainers/runtime-spec/blob/master/config.md
|
||||
[debian-node-tap]: https://packages.debian.org/stretch/node-tap
|
||||
[debian-nodejs]: https://packages.debian.org/stretch/nodejs
|
||||
[gentoo-nodejs]: https://packages.gentoo.org/packages/net-libs/nodejs
|
||||
[node-tap]: http://www.node-tap.org/
|
||||
[npm]: https://www.npmjs.com/
|
||||
[prove]: http://search.cpan.org/~leont/Test-Harness-3.39/bin/prove
|
||||
[runC]: https://github.com/opencontainers/runc
|
||||
[runtime-spec]: https://github.com/opencontainers/runtime-spec
|
||||
[tap-consumers]: https://testanything.org/consumers.html
|
||||
|
||||
[generate.1]: man/oci-runtime-tool-generate.1.md
|
||||
[validate.1]: man/oci-runtime-tool-validate.1.md
|
||||
|
30
vendor/github.com/opencontainers/runtime-tools/error/error.go
generated
vendored
30
vendor/github.com/opencontainers/runtime-tools/error/error.go
generated
vendored
@@ -86,6 +86,36 @@ func ParseLevel(level string) (Level, error) {
|
||||
return l, fmt.Errorf("%q is not a valid compliance level", level)
|
||||
}
|
||||
|
||||
// String takes a RFC 2119 compliance level constant and returns a string representation.
|
||||
func (level Level) String() string {
|
||||
switch level {
|
||||
case May:
|
||||
return "MAY"
|
||||
case Optional:
|
||||
return "OPTIONAL"
|
||||
case Should:
|
||||
return "SHOULD"
|
||||
case ShouldNot:
|
||||
return "SHOULD NOT"
|
||||
case Recommended:
|
||||
return "RECOMMENDED"
|
||||
case NotRecommended:
|
||||
return "NOT RECOMMENDED"
|
||||
case Must:
|
||||
return "MUST"
|
||||
case MustNot:
|
||||
return "MUST NOT"
|
||||
case Shall:
|
||||
return "SHALL"
|
||||
case ShallNot:
|
||||
return "SHALL NOT"
|
||||
case Required:
|
||||
return "REQUIRED"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("%d is not a valid compliance level", level))
|
||||
}
|
||||
|
||||
// Error returns the error message with specification reference.
|
||||
func (err *Error) Error() string {
|
||||
return fmt.Sprintf("%s\nRefer to: %s", err.Err.Error(), err.Reference)
|
||||
|
48
vendor/github.com/opencontainers/runtime-tools/filepath/abs.go
generated
vendored
Normal file
48
vendor/github.com/opencontainers/runtime-tools/filepath/abs.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package filepath
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var windowsAbs = regexp.MustCompile(`^[a-zA-Z]:\\.*$`)
|
||||
|
||||
// Abs is a version of path/filepath's Abs with an explicit operating
|
||||
// system and current working directory.
|
||||
func Abs(os, path, cwd string) (_ string, err error) {
|
||||
if IsAbs(os, path) {
|
||||
return Clean(os, path), nil
|
||||
}
|
||||
return Clean(os, Join(os, cwd, path)), nil
|
||||
}
|
||||
|
||||
// IsAbs is a version of path/filepath's IsAbs with an explicit
|
||||
// operating system.
|
||||
func IsAbs(os, path string) bool {
|
||||
if os == "windows" {
|
||||
// FIXME: copy hideous logic from Go's
|
||||
// src/path/filepath/path_windows.go into somewhere where we can
|
||||
// put 3-clause BSD licensed code.
|
||||
return windowsAbs.MatchString(path)
|
||||
}
|
||||
sep := Separator(os)
|
||||
|
||||
// POSIX has [1]:
|
||||
//
|
||||
// > If a pathname begins with two successive <slash> characters,
|
||||
// > the first component following the leading <slash> characters
|
||||
// > may be interpreted in an implementation-defined manner,
|
||||
// > although more than two leading <slash> characters shall be
|
||||
// > treated as a single <slash> character.
|
||||
//
|
||||
// And Boost treats // as non-absolute [2], but Linux [3,4], Python
|
||||
// [5] and Go [6] all treat // as absolute.
|
||||
//
|
||||
// [1]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
|
||||
// [2]: https://github.com/boostorg/filesystem/blob/boost-1.64.0/test/path_test.cpp#L861
|
||||
// [3]: http://man7.org/linux/man-pages/man7/path_resolution.7.html
|
||||
// [4]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/path-lookup.md?h=v4.12#n41
|
||||
// [5]: https://github.com/python/cpython/blob/v3.6.1/Lib/posixpath.py#L64-L66
|
||||
// [6]: https://go.googlesource.com/go/+/go1.8.3/src/path/path.go#199
|
||||
return strings.HasPrefix(path, string(sep))
|
||||
}
|
32
vendor/github.com/opencontainers/runtime-tools/filepath/ancestor.go
generated
vendored
Normal file
32
vendor/github.com/opencontainers/runtime-tools/filepath/ancestor.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package filepath
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IsAncestor returns true when pathB is an strict ancestor of pathA,
|
||||
// and false where the paths are equal or pathB is outside of pathA.
|
||||
// Paths that are not absolute will be made absolute with Abs.
|
||||
func IsAncestor(os, pathA, pathB, cwd string) (_ bool, err error) {
|
||||
if pathA == pathB {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
pathA, err = Abs(os, pathA, cwd)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
pathB, err = Abs(os, pathB, cwd)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
sep := Separator(os)
|
||||
if !strings.HasSuffix(pathA, string(sep)) {
|
||||
pathA = fmt.Sprintf("%s%c", pathA, sep)
|
||||
}
|
||||
if pathA == pathB {
|
||||
return false, nil
|
||||
}
|
||||
return strings.HasPrefix(pathB, pathA), nil
|
||||
}
|
74
vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
generated
vendored
Normal file
74
vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
package filepath
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Clean is an explicit-OS version of path/filepath's Clean.
|
||||
func Clean(os, path string) string {
|
||||
abs := IsAbs(os, path)
|
||||
sep := Separator(os)
|
||||
elements := strings.Split(path, string(sep))
|
||||
|
||||
// Replace multiple Separator elements with a single one.
|
||||
for i := 0; i < len(elements); i++ {
|
||||
if len(elements[i]) == 0 {
|
||||
elements = append(elements[:i], elements[i+1:]...)
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminate each . path name element (the current directory).
|
||||
for i := 0; i < len(elements); i++ {
|
||||
if elements[i] == "." && len(elements) > 1 {
|
||||
elements = append(elements[:i], elements[i+1:]...)
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminate each inner .. path name element (the parent directory)
|
||||
// along with the non-.. element that precedes it.
|
||||
for i := 1; i < len(elements); i++ {
|
||||
if i == 1 && abs && sep == '\\' {
|
||||
continue
|
||||
}
|
||||
if i > 0 && elements[i] == ".." {
|
||||
elements = append(elements[:i-1], elements[i+1:]...)
|
||||
i -= 2
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminate .. elements that begin a rooted path:
|
||||
// that is, replace "/.." by "/" at the beginning of a path,
|
||||
// assuming Separator is '/'.
|
||||
offset := 0
|
||||
if sep == '\\' {
|
||||
offset = 1
|
||||
}
|
||||
if abs {
|
||||
for len(elements) > offset && elements[offset] == ".." {
|
||||
elements = append(elements[:offset], elements[offset+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
cleaned := strings.Join(elements, string(sep))
|
||||
if abs {
|
||||
if sep == '/' {
|
||||
cleaned = fmt.Sprintf("%c%s", sep, cleaned)
|
||||
} else if len(elements) == 1 {
|
||||
cleaned = fmt.Sprintf("%s%c", cleaned, sep)
|
||||
}
|
||||
}
|
||||
|
||||
// If the result of this process is an empty string, Clean returns
|
||||
// the string ".".
|
||||
if len(cleaned) == 0 {
|
||||
cleaned = "."
|
||||
}
|
||||
|
||||
if cleaned == path {
|
||||
return path
|
||||
}
|
||||
return Clean(os, cleaned)
|
||||
}
|
6
vendor/github.com/opencontainers/runtime-tools/filepath/doc.go
generated
vendored
Normal file
6
vendor/github.com/opencontainers/runtime-tools/filepath/doc.go
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Package filepath implements Go's filepath package with explicit
|
||||
// operating systems (and for some functions and explicit working
|
||||
// directory). This allows tools built for one OS to operate on paths
|
||||
// targeting another OS. For example, a Linux build can determine
|
||||
// whether a path is absolute on Linux or on Windows.
|
||||
package filepath
|
9
vendor/github.com/opencontainers/runtime-tools/filepath/join.go
generated
vendored
Normal file
9
vendor/github.com/opencontainers/runtime-tools/filepath/join.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package filepath
|
||||
|
||||
import "strings"
|
||||
|
||||
// Join is an explicit-OS version of path/filepath's Join.
|
||||
func Join(os string, elem ...string) string {
|
||||
sep := Separator(os)
|
||||
return Clean(os, strings.Join(elem, string(sep)))
|
||||
}
|
9
vendor/github.com/opencontainers/runtime-tools/filepath/separator.go
generated
vendored
Normal file
9
vendor/github.com/opencontainers/runtime-tools/filepath/separator.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package filepath
|
||||
|
||||
// Separator is an explicit-OS version of path/filepath's Separator.
|
||||
func Separator(os string) rune {
|
||||
if os == "windows" {
|
||||
return '\\'
|
||||
}
|
||||
return '/'
|
||||
}
|
172
vendor/github.com/opencontainers/runtime-tools/generate/config.go
generated
vendored
Normal file
172
vendor/github.com/opencontainers/runtime-tools/generate/config.go
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
package generate
|
||||
|
||||
import (
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
func (g *Generator) initConfig() {
|
||||
if g.Config == nil {
|
||||
g.Config = &rspec.Spec{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigProcess() {
|
||||
g.initConfig()
|
||||
if g.Config.Process == nil {
|
||||
g.Config.Process = &rspec.Process{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigProcessConsoleSize() {
|
||||
g.initConfigProcess()
|
||||
if g.Config.Process.ConsoleSize == nil {
|
||||
g.Config.Process.ConsoleSize = &rspec.Box{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigProcessCapabilities() {
|
||||
g.initConfigProcess()
|
||||
if g.Config.Process.Capabilities == nil {
|
||||
g.Config.Process.Capabilities = &rspec.LinuxCapabilities{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigRoot() {
|
||||
g.initConfig()
|
||||
if g.Config.Root == nil {
|
||||
g.Config.Root = &rspec.Root{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigAnnotations() {
|
||||
g.initConfig()
|
||||
if g.Config.Annotations == nil {
|
||||
g.Config.Annotations = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigHooks() {
|
||||
g.initConfig()
|
||||
if g.Config.Hooks == nil {
|
||||
g.Config.Hooks = &rspec.Hooks{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinux() {
|
||||
g.initConfig()
|
||||
if g.Config.Linux == nil {
|
||||
g.Config.Linux = &rspec.Linux{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxIntelRdt() {
|
||||
g.initConfigLinux()
|
||||
if g.Config.Linux.IntelRdt == nil {
|
||||
g.Config.Linux.IntelRdt = &rspec.LinuxIntelRdt{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxSysctl() {
|
||||
g.initConfigLinux()
|
||||
if g.Config.Linux.Sysctl == nil {
|
||||
g.Config.Linux.Sysctl = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxSeccomp() {
|
||||
g.initConfigLinux()
|
||||
if g.Config.Linux.Seccomp == nil {
|
||||
g.Config.Linux.Seccomp = &rspec.LinuxSeccomp{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResources() {
|
||||
g.initConfigLinux()
|
||||
if g.Config.Linux.Resources == nil {
|
||||
g.Config.Linux.Resources = &rspec.LinuxResources{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResourcesBlockIO() {
|
||||
g.initConfigLinuxResources()
|
||||
if g.Config.Linux.Resources.BlockIO == nil {
|
||||
g.Config.Linux.Resources.BlockIO = &rspec.LinuxBlockIO{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResourcesCPU() {
|
||||
g.initConfigLinuxResources()
|
||||
if g.Config.Linux.Resources.CPU == nil {
|
||||
g.Config.Linux.Resources.CPU = &rspec.LinuxCPU{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResourcesMemory() {
|
||||
g.initConfigLinuxResources()
|
||||
if g.Config.Linux.Resources.Memory == nil {
|
||||
g.Config.Linux.Resources.Memory = &rspec.LinuxMemory{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResourcesNetwork() {
|
||||
g.initConfigLinuxResources()
|
||||
if g.Config.Linux.Resources.Network == nil {
|
||||
g.Config.Linux.Resources.Network = &rspec.LinuxNetwork{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigLinuxResourcesPids() {
|
||||
g.initConfigLinuxResources()
|
||||
if g.Config.Linux.Resources.Pids == nil {
|
||||
g.Config.Linux.Resources.Pids = &rspec.LinuxPids{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigSolaris() {
|
||||
g.initConfig()
|
||||
if g.Config.Solaris == nil {
|
||||
g.Config.Solaris = &rspec.Solaris{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigSolarisCappedCPU() {
|
||||
g.initConfigSolaris()
|
||||
if g.Config.Solaris.CappedCPU == nil {
|
||||
g.Config.Solaris.CappedCPU = &rspec.SolarisCappedCPU{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigSolarisCappedMemory() {
|
||||
g.initConfigSolaris()
|
||||
if g.Config.Solaris.CappedMemory == nil {
|
||||
g.Config.Solaris.CappedMemory = &rspec.SolarisCappedMemory{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigWindows() {
|
||||
g.initConfig()
|
||||
if g.Config.Windows == nil {
|
||||
g.Config.Windows = &rspec.Windows{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigWindowsHyperV() {
|
||||
g.initConfigWindows()
|
||||
if g.Config.Windows.HyperV == nil {
|
||||
g.Config.Windows.HyperV = &rspec.WindowsHyperV{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigWindowsResources() {
|
||||
g.initConfigWindows()
|
||||
if g.Config.Windows.Resources == nil {
|
||||
g.Config.Windows.Resources = &rspec.WindowsResources{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initConfigWindowsResourcesMemory() {
|
||||
g.initConfigWindowsResources()
|
||||
if g.Config.Windows.Resources.Memory == nil {
|
||||
g.Config.Windows.Resources.Memory = &rspec.WindowsMemoryResources{}
|
||||
}
|
||||
}
|
1591
vendor/github.com/opencontainers/runtime-tools/generate/generate.go
generated
vendored
1591
vendor/github.com/opencontainers/runtime-tools/generate/generate.go
generated
vendored
File diff suppressed because it is too large
Load Diff
3
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default.go
generated
vendored
3
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default.go
generated
vendored
@@ -2,7 +2,6 @@ package seccomp
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@@ -513,7 +512,7 @@ func DefaultProfile(rs *specs.Spec) *rspec.LinuxSeccomp {
|
||||
Args: []rspec.LinuxSeccompArg{
|
||||
{
|
||||
Index: sysCloneFlagsIndex,
|
||||
Value: syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWIPC | syscall.CLONE_NEWUSER | syscall.CLONE_NEWPID | syscall.CLONE_NEWNET,
|
||||
Value: CloneNewNS | CloneNewUTS | CloneNewIPC | CloneNewUser | CloneNewPID | CloneNewNet,
|
||||
ValueTwo: 0,
|
||||
Op: rspec.OpMaskedEqual,
|
||||
},
|
||||
|
15
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default_linux.go
generated
vendored
Normal file
15
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default_linux.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build linux
|
||||
|
||||
package seccomp
|
||||
|
||||
import "syscall"
|
||||
|
||||
// System values passed through on linux
|
||||
const (
|
||||
CloneNewIPC = syscall.CLONE_NEWIPC
|
||||
CloneNewNet = syscall.CLONE_NEWNET
|
||||
CloneNewNS = syscall.CLONE_NEWNS
|
||||
CloneNewPID = syscall.CLONE_NEWPID
|
||||
CloneNewUser = syscall.CLONE_NEWUSER
|
||||
CloneNewUTS = syscall.CLONE_NEWUTS
|
||||
)
|
15
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default_unsupported.go
generated
vendored
Normal file
15
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/seccomp_default_unsupported.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build !linux
|
||||
|
||||
package seccomp
|
||||
|
||||
// These are copied from linux/amd64 syscall values, as a reference for other
|
||||
// platforms to have access to
|
||||
const (
|
||||
CloneNewIPC = 0x8000000
|
||||
CloneNewNet = 0x40000000
|
||||
CloneNewNS = 0x20000
|
||||
CloneNewPID = 0x20000000
|
||||
CloneNewUser = 0x10000000
|
||||
CloneNewUTS = 0x4000000
|
||||
CloneNewCgroup = 0x02000000
|
||||
)
|
109
vendor/github.com/opencontainers/runtime-tools/generate/spec.go
generated
vendored
109
vendor/github.com/opencontainers/runtime-tools/generate/spec.go
generated
vendored
@@ -1,109 +0,0 @@
|
||||
package generate
|
||||
|
||||
import (
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
func (g *Generator) initSpec() {
|
||||
if g.spec == nil {
|
||||
g.spec = &rspec.Spec{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecProcess() {
|
||||
g.initSpec()
|
||||
if g.spec.Process == nil {
|
||||
g.spec.Process = &rspec.Process{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecProcessConsoleSize() {
|
||||
g.initSpecProcess()
|
||||
if g.spec.Process.ConsoleSize == nil {
|
||||
g.spec.Process.ConsoleSize = &rspec.Box{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecProcessCapabilities() {
|
||||
g.initSpecProcess()
|
||||
if g.spec.Process.Capabilities == nil {
|
||||
g.spec.Process.Capabilities = &rspec.LinuxCapabilities{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecRoot() {
|
||||
g.initSpec()
|
||||
if g.spec.Root == nil {
|
||||
g.spec.Root = &rspec.Root{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecAnnotations() {
|
||||
g.initSpec()
|
||||
if g.spec.Annotations == nil {
|
||||
g.spec.Annotations = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecHooks() {
|
||||
g.initSpec()
|
||||
if g.spec.Hooks == nil {
|
||||
g.spec.Hooks = &rspec.Hooks{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinux() {
|
||||
g.initSpec()
|
||||
if g.spec.Linux == nil {
|
||||
g.spec.Linux = &rspec.Linux{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxSysctl() {
|
||||
g.initSpecLinux()
|
||||
if g.spec.Linux.Sysctl == nil {
|
||||
g.spec.Linux.Sysctl = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxSeccomp() {
|
||||
g.initSpecLinux()
|
||||
if g.spec.Linux.Seccomp == nil {
|
||||
g.spec.Linux.Seccomp = &rspec.LinuxSeccomp{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxResources() {
|
||||
g.initSpecLinux()
|
||||
if g.spec.Linux.Resources == nil {
|
||||
g.spec.Linux.Resources = &rspec.LinuxResources{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxResourcesCPU() {
|
||||
g.initSpecLinuxResources()
|
||||
if g.spec.Linux.Resources.CPU == nil {
|
||||
g.spec.Linux.Resources.CPU = &rspec.LinuxCPU{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxResourcesMemory() {
|
||||
g.initSpecLinuxResources()
|
||||
if g.spec.Linux.Resources.Memory == nil {
|
||||
g.spec.Linux.Resources.Memory = &rspec.LinuxMemory{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxResourcesNetwork() {
|
||||
g.initSpecLinuxResources()
|
||||
if g.spec.Linux.Resources.Network == nil {
|
||||
g.spec.Linux.Resources.Network = &rspec.LinuxNetwork{}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) initSpecLinuxResourcesPids() {
|
||||
g.initSpecLinuxResources()
|
||||
if g.spec.Linux.Resources.Pids == nil {
|
||||
g.spec.Linux.Resources.Pids = &rspec.LinuxPids{}
|
||||
}
|
||||
}
|
29
vendor/github.com/opencontainers/runtime-tools/specerror/bundle.go
generated
vendored
Normal file
29
vendor/github.com/opencontainers/runtime-tools/specerror/bundle.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// ConfigInRootBundleDir represents "This REQUIRED file MUST reside in the root of the bundle directory"
|
||||
ConfigInRootBundleDir Code = 0xa001 + iota
|
||||
// ConfigConstName represents "This REQUIRED file MUST be named `config.json`."
|
||||
ConfigConstName
|
||||
// ArtifactsInSingleDir represents "When supplied, while these artifacts MUST all be present in a single directory on the local filesystem, that directory itself is not part of the bundle."
|
||||
ArtifactsInSingleDir
|
||||
)
|
||||
|
||||
var (
|
||||
containerFormatRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "bundle.md#container-format"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(ConfigInRootBundleDir, rfc2119.Must, containerFormatRef)
|
||||
register(ConfigConstName, rfc2119.Must, containerFormatRef)
|
||||
register(ArtifactsInSingleDir, rfc2119.Must, containerFormatRef)
|
||||
}
|
134
vendor/github.com/opencontainers/runtime-tools/specerror/config-linux.go
generated
vendored
Normal file
134
vendor/github.com/opencontainers/runtime-tools/specerror/config-linux.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// DefaultFilesystems represents "The following filesystems SHOULD be made available in each container's filesystem:"
|
||||
DefaultFilesystems Code = 0xc001 + iota
|
||||
// NSPathAbs represents "This value MUST be an absolute path in the runtime mount namespace."
|
||||
NSPathAbs
|
||||
// NSProcInPath represents "The runtime MUST place the container process in the namespace associated with that `path`."
|
||||
NSProcInPath
|
||||
// NSPathMatchTypeError represents "The runtime MUST generate an error if `path` is not associated with a namespace of type `type`."
|
||||
NSPathMatchTypeError
|
||||
// NSNewNSWithoutPath represents "If `path` is not specified, the runtime MUST create a new container namespace of type `type`."
|
||||
NSNewNSWithoutPath
|
||||
// NSInheritWithoutType represents "If a namespace type is not specified in the `namespaces` array, the container MUST inherit the runtime namespace of that type."
|
||||
NSInheritWithoutType
|
||||
// NSErrorOnDup represents "If a `namespaces` field contains duplicated namespaces with same `type`, the runtime MUST generate an error."
|
||||
NSErrorOnDup
|
||||
// UserNSMapOwnershipRO represents "The runtime SHOULD NOT modify the ownership of referenced filesystems to realize the mapping."
|
||||
UserNSMapOwnershipRO
|
||||
// DevicesAvailable represents "devices (array of objects, OPTIONAL) lists devices that MUST be available in the container."
|
||||
DevicesAvailable
|
||||
// DevicesFileNotMatch represents "If a file already exists at `path` that does not match the requested device, the runtime MUST generate an error."
|
||||
DevicesFileNotMatch
|
||||
// DevicesMajMinRequired represents "`major, minor` (int64, REQUIRED unless `type` is `p`) - major, minor numbers for the device."
|
||||
DevicesMajMinRequired
|
||||
// DevicesErrorOnDup represents "The same `type`, `major` and `minor` SHOULD NOT be used for multiple devices."
|
||||
DevicesErrorOnDup
|
||||
// DefaultDevices represents "In addition to any devices configured with this setting, the runtime MUST also supply default devices."
|
||||
DefaultDevices
|
||||
// CgroupsPathAbsOrRel represents "The value of `cgroupsPath` MUST be either an absolute path or a relative path."
|
||||
CgroupsPathAbsOrRel
|
||||
// CgroupsAbsPathRelToMount represents "In the case of an absolute path (starting with `/`), the runtime MUST take the path to be relative to the cgroups mount point."
|
||||
CgroupsAbsPathRelToMount
|
||||
// CgroupsPathAttach represents "If the value is specified, the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`."
|
||||
CgroupsPathAttach
|
||||
// CgroupsPathError represents "Runtimes MAY consider certain `cgroupsPath` values to be invalid, and MUST generate an error if this is the case."
|
||||
CgroupsPathError
|
||||
// DevicesApplyInOrder represents "The runtime MUST apply entries in the listed order."
|
||||
DevicesApplyInOrder
|
||||
// BlkIOWeightOrLeafWeightExist represents "You MUST specify at least one of `weight` or `leafWeight` in a given entry, and MAY specify both."
|
||||
BlkIOWeightOrLeafWeightExist
|
||||
// IntelRdtPIDWrite represents "If `intelRdt` is set, the runtime MUST write the container process ID to the `<container-id>/tasks` file in a mounted `resctrl` pseudo-filesystem, using the container ID from `start` and creating the `container-id` directory if necessary."
|
||||
IntelRdtPIDWrite
|
||||
// IntelRdtNoMountedResctrlError represents "If no mounted `resctrl` pseudo-filesystem is available in the runtime mount namespace, the runtime MUST generate an error."
|
||||
IntelRdtNoMountedResctrlError
|
||||
// NotManipResctrlWithoutIntelRdt represents "If `intelRdt` is not set, the runtime MUST NOT manipulate any `resctrl` pseudo-filesystems."
|
||||
NotManipResctrlWithoutIntelRdt
|
||||
// IntelRdtL3CacheSchemaWrite represents "If `l3CacheSchema` is set, runtimes MUST write the value to the `schemata` file in the `<container-id>` directory discussed in `intelRdt`."
|
||||
IntelRdtL3CacheSchemaWrite
|
||||
// IntelRdtL3CacheSchemaNotWrite represents "If `l3CacheSchema` is not set, runtimes MUST NOT write to `schemata` files in any `resctrl` pseudo-filesystems."
|
||||
IntelRdtL3CacheSchemaNotWrite
|
||||
// SeccSyscallsNamesRequired represents "`names` MUST contain at least one entry."
|
||||
SeccSyscallsNamesRequired
|
||||
// MaskedPathsAbs represents "maskedPaths (array of strings, OPTIONAL) will mask over the provided paths inside the container so that they cannot be read. The values MUST be absolute paths in the container namespace."
|
||||
MaskedPathsAbs
|
||||
// ReadonlyPathsAbs represents "readonlyPaths (array of strings, OPTIONAL) will set the provided paths as readonly inside the container. The values MUST be absolute paths in the container namespace."
|
||||
ReadonlyPathsAbs
|
||||
)
|
||||
|
||||
var (
|
||||
defaultFilesystemsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#default-filesystems"), nil
|
||||
}
|
||||
namespacesRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#namespaces"), nil
|
||||
}
|
||||
userNamespaceMappingsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#user-namespace-mappings"), nil
|
||||
}
|
||||
devicesRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#devices"), nil
|
||||
}
|
||||
defaultDevicesRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#default-devices"), nil
|
||||
}
|
||||
cgroupsPathRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#cgroups-path"), nil
|
||||
}
|
||||
deviceWhitelistRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#device-whitelist"), nil
|
||||
}
|
||||
blockIoRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#block-io"), nil
|
||||
}
|
||||
intelrdtRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#intelrdt"), nil
|
||||
}
|
||||
seccompRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#seccomp"), nil
|
||||
}
|
||||
maskedPathsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#masked-paths"), nil
|
||||
}
|
||||
readonlyPathsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#readonly-paths"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(DefaultFilesystems, rfc2119.Should, defaultFilesystemsRef)
|
||||
register(NSPathAbs, rfc2119.Must, namespacesRef)
|
||||
register(NSProcInPath, rfc2119.Must, namespacesRef)
|
||||
register(NSPathMatchTypeError, rfc2119.Must, namespacesRef)
|
||||
register(NSNewNSWithoutPath, rfc2119.Must, namespacesRef)
|
||||
register(NSInheritWithoutType, rfc2119.Must, namespacesRef)
|
||||
register(NSErrorOnDup, rfc2119.Must, namespacesRef)
|
||||
register(UserNSMapOwnershipRO, rfc2119.Should, userNamespaceMappingsRef)
|
||||
register(DevicesAvailable, rfc2119.Must, devicesRef)
|
||||
register(DevicesFileNotMatch, rfc2119.Must, devicesRef)
|
||||
register(DevicesMajMinRequired, rfc2119.Required, devicesRef)
|
||||
register(DevicesErrorOnDup, rfc2119.Should, devicesRef)
|
||||
register(DefaultDevices, rfc2119.Must, defaultDevicesRef)
|
||||
register(CgroupsPathAbsOrRel, rfc2119.Must, cgroupsPathRef)
|
||||
register(CgroupsAbsPathRelToMount, rfc2119.Must, cgroupsPathRef)
|
||||
register(CgroupsPathAttach, rfc2119.Must, cgroupsPathRef)
|
||||
register(CgroupsPathError, rfc2119.Must, cgroupsPathRef)
|
||||
register(DevicesApplyInOrder, rfc2119.Must, deviceWhitelistRef)
|
||||
register(BlkIOWeightOrLeafWeightExist, rfc2119.Must, blockIoRef)
|
||||
register(IntelRdtPIDWrite, rfc2119.Must, intelrdtRef)
|
||||
register(IntelRdtNoMountedResctrlError, rfc2119.Must, intelrdtRef)
|
||||
register(NotManipResctrlWithoutIntelRdt, rfc2119.Must, intelrdtRef)
|
||||
register(IntelRdtL3CacheSchemaWrite, rfc2119.Must, intelrdtRef)
|
||||
register(IntelRdtL3CacheSchemaNotWrite, rfc2119.Must, intelrdtRef)
|
||||
register(SeccSyscallsNamesRequired, rfc2119.Must, seccompRef)
|
||||
register(MaskedPathsAbs, rfc2119.Must, maskedPathsRef)
|
||||
register(ReadonlyPathsAbs, rfc2119.Must, readonlyPathsRef)
|
||||
}
|
32
vendor/github.com/opencontainers/runtime-tools/specerror/config-windows.go
generated
vendored
Normal file
32
vendor/github.com/opencontainers/runtime-tools/specerror/config-windows.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// WindowsLayerFoldersRequired represents "`layerFolders` MUST contain at least one entry."
|
||||
WindowsLayerFoldersRequired Code = 0xd001 + iota
|
||||
// WindowsHyperVPresent represents "If present, the container MUST be run with Hyper-V isolation."
|
||||
WindowsHyperVPresent
|
||||
// WindowsHyperVOmit represents "If omitted, the container MUST be run as a Windows Server container."
|
||||
WindowsHyperVOmit
|
||||
)
|
||||
|
||||
var (
|
||||
layerfoldersRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-windows.md#layerfolders"), nil
|
||||
}
|
||||
hypervRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-windows.md#hyperv"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(WindowsLayerFoldersRequired, rfc2119.Must, layerfoldersRef)
|
||||
register(WindowsHyperVPresent, rfc2119.Must, hypervRef)
|
||||
register(WindowsHyperVOmit, rfc2119.Must, hypervRef)
|
||||
}
|
188
vendor/github.com/opencontainers/runtime-tools/specerror/config.go
generated
vendored
Normal file
188
vendor/github.com/opencontainers/runtime-tools/specerror/config.go
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// SpecVersionInSemVer represents "`ociVersion` (string, REQUIRED) MUST be in SemVer v2.0.0 format and specifies the version of the Open Container Initiative Runtime Specification with which the bundle complies."
|
||||
SpecVersionInSemVer Code = 0xb001 + iota
|
||||
// RootOnWindowsRequired represents "On Windows, for Windows Server Containers, this field is REQUIRED."
|
||||
RootOnWindowsRequired
|
||||
// RootOnHyperVNotSet represents "For Hyper-V Containers, this field MUST NOT be set."
|
||||
RootOnHyperVNotSet
|
||||
// RootOnNonWindowsRequired represents "On all other platforms, this field is REQUIRED."
|
||||
RootOnNonWindowsRequired
|
||||
// RootPathOnWindowsGUID represents "On Windows, `path` MUST be a volume GUID path."
|
||||
RootPathOnWindowsGUID
|
||||
// RootPathOnPosixConvention represents "The value SHOULD be the conventional `rootfs`."
|
||||
RootPathOnPosixConvention
|
||||
// RootPathExist represents "A directory MUST exist at the path declared by the field."
|
||||
RootPathExist
|
||||
// RootReadonlyImplement represents "`readonly` (bool, OPTIONAL) If true then the root filesystem MUST be read-only inside the container, defaults to false."
|
||||
RootReadonlyImplement
|
||||
// RootReadonlyOnWindowsFalse represents "* On Windows, this field MUST be omitted or false."
|
||||
RootReadonlyOnWindowsFalse
|
||||
// MountsInOrder represents "The runtime MUST mount entries in the listed order."
|
||||
MountsInOrder
|
||||
// MountsDestAbs represents "Destination of mount point: path inside container. This value MUST be an absolute path."
|
||||
MountsDestAbs
|
||||
// MountsDestOnWindowsNotNested represents "Windows: one mount destination MUST NOT be nested within another mount (e.g., c:\\foo and c:\\foo\\bar)."
|
||||
MountsDestOnWindowsNotNested
|
||||
// MountsOptionsOnWindowsROSupport represents "Windows: runtimes MUST support `ro`, mounting the filesystem read-only when `ro` is given."
|
||||
MountsOptionsOnWindowsROSupport
|
||||
// ProcRequiredAtStart represents "This property is REQUIRED when `start` is called."
|
||||
ProcRequiredAtStart
|
||||
// ProcConsoleSizeIgnore represents "Runtimes MUST ignore `consoleSize` if `terminal` is `false` or unset."
|
||||
ProcConsoleSizeIgnore
|
||||
// ProcCwdAbs represents "cwd (string, REQUIRED) is the working directory that will be set for the executable. This value MUST be an absolute path."
|
||||
ProcCwdAbs
|
||||
// ProcArgsOneEntryRequired represents "This specification extends the IEEE standard in that at least one entry is REQUIRED, and that entry is used with the same semantics as `execvp`'s *file*."
|
||||
ProcArgsOneEntryRequired
|
||||
// PosixProcRlimitsTypeGenError represents "The runtime MUST generate an error for any values which cannot be mapped to a relevant kernel interface."
|
||||
PosixProcRlimitsTypeGenError
|
||||
// PosixProcRlimitsTypeGet represents "For each entry in `rlimits`, a `getrlimit(3)` on `type` MUST succeed."
|
||||
PosixProcRlimitsTypeGet
|
||||
// PosixProcRlimitsTypeValueError represents "valid values are defined in the ... man page"
|
||||
PosixProcRlimitsTypeValueError
|
||||
// PosixProcRlimitsSoftMatchCur represents "`rlim.rlim_cur` MUST match the configured value."
|
||||
PosixProcRlimitsSoftMatchCur
|
||||
// PosixProcRlimitsHardMatchMax represents "`rlim.rlim_max` MUST match the configured value."
|
||||
PosixProcRlimitsHardMatchMax
|
||||
// PosixProcRlimitsErrorOnDup represents "If `rlimits` contains duplicated entries with same `type`, the runtime MUST generate an error."
|
||||
PosixProcRlimitsErrorOnDup
|
||||
// LinuxProcCapError represents "Any value which cannot be mapped to a relevant kernel interface MUST cause an error."
|
||||
LinuxProcCapError
|
||||
// LinuxProcOomScoreAdjSet represents "If `oomScoreAdj` is set, the runtime MUST set `oom_score_adj` to the given value."
|
||||
LinuxProcOomScoreAdjSet
|
||||
// LinuxProcOomScoreAdjNotSet represents "If `oomScoreAdj` is not set, the runtime MUST NOT change the value of `oom_score_adj`."
|
||||
LinuxProcOomScoreAdjNotSet
|
||||
// PlatformSpecConfOnWindowsSet represents "This MUST be set if the target platform of this spec is `windows`."
|
||||
PlatformSpecConfOnWindowsSet
|
||||
// PosixHooksPathAbs represents "This specification extends the IEEE standard in that `path` MUST be absolute."
|
||||
PosixHooksPathAbs
|
||||
// PosixHooksTimeoutPositive represents "If set, `timeout` MUST be greater than zero."
|
||||
PosixHooksTimeoutPositive
|
||||
// PosixHooksCalledInOrder represents "Hooks MUST be called in the listed order."
|
||||
PosixHooksCalledInOrder
|
||||
// PosixHooksStateToStdin represents "The state of the container MUST be passed to hooks over stdin so that they may do work appropriate to the current state of the container."
|
||||
PosixHooksStateToStdin
|
||||
// PrestartTiming represents "The pre-start hooks MUST be called after the `start` operation is called but before the user-specified program command is executed."
|
||||
PrestartTiming
|
||||
// PoststartTiming represents "The post-start hooks MUST be called after the user-specified process is executed but before the `start` operation returns."
|
||||
PoststartTiming
|
||||
// PoststopTiming represents "The post-stop hooks MUST be called after the container is deleted but before the `delete` operation returns."
|
||||
PoststopTiming
|
||||
// AnnotationsKeyValueMap represents "Annotations MUST be a key-value map."
|
||||
AnnotationsKeyValueMap
|
||||
// AnnotationsKeyString represents "Keys MUST be strings."
|
||||
AnnotationsKeyString
|
||||
// AnnotationsKeyRequired represents "Keys MUST NOT be an empty string."
|
||||
AnnotationsKeyRequired
|
||||
// AnnotationsKeyReversedDomain represents "Keys SHOULD be named using a reverse domain notation - e.g. `com.example.myKey`."
|
||||
AnnotationsKeyReversedDomain
|
||||
// AnnotationsKeyReservedNS represents "Keys using the `org.opencontainers` namespace are reserved and MUST NOT be used by subsequent specifications."
|
||||
AnnotationsKeyReservedNS
|
||||
// AnnotationsKeyIgnoreUnknown represents "Implementations that are reading/processing this configuration file MUST NOT generate an error if they encounter an unknown annotation key."
|
||||
AnnotationsKeyIgnoreUnknown
|
||||
// AnnotationsValueString represents "Values MUST be strings."
|
||||
AnnotationsValueString
|
||||
// ExtensibilityIgnoreUnknownProp represents "Runtimes that are reading or processing this configuration file MUST NOT generate an error if they encounter an unknown property."
|
||||
ExtensibilityIgnoreUnknownProp
|
||||
// ValidValues represents "Runtimes that are reading or processing this configuration file MUST generate an error when invalid or unsupported values are encountered."
|
||||
ValidValues
|
||||
)
|
||||
|
||||
var (
|
||||
specificationVersionRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#specification-version"), nil
|
||||
}
|
||||
rootRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#root"), nil
|
||||
}
|
||||
mountsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#mounts"), nil
|
||||
}
|
||||
processRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#process"), nil
|
||||
}
|
||||
posixProcessRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#posix-process"), nil
|
||||
}
|
||||
linuxProcessRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#linux-process"), nil
|
||||
}
|
||||
platformSpecificConfigurationRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#platform-specific-configuration"), nil
|
||||
}
|
||||
posixPlatformHooksRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#posix-platform-hooks"), nil
|
||||
}
|
||||
prestartRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#prestart"), nil
|
||||
}
|
||||
poststartRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#poststart"), nil
|
||||
}
|
||||
poststopRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#poststop"), nil
|
||||
}
|
||||
annotationsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#annotations"), nil
|
||||
}
|
||||
extensibilityRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#extensibility"), nil
|
||||
}
|
||||
validValuesRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#valid-values"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(SpecVersionInSemVer, rfc2119.Must, specificationVersionRef)
|
||||
register(RootOnWindowsRequired, rfc2119.Required, rootRef)
|
||||
register(RootOnHyperVNotSet, rfc2119.Must, rootRef)
|
||||
register(RootOnNonWindowsRequired, rfc2119.Required, rootRef)
|
||||
register(RootPathOnWindowsGUID, rfc2119.Must, rootRef)
|
||||
register(RootPathOnPosixConvention, rfc2119.Should, rootRef)
|
||||
register(RootPathExist, rfc2119.Must, rootRef)
|
||||
register(RootReadonlyImplement, rfc2119.Must, rootRef)
|
||||
register(RootReadonlyOnWindowsFalse, rfc2119.Must, rootRef)
|
||||
register(MountsInOrder, rfc2119.Must, mountsRef)
|
||||
register(MountsDestAbs, rfc2119.Must, mountsRef)
|
||||
register(MountsDestOnWindowsNotNested, rfc2119.Must, mountsRef)
|
||||
register(MountsOptionsOnWindowsROSupport, rfc2119.Must, mountsRef)
|
||||
register(ProcRequiredAtStart, rfc2119.Required, processRef)
|
||||
register(ProcConsoleSizeIgnore, rfc2119.Must, processRef)
|
||||
register(ProcCwdAbs, rfc2119.Must, processRef)
|
||||
register(ProcArgsOneEntryRequired, rfc2119.Required, processRef)
|
||||
register(PosixProcRlimitsTypeGenError, rfc2119.Must, posixProcessRef)
|
||||
register(PosixProcRlimitsTypeGet, rfc2119.Must, posixProcessRef)
|
||||
register(PosixProcRlimitsTypeValueError, rfc2119.Should, posixProcessRef)
|
||||
register(PosixProcRlimitsSoftMatchCur, rfc2119.Must, posixProcessRef)
|
||||
register(PosixProcRlimitsHardMatchMax, rfc2119.Must, posixProcessRef)
|
||||
register(PosixProcRlimitsErrorOnDup, rfc2119.Must, posixProcessRef)
|
||||
register(LinuxProcCapError, rfc2119.Must, linuxProcessRef)
|
||||
register(LinuxProcOomScoreAdjSet, rfc2119.Must, linuxProcessRef)
|
||||
register(LinuxProcOomScoreAdjNotSet, rfc2119.Must, linuxProcessRef)
|
||||
register(PlatformSpecConfOnWindowsSet, rfc2119.Must, platformSpecificConfigurationRef)
|
||||
register(PosixHooksPathAbs, rfc2119.Must, posixPlatformHooksRef)
|
||||
register(PosixHooksTimeoutPositive, rfc2119.Must, posixPlatformHooksRef)
|
||||
register(PosixHooksCalledInOrder, rfc2119.Must, posixPlatformHooksRef)
|
||||
register(PosixHooksStateToStdin, rfc2119.Must, posixPlatformHooksRef)
|
||||
register(PrestartTiming, rfc2119.Must, prestartRef)
|
||||
register(PoststartTiming, rfc2119.Must, poststartRef)
|
||||
register(PoststopTiming, rfc2119.Must, poststopRef)
|
||||
register(AnnotationsKeyValueMap, rfc2119.Must, annotationsRef)
|
||||
register(AnnotationsKeyString, rfc2119.Must, annotationsRef)
|
||||
register(AnnotationsKeyRequired, rfc2119.Must, annotationsRef)
|
||||
register(AnnotationsKeyReversedDomain, rfc2119.Should, annotationsRef)
|
||||
register(AnnotationsKeyReservedNS, rfc2119.Must, annotationsRef)
|
||||
register(AnnotationsKeyIgnoreUnknown, rfc2119.Must, annotationsRef)
|
||||
register(AnnotationsValueString, rfc2119.Must, annotationsRef)
|
||||
register(ExtensibilityIgnoreUnknownProp, rfc2119.Must, extensibilityRef)
|
||||
register(ValidValues, rfc2119.Must, validValuesRef)
|
||||
}
|
150
vendor/github.com/opencontainers/runtime-tools/specerror/error.go
generated
vendored
150
vendor/github.com/opencontainers/runtime-tools/specerror/error.go
generated
vendored
@@ -13,46 +13,13 @@ const referenceTemplate = "https://github.com/opencontainers/runtime-spec/blob/v
|
||||
|
||||
// Code represents the spec violation, enumerating both
|
||||
// configuration violations and runtime violations.
|
||||
type Code int
|
||||
type Code int64
|
||||
|
||||
const (
|
||||
// NonError represents that an input is not an error
|
||||
NonError Code = iota
|
||||
NonError Code = 0x1a001 + iota
|
||||
// NonRFCError represents that an error is not a rfc2119 error
|
||||
NonRFCError
|
||||
|
||||
// ConfigFileExistence represents the error code of 'config.json' existence test
|
||||
ConfigFileExistence
|
||||
// ArtifactsInSingleDir represents the error code of artifacts place test
|
||||
ArtifactsInSingleDir
|
||||
|
||||
// SpecVersion represents the error code of specfication version test
|
||||
SpecVersion
|
||||
|
||||
// RootOnNonHyperV represents the error code of root setting test on non hyper-v containers
|
||||
RootOnNonHyperV
|
||||
// RootOnHyperV represents the error code of root setting test on hyper-v containers
|
||||
RootOnHyperV
|
||||
// PathFormatOnWindows represents the error code of the path format test on Window
|
||||
PathFormatOnWindows
|
||||
// PathName represents the error code of the path name test
|
||||
PathName
|
||||
// PathExistence represents the error code of the path existence test
|
||||
PathExistence
|
||||
// ReadonlyFilesystem represents the error code of readonly test
|
||||
ReadonlyFilesystem
|
||||
// ReadonlyOnWindows represents the error code of readonly setting test on Windows
|
||||
ReadonlyOnWindows
|
||||
|
||||
// DefaultFilesystems represents the error code of default filesystems test
|
||||
DefaultFilesystems
|
||||
|
||||
// CreateWithID represents the error code of 'create' lifecyle test with 'id' provided
|
||||
CreateWithID
|
||||
// CreateWithUniqueID represents the error code of 'create' lifecyle test with unique 'id' provided
|
||||
CreateWithUniqueID
|
||||
// CreateNewContainer represents the error code 'create' lifecyle test that creates new container
|
||||
CreateNewContainer
|
||||
)
|
||||
|
||||
type errorTemplate struct {
|
||||
@@ -69,52 +36,24 @@ type Error struct {
|
||||
Code Code
|
||||
}
|
||||
|
||||
var (
|
||||
containerFormatRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "bundle.md#container-format"), nil
|
||||
}
|
||||
specVersionRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#specification-version"), nil
|
||||
}
|
||||
rootRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#root"), nil
|
||||
}
|
||||
defaultFSRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#default-filesystems"), nil
|
||||
}
|
||||
runtimeCreateRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#create"), nil
|
||||
}
|
||||
)
|
||||
// LevelErrors represents Errors filtered into fatal and warnings.
|
||||
type LevelErrors struct {
|
||||
// Warnings holds Errors that were below a compliance-level threshold.
|
||||
Warnings []*Error
|
||||
|
||||
var ociErrors = map[Code]errorTemplate{
|
||||
// Bundle.md
|
||||
// Container Format
|
||||
ConfigFileExistence: {Level: rfc2119.Must, Reference: containerFormatRef},
|
||||
ArtifactsInSingleDir: {Level: rfc2119.Must, Reference: containerFormatRef},
|
||||
// Error holds errors that were at or above a compliance-level
|
||||
// threshold, as well as errors that are not Errors.
|
||||
Error *multierror.Error
|
||||
}
|
||||
|
||||
// Config.md
|
||||
// Specification Version
|
||||
SpecVersion: {Level: rfc2119.Must, Reference: specVersionRef},
|
||||
// Root
|
||||
RootOnNonHyperV: {Level: rfc2119.Required, Reference: rootRef},
|
||||
RootOnHyperV: {Level: rfc2119.Must, Reference: rootRef},
|
||||
// TODO: add tests for 'PathFormatOnWindows'
|
||||
PathFormatOnWindows: {Level: rfc2119.Must, Reference: rootRef},
|
||||
PathName: {Level: rfc2119.Should, Reference: rootRef},
|
||||
PathExistence: {Level: rfc2119.Must, Reference: rootRef},
|
||||
ReadonlyFilesystem: {Level: rfc2119.Must, Reference: rootRef},
|
||||
ReadonlyOnWindows: {Level: rfc2119.Must, Reference: rootRef},
|
||||
var ociErrors = map[Code]errorTemplate{}
|
||||
|
||||
// Config-Linux.md
|
||||
// Default Filesystems
|
||||
DefaultFilesystems: {Level: rfc2119.Should, Reference: defaultFSRef},
|
||||
func register(code Code, level rfc2119.Level, ref func(versiong string) (string, error)) {
|
||||
if _, ok := ociErrors[code]; ok {
|
||||
panic(fmt.Sprintf("should not regist a same code twice: %v", code))
|
||||
}
|
||||
|
||||
// Runtime.md
|
||||
// Create
|
||||
CreateWithID: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
CreateWithUniqueID: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
CreateNewContainer: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
ociErrors[code] = errorTemplate{Level: level, Reference: ref}
|
||||
}
|
||||
|
||||
// Error returns the error message with specification reference.
|
||||
@@ -122,6 +61,34 @@ func (err *Error) Error() string {
|
||||
return err.Err.Error()
|
||||
}
|
||||
|
||||
// NewRFCError creates an rfc2119.Error referencing a spec violation.
|
||||
//
|
||||
// A version string (for the version of the spec that was violated)
|
||||
// must be set to get a working URL.
|
||||
func NewRFCError(code Code, err error, version string) (*rfc2119.Error, error) {
|
||||
template := ociErrors[code]
|
||||
reference, err2 := template.Reference(version)
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
return &rfc2119.Error{
|
||||
Level: template.Level,
|
||||
Reference: reference,
|
||||
Err: err,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewRFCErrorOrPanic creates an rfc2119.Error referencing a spec
|
||||
// violation and panics on failure. This is handy for situations
|
||||
// where you can't be bothered to check NewRFCError for failure.
|
||||
func NewRFCErrorOrPanic(code Code, err error, version string) *rfc2119.Error {
|
||||
rfcError, err2 := NewRFCError(code, err, version)
|
||||
if err2 != nil {
|
||||
panic(err2.Error())
|
||||
}
|
||||
return rfcError
|
||||
}
|
||||
|
||||
// NewError creates an Error referencing a spec violation. The error
|
||||
// can be cast to an *Error for extracting structured information
|
||||
// about the level of the violation and a reference to the violated
|
||||
@@ -130,17 +97,12 @@ func (err *Error) Error() string {
|
||||
// A version string (for the version of the spec that was violated)
|
||||
// must be set to get a working URL.
|
||||
func NewError(code Code, err error, version string) error {
|
||||
template := ociErrors[code]
|
||||
reference, err2 := template.Reference(version)
|
||||
rfcError, err2 := NewRFCError(code, err, version)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
return &Error{
|
||||
Err: rfc2119.Error{
|
||||
Level: template.Level,
|
||||
Reference: reference,
|
||||
Err: err,
|
||||
},
|
||||
Err: *rfcError,
|
||||
Code: code,
|
||||
}
|
||||
}
|
||||
@@ -168,3 +130,23 @@ func FindError(err error, code Code) Code {
|
||||
}
|
||||
return NonRFCError
|
||||
}
|
||||
|
||||
// SplitLevel removes RFC 2119 errors with a level less than 'level'
|
||||
// from the source error. If the source error is not a multierror, it
|
||||
// is returned unchanged.
|
||||
func SplitLevel(errIn error, level rfc2119.Level) (levelErrors LevelErrors, errOut error) {
|
||||
merr, ok := errIn.(*multierror.Error)
|
||||
if !ok {
|
||||
return levelErrors, errIn
|
||||
}
|
||||
for _, err := range merr.Errors {
|
||||
e, ok := err.(*Error)
|
||||
if ok && e.Err.Level < level {
|
||||
fmt.Println(e)
|
||||
levelErrors.Warnings = append(levelErrors.Warnings, e)
|
||||
continue
|
||||
}
|
||||
levelErrors.Error = multierror.Append(levelErrors.Error, err)
|
||||
}
|
||||
return levelErrors, nil
|
||||
}
|
||||
|
23
vendor/github.com/opencontainers/runtime-tools/specerror/runtime-linux.go
generated
vendored
Normal file
23
vendor/github.com/opencontainers/runtime-tools/specerror/runtime-linux.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// DefaultRuntimeLinuxSymlinks represents "While creating the container (step 2 in the lifecycle), runtimes MUST create default symlinks if the source file exists after processing `mounts`."
|
||||
DefaultRuntimeLinuxSymlinks Code = 0xf001 + iota
|
||||
)
|
||||
|
||||
var (
|
||||
devSymbolicLinksRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime-linux.md#dev-symbolic-links"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(DefaultRuntimeLinuxSymlinks, rfc2119.Must, devSymbolicLinksRef)
|
||||
}
|
179
vendor/github.com/opencontainers/runtime-tools/specerror/runtime.go
generated
vendored
Normal file
179
vendor/github.com/opencontainers/runtime-tools/specerror/runtime.go
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
package specerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rfc2119 "github.com/opencontainers/runtime-tools/error"
|
||||
)
|
||||
|
||||
// define error codes
|
||||
const (
|
||||
// EntityOperSameContainer represents "The entity using a runtime to create a container MUST be able to use the operations defined in this specification against that same container."
|
||||
EntityOperSameContainer Code = 0xe001 + iota
|
||||
// StateIDUniq represents "`id` (string, REQUIRED) is the container's ID. This MUST be unique across all containers on this host."
|
||||
StateIDUniq
|
||||
// StateNewStatus represents "Additional values MAY be defined by the runtime, however, they MUST be used to represent new runtime states not defined above."
|
||||
StateNewStatus
|
||||
// DefaultStateJSONPattern represents "When serialized in JSON, the format MUST adhere to the default pattern."
|
||||
DefaultStateJSONPattern
|
||||
// EnvCreateImplement represents "The container's runtime environment MUST be created according to the configuration in `config.json`."
|
||||
EnvCreateImplement
|
||||
// EnvCreateError represents "If the runtime is unable to create the environment specified in the `config.json`, it MUST generate an error."
|
||||
EnvCreateError
|
||||
// ProcNotRunAtResRequest represents "While the resources requested in the `config.json` MUST be created, the user-specified program (from `process`) MUST NOT be run at this time."
|
||||
ProcNotRunAtResRequest
|
||||
// ConfigUpdatesWithoutAffect represents "Any updates to `config.json` after this step MUST NOT affect the container."
|
||||
ConfigUpdatesWithoutAffect
|
||||
// PrestartHooksInvoke represents "The prestart hooks MUST be invoked by the runtime."
|
||||
PrestartHooksInvoke
|
||||
// PrestartHookFailGenError represents "If any prestart hook fails, the runtime MUST generate an error, stop the container, and continue the lifecycle at step 9."
|
||||
PrestartHookFailGenError
|
||||
// ProcImplement represents "The runtime MUST run the user-specified program, as specified by `process`."
|
||||
ProcImplement
|
||||
// PoststartHooksInvoke represents "The poststart hooks MUST be invoked by the runtime."
|
||||
PoststartHooksInvoke
|
||||
// PoststartHookFailGenWarn represents "If any poststart hook fails, the runtime MUST log a warning, but the remaining hooks and lifecycle continue as if the hook had succeeded."
|
||||
PoststartHookFailGenWarn
|
||||
// UndoCreateSteps represents "The container MUST be destroyed by undoing the steps performed during create phase (step 2)."
|
||||
UndoCreateSteps
|
||||
// PoststopHooksInvoke represents "The poststop hooks MUST be invoked by the runtime."
|
||||
PoststopHooksInvoke
|
||||
// PoststopHookFailGenWarn represents "If any poststop hook fails, the runtime MUST log a warning, but the remaining hooks and lifecycle continue as if the hook had succeeded."
|
||||
PoststopHookFailGenWarn
|
||||
// ErrorsLeaveStateUnchange represents "Unless otherwise stated, generating an error MUST leave the state of the environment as if the operation were never attempted - modulo any possible trivial ancillary changes such as logging."
|
||||
ErrorsLeaveStateUnchange
|
||||
// WarnsLeaveFlowUnchange represents "Unless otherwise stated, logging a warning does not change the flow of the operation; it MUST continue as if the warning had not been logged."
|
||||
WarnsLeaveFlowUnchange
|
||||
// DefaultOperations represents "Unless otherwise stated, runtimes MUST support the default operations."
|
||||
DefaultOperations
|
||||
// QueryWithoutIDGenError represents "This operation MUST generate an error if it is not provided the ID of a container."
|
||||
QueryWithoutIDGenError
|
||||
// QueryNonExistGenError represents "Attempting to query a container that does not exist MUST generate an error."
|
||||
QueryNonExistGenError
|
||||
// QueryStateImplement represents "This operation MUST return the state of a container as specified in the State section."
|
||||
QueryStateImplement
|
||||
// CreateWithBundlePathAndID represents "This operation MUST generate an error if it is not provided a path to the bundle and the container ID to associate with the container."
|
||||
CreateWithBundlePathAndID
|
||||
// CreateWithUniqueID represents "If the ID provided is not unique across all containers within the scope of the runtime, or is not valid in any other way, the implementation MUST generate an error and a new container MUST NOT be created."
|
||||
CreateWithUniqueID
|
||||
// CreateNewContainer represents "This operation MUST create a new container."
|
||||
CreateNewContainer
|
||||
// PropsApplyExceptProcOnCreate represents "All of the properties configured in `config.json` except for `process` MUST be applied."
|
||||
PropsApplyExceptProcOnCreate
|
||||
// ProcArgsApplyUntilStart represents `process.args` MUST NOT be applied until triggered by the `start` operation."
|
||||
ProcArgsApplyUntilStart
|
||||
// PropApplyFailGenError represents "If the runtime cannot apply a property as specified in the configuration, it MUST generate an error."
|
||||
PropApplyFailGenError
|
||||
// PropApplyFailNotCreate represents "If the runtime cannot apply a property as specified in the configuration, a new container MUST NOT be created."
|
||||
PropApplyFailNotCreate
|
||||
// StartWithoutIDGenError represents "`start` operation MUST generate an error if it is not provided the container ID."
|
||||
StartWithoutIDGenError
|
||||
// StartNotCreatedHaveNoEffect represents "Attempting to `start` a container that is not `created` MUST have no effect on the container."
|
||||
StartNotCreatedHaveNoEffect
|
||||
// StartNotCreatedGenError represents "Attempting to `start` a container that is not `created` MUST generate an error."
|
||||
StartNotCreatedGenError
|
||||
// StartProcImplement represents "`start` operation MUST run the user-specified program as specified by `process`."
|
||||
StartProcImplement
|
||||
// StartWithProcUnsetGenError represents "`start` operation MUST generate an error if `process` was not set."
|
||||
StartWithProcUnsetGenError
|
||||
// KillWithoutIDGenError represents "`kill` operation MUST generate an error if it is not provided the container ID."
|
||||
KillWithoutIDGenError
|
||||
// KillNonCreateRunHaveNoEffect represents "Attempting to send a signal to a container that is neither `created` nor `running` MUST have no effect on the container."
|
||||
KillNonCreateRunHaveNoEffect
|
||||
// KillNonCreateRunGenError represents "Attempting to send a signal to a container that is neither `created` nor `running` MUST generate an error."
|
||||
KillNonCreateRunGenError
|
||||
// KillSignalImplement represents "`kill` operation MUST send the specified signal to the container process."
|
||||
KillSignalImplement
|
||||
// DeleteWithoutIDGenError represents "`delete` operation MUST generate an error if it is not provided the container ID."
|
||||
DeleteWithoutIDGenError
|
||||
// DeleteNonStopHaveNoEffect represents "Attempting to `delete` a container that is not `stopped` MUST have no effect on the container."
|
||||
DeleteNonStopHaveNoEffect
|
||||
// DeleteNonStopGenError represents "Attempting to `delete` a container that is not `stopped` MUST generate an error."
|
||||
DeleteNonStopGenError
|
||||
// DeleteResImplement represents "Deleting a container MUST delete the resources that were created during the `create` step."
|
||||
DeleteResImplement
|
||||
// DeleteOnlyCreatedRes represents "Note that resources associated with the container, but not created by this container, MUST NOT be deleted."
|
||||
DeleteOnlyCreatedRes
|
||||
)
|
||||
|
||||
var (
|
||||
scopeOfAContainerRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#scope-of-a-container"), nil
|
||||
}
|
||||
stateRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#state"), nil
|
||||
}
|
||||
lifecycleRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#lifecycle"), nil
|
||||
}
|
||||
errorsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#errors"), nil
|
||||
}
|
||||
warningsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#warnings"), nil
|
||||
}
|
||||
operationsRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#operations"), nil
|
||||
}
|
||||
queryStateRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#query-state"), nil
|
||||
}
|
||||
createRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#create"), nil
|
||||
}
|
||||
startRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#start"), nil
|
||||
}
|
||||
killRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#kill"), nil
|
||||
}
|
||||
deleteRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#delete"), nil
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(EntityOperSameContainer, rfc2119.Must, scopeOfAContainerRef)
|
||||
register(StateIDUniq, rfc2119.Must, stateRef)
|
||||
register(StateNewStatus, rfc2119.Must, stateRef)
|
||||
register(DefaultStateJSONPattern, rfc2119.Must, stateRef)
|
||||
register(EnvCreateImplement, rfc2119.Must, lifecycleRef)
|
||||
register(EnvCreateError, rfc2119.Must, lifecycleRef)
|
||||
register(ProcNotRunAtResRequest, rfc2119.Must, lifecycleRef)
|
||||
register(ConfigUpdatesWithoutAffect, rfc2119.Must, lifecycleRef)
|
||||
register(PrestartHooksInvoke, rfc2119.Must, lifecycleRef)
|
||||
register(PrestartHookFailGenError, rfc2119.Must, lifecycleRef)
|
||||
register(ProcImplement, rfc2119.Must, lifecycleRef)
|
||||
register(PoststartHooksInvoke, rfc2119.Must, lifecycleRef)
|
||||
register(PoststartHookFailGenWarn, rfc2119.Must, lifecycleRef)
|
||||
register(UndoCreateSteps, rfc2119.Must, lifecycleRef)
|
||||
register(PoststopHooksInvoke, rfc2119.Must, lifecycleRef)
|
||||
register(PoststopHookFailGenWarn, rfc2119.Must, lifecycleRef)
|
||||
register(ErrorsLeaveStateUnchange, rfc2119.Must, errorsRef)
|
||||
register(WarnsLeaveFlowUnchange, rfc2119.Must, warningsRef)
|
||||
register(DefaultOperations, rfc2119.Must, operationsRef)
|
||||
register(QueryWithoutIDGenError, rfc2119.Must, queryStateRef)
|
||||
register(QueryNonExistGenError, rfc2119.Must, queryStateRef)
|
||||
register(QueryStateImplement, rfc2119.Must, queryStateRef)
|
||||
register(CreateWithBundlePathAndID, rfc2119.Must, createRef)
|
||||
register(CreateWithUniqueID, rfc2119.Must, createRef)
|
||||
register(CreateNewContainer, rfc2119.Must, createRef)
|
||||
register(PropsApplyExceptProcOnCreate, rfc2119.Must, createRef)
|
||||
register(ProcArgsApplyUntilStart, rfc2119.Must, createRef)
|
||||
register(PropApplyFailGenError, rfc2119.Must, createRef)
|
||||
register(PropApplyFailNotCreate, rfc2119.Must, createRef)
|
||||
register(StartWithoutIDGenError, rfc2119.Must, startRef)
|
||||
register(StartNotCreatedHaveNoEffect, rfc2119.Must, startRef)
|
||||
register(StartNotCreatedGenError, rfc2119.Must, startRef)
|
||||
register(StartProcImplement, rfc2119.Must, startRef)
|
||||
register(StartWithProcUnsetGenError, rfc2119.Must, startRef)
|
||||
register(KillWithoutIDGenError, rfc2119.Must, killRef)
|
||||
register(KillNonCreateRunHaveNoEffect, rfc2119.Must, killRef)
|
||||
register(KillNonCreateRunGenError, rfc2119.Must, killRef)
|
||||
register(KillSignalImplement, rfc2119.Must, killRef)
|
||||
register(DeleteWithoutIDGenError, rfc2119.Must, deleteRef)
|
||||
register(DeleteNonStopHaveNoEffect, rfc2119.Must, deleteRef)
|
||||
register(DeleteNonStopGenError, rfc2119.Must, deleteRef)
|
||||
register(DeleteResImplement, rfc2119.Must, deleteRef)
|
||||
register(DeleteOnlyCreatedRes, rfc2119.Must, deleteRef)
|
||||
}
|
734
vendor/github.com/opencontainers/runtime-tools/validate/validate.go
generated
vendored
734
vendor/github.com/opencontainers/runtime-tools/validate/validate.go
generated
vendored
@@ -13,40 +13,47 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
osFilepath "github.com/opencontainers/runtime-tools/filepath"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/syndtr/gocapability/capability"
|
||||
|
||||
"github.com/opencontainers/runtime-tools/specerror"
|
||||
"github.com/xeipuuv/gojsonschema"
|
||||
)
|
||||
|
||||
const specConfig = "config.json"
|
||||
|
||||
var (
|
||||
defaultRlimits = []string{
|
||||
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html
|
||||
posixRlimits = []string{
|
||||
"RLIMIT_AS",
|
||||
"RLIMIT_CORE",
|
||||
"RLIMIT_CPU",
|
||||
"RLIMIT_DATA",
|
||||
"RLIMIT_FSIZE",
|
||||
"RLIMIT_LOCKS",
|
||||
"RLIMIT_NOFILE",
|
||||
"RLIMIT_STACK",
|
||||
}
|
||||
|
||||
// https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/man2/getrlimit.2?h=man-pages-4.13
|
||||
linuxRlimits = append(posixRlimits, []string{
|
||||
"RLIMIT_MEMLOCK",
|
||||
"RLIMIT_MSGQUEUE",
|
||||
"RLIMIT_NICE",
|
||||
"RLIMIT_NOFILE",
|
||||
"RLIMIT_NPROC",
|
||||
"RLIMIT_RSS",
|
||||
"RLIMIT_RTPRIO",
|
||||
"RLIMIT_RTTIME",
|
||||
"RLIMIT_SIGPENDING",
|
||||
"RLIMIT_STACK",
|
||||
}
|
||||
}...)
|
||||
|
||||
configSchemaTemplate = "https://raw.githubusercontent.com/opencontainers/runtime-spec/v%s/schema/config-schema.json"
|
||||
)
|
||||
|
||||
// Validator represents a validator for runtime bundle
|
||||
@@ -58,23 +65,20 @@ type Validator struct {
|
||||
}
|
||||
|
||||
// NewValidator creates a Validator
|
||||
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platform string) Validator {
|
||||
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platform string) (Validator, error) {
|
||||
if hostSpecific && platform != runtime.GOOS {
|
||||
platform = runtime.GOOS
|
||||
return Validator{}, fmt.Errorf("When hostSpecific is set, platform must be same as the host platform")
|
||||
}
|
||||
return Validator{
|
||||
spec: spec,
|
||||
bundlePath: bundlePath,
|
||||
HostSpecific: hostSpecific,
|
||||
platform: platform,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewValidatorFromPath creates a Validator with specified bundle path
|
||||
func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string) (Validator, error) {
|
||||
if hostSpecific && platform != runtime.GOOS {
|
||||
platform = runtime.GOOS
|
||||
}
|
||||
if bundlePath == "" {
|
||||
return Validator{}, fmt.Errorf("bundle path shouldn't be empty")
|
||||
}
|
||||
@@ -86,7 +90,7 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string)
|
||||
configPath := filepath.Join(bundlePath, specConfig)
|
||||
content, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return Validator{}, specerror.NewError(specerror.ConfigFileExistence, err, rspec.Version)
|
||||
return Validator{}, specerror.NewError(specerror.ConfigInRootBundleDir, err, rspec.Version)
|
||||
}
|
||||
if !utf8.Valid(content) {
|
||||
return Validator{}, fmt.Errorf("%q is not encoded in UTF-8", configPath)
|
||||
@@ -96,38 +100,109 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string)
|
||||
return Validator{}, err
|
||||
}
|
||||
|
||||
return NewValidator(&spec, bundlePath, hostSpecific, platform), nil
|
||||
return NewValidator(&spec, bundlePath, hostSpecific, platform)
|
||||
}
|
||||
|
||||
// CheckAll checks all parts of runtime bundle
|
||||
func (v *Validator) CheckAll() error {
|
||||
var errs *multierror.Error
|
||||
errs = multierror.Append(errs, v.CheckJSONSchema())
|
||||
errs = multierror.Append(errs, v.CheckPlatform())
|
||||
errs = multierror.Append(errs, v.CheckRoot())
|
||||
errs = multierror.Append(errs, v.CheckMandatoryFields())
|
||||
errs = multierror.Append(errs, v.CheckSemVer())
|
||||
errs = multierror.Append(errs, v.CheckMounts())
|
||||
errs = multierror.Append(errs, v.CheckProcess())
|
||||
errs = multierror.Append(errs, v.CheckHooks())
|
||||
errs = multierror.Append(errs, v.CheckLinux())
|
||||
errs = multierror.Append(errs, v.CheckAnnotations())
|
||||
if v.platform == "linux" || v.platform == "solaris" {
|
||||
errs = multierror.Append(errs, v.CheckHooks())
|
||||
}
|
||||
|
||||
return errs.ErrorOrNil()
|
||||
}
|
||||
|
||||
// JSONSchemaURL returns the URL for the JSON Schema specifying the
|
||||
// configuration format. It consumes configSchemaTemplate, but we
|
||||
// provide it as a function to isolate consumers from inconsistent
|
||||
// naming as runtime-spec evolves.
|
||||
func JSONSchemaURL(version string) (url string, err error) {
|
||||
ver, err := semver.Parse(version)
|
||||
if err != nil {
|
||||
return "", specerror.NewError(specerror.SpecVersionInSemVer, err, rspec.Version)
|
||||
}
|
||||
configRenamedToConfigSchemaVersion, err := semver.Parse("1.0.0-rc2") // config.json became config-schema.json in 1.0.0-rc2
|
||||
if ver.Compare(configRenamedToConfigSchemaVersion) == -1 {
|
||||
return "", fmt.Errorf("unsupported configuration version (older than %s)", configRenamedToConfigSchemaVersion)
|
||||
}
|
||||
return fmt.Sprintf(configSchemaTemplate, version), nil
|
||||
}
|
||||
|
||||
// CheckJSONSchema validates the configuration against the
|
||||
// runtime-spec JSON Schema, using the version of the schema that
|
||||
// matches the configuration's declared version.
|
||||
func (v *Validator) CheckJSONSchema() (errs error) {
|
||||
logrus.Debugf("check JSON schema")
|
||||
|
||||
url, err := JSONSchemaURL(v.spec.Version)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
return errs
|
||||
}
|
||||
|
||||
schemaLoader := gojsonschema.NewReferenceLoader(url)
|
||||
documentLoader := gojsonschema.NewGoLoader(v.spec)
|
||||
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
return errs
|
||||
}
|
||||
|
||||
if !result.Valid() {
|
||||
for _, resultError := range result.Errors() {
|
||||
errs = multierror.Append(errs, errors.New(resultError.String()))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
// CheckRoot checks status of v.spec.Root
|
||||
func (v *Validator) CheckRoot() (errs error) {
|
||||
logrus.Debugf("check root")
|
||||
|
||||
if v.platform == "windows" && v.spec.Windows != nil && v.spec.Windows.HyperV != nil {
|
||||
if v.spec.Root != nil {
|
||||
if v.platform == "windows" && v.spec.Windows != nil {
|
||||
if v.spec.Windows.HyperV != nil {
|
||||
if v.spec.Root != nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.RootOnHyperVNotSet, fmt.Errorf("for Hyper-V containers, Root must not be set"), rspec.Version))
|
||||
}
|
||||
return
|
||||
} else if v.spec.Root == nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.RootOnHyperV, fmt.Errorf("for Hyper-V containers, Root must not be set"), rspec.Version))
|
||||
specerror.NewError(specerror.RootOnWindowsRequired, fmt.Errorf("on Windows, for Windows Server Containers, this field is REQUIRED"), rspec.Version))
|
||||
return
|
||||
}
|
||||
return
|
||||
} else if v.spec.Root == nil {
|
||||
} else if v.platform != "windows" && v.spec.Root == nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.RootOnNonHyperV, fmt.Errorf("for non-Hyper-V containers, Root must be set"), rspec.Version))
|
||||
specerror.NewError(specerror.RootOnNonWindowsRequired, fmt.Errorf("on all other platforms, this field is REQUIRED"), rspec.Version))
|
||||
return
|
||||
}
|
||||
|
||||
if v.platform == "windows" {
|
||||
matched, err := regexp.MatchString(`\\\\[?]\\Volume[{][a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}[}]\\`, v.spec.Root.Path)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
} else if !matched {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.RootPathOnWindowsGUID, fmt.Errorf("root.path is %q, but it MUST be a volume GUID path when target platform is windows", v.spec.Root.Path), rspec.Version))
|
||||
}
|
||||
|
||||
if v.spec.Root.Readonly {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.RootReadonlyOnWindowsFalse, fmt.Errorf("root.readonly field MUST be omitted or false when target platform is windows"), rspec.Version))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,7 +214,7 @@ func (v *Validator) CheckRoot() (errs error) {
|
||||
|
||||
if filepath.Base(v.spec.Root.Path) != "rootfs" {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.PathName, fmt.Errorf("path name should be the conventional 'rootfs'"), rspec.Version))
|
||||
specerror.NewError(specerror.RootPathOnPosixConvention, fmt.Errorf("path name should be the conventional 'rootfs'"), rspec.Version))
|
||||
}
|
||||
|
||||
var rootfsPath string
|
||||
@@ -159,10 +234,10 @@ func (v *Validator) CheckRoot() (errs error) {
|
||||
|
||||
if fi, err := os.Stat(rootfsPath); err != nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.PathExistence, fmt.Errorf("cannot find the root path %q", rootfsPath), rspec.Version))
|
||||
specerror.NewError(specerror.RootPathExist, fmt.Errorf("cannot find the root path %q", rootfsPath), rspec.Version))
|
||||
} else if !fi.IsDir() {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.PathExistence, fmt.Errorf("root.path %q is not a directory", rootfsPath), rspec.Version))
|
||||
specerror.NewError(specerror.RootPathExist, fmt.Errorf("root.path %q is not a directory", rootfsPath), rspec.Version))
|
||||
}
|
||||
|
||||
rootParent := filepath.Dir(absRootPath)
|
||||
@@ -171,13 +246,6 @@ func (v *Validator) CheckRoot() (errs error) {
|
||||
specerror.NewError(specerror.ArtifactsInSingleDir, fmt.Errorf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath), rspec.Version))
|
||||
}
|
||||
|
||||
if v.platform == "windows" {
|
||||
if v.spec.Root.Readonly {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.ReadonlyOnWindows, fmt.Errorf("root.readonly field MUST be omitted or false when target platform is windows"), rspec.Version))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -189,7 +257,7 @@ func (v *Validator) CheckSemVer() (errs error) {
|
||||
_, err := semver.Parse(version)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(specerror.SpecVersion, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
|
||||
specerror.NewError(specerror.SpecVersionInSemVer, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
|
||||
}
|
||||
if version != rspec.Version {
|
||||
errs = multierror.Append(errs, fmt.Errorf("validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version))
|
||||
@@ -202,19 +270,29 @@ func (v *Validator) CheckSemVer() (errs error) {
|
||||
func (v *Validator) CheckHooks() (errs error) {
|
||||
logrus.Debugf("check hooks")
|
||||
|
||||
if v.platform != "linux" && v.platform != "solaris" {
|
||||
errs = multierror.Append(errs, fmt.Errorf("For %q platform, the configuration structure does not support hooks", v.platform))
|
||||
return
|
||||
}
|
||||
|
||||
if v.spec.Hooks != nil {
|
||||
errs = multierror.Append(errs, checkEventHooks("pre-start", v.spec.Hooks.Prestart, v.HostSpecific))
|
||||
errs = multierror.Append(errs, checkEventHooks("post-start", v.spec.Hooks.Poststart, v.HostSpecific))
|
||||
errs = multierror.Append(errs, checkEventHooks("post-stop", v.spec.Hooks.Poststop, v.HostSpecific))
|
||||
errs = multierror.Append(errs, v.checkEventHooks("prestart", v.spec.Hooks.Prestart, v.HostSpecific))
|
||||
errs = multierror.Append(errs, v.checkEventHooks("poststart", v.spec.Hooks.Poststart, v.HostSpecific))
|
||||
errs = multierror.Append(errs, v.checkEventHooks("poststop", v.spec.Hooks.Poststop, v.HostSpecific))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func checkEventHooks(hookType string, hooks []rspec.Hook, hostSpecific bool) (errs error) {
|
||||
for _, hook := range hooks {
|
||||
if !filepath.IsAbs(hook.Path) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("the %s hook %v: is not absolute path", hookType, hook.Path))
|
||||
func (v *Validator) checkEventHooks(hookType string, hooks []rspec.Hook, hostSpecific bool) (errs error) {
|
||||
for i, hook := range hooks {
|
||||
if !osFilepath.IsAbs(v.platform, hook.Path) {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.PosixHooksPathAbs,
|
||||
fmt.Errorf("hooks.%s[%d].path %v: is not absolute path",
|
||||
hookType, i, hook.Path),
|
||||
rspec.Version))
|
||||
}
|
||||
|
||||
if hostSpecific {
|
||||
@@ -246,8 +324,12 @@ func (v *Validator) CheckProcess() (errs error) {
|
||||
}
|
||||
|
||||
process := v.spec.Process
|
||||
if !filepath.IsAbs(process.Cwd) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("cwd %q is not an absolute path", process.Cwd))
|
||||
if !osFilepath.IsAbs(v.platform, process.Cwd) {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.ProcCwdAbs,
|
||||
fmt.Errorf("cwd %q is not an absolute path", process.Cwd),
|
||||
rspec.Version))
|
||||
}
|
||||
|
||||
for _, env := range process.Env {
|
||||
@@ -257,9 +339,13 @@ func (v *Validator) CheckProcess() (errs error) {
|
||||
}
|
||||
|
||||
if len(process.Args) == 0 {
|
||||
errs = multierror.Append(errs, fmt.Errorf("args must not be empty"))
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.ProcArgsOneEntryRequired,
|
||||
fmt.Errorf("args must not be empty"),
|
||||
rspec.Version))
|
||||
} else {
|
||||
if filepath.IsAbs(process.Args[0]) {
|
||||
if filepath.IsAbs(process.Args[0]) && v.spec.Root != nil {
|
||||
var rootfsPath string
|
||||
if filepath.IsAbs(v.spec.Root.Path) {
|
||||
rootfsPath = v.spec.Root.Path
|
||||
@@ -281,12 +367,15 @@ func (v *Validator) CheckProcess() (errs error) {
|
||||
}
|
||||
}
|
||||
|
||||
if v.spec.Process.Capabilities != nil {
|
||||
errs = multierror.Append(errs, v.CheckCapabilities())
|
||||
if v.platform == "linux" || v.platform == "solaris" {
|
||||
errs = multierror.Append(errs, v.CheckRlimits())
|
||||
}
|
||||
errs = multierror.Append(errs, v.CheckRlimits())
|
||||
|
||||
if v.platform == "linux" {
|
||||
if v.spec.Process.Capabilities != nil {
|
||||
errs = multierror.Append(errs, v.CheckCapabilities())
|
||||
}
|
||||
|
||||
if len(process.ApparmorProfile) > 0 {
|
||||
profilePath := filepath.Join(v.bundlePath, v.spec.Root.Path, "/etc/apparmor.d", process.ApparmorProfile)
|
||||
_, err := os.Stat(profilePath)
|
||||
@@ -301,60 +390,61 @@ func (v *Validator) CheckProcess() (errs error) {
|
||||
|
||||
// CheckCapabilities checks v.spec.Process.Capabilities
|
||||
func (v *Validator) CheckCapabilities() (errs error) {
|
||||
if v.platform != "linux" {
|
||||
errs = multierror.Append(errs, fmt.Errorf("For %q platform, the configuration structure does not support process.capabilities", v.platform))
|
||||
return
|
||||
}
|
||||
|
||||
process := v.spec.Process
|
||||
if v.platform == "linux" {
|
||||
var effective, permitted, inheritable, ambient bool
|
||||
caps := make(map[string][]string)
|
||||
var effective, permitted, inheritable, ambient bool
|
||||
caps := make(map[string][]string)
|
||||
|
||||
for _, cap := range process.Capabilities.Bounding {
|
||||
caps[cap] = append(caps[cap], "bounding")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Effective {
|
||||
caps[cap] = append(caps[cap], "effective")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Inheritable {
|
||||
caps[cap] = append(caps[cap], "inheritable")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Permitted {
|
||||
caps[cap] = append(caps[cap], "permitted")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Ambient {
|
||||
caps[cap] = append(caps[cap], "ambient")
|
||||
for _, cap := range process.Capabilities.Bounding {
|
||||
caps[cap] = append(caps[cap], "bounding")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Effective {
|
||||
caps[cap] = append(caps[cap], "effective")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Inheritable {
|
||||
caps[cap] = append(caps[cap], "inheritable")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Permitted {
|
||||
caps[cap] = append(caps[cap], "permitted")
|
||||
}
|
||||
for _, cap := range process.Capabilities.Ambient {
|
||||
caps[cap] = append(caps[cap], "ambient")
|
||||
}
|
||||
|
||||
for capability, owns := range caps {
|
||||
if err := CapValid(capability, v.HostSpecific); err != nil {
|
||||
errs = multierror.Append(errs, fmt.Errorf("capability %q is not valid, man capabilities(7)", capability))
|
||||
}
|
||||
|
||||
for capability, owns := range caps {
|
||||
if err := CapValid(capability, v.HostSpecific); err != nil {
|
||||
errs = multierror.Append(errs, fmt.Errorf("capability %q is not valid, man capabilities(7)", capability))
|
||||
effective, permitted, ambient, inheritable = false, false, false, false
|
||||
for _, set := range owns {
|
||||
if set == "effective" {
|
||||
effective = true
|
||||
continue
|
||||
}
|
||||
|
||||
effective, permitted, ambient, inheritable = false, false, false, false
|
||||
for _, set := range owns {
|
||||
if set == "effective" {
|
||||
effective = true
|
||||
continue
|
||||
}
|
||||
if set == "inheritable" {
|
||||
inheritable = true
|
||||
continue
|
||||
}
|
||||
if set == "permitted" {
|
||||
permitted = true
|
||||
continue
|
||||
}
|
||||
if set == "ambient" {
|
||||
ambient = true
|
||||
continue
|
||||
}
|
||||
if set == "inheritable" {
|
||||
inheritable = true
|
||||
continue
|
||||
}
|
||||
if effective && !permitted {
|
||||
errs = multierror.Append(errs, fmt.Errorf("effective capability %q is not allowed, as it's not permitted", capability))
|
||||
if set == "permitted" {
|
||||
permitted = true
|
||||
continue
|
||||
}
|
||||
if ambient && !(effective && inheritable) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("ambient capability %q is not allowed, as it's not permitted and inheribate", capability))
|
||||
if set == "ambient" {
|
||||
ambient = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logrus.Warnf("process.capabilities validation not yet implemented for OS %q", v.platform)
|
||||
if effective && !permitted {
|
||||
errs = multierror.Append(errs, fmt.Errorf("effective capability %q is not allowed, as it's not permitted", capability))
|
||||
}
|
||||
if ambient && !(permitted && inheritable) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("ambient capability %q is not allowed, as it's not permitted and inheribate", capability))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
@@ -362,11 +452,21 @@ func (v *Validator) CheckCapabilities() (errs error) {
|
||||
|
||||
// CheckRlimits checks v.spec.Process.Rlimits
|
||||
func (v *Validator) CheckRlimits() (errs error) {
|
||||
if v.platform != "linux" && v.platform != "solaris" {
|
||||
errs = multierror.Append(errs, fmt.Errorf("For %q platform, the configuration structure does not support process.rlimits", v.platform))
|
||||
return
|
||||
}
|
||||
|
||||
process := v.spec.Process
|
||||
for index, rlimit := range process.Rlimits {
|
||||
for i := index + 1; i < len(process.Rlimits); i++ {
|
||||
if process.Rlimits[index].Type == process.Rlimits[i].Type {
|
||||
errs = multierror.Append(errs, fmt.Errorf("rlimit can not contain the same type %q", process.Rlimits[index].Type))
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.PosixProcRlimitsErrorOnDup,
|
||||
fmt.Errorf("rlimit can not contain the same type %q",
|
||||
process.Rlimits[index].Type),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
errs = multierror.Append(errs, v.rlimitValid(rlimit))
|
||||
@@ -430,31 +530,33 @@ func (v *Validator) CheckMounts() (errs error) {
|
||||
if supportedTypes != nil && !supportedTypes[mountA.Type] {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unsupported mount type %q", mountA.Type))
|
||||
}
|
||||
if v.platform == "windows" {
|
||||
if err := pathValid(v.platform, mountA.Destination); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
if err := pathValid(v.platform, mountA.Source); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
} else {
|
||||
if err := pathValid(v.platform, mountA.Destination); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
if !osFilepath.IsAbs(v.platform, mountA.Destination) {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.MountsDestAbs,
|
||||
fmt.Errorf("mounts[%d].destination %q is not absolute",
|
||||
i,
|
||||
mountA.Destination),
|
||||
rspec.Version))
|
||||
}
|
||||
for j, mountB := range v.spec.Mounts {
|
||||
if i == j {
|
||||
continue
|
||||
}
|
||||
// whether B.Desination is nested within A.Destination
|
||||
nested, err := nestedValid(v.platform, mountA.Destination, mountB.Destination)
|
||||
nested, err := osFilepath.IsAncestor(v.platform, mountA.Destination, mountB.Destination, ".")
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
}
|
||||
if nested {
|
||||
if v.platform == "windows" && i < j {
|
||||
errs = multierror.Append(errs, fmt.Errorf("on Windows, %v nested within %v is forbidden", mountB.Destination, mountA.Destination))
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.MountsDestOnWindowsNotNested,
|
||||
fmt.Errorf("on Windows, %v nested within %v is forbidden",
|
||||
mountB.Destination, mountA.Destination),
|
||||
rspec.Version))
|
||||
}
|
||||
if i > j {
|
||||
logrus.Warnf("%v will be covered by %v", mountB.Destination, mountA.Destination)
|
||||
@@ -475,200 +577,18 @@ func (v *Validator) CheckPlatform() (errs error) {
|
||||
return
|
||||
}
|
||||
|
||||
if v.HostSpecific && v.platform != runtime.GOOS {
|
||||
errs = multierror.Append(errs, fmt.Errorf("platform %q differs from the host %q, skipping host-specific checks", v.platform, runtime.GOOS))
|
||||
v.HostSpecific = false
|
||||
}
|
||||
|
||||
if v.platform == "windows" {
|
||||
if v.spec.Windows == nil {
|
||||
errs = multierror.Append(errs, errors.New("'windows' MUST be set when platform is `windows`"))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CheckLinux checks v.spec.Linux
|
||||
func (v *Validator) CheckLinux() (errs error) {
|
||||
logrus.Debugf("check linux")
|
||||
|
||||
if v.spec.Linux == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var nsTypeList = map[rspec.LinuxNamespaceType]struct {
|
||||
num int
|
||||
newExist bool
|
||||
}{
|
||||
rspec.PIDNamespace: {0, false},
|
||||
rspec.NetworkNamespace: {0, false},
|
||||
rspec.MountNamespace: {0, false},
|
||||
rspec.IPCNamespace: {0, false},
|
||||
rspec.UTSNamespace: {0, false},
|
||||
rspec.UserNamespace: {0, false},
|
||||
rspec.CgroupNamespace: {0, false},
|
||||
}
|
||||
|
||||
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
|
||||
ns := v.spec.Linux.Namespaces[index]
|
||||
if !namespaceValid(ns) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("namespace %v is invalid", ns))
|
||||
}
|
||||
|
||||
tmpItem := nsTypeList[ns.Type]
|
||||
tmpItem.num = tmpItem.num + 1
|
||||
if tmpItem.num > 1 {
|
||||
errs = multierror.Append(errs, fmt.Errorf("duplicated namespace %q", ns.Type))
|
||||
}
|
||||
|
||||
if len(ns.Path) == 0 {
|
||||
tmpItem.newExist = true
|
||||
}
|
||||
nsTypeList[ns.Type] = tmpItem
|
||||
}
|
||||
|
||||
if (len(v.spec.Linux.UIDMappings) > 0 || len(v.spec.Linux.GIDMappings) > 0) && !nsTypeList[rspec.UserNamespace].newExist {
|
||||
errs = multierror.Append(errs, errors.New("the UID/GID mappings requires a new User namespace to be specified as well"))
|
||||
} else if len(v.spec.Linux.UIDMappings) > 5 {
|
||||
errs = multierror.Append(errs, errors.New("only 5 UID mappings are allowed (linux kernel restriction)"))
|
||||
} else if len(v.spec.Linux.GIDMappings) > 5 {
|
||||
errs = multierror.Append(errs, errors.New("only 5 GID mappings are allowed (linux kernel restriction)"))
|
||||
}
|
||||
|
||||
for k := range v.spec.Linux.Sysctl {
|
||||
if strings.HasPrefix(k, "net.") && !nsTypeList[rspec.NetworkNamespace].newExist {
|
||||
errs = multierror.Append(errs, fmt.Errorf("sysctl %v requires a new Network namespace to be specified as well", k))
|
||||
}
|
||||
if strings.HasPrefix(k, "fs.mqueue.") {
|
||||
if !nsTypeList[rspec.MountNamespace].newExist || !nsTypeList[rspec.IPCNamespace].newExist {
|
||||
errs = multierror.Append(errs, fmt.Errorf("sysctl %v requires a new IPC namespace and Mount namespace to be specified as well", k))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if v.platform == "linux" && !nsTypeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
|
||||
errs = multierror.Append(errs, fmt.Errorf("on Linux, hostname requires a new UTS namespace to be specified as well"))
|
||||
}
|
||||
|
||||
// Linux devices validation
|
||||
devList := make(map[string]bool)
|
||||
devTypeList := make(map[string]bool)
|
||||
for index := 0; index < len(v.spec.Linux.Devices); index++ {
|
||||
device := v.spec.Linux.Devices[index]
|
||||
if !deviceValid(device) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("device %v is invalid", device))
|
||||
}
|
||||
|
||||
if _, exists := devList[device.Path]; exists {
|
||||
errs = multierror.Append(errs, fmt.Errorf("device %s is duplicated", device.Path))
|
||||
} else {
|
||||
var rootfsPath string
|
||||
if filepath.IsAbs(v.spec.Root.Path) {
|
||||
rootfsPath = v.spec.Root.Path
|
||||
} else {
|
||||
rootfsPath = filepath.Join(v.bundlePath, v.spec.Root.Path)
|
||||
}
|
||||
absPath := filepath.Join(rootfsPath, device.Path)
|
||||
fi, err := os.Stat(absPath)
|
||||
if os.IsNotExist(err) {
|
||||
devList[device.Path] = true
|
||||
} else if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
} else {
|
||||
fStat, ok := fi.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
errs = multierror.Append(errs, fmt.Errorf("cannot determine state for device %s", device.Path))
|
||||
continue
|
||||
}
|
||||
var devType string
|
||||
switch fStat.Mode & syscall.S_IFMT {
|
||||
case syscall.S_IFCHR:
|
||||
devType = "c"
|
||||
case syscall.S_IFBLK:
|
||||
devType = "b"
|
||||
case syscall.S_IFIFO:
|
||||
devType = "p"
|
||||
default:
|
||||
devType = "unmatched"
|
||||
}
|
||||
if devType != device.Type || (devType == "c" && device.Type == "u") {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
|
||||
continue
|
||||
}
|
||||
if devType != "p" {
|
||||
dev := fStat.Rdev
|
||||
major := (dev >> 8) & 0xfff
|
||||
minor := (dev & 0xff) | ((dev >> 12) & 0xfff00)
|
||||
if int64(major) != device.Major || int64(minor) != device.Minor {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.FileMode != nil {
|
||||
expectedPerm := *device.FileMode & os.ModePerm
|
||||
actualPerm := fi.Mode() & os.ModePerm
|
||||
if expectedPerm != actualPerm {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.UID != nil {
|
||||
if *device.UID != fStat.Uid {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.GID != nil {
|
||||
if *device.GID != fStat.Gid {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unify u->c when comparing, they are synonyms
|
||||
var devID string
|
||||
if device.Type == "u" {
|
||||
devID = fmt.Sprintf("%s:%d:%d", "c", device.Major, device.Minor)
|
||||
} else {
|
||||
devID = fmt.Sprintf("%s:%d:%d", device.Type, device.Major, device.Minor)
|
||||
}
|
||||
|
||||
if _, exists := devTypeList[devID]; exists {
|
||||
logrus.Warnf("type:%s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor)
|
||||
} else {
|
||||
devTypeList[devID] = true
|
||||
}
|
||||
}
|
||||
|
||||
if v.spec.Linux.Resources != nil {
|
||||
errs = multierror.Append(errs, v.CheckLinuxResources())
|
||||
}
|
||||
|
||||
if v.spec.Linux.Seccomp != nil {
|
||||
errs = multierror.Append(errs, v.CheckSeccomp())
|
||||
}
|
||||
|
||||
switch v.spec.Linux.RootfsPropagation {
|
||||
case "":
|
||||
case "private":
|
||||
case "rprivate":
|
||||
case "slave":
|
||||
case "rslave":
|
||||
case "shared":
|
||||
case "rshared":
|
||||
case "unbindable":
|
||||
case "runbindable":
|
||||
default:
|
||||
errs = multierror.Append(errs, errors.New("rootfsPropagation must be empty or one of \"private|rprivate|slave|rslave|shared|rshared|unbindable|runbindable\""))
|
||||
}
|
||||
|
||||
for _, maskedPath := range v.spec.Linux.MaskedPaths {
|
||||
if !strings.HasPrefix(maskedPath, "/") {
|
||||
errs = multierror.Append(errs, fmt.Errorf("maskedPath %v is not an absolute path", maskedPath))
|
||||
}
|
||||
}
|
||||
|
||||
for _, readonlyPath := range v.spec.Linux.ReadonlyPaths {
|
||||
if !strings.HasPrefix(readonlyPath, "/") {
|
||||
errs = multierror.Append(errs, fmt.Errorf("readonlyPath %v is not an absolute path", readonlyPath))
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.PlatformSpecConfOnWindowsSet,
|
||||
fmt.Errorf("'windows' MUST be set when platform is `windows`"),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,7 +630,7 @@ func (v *Validator) CheckLinuxResources() (errs error) {
|
||||
}
|
||||
for index := 0; index < len(r.Devices); index++ {
|
||||
switch r.Devices[index].Type {
|
||||
case "a", "b", "c":
|
||||
case "a", "b", "c", "":
|
||||
default:
|
||||
errs = multierror.Append(errs, fmt.Errorf("type of devices %s is invalid", r.Devices[index].Type))
|
||||
}
|
||||
@@ -726,44 +646,41 @@ func (v *Validator) CheckLinuxResources() (errs error) {
|
||||
}
|
||||
}
|
||||
|
||||
if r.BlockIO != nil && r.BlockIO.WeightDevice != nil {
|
||||
for i, weightDevice := range r.BlockIO.WeightDevice {
|
||||
if weightDevice.Weight == nil && weightDevice.LeafWeight == nil {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.BlkIOWeightOrLeafWeightExist,
|
||||
fmt.Errorf("linux.resources.blockIO.weightDevice[%d] specifies neither weight nor leafWeight", i),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CheckSeccomp checkc v.spec.Linux.Seccomp
|
||||
func (v *Validator) CheckSeccomp() (errs error) {
|
||||
logrus.Debugf("check linux seccomp")
|
||||
// CheckAnnotations checks v.spec.Annotations
|
||||
func (v *Validator) CheckAnnotations() (errs error) {
|
||||
logrus.Debugf("check annotations")
|
||||
|
||||
s := v.spec.Linux.Seccomp
|
||||
if !seccompActionValid(s.DefaultAction) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("seccomp defaultAction %q is invalid", s.DefaultAction))
|
||||
}
|
||||
for index := 0; index < len(s.Syscalls); index++ {
|
||||
if !syscallValid(s.Syscalls[index]) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("syscall %v is invalid", s.Syscalls[index]))
|
||||
reversedDomain := regexp.MustCompile(`^[A-Za-z]{2,6}(\.[A-Za-z0-9-]{1,63})+$`)
|
||||
for key := range v.spec.Annotations {
|
||||
if strings.HasPrefix(key, "org.opencontainers") {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.AnnotationsKeyReservedNS,
|
||||
fmt.Errorf("key %q is reserved", key),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
for index := 0; index < len(s.Architectures); index++ {
|
||||
switch s.Architectures[index] {
|
||||
case rspec.ArchX86:
|
||||
case rspec.ArchX86_64:
|
||||
case rspec.ArchX32:
|
||||
case rspec.ArchARM:
|
||||
case rspec.ArchAARCH64:
|
||||
case rspec.ArchMIPS:
|
||||
case rspec.ArchMIPS64:
|
||||
case rspec.ArchMIPS64N32:
|
||||
case rspec.ArchMIPSEL:
|
||||
case rspec.ArchMIPSEL64:
|
||||
case rspec.ArchMIPSEL64N32:
|
||||
case rspec.ArchPPC:
|
||||
case rspec.ArchPPC64:
|
||||
case rspec.ArchPPC64LE:
|
||||
case rspec.ArchS390:
|
||||
case rspec.ArchS390X:
|
||||
case rspec.ArchPARISC:
|
||||
case rspec.ArchPARISC64:
|
||||
default:
|
||||
errs = multierror.Append(errs, fmt.Errorf("seccomp architecture %q is invalid", s.Architectures[index]))
|
||||
|
||||
if !reversedDomain.MatchString(key) {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.AnnotationsKeyReversedDomain,
|
||||
fmt.Errorf("key %q SHOULD be named using a reverse domain notation", key),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -793,17 +710,6 @@ func CapValid(c string, hostSpecific bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LastCap return last cap of system
|
||||
func LastCap() capability.Cap {
|
||||
last := capability.CAP_LAST_CAP
|
||||
// hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap
|
||||
if last == capability.Cap(63) {
|
||||
last = capability.CAP_BLOCK_SUSPEND
|
||||
}
|
||||
|
||||
return last
|
||||
}
|
||||
|
||||
func envValid(env string) bool {
|
||||
items := strings.Split(env, "=")
|
||||
if len(items) < 2 {
|
||||
@@ -826,12 +732,19 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
|
||||
}
|
||||
|
||||
if v.platform == "linux" {
|
||||
for _, val := range defaultRlimits {
|
||||
for _, val := range linuxRlimits {
|
||||
if val == rlimit.Type {
|
||||
return
|
||||
}
|
||||
}
|
||||
errs = multierror.Append(errs, fmt.Errorf("rlimit type %q is invalid", rlimit.Type))
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
|
||||
} else if v.platform == "solaris" {
|
||||
for _, val := range posixRlimits {
|
||||
if val == rlimit.Type {
|
||||
return
|
||||
}
|
||||
}
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
|
||||
} else {
|
||||
logrus.Warnf("process.rlimits validation not yet implemented for platform %q", v.platform)
|
||||
}
|
||||
@@ -839,135 +752,6 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
|
||||
return
|
||||
}
|
||||
|
||||
func namespaceValid(ns rspec.LinuxNamespace) bool {
|
||||
switch ns.Type {
|
||||
case rspec.PIDNamespace:
|
||||
case rspec.NetworkNamespace:
|
||||
case rspec.MountNamespace:
|
||||
case rspec.IPCNamespace:
|
||||
case rspec.UTSNamespace:
|
||||
case rspec.UserNamespace:
|
||||
case rspec.CgroupNamespace:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
if ns.Path != "" && !filepath.IsAbs(ns.Path) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func pathValid(os, path string) error {
|
||||
if os == "windows" {
|
||||
matched, err := regexp.MatchString("^[a-zA-Z]:(\\\\[^\\\\/<>|:*?\"]+)+$", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !matched {
|
||||
return fmt.Errorf("invalid windows path %v", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if !filepath.IsAbs(path) {
|
||||
return fmt.Errorf("%v is not an absolute path", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check whether pathB is nested whithin pathA
|
||||
func nestedValid(os, pathA, pathB string) (bool, error) {
|
||||
if pathA == pathB {
|
||||
return false, nil
|
||||
}
|
||||
if pathA == "/" && pathB != "" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var sep string
|
||||
if os == "windows" {
|
||||
sep = "\\"
|
||||
} else {
|
||||
sep = "/"
|
||||
}
|
||||
|
||||
splitedPathA := strings.Split(filepath.Clean(pathA), sep)
|
||||
splitedPathB := strings.Split(filepath.Clean(pathB), sep)
|
||||
lenA := len(splitedPathA)
|
||||
lenB := len(splitedPathB)
|
||||
|
||||
if lenA > lenB {
|
||||
if (lenA - lenB) == 1 {
|
||||
// if pathA is longer but not end with separator
|
||||
if splitedPathA[lenA-1] != "" {
|
||||
return false, nil
|
||||
}
|
||||
splitedPathA = splitedPathA[:lenA-1]
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
for i, partA := range splitedPathA {
|
||||
if partA != splitedPathB[i] {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func deviceValid(d rspec.LinuxDevice) bool {
|
||||
switch d.Type {
|
||||
case "b", "c", "u":
|
||||
if d.Major <= 0 || d.Minor <= 0 {
|
||||
return false
|
||||
}
|
||||
case "p":
|
||||
if d.Major > 0 || d.Minor > 0 {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func seccompActionValid(secc rspec.LinuxSeccompAction) bool {
|
||||
switch secc {
|
||||
case rspec.ActKill:
|
||||
case rspec.ActTrap:
|
||||
case rspec.ActErrno:
|
||||
case rspec.ActTrace:
|
||||
case rspec.ActAllow:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func syscallValid(s rspec.LinuxSyscall) bool {
|
||||
if !seccompActionValid(s.Action) {
|
||||
return false
|
||||
}
|
||||
for index := 0; index < len(s.Args); index++ {
|
||||
arg := s.Args[index]
|
||||
switch arg.Op {
|
||||
case rspec.OpNotEqual:
|
||||
case rspec.OpLessThan:
|
||||
case rspec.OpLessEqual:
|
||||
case rspec.OpEqualTo:
|
||||
case rspec.OpGreaterEqual:
|
||||
case rspec.OpGreaterThan:
|
||||
case rspec.OpMaskedEqual:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isStruct(t reflect.Type) bool {
|
||||
return t.Kind() == reflect.Struct
|
||||
}
|
||||
@@ -1046,5 +830,9 @@ func checkMandatory(obj interface{}) (errs error) {
|
||||
func (v *Validator) CheckMandatoryFields() error {
|
||||
logrus.Debugf("check mandatory fields")
|
||||
|
||||
if v.spec == nil {
|
||||
return fmt.Errorf("Spec can't be nil")
|
||||
}
|
||||
|
||||
return checkMandatory(v.spec)
|
||||
}
|
||||
|
230
vendor/github.com/opencontainers/runtime-tools/validate/validate_linux.go
generated
vendored
Normal file
230
vendor/github.com/opencontainers/runtime-tools/validate/validate_linux.go
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
// +build linux
|
||||
|
||||
package validate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/syndtr/gocapability/capability"
|
||||
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
osFilepath "github.com/opencontainers/runtime-tools/filepath"
|
||||
"github.com/opencontainers/runtime-tools/specerror"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// LastCap return last cap of system
|
||||
func LastCap() capability.Cap {
|
||||
last := capability.CAP_LAST_CAP
|
||||
// hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap
|
||||
if last == capability.Cap(63) {
|
||||
last = capability.CAP_BLOCK_SUSPEND
|
||||
}
|
||||
|
||||
return last
|
||||
}
|
||||
|
||||
func deviceValid(d rspec.LinuxDevice) bool {
|
||||
switch d.Type {
|
||||
case "b", "c", "u":
|
||||
if d.Major <= 0 || d.Minor <= 0 {
|
||||
return false
|
||||
}
|
||||
case "p":
|
||||
if d.Major != 0 || d.Minor != 0 {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckLinux checks v.spec.Linux
|
||||
func (v *Validator) CheckLinux() (errs error) {
|
||||
logrus.Debugf("check linux")
|
||||
|
||||
if v.spec.Linux == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var nsTypeList = map[rspec.LinuxNamespaceType]struct {
|
||||
num int
|
||||
newExist bool
|
||||
}{
|
||||
rspec.PIDNamespace: {0, false},
|
||||
rspec.NetworkNamespace: {0, false},
|
||||
rspec.MountNamespace: {0, false},
|
||||
rspec.IPCNamespace: {0, false},
|
||||
rspec.UTSNamespace: {0, false},
|
||||
rspec.UserNamespace: {0, false},
|
||||
rspec.CgroupNamespace: {0, false},
|
||||
}
|
||||
|
||||
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
|
||||
ns := v.spec.Linux.Namespaces[index]
|
||||
if ns.Path != "" && !osFilepath.IsAbs(v.platform, ns.Path) {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.NSPathAbs, fmt.Errorf("namespace.path %q is not an absolute path", ns.Path), rspec.Version))
|
||||
}
|
||||
|
||||
tmpItem := nsTypeList[ns.Type]
|
||||
tmpItem.num = tmpItem.num + 1
|
||||
if tmpItem.num > 1 {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.NSErrorOnDup, fmt.Errorf("duplicated namespace %q", ns.Type), rspec.Version))
|
||||
}
|
||||
|
||||
if len(ns.Path) == 0 {
|
||||
tmpItem.newExist = true
|
||||
}
|
||||
nsTypeList[ns.Type] = tmpItem
|
||||
}
|
||||
|
||||
if (len(v.spec.Linux.UIDMappings) > 0 || len(v.spec.Linux.GIDMappings) > 0) && !nsTypeList[rspec.UserNamespace].newExist {
|
||||
errs = multierror.Append(errs, errors.New("the UID/GID mappings requires a new User namespace to be specified as well"))
|
||||
}
|
||||
|
||||
for k := range v.spec.Linux.Sysctl {
|
||||
if strings.HasPrefix(k, "net.") && !nsTypeList[rspec.NetworkNamespace].newExist {
|
||||
errs = multierror.Append(errs, fmt.Errorf("sysctl %v requires a new Network namespace to be specified as well", k))
|
||||
}
|
||||
if strings.HasPrefix(k, "fs.mqueue.") {
|
||||
if !nsTypeList[rspec.MountNamespace].newExist || !nsTypeList[rspec.IPCNamespace].newExist {
|
||||
errs = multierror.Append(errs, fmt.Errorf("sysctl %v requires a new IPC namespace and Mount namespace to be specified as well", k))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if v.platform == "linux" && !nsTypeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
|
||||
errs = multierror.Append(errs, fmt.Errorf("on Linux, hostname requires a new UTS namespace to be specified as well"))
|
||||
}
|
||||
|
||||
// Linux devices validation
|
||||
devList := make(map[string]bool)
|
||||
devTypeList := make(map[string]bool)
|
||||
for index := 0; index < len(v.spec.Linux.Devices); index++ {
|
||||
device := v.spec.Linux.Devices[index]
|
||||
if !deviceValid(device) {
|
||||
errs = multierror.Append(errs, fmt.Errorf("device %v is invalid", device))
|
||||
}
|
||||
|
||||
if _, exists := devList[device.Path]; exists {
|
||||
errs = multierror.Append(errs, fmt.Errorf("device %s is duplicated", device.Path))
|
||||
} else {
|
||||
var rootfsPath string
|
||||
if filepath.IsAbs(v.spec.Root.Path) {
|
||||
rootfsPath = v.spec.Root.Path
|
||||
} else {
|
||||
rootfsPath = filepath.Join(v.bundlePath, v.spec.Root.Path)
|
||||
}
|
||||
absPath := filepath.Join(rootfsPath, device.Path)
|
||||
fi, err := os.Stat(absPath)
|
||||
if os.IsNotExist(err) {
|
||||
devList[device.Path] = true
|
||||
} else if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
} else {
|
||||
fStat, ok := fi.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesAvailable,
|
||||
fmt.Errorf("cannot determine state for device %s", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
var devType string
|
||||
switch fStat.Mode & syscall.S_IFMT {
|
||||
case syscall.S_IFCHR:
|
||||
devType = "c"
|
||||
case syscall.S_IFBLK:
|
||||
devType = "b"
|
||||
case syscall.S_IFIFO:
|
||||
devType = "p"
|
||||
default:
|
||||
devType = "unmatched"
|
||||
}
|
||||
if devType != device.Type || (devType == "c" && device.Type == "u") {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
|
||||
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
if devType != "p" {
|
||||
dev := fStat.Rdev
|
||||
major := (dev >> 8) & 0xfff
|
||||
minor := (dev & 0xff) | ((dev >> 12) & 0xfff00)
|
||||
if int64(major) != device.Major || int64(minor) != device.Minor {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
|
||||
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.FileMode != nil {
|
||||
expectedPerm := *device.FileMode & os.ModePerm
|
||||
actualPerm := fi.Mode() & os.ModePerm
|
||||
if expectedPerm != actualPerm {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
|
||||
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.UID != nil {
|
||||
if *device.UID != fStat.Uid {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
|
||||
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if device.GID != nil {
|
||||
if *device.GID != fStat.Gid {
|
||||
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
|
||||
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unify u->c when comparing, they are synonyms
|
||||
var devID string
|
||||
if device.Type == "u" {
|
||||
devID = fmt.Sprintf("%s:%d:%d", "c", device.Major, device.Minor)
|
||||
} else {
|
||||
devID = fmt.Sprintf("%s:%d:%d", device.Type, device.Major, device.Minor)
|
||||
}
|
||||
|
||||
if _, exists := devTypeList[devID]; exists {
|
||||
logrus.Warnf("%v", specerror.NewError(specerror.DevicesErrorOnDup, fmt.Errorf("type:%s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor), rspec.Version))
|
||||
} else {
|
||||
devTypeList[devID] = true
|
||||
}
|
||||
}
|
||||
|
||||
if v.spec.Linux.Resources != nil {
|
||||
errs = multierror.Append(errs, v.CheckLinuxResources())
|
||||
}
|
||||
|
||||
for _, maskedPath := range v.spec.Linux.MaskedPaths {
|
||||
if !strings.HasPrefix(maskedPath, "/") {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.MaskedPathsAbs,
|
||||
fmt.Errorf("maskedPath %v is not an absolute path", maskedPath),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
|
||||
for _, readonlyPath := range v.spec.Linux.ReadonlyPaths {
|
||||
if !strings.HasPrefix(readonlyPath, "/") {
|
||||
errs = multierror.Append(errs,
|
||||
specerror.NewError(
|
||||
specerror.ReadonlyPathsAbs,
|
||||
fmt.Errorf("readonlyPath %v is not an absolute path", readonlyPath),
|
||||
rspec.Version))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
17
vendor/github.com/opencontainers/runtime-tools/validate/validate_unsupported.go
generated
vendored
Normal file
17
vendor/github.com/opencontainers/runtime-tools/validate/validate_unsupported.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// +build !linux
|
||||
|
||||
package validate
|
||||
|
||||
import (
|
||||
"github.com/syndtr/gocapability/capability"
|
||||
)
|
||||
|
||||
// LastCap return last cap of system
|
||||
func LastCap() capability.Cap {
|
||||
return capability.Cap(-1)
|
||||
}
|
||||
|
||||
// CheckLinux is a noop on this platform
|
||||
func (v *Validator) CheckLinux() (errs error) {
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user