第 12 章 配置 seccomp 配置集

OpenShift Container Platform 容器或 pod 运行一个应用程序,它执行一个或多个定义明确的任务。应用程序通常只需要底层操作系统内核 API 的一小部分。安全计算模式 seccomp 是一个 Linux 内核功能,可用于将容器中运行的进程限制为仅使用可用系统调用的子集。

restricted-v2 SCC 适用于 4.12 中的所有新创建的 pod。默认 seccomp 配置集 runtime/default 应用到这些 pod。

seccomp 配置集作为 JSON 文件存储在磁盘上。

重要

seccomp 配置集不能应用到特权容器。

12.1. 验证应用到 pod 的默认 seccomp 配置集

OpenShift Container Platform 附带了一个默认的 seccomp 配置集,它被引用为 runtime/default。在 4.12 中,新创建的 pod 将安全上下文约束 (SCC) 设置为 restricted-v2,默认的 seccomp 配置集应用到 pod。

流程

  1. 您可以运行以下命令来验证 pod 上设置了安全性上下文约束(SCC) 和默认 seccomp 配置集:

    1. 验证在命名空间中运行的 pod:

      $ oc get pods -n <namespace>

      例如,要验证在 workshop 命名空间中运行的 pod,请运行以下命令:

      $ oc get pods -n workshop

      输出示例

      NAME                READY   STATUS      RESTARTS   AGE
      parksmap-1-4xkwf    1/1     Running     0          2m17s
      parksmap-1-deploy   0/1     Completed   0          2m22s

    2. 检查 pod:

      $ oc get pod parksmap-1-4xkwf -n workshop -o yaml

      输出示例

      apiVersion: v1
      kind: Pod
      metadata:
        annotations:
          k8s.v1.cni.cncf.io/network-status: |-
            [{
                "name": "openshift-sdn",
                "interface": "eth0",
                "ips": [
                    "10.131.0.18"
                ],
                "default": true,
                "dns": {}
            }]
          k8s.v1.cni.cncf.io/networks-status: |-
            [{
                "name": "openshift-sdn",
                "interface": "eth0",
                "ips": [
                    "10.131.0.18"
                ],
                "default": true,
                "dns": {}
            }]
          openshift.io/deployment-config.latest-version: "1"
          openshift.io/deployment-config.name: parksmap
          openshift.io/deployment.name: parksmap-1
          openshift.io/generated-by: OpenShiftWebConsole
          openshift.io/scc: restricted-v2 1
          seccomp.security.alpha.kubernetes.io/pod: runtime/default 2

      1
      如果您的工作负载无法访问其他 SCC,则默认添加 restricted-v2 SCC。
      2
      4.12 中新创建的 pod 会将 seccomp 配置集配置为 runtime/default,如 SCC 强制。

12.1.1. 升级的集群

在升级到 4.12 的集群中,所有经过身份验证的用户都可以访问 restrictedrestricted-v2 SCC。

由 SCC restricted 接受的负载,例如升级的 OpenShift Container Platform v4.10 集群可以被 restricted-v2 接受。这是因为 restricted-v2restrictedrestricted-v2 间是更加严格的 restrictive SCC。

注意

工作负载必须能够使用 retricted-v2 运行。

相反,对于需要 privilegeEscalation: true 的工作负载,此工作负载将继续对任何经过身份验证的用户使用 restricted SCC。这是因为 restricted-v2 不允许 privilegeEscalation

12.1.2. 新安装的集群

对于新安装的 OpenShift Container Platform 4.11 或更高版本的集群,restricted-v2 会将 restricted SCC 替换为可供任何经过身份验证的用户使用的 SCC。具有 privilegeEscalation: true 的工作负载不会接受到集群中,因为 restricted-v2 是默认可供经过身份验证的用户使用的唯一 SCC。

privilegeEscalationrestricted 允许但不被 restricted-v2 允许。更多功能会被 restricted-v2 决绝,但会被 restricted SCC 允许。

具有 privilegeEscalation: true 的工作负载可能会被接受到新安装的 OpenShift Container Platform v4.11 或更高版本的集群中。要使用 RoleBinding 运行以下命令,为运行工作负载(或任何其他可以接受此工作负载的 ServiceAccount)授予 restricted SCC 的访问权限:

$ oc -n <workload-namespace> adm policy add-scc-to-user <scc-name> -z <serviceaccount_name>

在 OpenShift Container Platform 4.12 中,添加 pod 注解 seccomp.security.alpha.kubernetes.io/pod: runtime/defaultcontainer.seccomp.security.alpha.kubernetes.io/<container_name>: runtime/default 已被弃用。