Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.9] Remove ambient capabilities #1558

Merged
merged 2 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
}
}
}

// Remove all ambient capabilities. Kubernetes is not yet ambient capabilities aware
// and pods expect that switching to a non-root user results in the capabilities being
// dropped. This should be revisited in the future.
specgen.Spec().Process.Capabilities.Ambient = []string{}

specgen.SetProcessSelinuxLabel(processLabel)
specgen.SetLinuxMountLabel(mountLabel)
specgen.SetProcessNoNewPrivileges(linux.GetSecurityContext().GetNoNewPrivs())
Expand Down
5 changes: 5 additions & 0 deletions server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest

privileged := s.privilegedSandbox(req)

// Remove all ambient capabilities. Kubernetes is not yet ambient capabilities aware
// and pods expect that switching to a non-root user results in the capabilities being
// dropped. This should be revisited in the future.
g.Spec().Process.Capabilities.Ambient = []string{}

securityContext := req.GetConfig().GetLinux().GetSecurityContext()
if securityContext == nil {
logrus.Warn("no security context found in config.")
Expand Down
32 changes: 32 additions & 0 deletions test/ctr.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1077,3 +1077,35 @@ function teardown() {
cleanup_pods
stop_crio
}

@test "ctr with non-root user has no effective capabilities" {
start_crio
run crictl runs "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"

newconfig=$(cat "$TESTDATA"/container_redis.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["linux"]["security_context"]["run_as_username"] = "redis"; json.dump(obj, sys.stdout)')
echo "$newconfig" > "$TESTDIR"/container_user.json

run crictl create "$pod_id" "$TESTDIR"/container_user.json "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run crictl start "$ctr_id"
[ "$status" -eq 0 ]

run crictl exec --sync "$ctr_id" grep "CapEff:\s0000000000000000" /proc/1/status
echo "$output"
[ "$status" -eq 0 ]

run crictl stops "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
run crictl rms "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
cleanup_ctrs
cleanup_pods
stop_crio
}