Protecting Secrets and tenant boundaries
Combine credential handling, encryption, RBAC, admission and network controls around realistic trust boundaries.
What you will understand
- Explain why base64 Secret data is not encryption
- Trace credential access through API, mounts and application logging
- Assess what namespace controls provide for mutually untrusted tenants
Builds on: Security contexts and Pod Security
Mental model: a Secret is sensitive API data, not an automatic vault
A Kubernetes Secret stores small sensitive values for applications and integrations. Its data field is base64-encoded because the API must represent bytes in text. Anyone who can read those encoded values can decode them. Encoding is not encryption, and moving a password from a ConfigMap to a Secret does not by itself make every storage, access and logging path safe.
Encryption at rest protects stored API data according to the control plane’s configured encryption provider. It is not universally enabled merely because an object is kind Secret. Managed providers may configure it as part of the service; self-managed clusters need deliberate API server configuration, key handling and verification. Existing stored objects can require a rewrite after encryption configuration changes. Key management, control-plane access and backups remain part of the boundary. At-rest encryption also does not stop an authorized API reader from receiving plaintext Secret data.
Encoding, storage protection and delivery are separate boundaries
Trace a Secret through base64 representation, at-rest encryption and file consumption without exposing its value.
Base64 is reversible representation, not encryption. A reader of the value can recover the original bytes.
- Secret API object to API serverencoded bytes
Read the complete visual sequence
- Represent bytes in API data
Base64 is reversible representation, not encryption. A reader of the value can recover the original bytes.
- Protect persisted data deliberately
The API server encryption provider can encrypt selected stored resources. This must be configured and existing data handled appropriately.
- Deliver only to the intended process
The node projects the chosen Secret as a volume for the Pod, subject to access and filesystem configuration.
- Rotate application use
An updated projected file can arrive eventually, but the process must reread it and the old external credential must be retired safely.
Environment variable never refreshes
The Secret changes but the running process keeps its original environment.
- Initial credential injected
At startup the process receives an environment value derived from the Secret.
- Secret object rotates
The API value changes, but the existing environment of that process is unchanged.
- Complete the rotation workflow
Recreate the container to refresh its Secret-derived environment, or change to a supported file-reload design. Verify the new credential before retiring the old one.
About this model
No real credential values are shown; encryption provider configuration is cluster-specific.
Walkthrough: minimize every place credentials can appear
The following Pod fragment shows file-based Secret consumption without embedding the credential value in the workload manifest. This optional exercise requires a separately provisioned throwaway Secret or an approved external credential workflow; the module lab’s baseline does not create this Secret. Keep real credentials out of examples, shell history and version control.
# Fragment: spec of a workload that does not need Kubernetes API access.
automountServiceAccountToken: false
containers:
- name: application
image: busybox:1.36
command: ["sh", "-c", "test -r /credentials/password; sleep 3600"]
volumeMounts:
- name: credential
mountPath: /credentials
readOnly: true
volumes:
- name: credential
secret:
secretName: application-login
defaultMode: 0400 # Ensure the configured process UID can read it.
A Secret volume can be updated eventually when the Secret changes, but the application must reread the file or reload its configuration. A mount through subPath does not receive normal projected updates. A Secret injected as an environment variable does not update in an already running process when the Secret object changes. Plan rotation around both the external credential’s validity and the application’s consumption method; updating one API object is not a complete rotation procedure.
File permissions must match the process identity. The 0400 example is appropriate only when the intended process owns or can validly read the file under the actual volume and security context arrangement. A non-root process may need an intentionally designed group-readable mode and group settings. Do not solve a permission error by logging the Secret content to prove that it exists. Check file metadata and access results without revealing values.
A namespace boundary is assembled from several controls
Show API permission, workload admission and network enforcement controlling different tenant paths.
RBAC determines whether the tenant may create a Pod or directly read a Secret. These are distinct actions.
- Tenant identity to RBACcreate Pod?
Read the complete visual sequence
- Authorize the API action
RBAC determines whether the tenant may create a Pod or directly read a Secret. These are distinct actions.
- Constrain the proposal
Admission can restrict privileges, mounts and identity selection after API authorization. Namespace existence alone does not add these constraints.
- Constrain network edges
An enforcing data plane applies NetworkPolicy to workload traffic. RBAC does not control arbitrary application TCP connections.
- Review indirect credential access
A Pod creator may mount namespace Secrets unless the permitted workload configuration prevents that access. Audit indirect paths, not only get secrets.
Direct read denied but mount allowed
A tenant reaches a Secret through an unrestricted Pod specification.
- Direct get is denied
RBAC denies the tenant get secrets, which closes only the direct API read path.
- Pod creation permits a mount
The tenant can create a Pod referencing the Secret because the workload admission boundary did not restrict it.
- Credential becomes accessible
The admitted workload can consume the mounted Secret. Restrict workload capabilities and use stronger tenant boundaries where required.
About this model
Cooperative shared-cluster tenancy example; mutually hostile workloads may need stronger isolation.
Practice: verify access, presence and reload without revealing data
kubectl get secret application-login
kubectl describe secret application-login
# Describe lists keys and sizes, not decoded credential contents.
kubectl auth can-i get secrets -n learning
kubectl exec application -- sh -c 'test -r /credentials/password && echo readable'
kubectl get pod application -o yaml
The last command can show whether unexpected credential mounts or ServiceAccount settings were admitted. Treat Pod environment output and application debug endpoints as sensitive because they may expose secret-derived values. When extending the security lab with this Secret example, use only throwaway credentials, then rotate one value and observe whether the mounted file and application behavior change. Record reload behavior rather than printing the value itself.
A tenant boundary combines several controls. RBAC limits API operations; admission limits which Pod configurations those operations can create; NetworkPolicy constrains permitted traffic when enforced; quotas limit declared resource consumption; and node or cluster isolation limits shared host risk. Namespaces organize these controls but do not automatically supply all of them. Users allowed to create Pods in a namespace can often consume that namespace’s Secrets indirectly, even without direct get secrets, unless additional controls restrict workload creation and credential use.
Pitfalls: shared cluster trust is a design decision
A privileged tenant workload or hostPath mount can bypass assumptions about namespace isolation. Some API resources are cluster-scoped, and CRDs or admission webhooks may affect many tenants. Two cooperative application teams and two mutually hostile customers require different boundaries. For stronger isolation, consider dedicated nodes with enforced placement rules, virtualized control planes or separate clusters, while evaluating which data-plane and host resources remain shared. Never describe quotas or a namespace label as a complete security sandbox.
Check your understanding
A user cannot get Secrets directly but can create arbitrary Pods in the same namespace. Is the Secret necessarily protected from that user?
No. The user may create a Pod that mounts the Secret or uses a more powerful ServiceAccount, depending on admission rules and available identities. Analyze indirect access paths as well as direct API verbs. Protecting credentials requires constraints on workload creation, identity selection and mounts, in addition to limiting Secret read permission.
Next, use these boundaries while diagnosing failures. Operational visibility should reveal the responsible layer without collecting credentials or unnecessary tenant data.
Primary documentation
Go to the source
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise