Skip to content

Permission 拒绝

错误信息

                permission 拒绝虽然 trying 到连接到 Docker daemon socket
              

快速摘要

current 用户 lacks 必要 permissions 到执行 command or access resource.

为什么发生

  • 用户是 不 in docker 分组 and cannot access Docker daemon

  • 容器用户做 不有 编写 permission 到 mounted 体积

  • Kubernetes RBAC 规则拒绝 service account access 到 resource

  • File permissions on host prevent 容器从 读取 or 编写

最小示例

✗ 错误代码
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket
✓ 修复代码
$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker ps  # now works

用户是 不 in docker 分组. fix 添加用户到 分组 and refreshes 分组 membership.

如何诊断

  • 检查错误消息 for 特定 resource 是拒绝

  • 验证用户运行 command and 它们的分组 membership

  • In Kubernetes, 检查 RBAC roles and bindings 使用 kubectl 认证能-i

  • 检查 file permissions on host: ls -la /path/到/file

如何修复

  • 添加用户到 docker 分组: sudo usermod -aG docker $USER (然后 re-登录)

  • Fix file permissions: chmod or chown file or directory

  • 创建 or 更新 RBAC Role/RoleBinding 到 grant 必需 permissions

  • 设置正确用户 in Dockerfile 使用 USER directive

如何预防

  • 设置 proper RBAC roles for service accounts 从开始

  • Use 最少-privilege 用户 in 容器

  • Document 必需 permissions for 每个 service

相关资源

相关术语

← 返回语言