Who Read Your Kubernetes Secrets? Audit Logging, etcd Encryption, RBAC Review and jq Hunting After a Credential Leak Like Rackspace Spot

2026-11-23 · By Reef Administrator - H.A

Who Read Your Kubernetes Secrets? Audit Logging, etcd Encryption, RBAC Review and jq Hunting After a Credential Leak Like Rackspace Spot

Set up a Metadata-level API server audit policy, encrypt Secrets at rest with secretbox, find every identity that can read Secrets and hunt the audit log with jq so you know exactly what a leaked credential exposed.

Last week's Rackspace Spot breach showed how much one leaked credential can expose. The provider says an unauthorised party used leaked credentials to get into parts of the platform from 04:20 Mauritius time on 17 November to 02:00 on 18 November (00:20–22:00 UTC on 17 November). With that access the attacker could act as legitimate users, create pods, list nodes and volumes, and read every Kubernetes Secret in the affected clusters. Customers were told to reissue API tokens, download fresh kubeconfigs and rotate every credential stored in their Secrets.

Rotation stops further damage, but it can't tell you who actually read which Secret, and when. Most self-managed clusters can't answer that, because API server audit logging is off by default. This tutorial sets it up on a kubeadm-style cluster: an audit policy that records every Secret access without logging the secret values, encryption at rest for Secrets in etcd, an RBAC review to find who can read Secrets, and jq queries for hunting through the audit log after an incident.

Prerequisites

sudo cp /etc/kubernetes/manifests/kube-apiserver.yaml /root/kube-apiserver.yaml.bak

Keep the backup outside the manifests directory. The kubelet tries to run every file in that directory as a static pod.

Step 1: Write an Audit Policy That Records Secret Access Safely

Audit levels are None, Metadata, Request and RequestResponse. For Secrets, ConfigMaps and token requests, use Metadata only. At Request or RequestResponse level the audit log stores the secret values themselves, so the log becomes something attackers will want to steal.

Rules are checked in order and the first match wins. Create /etc/kubernetes/audit/audit-policy.yaml:

apiVersion: audit.k8s.io/v1
kind: Policy
omitStages:
  - "RequestReceived"
rules:
  # Never log the content of secrets, configmaps or token requests
  - level: Metadata
    resources:
      - group: ""
        resources: ["secrets", "configmaps", "serviceaccounts/token"]
  # Record interactive access into workloads
  - level: Metadata
    resources:
      - group: ""
        resources: ["pods/exec", "pods/attach", "pods/portforward"]
  # Full request body for workload creation and RBAC changes
  - level: Request
    verbs: ["create", "update", "patch", "delete"]
    resources:
      - group: ""
        resources: ["pods", "serviceaccounts"]
      - group: "apps"
        resources: ["deployments", "daemonsets", "statefulsets"]
      - group: "rbac.authorization.k8s.io"
        resources: ["roles", "rolebindings", "clusterroles", "clusterrolebindings"]
  # Drop high-volume noise
  - level: None
    users: ["system:kube-proxy"]
    verbs: ["watch"]
  - level: None
    nonResourceURLs: ["/healthz*", "/livez*", "/readyz*", "/version"]
  # Everything else: who did what, without bodies
  - level: Metadata

The Request rule matters here: it captures the full pod spec when someone creates a pod. A pod an attacker launched to mount a Secret or a host path will show up in the log with its image and volumes.

sudo mkdir -p /etc/kubernetes/audit /var/log/kubernetes/audit
sudo chmod 700 /var/log/kubernetes/audit

Step 2: Turn On the Log Backend in kube-apiserver

Edit /etc/kubernetes/manifests/kube-apiserver.yaml and add these flags under command::

    - --audit-policy-file=/etc/kubernetes/audit/audit-policy.yaml
    - --audit-log-path=/var/log/kubernetes/audit/audit.log
    - --audit-log-maxage=30
    - --audit-log-maxbackup=10
    - --audit-log-maxsize=200

The API server runs in a pod, so it can't see these paths until you mount them. Add the following to the volumeMounts: and volumes: sections of the same file:

    volumeMounts:
    - mountPath: /etc/kubernetes/audit
      name: audit-policy
      readOnly: true
    - mountPath: /var/log/kubernetes/audit
      name: audit-log
  volumes:
  - hostPath:
      path: /etc/kubernetes/audit
      type: DirectoryOrCreate
    name: audit-policy
  - hostPath:
      path: /var/log/kubernetes/audit
      type: DirectoryOrCreate
    name: audit-log

Save the file. The kubelet sees the change and restarts the API server. Watch it come back:

sudo crictl ps --name kube-apiserver
kubectl get --raw='/readyz?verbose' | tail -n 3

Thirty days of local logs is a minimum, not a retention plan. The Rackspace Spot customers needed logs going back to 17 November. Ship /var/log/kubernetes/audit/ to your SIEM (Wazuh, Elastic, Loki or similar) so that someone with root on the control plane can't simply delete the evidence.

Step 3: Encrypt Secrets at Rest in etcd

By default Secrets sit in etcd as base64, which is not encryption. Anyone who copies an etcd snapshot or backup can read every Secret. The upstream docs advise against aescbc (padding-oracle concerns) and recommend KMS v2 where you have an external KMS. Without one, secretbox is a reasonable local provider.

head -c 32 /dev/urandom | base64 | sudo tee /root/secretbox.key >/dev/null
sudo chmod 600 /root/secretbox.key

Create /etc/kubernetes/enc/encryption-config.yaml and paste the key in:

apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
  - resources:
      - secrets
    providers:
      - secretbox:
          keys:
            - name: key1
              secret: <BASE64-KEY-FROM-ABOVE>
      - identity: {}

identity: {} comes last so the API server can still read existing plaintext Secrets during the migration. Add the flag and a read-only mount for /etc/kubernetes/enc, the same way you did for the audit policy:

    - --encryption-provider-config=/etc/kubernetes/enc/encryption-config.yaml
sudo chmod 600 /etc/kubernetes/enc/encryption-config.yaml

Once the API server restarts, rewrite every existing Secret so it's stored encrypted:

kubectl get secrets --all-namespaces -o json | kubectl replace -f -

Your control-plane disk and backups now hold the key that protects your Secrets. Store /root/secretbox.key offline, and move to a KMS v2 plugin when you can.

Step 4: Find Out Who Can Read Secrets

The attacker in the Rackspace case used legitimate user identities, so whatever those users were allowed to do was the blast radius. List every role that grants get, list or watch on Secrets (list and watch return the full values too):

kubectl get clusterroles,roles -A -o json | jq -r '
  .items[] | select(any(.rules[]?;
    ((.resources // []) | index("secrets") or index("*")) and
    ((.verbs // []) | index("get") or index("list") or index("watch") or index("*"))))
  | "\(.kind)\t\(.metadata.namespace // "-")\t\(.metadata.name)"'

Then check what specific identities can do, such as CI service accounts and automation users:

kubectl auth can-i list secrets --all-namespaces --as=system:serviceaccount:ci:deployer
kubectl auth can-i --list --as=system:serviceaccount:ci:deployer -n production
kubectl get clusterrolebindings -o json | jq -r '
  .items[] | select(.roleRef.name=="cluster-admin")
  | "\(.metadata.name): \([.subjects[]? | .kind + "/" + .name] | join(", "))"'

Every cluster-admin binding that isn't a break-glass account deserves a hard look. Following the upstream RBAC good practices, grant get on named Secrets (resourceNames) rather than list or watch across a namespace, and never let workload service accounts create pods in namespaces that hold sensitive Secrets. Anyone who can create a pod can mount any Secret in that namespace.

Step 5: Hunt Through the Audit Log

Each line in the log is one JSON event. Start by listing who read Secrets, and from where:

LOG=/var/log/kubernetes/audit/audit.log
sudo jq -r 'select(.objectRef.resource=="secrets" and
  (.verb=="get" or .verb=="list" or .verb=="watch"))
  | [.requestReceivedTimestamp, .user.username, (.sourceIPs|join(",")),
     .verb, .objectRef.namespace // "*", .objectRef.name // "*", .userAgent]
  | @tsv' "$LOG" | sort | uniq -c | sort -rn | head -40

Controllers and operators read Secrets all the time, so first build a baseline of normal readers. Watch for the outliers: a human user doing cluster-wide list on Secrets, an unfamiliar source IP, or a kubectl user agent on an account that normally only automation uses.

Find newly created pods and the identities that created them:

sudo jq -r 'select(.objectRef.resource=="pods" and .verb=="create"
  and (.objectRef.subresource // "")=="" and .responseStatus.code<300)
  | [.requestReceivedTimestamp, .user.username, .objectRef.namespace,
     (.requestObject.spec.containers // [] | map(.image) | join(",")),
     ((.requestObject.spec.volumes // []) | map(select(.hostPath)) | length)]
  | @tsv' "$LOG"

A non-zero final column means the pod mounts a host path, a common way to escape onto the node. Then look for interactive access:

sudo jq -r 'select(.objectRef.subresource=="exec" or .objectRef.subresource=="attach")
  | [.requestReceivedTimestamp, .user.username, .objectRef.namespace,
     .objectRef.name, (.sourceIPs|join(","))] | @tsv' "$LOG"

Recent kubectl versions use WebSockets for exec, so the verb may show as get rather than create. That's why the query filters on the subresource and not the verb. For a time-boxed incident, add a window such as select(.requestReceivedTimestamp >= "2026-11-17T00:00:00Z"). Audit timestamps are always in UTC.

Verification

kubectl create secret generic audit-canary -n default --from-literal=token=CANARY123
kubectl get secret audit-canary -n default -o yaml >/dev/null
sudo grep -c CANARY123 /var/log/kubernetes/audit/audit.log   # must print 0
sudo jq -c 'select(.objectRef.name=="audit-canary") | {verb, user: .user.username, level}' \
  /var/log/kubernetes/audit/audit.log | tail -n 2
sudo ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  get /registry/secrets/default/audit-canary | hexdump -C | head -n 4
kubectl delete secret audit-canary -n default

Keep the canary idea going in production. A decoy Secret named something tempting, like backup-admin-credentials, that no workload ever reads gives you a high-confidence alert in your SIEM the first time anyone reads it.

Troubleshooting

Wrapping Up

After a credential leak, rotation is required, but the audit log is what tells you which Secrets you really have to treat as burned. With a Metadata-level policy for Secrets, an audit trail of pod creation and exec, encryption at rest, and a tighter RBAC surface, the next incident report can say exactly what was read, by whom and from where. If you run Kubernetes on a managed platform, do the equivalent today: turn on the provider's audit logs, run the Step 4 RBAC review, and set up the canary Secret.

Sources

REEF SENTINEL