13.6. 安全性上下文约束参考命令
您可以使用 CLI,将实例中的 SCC 作为常规 API 对象来管理。
注意
您必须具有 cluster-admin
特权才能管理 SCC。
重要
不要修改默认 SCC。自定义默认 SCC 会导致升级时出现问题。如果默认 SCC 不能满足要求,请创建新的 SCC。
13.6.1. 列出 SCC
获取当前的 SCC 列表:
$ oc get scc NAME PRIV CAPS SELINUX RUNASUSER FSGROUP SUPGROUP PRIORITY READONLYROOTFS VOLUMES anyuid false [] MustRunAs RunAsAny RunAsAny RunAsAny 10 false [configMap downwardAPI emptyDir persistentVolumeClaim projected secret] hostaccess false [] MustRunAs MustRunAsRange MustRunAs RunAsAny <none> false [configMap downwardAPI emptyDir hostPath persistentVolumeClaim projected secret] hostmount-anyuid false [] MustRunAs RunAsAny RunAsAny RunAsAny <none> false [configMap downwardAPI emptyDir hostPath nfs persistentVolumeClaim projected secret] hostnetwork false [] MustRunAs MustRunAsRange MustRunAs MustRunAs <none> false [configMap downwardAPI emptyDir persistentVolumeClaim projected secret] node-exporter false [] RunAsAny RunAsAny RunAsAny RunAsAny <none> false [*] nonroot false [] MustRunAs MustRunAsNonRoot RunAsAny RunAsAny <none> false [configMap downwardAPI emptyDir persistentVolumeClaim projected secret] privileged true [*] RunAsAny RunAsAny RunAsAny RunAsAny <none> false [*] restricted false [] MustRunAs MustRunAsRange MustRunAs RunAsAny <none> false [configMap downwardAPI emptyDir persistentVolumeClaim projected secret]
13.6.2. 检查 SCC
您可以查看特定 SCC 的信息,包括这个 SCC 应用到哪些用户、服务帐户和组。
例如,检查 restricted
SCC:
$ oc describe scc restricted Name: restricted Priority: <none> Access: Users: <none> 1 Groups: system:authenticated 2 Settings: Allow Privileged: false Default Add Capabilities: <none> Required Drop Capabilities: KILL,MKNOD,SYS_CHROOT,SETUID,SETGID Allowed Capabilities: <none> Allowed Seccomp Profiles: <none> Allowed Volume Types: configMap,downwardAPI,emptyDir,persistentVolumeClaim,projected,secret Allow Host Network: false Allow Host Ports: false Allow Host PID: false Allow Host IPC: false Read Only Root Filesystem: false Run As User Strategy: MustRunAsRange UID: <none> UID Range Min: <none> UID Range Max: <none> SELinux Context Strategy: MustRunAs User: <none> Role: <none> Type: <none> Level: <none> FSGroup Strategy: MustRunAs Ranges: <none> Supplemental Groups Strategy: RunAsAny Ranges: <none>
注意
要在升级过程中保留自定义 SCC,请不要编辑默认 SCC 的设置。
13.6.3. 删除 SCC
删除 SCC:
$ oc delete scc <scc_name>
注意
如果删除了某一默认 SCC,重启集群时会重新生成该 SCC。
13.6.4. 更新 SCC
更新现有的 SCC:
$ oc edit scc <scc_name>
注意
要在升级过程中保留自定义 SCC,请不要编辑默认 SCC 的设置。