简体   繁体   English

容器禁用服务帐户

[英]container disable service account

I have some containers that will be runnin users code in them. 我有一些容器将在其中运行用户代码。 In order to strengthen security, I want to prevent them from having access to kubernetes api via the service account mechanism, but don't want to turn it off globally. 为了加强安全性,我想阻止他们通过服务帐户机制访问kubernetes api,但不希望全局关闭它。 The documentation says you can switch the service account name but only to another valid name. 文档说您可以切换服务帐户名称,但只能切换到另一个有效名称。 Are there alternatives that I missed? 有没有我错过的替代品? Can you restrict the account to have 0 permissions? 您可以将帐户限制为0权限吗? Can you overmount the volume with a different one thats empty? 你可以用另一个空的超载音量吗? Any other ideas? 还有其他想法吗?

In Kubernetes 1.6+, you can disable service account mounting on a Pod: 在Kubernetes 1.6+中,您可以在Pod上禁用服务帐户安装:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  automountServiceAccountToken: false
  ...

See https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ 请参阅https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

The easiest hack is to mount an emptyDir over the location that the serviceAccount secret would have been mounted. 最简单的方法是在serviceAccount secret将被挂载的位置上挂载一个emptyDir。 Something like: 就像是:

containers:
- name: running-user-code
  image: something-i-dont-trust
  volumeMounts:
  - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
    name: no-api-access-please
    readOnly: true
volumes:
- name: no-api-access-please
  emptyDir: {}

There is more discussion in Kubernetes Issue #16779 on potential solutions (and that's where I stole the emptyDir example from). 在Kubernetes 问题#16779中有关于潜在解决方案的更多讨论(这就是我从中窃取emptyDir示例的地方)。

Service accounts only authenticate to the API, they don't inherently have authorization to perform any read or write API actions. 服务帐户仅对API进行身份验证,它们本身并不具有执行任何读取或写入API操作的授权。

If you want to secure your cluster, run with an authorization mode other than AlwaysAllow (which gives any authenticated API user complete read/write access), and selectively grant permissions to certain service accounts or namespaces 如果要保护群集,请使用AlwaysAllow以外的授权模式运行(为任何经过身份验证的API用户提供完整的读/写访问权限),并有选择地向某些服务帐户或命名空间授予权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM