Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To restrict direct API access to Kubernetes Secrets, grant only the required verbs on the required Secret through a namespaced Role, then bind that role with a RoleBinding in the namespace. For a subject that needs one named Secret, a narrow get grant can be appropriate. But RBAC on Secret objects is only one part of the boundary: users who can create workloads may be able to arrange indirect access to Secrets available in that namespace.

How do I stop users from reading Kubernetes Secrets?

Start by identifying the exact identity, namespace, Secret, and operation it needs. Kubernetes RBAC controls API requests; a namespaced Role and RoleBinding are preferable to cluster-wide grants when the access is needed in only one namespace. A RoleBinding can bind either a namespaced Role or a ClusterRole, but its grant applies within the binding’s namespace. A ClusterRoleBinding, by contrast, can grant access across the cluster. See the Kubernetes RBAC documentation.

For a subject that only needs to retrieve one Secret, the following illustrative policy grants get on the named Secret in namespace app to a dedicated ServiceAccount. Change the names to match your environment. A human identity can be used as a User or Group subject instead.

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: app-secret-reader
  namespace: app
rules:
- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: ["app-credentials"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: app-secret-reader
  namespace: app
subjects:
- kind: ServiceAccount
  name: app-reader
  namespace: app
  # A User or Group subject can be used for a human identity instead.
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: app-secret-reader

This is an example pattern, not a universal policy or a tested manifest. Confirm the subject’s other bindings and permissions before relying on it. The resourceNames restriction illustrates named get access; it is not a universal way to constrain every operation. In particular, top-level create requests cannot be restricted by resource name.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Grant only the verbs the job requires

For Secrets, get, list, and watch are all sensitive because they can reveal Secret contents. Kubernetes explicitly warns that “Granting list access to Secrets implicitly lets the subject fetch the contents of the Secrets.” If an identity only needs one named Secret, avoid list and watch; add a verb only when the task requires it. See Good practices for Kubernetes Secrets.

Can I allow access to one Secret only?

Use resourceNames in a Role rule to target a named Secret for an operation such as get, as in the example above. Keep the rule limited to the required verb and bind it only to the intended identity. Do not assume this setting makes every kind of request name-restricted: Kubernetes notes that top-level create requests cannot be restricted by resource name, and list or watch access should not be added casually because those verbs disclose Secret data.

Does the Kubernetes view role include Secrets?

No. The built-in view role does not grant Secret reads. The built-in edit role does allow Secret access and permits running Pods as any ServiceAccount in its namespace, so it is not a safe substitute for a narrowly scoped read-only grant. Role names alone are not a reliable audit: inspect the actual Roles, ClusterRoles, and bindings that apply to the identity. See Kubernetes user-facing roles.

Why direct Secret permissions are not the whole boundary

A principal without direct permission to read Secret objects may still obtain Secret data indirectly if it can create a Pod or workload in a namespace where the Secret is available. A workload can be configured to use a Secret, or to run as a ServiceAccount whose permissions enable access. Review workload-creation permissions and the permissions of ServiceAccounts available to workloads alongside direct Secret grants. Kubernetes describes namespace boundaries as weak when principals can create workloads there; its RBAC good practices recommend least privilege while warning against treating such within-namespace boundaries as strong isolation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use namespaces to separate trust boundaries

Place workloads and Secrets with different trust requirements in separate namespaces, then grant access within the appropriate namespace. A namespaced RoleBinding limits where its grant applies, but namespace separation is not a substitute for controlling who can create workloads or use ServiceAccounts in each namespace.

Expose a Secret only to the container that needs it

Within a multi-container Pod, mount a Secret or expose it as an environment variable only to the container that requires it. This reduces unnecessary exposure among containers in that Pod, but does not change which principals can retrieve the Secret through the Kubernetes API.

What RBAC does not protect: Secret data at rest

RBAC governs access to Kubernetes API resources; it does not encrypt Secret data stored in etcd. Kubernetes documents that Secret data is unencrypted in etcd by default and recommends configuring encryption at rest as a separate safeguard. Depending on the architecture, an external Secret Store provider may also be appropriate for secrets held outside the cluster. See Encrypting Confidential Data at Rest.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Review Secret access over time

  • Check direct Secret permissions in both namespaced Roles and ClusterRoles, and inspect the RoleBindings and ClusterRoleBindings that grant them.
  • Look for unnecessary get, list, and watch grants, as well as broad built-in role assignments such as edit.
  • Review who can create Pods and other workloads in each namespace, and which ServiceAccounts those workloads can use.
  • Revisit namespace boundaries and storage protections when workloads, identities, or cluster configuration change.

The annotation kubernetes.io/enforce-mountable-secrets is deprecated since Kubernetes v1.32; current Kubernetes guidance points to separate namespaces for isolating access to mounted Secrets. See Kubernetes labels, annotations, and taints.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.