|
|
|
|
@@ -180,6 +180,7 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
|
|
|
|
|
func TestContainerCapabilities(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
for desc, test := range map[string]struct {
|
|
|
|
|
capability *runtime.Capability
|
|
|
|
|
@@ -229,7 +230,7 @@ func TestContainerCapabilities(t *testing.T) {
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
|
|
|
|
|
containerConfig.Linux.SecurityContext.Capabilities = test.capability
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
for _, include := range test.includes {
|
|
|
|
|
@@ -251,13 +252,14 @@ func TestContainerCapabilities(t *testing.T) {
|
|
|
|
|
func TestContainerSpecTty(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
for _, tty := range []bool{true, false} {
|
|
|
|
|
containerConfig.Tty = tty
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
assert.Equal(t, tty, spec.Process.Terminal)
|
|
|
|
|
@@ -272,6 +274,7 @@ func TestContainerSpecTty(t *testing.T) {
|
|
|
|
|
func TestContainerSpecDefaultPath(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
expectedDefault := "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
@@ -283,7 +286,7 @@ func TestContainerSpecDefaultPath(t *testing.T) {
|
|
|
|
|
imageConfig.Env = append(imageConfig.Env, pathenv)
|
|
|
|
|
expected = pathenv
|
|
|
|
|
}
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
assert.Contains(t, spec.Process.Env, expected)
|
|
|
|
|
@@ -293,13 +296,14 @@ func TestContainerSpecDefaultPath(t *testing.T) {
|
|
|
|
|
func TestContainerSpecReadonlyRootfs(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
for _, readonly := range []bool{true, false} {
|
|
|
|
|
containerConfig.Linux.SecurityContext.ReadonlyRootfs = readonly
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
assert.Equal(t, readonly, spec.Root.Readonly)
|
|
|
|
|
@@ -309,6 +313,7 @@ func TestContainerSpecReadonlyRootfs(t *testing.T) {
|
|
|
|
|
func TestContainerSpecWithExtraMounts(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
@@ -337,7 +342,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
|
|
|
|
|
Readonly: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, extraMounts, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, extraMounts, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
var mounts, sysMounts, devMounts []runtimespec.Mount
|
|
|
|
|
@@ -369,6 +374,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
|
|
|
|
|
func TestContainerAndSandboxPrivileged(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
@@ -404,7 +410,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) {
|
|
|
|
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
|
|
|
|
Privileged: test.sandboxPrivileged,
|
|
|
|
|
}
|
|
|
|
|
_, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
_, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
if test.expectError {
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
} else {
|
|
|
|
|
@@ -568,6 +574,7 @@ func TestPrivilegedBindMount(t *testing.T) {
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
|
|
|
|
|
@@ -591,7 +598,7 @@ func TestPrivilegedBindMount(t *testing.T) {
|
|
|
|
|
containerConfig.Linux.SecurityContext.Privileged = test.privileged
|
|
|
|
|
sandboxConfig.Linux.SecurityContext.Privileged = test.privileged
|
|
|
|
|
|
|
|
|
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
if test.expectedSysFSRO {
|
|
|
|
|
@@ -717,6 +724,7 @@ func TestPidNamespace(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
@@ -747,7 +755,7 @@ func TestPidNamespace(t *testing.T) {
|
|
|
|
|
} {
|
|
|
|
|
t.Logf("TestCase %q", desc)
|
|
|
|
|
containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS}
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Contains(t, spec.Linux.Namespaces, test.expected)
|
|
|
|
|
}
|
|
|
|
|
@@ -757,11 +765,12 @@ func TestNoDefaultRunMount(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
for _, mount := range spec.Mounts {
|
|
|
|
|
assert.NotEqual(t, "/run", mount.Destination)
|
|
|
|
|
@@ -903,6 +912,7 @@ func TestGenerateApparmorSpecOpts(t *testing.T) {
|
|
|
|
|
func TestMaskedAndReadonlyPaths(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
@@ -977,7 +987,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
|
|
|
|
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
|
|
|
|
Privileged: test.privileged,
|
|
|
|
|
}
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
if !test.privileged { // specCheck presumes an unprivileged container
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
@@ -990,6 +1000,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
|
|
|
|
|
func TestHostname(t *testing.T) {
|
|
|
|
|
testID := "test-id"
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
@@ -1023,7 +1034,7 @@ func TestHostname(t *testing.T) {
|
|
|
|
|
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
|
|
|
|
NamespaceOptions: &runtime.NamespaceOption{Network: test.networkNs},
|
|
|
|
|
}
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(testID, testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
specCheck(t, testID, testSandboxID, testPid, spec)
|
|
|
|
|
assert.Contains(t, spec.Process.Env, test.expectedEnv)
|
|
|
|
|
@@ -1035,7 +1046,7 @@ func TestDisableCgroup(t *testing.T) {
|
|
|
|
|
ociRuntime := config.Runtime{}
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
c.config.DisableCgroup = true
|
|
|
|
|
spec, err := c.containerSpec("test-id", "sandbox-id", 1234, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec("test-id", "sandbox-id", 1234, "", "container-name", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
t.Log("resource limit should not be set")
|
|
|
|
|
@@ -1121,6 +1132,7 @@ func TestPrivilegedDevices(t *testing.T) {
|
|
|
|
|
testPid := uint32(1234)
|
|
|
|
|
c := newTestCRIService()
|
|
|
|
|
testSandboxID := "sandbox-id"
|
|
|
|
|
testContainerName := "container-name"
|
|
|
|
|
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
|
|
|
|
|
|
|
|
|
for desc, test := range map[string]struct {
|
|
|
|
|
@@ -1157,7 +1169,7 @@ func TestPrivilegedDevices(t *testing.T) {
|
|
|
|
|
ociRuntime := config.Runtime{
|
|
|
|
|
PrivilegedWithoutHostDevices: test.privilegedWithoutHostDevices,
|
|
|
|
|
}
|
|
|
|
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
spec, err := c.containerSpec(t.Name(), testSandboxID, testPid, "", testContainerName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
hostDevices, err := devices.HostDevices()
|
|
|
|
|
|