【问题标题】:OpenShift 4.3 - Attach PVC to pod without privileged accessOpenShift 4.3 - 在没有特权访问的情况下将 PVC 附加到 pod
【发布时间】:2020-07-16 15:25:23
【问题描述】:

我正在尝试在没有特权访问的情况下将 PVC 挂载到 MongoDB 部署。 我尝试通过以下方式为 pod 设置 anyuid

oc adm policy add-scc-to-user anyuid -z default --as system:admin

在部署中我使用securityContext 配置。我尝试了fsGroup 等的几种组合:

spec:
      securityContext:
        runAsUser: 99
        runAsGroup: 99
        supplementalGroups:
          - 99
        fsGroup: 99

当我转到 pod uid 并且 guid 设置正确时:

bash-4.2$ id
uid=99(nobody) gid=99(nobody) groups=99(nobody)
bash-4.2$ whoami
nobody
bash-4.2$ cd /var/lib/mongodb/data
bash-4.2$ touch test.txt
touch: cannot touch 'test.txt': Permission denied

但是pod无法写入pvc目录:

ERROR: Couldn't write into /var/lib/mongodb/data
CAUSE: current user doesn't have permissions for writing to /var/lib/mongodb/data directory
DETAILS: current user id = 99, user groups: 99 0
DETAILS: directory permissions: drwxr-xr-x owned by 0:0, SELinux: system_u:object_r:container_file_t:s0:c234,c491

我也尝试使用 PVC 实例化 MySQL 模板,而无需从 OpenShift 目录更改任何配置,这是同样的问题。

感谢您的帮助。

【问题讨论】:

    标签: openshift


    【解决方案1】:

    临时解决方案是使用具有root权限的init容器来更改挂载路径的所有者:

    initContainers:
        - name: mongodb-init
          image: alpine
          command: ["sh", "-c", "chown -R 99 /var/lib/mongodb/data"]
          volumeMounts:
          - mountPath: /var/lib/mongodb/data
            name: mongodb-pvc
    

    但我也在研究名为 Udica 的工具。可为容器生成 SELinux 安全策略:https://github.com/containers/udica

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-02
      • 2010-11-23
      • 2011-10-23
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      相关资源
      最近更新 更多