This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop effective and permitted cap for non-root user.
Signed-off-by: Lantao Liu <[email protected]>
- Loading branch information
1 parent
cf0e0a1
commit bdbc2ab
Showing
6 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM busybox | ||
|
||
RUN mkdir /workdir | ||
RUN chmod 700 /workdir | ||
RUN chown nobody /workdir | ||
WORKDIR /workdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
all: build | ||
|
||
PROJ=gcr.io/k8s-cri-containerd | ||
VERSION=1.0 | ||
IMAGE=$(PROJ)/private-workdir:$(VERSION) | ||
|
||
build: | ||
docker build -t $(IMAGE) . | ||
|
||
push: | ||
gcloud docker -- push $(IMAGE) | ||
|
||
.PHONY: build push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" | ||
) | ||
|
||
func TestNonRootUserCap(t *testing.T) { | ||
for name, test := range map[string]struct { | ||
uid int64 | ||
startOK bool | ||
}{ | ||
"shouldn't be able to run container with a private workdir only accessible to nobody as a non-root user": { | ||
uid: 1234, | ||
startOK: false, | ||
}, | ||
"shouldn be able to run container with a private workdir only accessible to nobody as root": { | ||
uid: 0, | ||
startOK: true, | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
t.Log("Create a sandbox") | ||
sbConfig := PodSandboxConfig("sandbox", "non-root-user-cap") | ||
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler) | ||
require.NoError(t, err) | ||
// Make sure the sandbox is cleaned up. | ||
defer func() { | ||
assert.NoError(t, runtimeService.StopPodSandbox(sb)) | ||
assert.NoError(t, runtimeService.RemovePodSandbox(sb)) | ||
}() | ||
|
||
const ( | ||
testImage = "gcr.io/k8s-cri-containerd/private-workdir:1.0" | ||
containerName = "test-container" | ||
) | ||
t.Logf("Pull test image %q", testImage) | ||
img, err := imageService.PullImage(&runtime.ImageSpec{Image: testImage}, nil, sbConfig) | ||
require.NoError(t, err) | ||
defer func() { | ||
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img})) | ||
}() | ||
|
||
t.Log("Create a container to print capabilities") | ||
cnConfig := ContainerConfig( | ||
containerName, | ||
testImage, | ||
WithCommand("ls", "/"), | ||
WithLogPath(containerName), | ||
WithRunAsUser(test.uid), | ||
) | ||
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig) | ||
require.NoError(t, err) | ||
|
||
t.Log("Start the container") | ||
if test.startOK { | ||
require.NoError(t, runtimeService.StartContainer(cn)) | ||
} else { | ||
require.Error(t, runtimeService.StartContainer(cn)) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters