【问题标题】:Mounting SSH keys for SSL for Postgres为 Postgres 安装 SSL 的 SSH 密钥
【发布时间】:2020-02-23 23:52:17
【问题描述】:

我正在为 Postgres9.6 连接设置 SSL。我无法在具有适当权限的 Kubernetes 密钥中挂载 SSH 私钥和证书。我相信如果没有在 Kubernetes 容器上设置任何明确的用户 ID,挂载的秘密应该由 root 拥有。我已经为八进制0640 设置了十进制416。如果文件由 root 拥有,这是 Postgres 的建议。

感谢任何帮助。

错误:

 FATAL:  could not load private key file "/var/lib/postgresql/certs/server.key": Permission denied

Helm statefulset 配置:

  volumes:  
  - name: {{ .Values.certs_secret.volume_name }}
    secret:
      secretName: {{ .Values.certs_secret.secret_name }}
      items:
      - key: server.key
        path: server.key
        mode: 416  
      - key: server.crt
        path: server.crt
        mode: 511 
  containers:
  - name: {{ .Chart.Name }}
    args: 
      - -c
      - ssl=on
      - -c
      - ssl_cert_file={{ .Values.certs_secret.cert_path }}
      - -c
      - ssl_key_file={{ .Values.certs_secret.private_key_path }}
    volumeMounts:
    - name: {{ .Values.certs_secret.volume_name }}
      mountPath: {{ .Values.certs_secret.mount_path }}

更新

我在没有打开 SSL 的情况下执行了,发现秘密文件被挂载为符号链接。这会是个问题吗?群集位于 AKS 中。

root@postgres-timescale-db-0:/var/lib/postgresql/certs# find . -ls
        2      0 drwxrwxrwt   3 root     root          120 Oct 29 16:40 .
        8      0 lrwxrwxrwx   1 root     root           31 Oct 29 16:40 ./..data -> ..2019_10_29_16_40_00.233198123
        7      0 lrwxrwxrwx   1 root     root           17 Oct 29 16:40 ./server.crt -> ..data/server.crt
        6      0 lrwxrwxrwx   1 root     root           17 Oct 29 16:40 ./server.key -> ..data/server.key
        3      0 drwxr-xr-x   2 root     root           80 Oct 29 16:40 ./..2019_10_29_16_40_00.233198123
        5      8 -rwxrwxrwx   1 root     root         4450 Oct 29 16:40 ./..2019_10_29_16_40_00.233198123/server.crt
        4      4 -rw-r-----   1 root     root         1679 Oct 29 16:40 ./..2019_10_29_16_40_00.233198123/server.key

【问题讨论】:

  • 使用的图片是postgres:9.6

标签: postgresql kubernetes kubernetes-helm


【解决方案1】:

postgres 以什么用户身份运行 - root 或其他?一些 Docker 镜像使用 postgresuid 的 999...

如果没有完整的部署配置,我建议,一旦您了解用户,请查看 this doc,了解如何配置 securityContext 以设置挂载卷中目录和文件的所有权。

【讨论】:

  • 不能使用securitycontext(设置用户,groud ids),尤其是第一次,因为它阻碍了数据文件夹的创建。我相信 postgres 以 root 身份运行 docker 入口点文件(创建 postgres 用户、具有适当所有权和权限的数据文件),然后降级为 postgres 用户
  • 我在原始帖子中添加了长长的文件列表 (/var/lib/postgresql/certs)。如果有线索请告知。
  • "...找到的秘密文件被挂载为符号链接" - 这就是从 configMap-s 和秘密创建的文件的显示方式,所以它是“正常的”。我看到你可以在容器中获得一个 shell - 你可以让 postgres 运行的用户吗?例如。在容器内执行ps -f
  • 这就是询问用户的原因:server.key 文件的权限设置为 0640 - root 用户读+写,root 组读;如果 postgres 不是以 root 身份运行,而是以其他用户身份运行,则该用户没有读取文件的权限。将模式设置为 0644,或者根本不设置它,因为这是秘密的默认设置,将允许该用户读取文件。是的,其他用户也可以读取该文件。这就是为什么我建议您查看 securityContext(特别是 fsGroup) - 如果它不是 root,则值得尝试将其设置为 postgres 用户的组
  • 设置 fsGroup 并设置 server.key 为 416 和 server.crt 为 511 使 Postgres 为连接启用 SSL。可以使用select * from pg_stat_ssl;进行验证。
猜你喜欢
  • 1970-01-01
  • 2017-05-10
  • 2015-02-03
  • 2018-08-18
  • 1970-01-01
  • 2013-08-09
  • 2015-07-11
  • 2014-11-15
  • 2021-03-26
相关资源
最近更新 更多