Appearance

Protecting Secrets and tenant boundaries

Follow a credential from its Kubernetes Secret to the application, then reason about who can read it.

What you will understand

  • Distinguish Base64 encoding, encryption at rest, and access control.
  • Deliver a Secret as a read-only file and verify presence without logging its contents.
  • Identify the controls needed when multiple teams share a cluster.

Builds on: Security contexts and Pod Security

Where a credential travels

A frontend needs a database password. Putting it directly in a Deployment would copy the value into every manifest and every place the manifest is reviewed. A Kubernetes Secret gives the credential its own API object. The workload can refer to the object by name. In a typical manifest, values in data use Base64 so binary values can be represented as text. Anyone who can read that field can decode it. Encryption at rest is configured separately at the API server or through the managed cluster service.

Follow the password in the scene. An authorized client or deployment process writes the Secret. Kubernetes stores it as API data. A Pod specification requests it as a volume, and the kubelet writes the selected content into a mount. Every boundary has its own access checks, and every process with access to the mounted file can read it.

Follow the password and its access boundaries

Encoding represents the bytes, storage encryption protects persistence when configured, and a mount delivers the credential to the app.

  1. Represent bytes in a Secret

    Base64 is reversible representation, not encryption. A reader of the value can recover the original bytes.

  2. Protect stored API data

    The API server encryption provider can encrypt selected stored resources. This must be configured and existing data handled appropriately.

  3. Give the app its credential file

    The node projects the chosen Secret as a volume for the Pod, subject to access and filesystem configuration.

  4. Reload or restart after rotation

    An updated projected file can arrive eventually, but the process must reread it and the old external credential must be retired safely.

No real credential values are shown; encryption provider configuration is cluster-specific.

Mount a Secret and plan its rotation

The snippet goes inside a Pod spec. In the same namespace, create application-login with a dummy password key. The mount exposes that key as /credentials/password and is read-only inside the container. Check that the file’s mode and ownership allow the actual process identity to read it. automountServiceAccountToken: false avoids automatically mounting an API token in a workload that uses no API calls.

# 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.

If a Secret volume is mounted normally, kubelet updates its files eventually when the Secret changes. The application still needs to reload or reread them. Secret environment variables are set at container startup and changing the source does not change a running process’s environment. A mount using subPath does not receive automatic Secret volume updates.

Verify access without revealing the password

In a lab namespace, check whether your identity is allowed to read Secrets. Check file readability with the example command so its actual value never appears in console output. If you exercise rotation, use a dummy credential and verify that the app behaves correctly with the new one. A readable file proves the mount worked. A successful login with the new credential proves the app picked it up.

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

Practice with dummy data in the security lab. Try the tenant scene to see which layer controls each path.

Which layer handles each tenant risk?

RBAC, admission, network policy, and credential checks govern different ways one workload can affect another.

  1. Scope API actions

    RBAC determines whether the tenant may create a Pod or directly read a Secret. These are distinct actions.

  2. Constrain Pod proposals

    Admission can restrict privileges, mounts and identity selection after API authorization. Namespace existence alone does not add these constraints.

  3. Restrict network traffic

    An enforcing data plane applies NetworkPolicy to workload traffic. RBAC does not control arbitrary application TCP connections.

  4. Review indirect access to Secrets

    A Pod creator may mount namespace Secrets unless the permitted workload configuration prevents that access. Audit indirect paths, not only get secrets.

Cooperative shared-cluster tenancy example; mutually hostile workloads may need stronger isolation.

Protect the rest of the tenant boundary

A namespace scopes many resources. Its boundary also depends on who may create workloads, which API permissions they hold, and which connections and runtime settings are allowed. A user who can create arbitrary Pods in a namespace can potentially mount Secrets there. Use scoped RBAC, admission rules, and enforced network policies together. For tenants requiring a stronger trust boundary, dedicated nodes or clusters may be appropriate.

Check your understanding

You rotated a Secret mounted as a file, but the app still tries the old database password. What would you verify?

Verify whether the file was refreshed and how the app reloads it. An ordinary volume may update after a delay, while a subPath mount stays unchanged. An app that reads once at startup needs a supported reload or a controlled restart.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu