简体   繁体   English

Kubernetes 秘密真的是秘密吗?

[英]Kubernetes secret is really secret?

While I developed an API server, I needed to give some account information to API server, which should not be shown to anyone.当我开发了一个 API 服务器时,我需要向 API 服务器提供一些帐户信息,这些信息不应该向任何人显示。 K8s recommends secret for this kind of situation, so I used. K8s针对这种情况推荐secret,所以我用了。

But I wonder if the secret is really secret.但我想知道这个秘密是否真的是秘密。 Secret is just base 64 "encoded" text, not "encrypted". Secret 只是 base 64“编码”文本,而不是“加密”文本。

When I see an arbitary secret like below,当我看到像下面这样的任意秘密时,

namespace: ZGVmYXVsdA==

I can easily know the real value of it by decoding.通过解码我可以很容易地知道它的真正价值。

namespace: default

In such a this situation, is secret really helpful for security?在这种情况下,秘密真的对安全有帮助吗? What I know about the security advantage of secret is that it is on-memory not on-node file system.我所知道的秘密的安全优势是它是内存而不是节点文件系统。 But I think that is not enough for security.但我认为这还不够安全。

Thank you.谢谢你。

FromKubernetes Secrets documentation :来自Kubernetes 秘密文档

Risks风险

  • In the API server, secret data is stored in etcd( by default, etcd data is not encrypted );在 API 服务器中,secret 数据存储在 etcd 中(默认情况下,etcd 数据未加密); therefore:所以:
    1. Administrators should enable encryption at rest for cluster data (requires v1.13 or later).管理员应在 rest 为集群数据启用加密(需要 v1.13 或更高版本)。
    2. Administrators should limit access to etcd to admin users.管理员应将 etcd 的访问权限限制为管理员用户。
    3. Administrators may want to wipe/shred disks used by etcd when no longer in use.管理员可能希望在不再使用时擦除/粉碎 etcd 使用的磁盘。
    4. If running etcd in a cluster, administrators should make sure to use SSL/TLS for etcd peer-to-peer communication.如果在集群中运行 etcd,管理员应确保使用 SSL/TLS 进行 etcd 对等通信。
  • If you configure the secret through a manifest (JSON or YAML) file which has the secret data encoded as base64, sharing this file or checking it in to a source repository means the secret is compromised.如果您通过清单(JSON 或 YAML)文件配置密钥,该文件具有编码为 base64 的密钥数据,则共享此文件或将其签入源存储库意味着密钥已泄露。 Base64 encoding is not an encryption method and is considered the same as plain text. Base64 编码不是一种加密方法,被认为与纯文本相同。
  • Applications still need to protect the value of secret after reading it from the volume, such as not accidentally logging it or transmitting it to an untrusted party.应用程序在从卷中读取它后仍然需要保护它的值,例如不意外地记录它或将其传输给不受信任的一方。
  • A user who can create a Pod that uses a secret can also see the value of that secret.可以创建使用秘密的 Pod 的用户也可以看到该秘密的值。 Even if the API server policy does not allow that user to read the Secret, the user could run a Pod which exposes the secret.即使 API 服务器策略不允许该用户读取 Secret,用户也可以运行暴露该 Secret 的 Pod。
  • Currently, anyone with root permission on any node can read any secret from the API server , by impersonating the kubelet.目前,在任何节点上具有 root 权限的任何人都可以通过模拟 kubelet 从 API 服务器读取任何机密 It is a planned feature to only send secrets to nodes that actually require them, to restrict the impact of a root exploit on a single node.这是一个计划的功能,只向实际需要它们的节点发送秘密,以限制根漏洞对单个节点的影响。

Also check great post Can Kubernetes Keep a Secret?另请查看很棒的帖子Kubernetes 可以保密吗? It all depends what tool you're using , especcially " What's wrong with Kubernetes plain Secrets? " part.. 这完全取决于您使用的是什么工具,尤其是“ Kubernetes 普通秘密有什么问题? ”部分..

I hope that answered your question, but generally @Harsh Manvar is right: you should have an access first to that secret.我希望这回答了您的问题,但通常@Harsh Manvar 是正确的:您应该首先访问该秘密。

You should limit access using authorization policies such as RBAC.您应该使用授权策略(例如 RBAC)来限制访问。

You'll need to create a Role/ClusterRole with appropriate permissions and then bind (using RoleBinding/ClusterRoleBinding ) that to a user and/or a service account (can be used in pod definition then), depending on your use case.您需要创建一个具有适当权限的Role/ClusterRole ,然后根据您的用例将其绑定(使用RoleBinding/ClusterRoleBinding )到用户和/或服务帐户(然后可以在 pod 定义中使用)。

You can look at the documentation here to create Role & ClusterRole and the docs here for RoleBinding and ClusterRoleBinding.您可以在此处查看文档以创建角色和 ClusterRole,并在此处查看用于 RoleBinding 和 ClusterRoleBinding 的文档。

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

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