如何做一份网站推广方案杭州seo培训
作者:雅泽
securityContext是用来控制容器内的用户权限,你想用什么用户去执行程序或者执行操作等等。
1. securityContext介绍
安全上下文(Security Context)定义 Pod 或 Container 的特权与访问控制设置。 安全上下文包括但不限于:
自主访问控制(Discretionary Access Control):基于 用户 ID(UID)和组 ID(GID). 来判定对对象(例如文件)的访问权限。
安全性增强的 Linux(SELinux): 为对象赋予安全性标签。
以特权模式或者非特权模式运行。
Linux 权能: 为进程赋予 root 用户的部分特权而非全部特权。
AppArmor:使用程序框架来限制个别程序的权能。
Seccomp:过滤进程的系统调用。
AllowPrivilegeEscalation:控制进程是否可以获得超出其父进程的特权。 此布尔值直接控制是否为容器进程设置 no_new_privs标志。 当容器以特权模式运行或者具有 CAP_SYS_ADMIN 权能时,AllowPrivilegeEscalation 总是为 true。
readOnlyRootFilesystem:以只读方式加载容器的根文件系统。
2. 如何为Pod设置安全性上下文
要为 Pod 设置安全性设置,可在 Pod 规约中包含 securityContext 字段。securityContext 字段值是一个 PodSecurityContext 对象。你为 Pod 所设置的安全性配置会应用到 Pod 中所有 Container 上。 下面是一个 Pod 的配置文件,该 Pod 定义了 securityContext 和一个 emptyDir 卷。
apiVersion: v1
kind: Pod
metadata:name: security-context-demo
spec:securityContext:runAsUser: 1000runAsGroup: 3000fsGroup: 2000volumes:- name: sec-ctx-volemptyDir: {}containers:- name: sec-ctx-demoimage: busyboxcommand: [ "sh", "-c", "sleep 1h" ]volumeMounts:- name: sec-ctx-volmountPath: /data/demosecurityContext:allowPrivilegeEscalation: false
3. 为Container设置安全性上下文
我们可以在pod层面和container层面设置上下文,但是如果2个同时配置了,那么container的级别要高于pod的级别,也就是container会覆盖pod中的securityContext配置。
[root@VM-4-3-centos ~]# cat security-context-2.yaml
apiVersion: v1
kind: Pod
metadata:name: security-context-demo-2
spec:securityContext:runAsUser: 1000containers:- name: sec-ctx-demo-2image: empiregeneral/node-hello:1.0securityContext:runAsUser: 2000allowPrivilegeEscalation: false
4. Pod的特权模式运行
Privileged-决定是否 Pod 中的某容器可以启用特权模式。 默认情况下,容器是不可以访问宿主上的任何设备的,不过一个“privileged(特权的)” 容器则被授权访问宿主上所有设备。 这种容器几乎享有宿主上运行的进程的所有访问权限。 对于需要使用 Linux 权能字(如操控网络堆栈和访问设备)的容器而言是有用的。
image: busybox:latestimagePullPolicy: Alwaysname: security-contextresources:limits:cpu: 500mmemory: 1Girequests:cpu: 250mmemory: 256MisecurityContext:privileged: trueterminationMessagePath: /dev/termination-logterminationMessagePolicy: File
在上下文配置上这个字段,后续pod就可以获取宿主机的访问权限了。
更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw