daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
//go:build !windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2022-08-31 20:12:30 +00:00
|
|
|
"io/fs"
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
"os"
|
2022-08-31 20:12:30 +00:00
|
|
|
"strings"
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-12-21 17:41:00 +00:00
|
|
|
"dario.cat/mergo"
|
2023-06-09 15:04:28 +00:00
|
|
|
runtimeoptions_v1 "github.com/containerd/containerd/pkg/runtimeoptions/v1"
|
2023-02-17 19:12:06 +00:00
|
|
|
"github.com/containerd/containerd/plugin"
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
|
2023-07-03 11:14:14 +00:00
|
|
|
"github.com/docker/docker/api/types/system"
|
|
|
|
"github.com/docker/docker/daemon/config"
|
|
|
|
"github.com/docker/docker/errdefs"
|
2023-07-11 14:26:28 +00:00
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
"google.golang.org/protobuf/proto"
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
)
|
|
|
|
|
2022-08-31 21:24:22 +00:00
|
|
|
func TestSetupRuntimes(t *testing.T) {
|
2023-02-17 19:12:06 +00:00
|
|
|
cases := []struct {
|
|
|
|
name string
|
2022-08-31 21:24:22 +00:00
|
|
|
config *config.Config
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr string
|
|
|
|
}{
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "Empty",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "either a runtimeType or a path must be configured",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "ArgsOnly",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {Args: []string{"foo", "bar"}},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "either a runtimeType or a path must be configured",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "OptionsOnly",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {Options: map[string]interface{}{"hello": "world"}},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "either a runtimeType or a path must be configured",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "PathAndType",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {Path: "/bin/true", Type: "io.containerd.runsc.v1"},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "cannot configure both",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "PathAndOptions",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {Path: "/bin/true", Options: map[string]interface{}{"a": "b"}},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "options cannot be used with a path runtime",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 21:24:22 +00:00
|
|
|
name: "TypeAndArgs",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {Type: "io.containerd.runsc.v1", Args: []string{"--version"}},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
expectErr: "args cannot be used with a runtimeType runtime",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PathArgsOptions",
|
2022-08-31 21:24:22 +00:00
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"--version"},
|
|
|
|
Options: map[string]interface{}{"hmm": 3},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
expectErr: "options cannot be used with a path runtime",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "TypeOptionsArgs",
|
2022-08-31 21:24:22 +00:00
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {
|
|
|
|
Type: "io.containerd.kata.v2",
|
|
|
|
Options: map[string]interface{}{"a": "b"},
|
|
|
|
Args: []string{"--help"},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
expectErr: "args cannot be used with a runtimeType runtime",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PathArgsTypeOptions",
|
2022-08-31 21:24:22 +00:00
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"myruntime": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"foo"},
|
|
|
|
Type: "io.containerd.runsc.v1",
|
|
|
|
Options: map[string]interface{}{"a": "b"},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
expectErr: "cannot configure both",
|
|
|
|
},
|
2022-08-31 21:24:22 +00:00
|
|
|
{
|
|
|
|
name: "CannotOverrideStockRuntime",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
config.StockRuntimeName: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectErr: `runtime name 'runc' is reserved`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "SetStockRuntimeAsDefault",
|
|
|
|
config: &config.Config{
|
|
|
|
CommonConfig: config.CommonConfig{
|
|
|
|
DefaultRuntime: config.StockRuntimeName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "SetLinuxRuntimeAsDefault",
|
|
|
|
config: &config.Config{
|
|
|
|
CommonConfig: config.CommonConfig{
|
|
|
|
DefaultRuntime: linuxV2RuntimeName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "CannotSetBogusRuntimeAsDefault",
|
|
|
|
config: &config.Config{
|
|
|
|
CommonConfig: config.CommonConfig{
|
|
|
|
DefaultRuntime: "notdefined",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectErr: "specified default runtime 'notdefined' does not exist",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "SetDefinedRuntimeAsDefault",
|
|
|
|
config: &config.Config{
|
2023-07-03 11:14:14 +00:00
|
|
|
Runtimes: map[string]system.Runtime{
|
2022-08-31 21:24:22 +00:00
|
|
|
"some-runtime": {
|
|
|
|
Path: "/usr/local/bin/file-not-found",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CommonConfig: config.CommonConfig{
|
|
|
|
DefaultRuntime: "some-runtime",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
}
|
2022-08-31 21:24:22 +00:00
|
|
|
for _, tc := range cases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-02-17 19:12:06 +00:00
|
|
|
cfg, err := config.New()
|
|
|
|
assert.NilError(t, err)
|
2022-08-17 21:13:49 +00:00
|
|
|
cfg.Root = t.TempDir()
|
2022-08-31 21:24:22 +00:00
|
|
|
assert.NilError(t, mergo.Merge(cfg, tc.config, mergo.WithOverride))
|
2022-08-31 20:12:30 +00:00
|
|
|
assert.Assert(t, initRuntimesDir(cfg))
|
2023-02-17 19:12:06 +00:00
|
|
|
|
2022-08-31 20:12:30 +00:00
|
|
|
_, err = setupRuntimes(cfg)
|
2022-08-31 21:24:22 +00:00
|
|
|
if tc.expectErr == "" {
|
|
|
|
assert.NilError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.ErrorContains(t, err, tc.expectErr)
|
|
|
|
}
|
2023-02-17 19:12:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
func TestGetRuntime(t *testing.T) {
|
|
|
|
// Configured runtimes can have any arbitrary name, including names
|
|
|
|
// which would not be allowed as implicit runtime names. Explicit takes
|
|
|
|
// precedence over implicit.
|
2023-02-17 19:12:06 +00:00
|
|
|
const configuredRtName = "my/custom.runtime.v1"
|
2023-07-03 11:14:14 +00:00
|
|
|
configuredRuntime := system.Runtime{Path: "/bin/true"}
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
|
2023-02-17 19:12:06 +00:00
|
|
|
const rtWithArgsName = "withargs"
|
2023-07-03 11:14:14 +00:00
|
|
|
rtWithArgs := system.Runtime{
|
2023-02-17 19:12:06 +00:00
|
|
|
Path: "/bin/false",
|
|
|
|
Args: []string{"--version"},
|
|
|
|
}
|
|
|
|
|
|
|
|
const shimWithOptsName = "shimwithopts"
|
2023-07-03 11:14:14 +00:00
|
|
|
shimWithOpts := system.Runtime{
|
2023-02-17 19:12:06 +00:00
|
|
|
Type: plugin.RuntimeRuncV2,
|
|
|
|
Options: map[string]interface{}{"IoUid": 42},
|
|
|
|
}
|
|
|
|
|
|
|
|
const shimAliasName = "wasmedge"
|
2023-07-03 11:14:14 +00:00
|
|
|
shimAlias := system.Runtime{Type: "io.containerd.wasmedge.v1"}
|
2023-02-17 19:12:06 +00:00
|
|
|
|
|
|
|
const configuredShimByPathName = "shimwithpath"
|
2023-07-03 11:14:14 +00:00
|
|
|
configuredShimByPath := system.Runtime{Type: "/path/to/my/shim"}
|
2023-02-17 19:12:06 +00:00
|
|
|
|
2023-06-09 15:04:28 +00:00
|
|
|
// A runtime configured with the generic 'runtimeoptions/v1.Options' shim configuration options.
|
|
|
|
// https://gvisor.dev/docs/user_guide/containerd/configuration/#:~:text=to%20the%20shim.-,Containerd%201.3%2B,-Starting%20in%201.3
|
|
|
|
const gvisorName = "gvisor"
|
2023-07-03 11:14:14 +00:00
|
|
|
gvisorRuntime := system.Runtime{
|
2023-06-09 15:04:28 +00:00
|
|
|
Type: "io.containerd.runsc.v1",
|
|
|
|
Options: map[string]interface{}{
|
|
|
|
"TypeUrl": "io.containerd.runsc.v1.options",
|
|
|
|
"ConfigPath": "/path/to/runsc.toml",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:11:08 +00:00
|
|
|
cfg, err := config.New()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2022-08-17 21:13:49 +00:00
|
|
|
cfg.Root = t.TempDir()
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes = map[string]system.Runtime{
|
2023-02-17 19:12:06 +00:00
|
|
|
configuredRtName: configuredRuntime,
|
|
|
|
rtWithArgsName: rtWithArgs,
|
|
|
|
shimWithOptsName: shimWithOpts,
|
|
|
|
shimAliasName: shimAlias,
|
|
|
|
configuredShimByPathName: configuredShimByPath,
|
2023-06-09 15:04:28 +00:00
|
|
|
gvisorName: gvisorRuntime,
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
}
|
2022-08-31 20:12:30 +00:00
|
|
|
assert.NilError(t, initRuntimesDir(cfg))
|
|
|
|
runtimes, err := setupRuntimes(cfg)
|
|
|
|
assert.NilError(t, err)
|
2022-08-17 21:13:49 +00:00
|
|
|
|
2022-08-31 20:12:30 +00:00
|
|
|
stockRuntime, ok := runtimes.configured[config.StockRuntimeName]
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
assert.Assert(t, ok, "stock runtime could not be found (test needs to be updated)")
|
2022-08-31 20:12:30 +00:00
|
|
|
stockRuntime.Features = nil
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
|
2023-07-11 14:26:28 +00:00
|
|
|
configdOpts := proto.Clone(stockRuntime.Opts.(*v2runcoptions.Options)).(*v2runcoptions.Options)
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
configdOpts.BinaryName = configuredRuntime.Path
|
2022-08-31 20:12:30 +00:00
|
|
|
wantConfigdRuntime := &shimConfig{
|
|
|
|
Shim: stockRuntime.Shim,
|
2023-07-11 14:26:28 +00:00
|
|
|
Opts: configdOpts,
|
2022-08-31 20:12:30 +00:00
|
|
|
}
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
name, runtime string
|
2022-08-31 20:12:30 +00:00
|
|
|
want *shimConfig
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
}{
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "StockRuntime",
|
|
|
|
runtime: config.StockRuntimeName,
|
|
|
|
want: stockRuntime,
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "ShimName",
|
|
|
|
runtime: "io.containerd.my-shim.v42",
|
|
|
|
want: &shimConfig{Shim: "io.containerd.my-shim.v42"},
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// containerd is pretty loose about the format of runtime names. Perhaps too
|
|
|
|
// loose. The only requirements are that the name contain a dot and (depending
|
|
|
|
// on the containerd version) not start with a dot. It does not enforce any
|
|
|
|
// particular format of the dot-delimited components of the name.
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "VersionlessShimName",
|
|
|
|
runtime: "io.containerd.my-shim",
|
|
|
|
want: &shimConfig{Shim: "io.containerd.my-shim"},
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "IllformedShimName",
|
|
|
|
runtime: "myshim",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "EmptyString",
|
|
|
|
runtime: "",
|
2022-08-31 21:24:22 +00:00
|
|
|
want: stockRuntime,
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PathToShim",
|
|
|
|
runtime: "/path/to/runc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PathToShimName",
|
|
|
|
runtime: "/path/to/io.containerd.runc.v2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "RelPathToShim",
|
|
|
|
runtime: "my/io.containerd.runc.v2",
|
|
|
|
},
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "ConfiguredRuntime",
|
|
|
|
runtime: configuredRtName,
|
|
|
|
want: wantConfigdRuntime,
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "ShimWithOpts",
|
|
|
|
runtime: shimWithOptsName,
|
|
|
|
want: &shimConfig{
|
|
|
|
Shim: shimWithOpts.Type,
|
|
|
|
Opts: &v2runcoptions.Options{IoUid: 42},
|
|
|
|
},
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "ShimAlias",
|
|
|
|
runtime: shimAliasName,
|
|
|
|
want: &shimConfig{Shim: shimAlias.Type},
|
2023-02-17 19:12:06 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-31 20:12:30 +00:00
|
|
|
name: "ConfiguredShimByPath",
|
|
|
|
runtime: configuredShimByPathName,
|
|
|
|
want: &shimConfig{Shim: configuredShimByPath.Type},
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
},
|
2023-06-09 15:04:28 +00:00
|
|
|
{
|
|
|
|
name: "ConfiguredShimWithRuntimeoptionsShimConfig",
|
|
|
|
runtime: gvisorName,
|
|
|
|
want: &shimConfig{
|
|
|
|
Shim: gvisorRuntime.Type,
|
|
|
|
Opts: &runtimeoptions_v1.Options{
|
|
|
|
TypeUrl: gvisorRuntime.Options["TypeUrl"].(string),
|
|
|
|
ConfigPath: gvisorRuntime.Options["ConfigPath"].(string),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
} {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-08-31 20:12:30 +00:00
|
|
|
shim, opts, err := runtimes.Get(tt.runtime)
|
|
|
|
if tt.want != nil {
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
assert.Check(t, err)
|
2022-08-31 20:12:30 +00:00
|
|
|
got := &shimConfig{Shim: shim, Opts: opts}
|
2023-07-11 14:26:28 +00:00
|
|
|
assert.Check(t, is.DeepEqual(got, tt.want,
|
|
|
|
cmpopts.IgnoreUnexported(runtimeoptions_v1.Options{}),
|
|
|
|
cmpopts.IgnoreUnexported(v2runcoptions.Options{}),
|
|
|
|
))
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
} else {
|
2022-08-31 20:12:30 +00:00
|
|
|
assert.Check(t, is.Equal(shim, ""))
|
|
|
|
assert.Check(t, is.Nil(opts))
|
|
|
|
assert.Check(t, errdefs.IsInvalidParameter(err), "[%T] %[1]v", err)
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-08-31 20:12:30 +00:00
|
|
|
t.Run("RuntimeWithArgs", func(t *testing.T) {
|
|
|
|
shim, opts, err := runtimes.Get(rtWithArgsName)
|
|
|
|
assert.Check(t, err)
|
|
|
|
assert.Check(t, is.Equal(shim, stockRuntime.Shim))
|
|
|
|
runcopts, ok := opts.(*v2runcoptions.Options)
|
|
|
|
if assert.Check(t, ok, "runtimes.Get() opts = type %T, want *v2runcoptions.Options", opts) {
|
|
|
|
wrapper, err := os.ReadFile(runcopts.BinaryName)
|
|
|
|
if assert.Check(t, err) {
|
|
|
|
assert.Check(t, is.Contains(string(wrapper),
|
|
|
|
strings.Join(append([]string{rtWithArgs.Path}, rtWithArgs.Args...), " ")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRuntime_PreflightCheck(t *testing.T) {
|
|
|
|
cfg, err := config.New()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
cfg.Root = t.TempDir()
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes = map[string]system.Runtime{
|
2022-08-31 20:12:30 +00:00
|
|
|
"path-only": {
|
|
|
|
Path: "/usr/local/bin/file-not-found",
|
|
|
|
},
|
|
|
|
"with-args": {
|
|
|
|
Path: "/usr/local/bin/file-not-found",
|
|
|
|
Args: []string{"--arg"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.NilError(t, initRuntimesDir(cfg))
|
|
|
|
runtimes, err := setupRuntimes(cfg)
|
|
|
|
assert.NilError(t, err, "runtime paths should not be validated during setupRuntimes()")
|
|
|
|
|
|
|
|
t.Run("PathOnly", func(t *testing.T) {
|
|
|
|
_, _, err := runtimes.Get("path-only")
|
|
|
|
assert.NilError(t, err, "custom runtimes without wrapper scripts should not have pre-flight checks")
|
|
|
|
})
|
|
|
|
t.Run("WithArgs", func(t *testing.T) {
|
|
|
|
_, _, err := runtimes.Get("with-args")
|
|
|
|
assert.ErrorIs(t, err, fs.ErrNotExist)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestRuntimeWrapping checks that reloading runtime config does not delete or
|
|
|
|
// modify existing wrapper scripts, which could break lifecycle management of
|
|
|
|
// existing containers.
|
|
|
|
func TestRuntimeWrapping(t *testing.T) {
|
|
|
|
cfg, err := config.New()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
cfg.Root = t.TempDir()
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes = map[string]system.Runtime{
|
2022-08-31 20:12:30 +00:00
|
|
|
"change-args": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
"dupe": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
"change-path": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"baz"},
|
|
|
|
},
|
|
|
|
"drop-args": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"some", "arguments"},
|
|
|
|
},
|
|
|
|
"goes-away": {
|
|
|
|
Path: "/bin/true",
|
|
|
|
Args: []string{"bye"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.NilError(t, initRuntimesDir(cfg))
|
|
|
|
rt, err := setupRuntimes(cfg)
|
|
|
|
assert.Check(t, err)
|
|
|
|
|
|
|
|
type WrapperInfo struct{ BinaryName, Content string }
|
|
|
|
wrappers := make(map[string]WrapperInfo)
|
|
|
|
for name := range cfg.Runtimes {
|
|
|
|
_, opts, err := rt.Get(name)
|
|
|
|
if assert.Check(t, err, "rt.Get(%q)", name) {
|
|
|
|
binary := opts.(*v2runcoptions.Options).BinaryName
|
|
|
|
content, err := os.ReadFile(binary)
|
|
|
|
assert.Check(t, err, "could not read wrapper script contents for runtime %q", binary)
|
|
|
|
wrappers[name] = WrapperInfo{BinaryName: binary, Content: string(content)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes["change-args"] = system.Runtime{
|
2022-08-31 20:12:30 +00:00
|
|
|
Path: cfg.Runtimes["change-args"].Path,
|
|
|
|
Args: []string{"baz", "quux"},
|
|
|
|
}
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes["change-path"] = system.Runtime{
|
2022-08-31 20:12:30 +00:00
|
|
|
Path: "/bin/false",
|
|
|
|
Args: cfg.Runtimes["change-path"].Args,
|
|
|
|
}
|
2023-07-03 11:14:14 +00:00
|
|
|
cfg.Runtimes["drop-args"] = system.Runtime{
|
2022-08-31 20:12:30 +00:00
|
|
|
Path: cfg.Runtimes["drop-args"].Path,
|
|
|
|
}
|
|
|
|
delete(cfg.Runtimes, "goes-away")
|
|
|
|
|
|
|
|
_, err = setupRuntimes(cfg)
|
|
|
|
assert.Check(t, err)
|
|
|
|
|
|
|
|
for name, info := range wrappers {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
content, err := os.ReadFile(info.BinaryName)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, info.Content, string(content))
|
|
|
|
})
|
|
|
|
}
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
}
|