openshift - 访问 hostPath 的自定义 SCC 在 pod 上引发权限被拒绝
问题描述
我使用openshift 4.7
并拥有这个自定义SCC
(目标是对主机节点中的某些目录具有只读访问权限):
allowHostDirVolumePlugin: true
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegeEscalation: false
allowPrivilegedContainer: false
apiVersion: security.openshift.io/v1
fsGroup:
type: RunAsAny
groups:
- system:cluster-admins
kind: SecurityContextConstraints
metadata:
annotations:
kubernetes.io/description: 'test scc'
name: test-access
priority: 15
readOnlyRootFilesystem: true
runAsUser:
type: RunAsAny
seLinuxContext:
type: RunAsAny
supplementalGroups:
type: RunAsAny
volumes:
- 'hostPath'
- 'secret'
这是我的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-test
namespace: ubuntu-test
spec:
replicas: 1
selector:
matchLabels:
app: ubuntu-test
template:
metadata:
labels:
app: ubuntu-test
spec:
serviceAccountName: ubuntu-test
containers:
- name: ubuntu-test
image: ubuntu:latest
command: [ "/bin/bash", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
resources:
limits:
cpu: 100m
memory: 256Mi
volumeMounts:
- name: docker
readOnly: true
mountPath: /var/lib/docker/containers
- name: containers
readOnly: true
mountPath: /var/log/containers
- name: pods
readOnly: true
mountPath: /var/log/pods
volumes:
- name: docker
hostPath:
path: /var/lib/docker/containers
type: ''
- name: containers
hostPath:
path: /var/log/containers
type: ''
- name: pods
hostPath:
path: /var/log/pods
type: ''
但是当我rsh
到容器时,我看不到已安装的hostPath
:
root@ubuntu-test-6b4fcb5bd7-fnc6f:/# ls /var/log/pods
ls: cannot open directory '/var/log/pods': Permission denied
当我检查权限时,一切似乎都很好:
drwxr-xr-x. 44 root root 8192 Oct 12 14:30 pods
解决方案
推荐阅读
- amazon-web-services - 使用 for_each 的多个 aws_rds_cluster_instance
- javascript - 如何在javascript中每X秒验证一次执行一个函数
- python - 有没有办法使用曼哈顿距离选择 Numpy 2D 数组的子集?
- flutter - 未找到设置为参数“image”的文件“assets/background.png”。pub 以退出代码 1 结束
- visual-studio-code - 在 VS Code 中,快速切换窗口和切换窗口有什么区别?
- reactjs - SharePoint Online web 部件
- txt - 更新插件和robot.txt
- python - 通过正则表达式模式并在数据框中返回标签的最快方法
- android - 升级cordova-android 10后构建失败
- node.js - 对于模型“”的路径“”中的值“”,MongoDB 转换为 ObjectId 失败