containerd/pkg/cri/server
Fabiano Fidêncio f1c7993311 seutil: Fix setting the "container_kvm_t" label
The ability to handle KVM based runtimes with SELinux has been added as
part of d715d00906.

However, that commit introduced some logic to check whether the
"container_kvm_t" label would or not be present in the system, and while
the intentions were good, there's two major issues with the approach:
1. Inspecting "/etc/selinux/targeted/contexts/customizable_types" is not
   the way to go, as it doesn't list the "container_kvm_t" at all.
2. There's no need to check for the label, as if the label is invalid an
   "Invalid Label" error will be returned and that's it.

With those two in mind, let's simplify the logic behind setting the
"container_kvm_t" label, removing all the unnecessary code.

Here's an output of VMM process running, considering:
* The state before this patch:
  ```
  $ containerd --version
  containerd github.com/containerd/containerd v1.6.0-beta.3-88-g7fa44fc98 7fa44fc98f
  $ kubectl apply -f ~/simple-pod.yaml
  pod/nginx created
  $ ps -auxZ | grep cloud-hypervisor
  system_u:system_r:container_runtime_t:s0 root 609717 4.0  0.5 2987512 83588 ?    Sl   08:32   0:00 /usr/bin/cloud-hypervisor --api-socket /run/vc/vm/be9d5cbabf440510d58d89fc8a8e77c27e96ddc99709ecaf5ab94c6b6b0d4c89/clh-api.sock
  ```

* The state after this patch:
  ```
  $ containerd --version
  containerd github.com/containerd/containerd v1.6.0-beta.3-89-ga5f2113c9 a5f2113c9fc15b19b2c364caaedb99c22de4eb32
  $ kubectl apply -f ~/simple-pod.yaml
  pod/nginx created
  $ ps -auxZ | grep cloud-hypervisor
  system_u:system_r:container_kvm_t:s0:c638,c999 root 614842 14.0  0.5 2987512 83228 ? Sl 08:40   0:00 /usr/bin/cloud-hypervisor --api-socket /run/vc/vm/f8ff838afdbe0a546f6995fe9b08e0956d0d0cdfe749705d7ce4618695baa68c/clh-api.sock
  ```

Note, the tests were performed using the following configuration snippet:
```
[plugins]
  [plugins.cri]
    enable_selinux = true
    [plugins.cri.containerd]
      [plugins.cri.containerd.runtimes]
        [plugins.cri.containerd.runtimes.kata]
           runtime_type = "io.containerd.kata.v2"
           privileged_without_host_devices = true
```

And using the following pod yaml:
```
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  runtimeClassName: kata
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
```

Fixes: #6371

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
2021-12-14 00:09:17 +01:00
..
bandwidth Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
testing go.mod: github.com/containerd/go-cni v1.0.2 2021-04-14 09:09:18 +02:00
cni_conf_syncer.go go.mod: github.com/containerd/go-cni v1.0.2 2021-04-14 09:09:18 +02:00
container_attach.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_create_linux_test.go Merge pull request #5627 from payall4u/payall4u/cri-support-cgroup-v2 2021-09-09 23:10:33 +08:00
container_create_linux.go cri: add devices for privileged container 2021-09-10 10:16:26 +08:00
container_create_other_test.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
container_create_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
container_create_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_create_windows_test.go Added windows hostProcess cni skip 2021-08-11 22:23:49 +01:00
container_create_windows.go Added windows hostProcess cni skip 2021-08-11 22:23:49 +01:00
container_create.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
container_exec.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_execsync.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_list_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_list.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
container_log_reopen.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_remove_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
container_remove.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
container_start_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
container_start.go Merge pull request #6111 from crosbymichael/latency-metrics 2021-11-16 16:59:33 -08:00
container_stats_list_linux_test.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
container_stats_list_linux.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
container_stats_list_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
container_stats_list_windows.go Remove redundant build tags 2021-08-05 22:27:46 -07:00
container_stats_list.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_stats.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_status_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
container_status.go switch usage directly to errdefs.(ErrAlreadyExists and ErrNotFound) 2021-09-24 18:26:58 +08:00
container_stop_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
container_stop.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
container_update_resources_linux_test.go Adds Windows resource limits support 2021-09-25 13:20:55 -07:00
container_update_resources_linux.go Adds Windows resource limits support 2021-09-25 13:20:55 -07:00
container_update_resources_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
container_update_resources_windows.go Adds Windows resource limits support 2021-09-25 13:20:55 -07:00
container_update_resources.go Adds Windows resource limits support 2021-09-25 13:20:55 -07:00
events_test.go cleanup: import from k8s.io/utils/clock/testing instead 2021-09-30 23:34:56 +08:00
events.go cleanup: import from k8s.io/utils/clock/testing instead 2021-09-30 23:34:56 +08:00
helpers_linux_test.go refactor: move from io/ioutil to io and os package 2021-09-21 09:50:38 +08:00
helpers_linux.go seutil: Fix setting the "container_kvm_t" label 2021-12-14 00:09:17 +01:00
helpers_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
helpers_selinux_linux_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
helpers_test.go Output a warning for label image labels instead of erroring 2021-10-14 19:25:48 +01:00
helpers_windows.go Remove redundant build tags 2021-08-05 22:27:46 -07:00
helpers.go cleanup: add more description on comment 2021-11-09 19:13:37 +08:00
image_list_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
image_list.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
image_pull_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
image_pull.go [CRI] Fix panic when registry.mirrors use localhost 2021-11-19 10:56:46 +08:00
image_remove.go switch usage directly to errdefs.(ErrAlreadyExists and ErrNotFound) 2021-09-24 18:26:58 +08:00
image_status_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
image_status.go switch usage directly to errdefs.(ErrAlreadyExists and ErrNotFound) 2021-09-24 18:26:58 +08:00
imagefs_info_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
imagefs_info.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
instrumented_service.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
metrics.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
opts.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
restart.go refactor: move from io/ioutil to io and os package 2021-09-21 09:50:38 +08:00
sandbox_list_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
sandbox_list.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
sandbox_portforward_linux.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
sandbox_portforward_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
sandbox_portforward_windows.go cri/server: use consistent alias for pkg/ioutil 2021-12-09 17:47:22 +01:00
sandbox_portforward.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
sandbox_remove.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
sandbox_run_linux_test.go CRI: Support enable_unprivileged_icmp and enable_unprivileged_ports options 2021-11-15 18:30:09 +02:00
sandbox_run_linux.go CRI: Support enable_unprivileged_icmp and enable_unprivileged_ports options 2021-11-15 18:30:09 +02:00
sandbox_run_other_test.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
sandbox_run_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
sandbox_run_test.go add ip_pref CNI options for primary pod ip 2021-09-10 10:04:21 -04:00
sandbox_run_windows_test.go Add RunAsUserName functionality for the Windows Pod Sandbox Container 2021-08-23 07:35:22 -07:00
sandbox_run_windows.go Add RunAsUserName functionality for the Windows Pod Sandbox Container 2021-08-23 07:35:22 -07:00
sandbox_run.go Merge pull request #6111 from crosbymichael/latency-metrics 2021-11-16 16:59:33 -08:00
sandbox_stats_linux.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
sandbox_stats_list.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
sandbox_stats_other.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
sandbox_stats_windows.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
sandbox_stats.go Implement CRI container and pods stats 2021-11-03 17:52:05 -07:00
sandbox_status_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
sandbox_status.go Added windows hostProcess cni skip 2021-08-11 22:23:49 +01:00
sandbox_stop_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
sandbox_stop.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
service_linux.go Add CNI conf based on runtime class 2021-09-17 19:05:06 +00:00
service_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
service_test.go Merge pull request #4695 from crosbymichael/cri-class 2021-10-08 09:27:49 -07:00
service_windows.go Add CNI conf based on runtime class 2021-09-17 19:05:06 +00:00
service.go Add CNI conf based on runtime class 2021-09-17 19:05:06 +00:00
snapshots.go Refactor pkg packages 2020-10-08 17:30:17 -07:00
status.go Add CNI conf based on runtime class 2021-09-17 19:05:06 +00:00
streaming_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
streaming.go Refactor pkg packages 2020-10-08 17:30:17 -07:00
update_runtime_config_test.go bump CNI to spec v1.0.0 2021-10-22 10:58:40 +08:00
update_runtime_config.go Add CNI conf based on runtime class 2021-09-17 19:05:06 +00:00
version.go add alpha version 2021-07-06 11:40:20 -05:00