RTFM_ security field notes

Kubernetes

Enumerate a cluster, deploy a pod and query the API from a compromised service account.

Review leads, not findings by themselves:

  • Git repository reachable from the application
  • SSRF (http://metadata-db/)
  • Docker socket reachable from a container
  • Legacy Helm/Tiller exposure, where that component exists
  • Unintended service exposure through NodePort
  • Unexpected jobs or workloads
  • Sensitive values in environment variables
  • No resource limits (DoS)
  • Service-account token mounting and its effective permissions

Basics

kubectl manages a cluster from a user workstation. kubelet only manages a single node. kubectx switches between clusters, and kubens is its equivalent for namespaces.

rbac stands for “Role Based Access Control”: it is the system that governs user rights on the cluster. Rights apply to cluster resources (pods, namespaces, deployments and so on) at the following levels: create, get, delete, list, update.

kubectl api-resources lists resource types, not object instances. kubectl get all lists a subset of common resources in the selected namespace; it does not include every object type or Secrets.

List pods: kubectl get pod

List secrets: kubectl get secret

Describe an object: kubectl describe <object_type>/<object_name>

Obtain a shell in a container, if permitted: kubectl exec -it <POD_NAME> -n <NAMESPACE> -- sh

Set a default namespace with kubectl config set-context --current --namespace=<namespace_name>. Objects across all namespaces can also be listed by adding the --all-namespaces argument to a kubectl get command.

Deploying an offensive pod

Creating a pod changes cluster state and requires API and admission permissions. This manifest is not privileged and does not itself grant host or cluster access.

Legacy toolbox pod manifest
apiVersion: v1
kind: Pod
metadata:
    name: exegol
    labels:
        app: exegol
spec:
    containers:
    - image: nwodtuhs/exegol:stable
      command:
        - "sleep"
        - "604800"
      imagePullPolicy: IfNotPresent
      name: exegol
    restartPolicy: Always

Start it with kubectl apply -f <deploy_file>.

Creating a network policy

Allow-all example, not hardening: this policy selects every pod in its namespace and allows all ingress and egress. Enforcement requires a network plugin that implements NetworkPolicy.

Allow-all policy manifest
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: web-allow-all
spec:
  podSelector: {}
  ingress:
  - {}
  egress:
  - {}

Use through cURL

Retrieving the token and the API

In a pod with service-account credentials mounted, the API token and CA are usually under /var/run/secrets/kubernetes.io/serviceaccount. Mounting can be disabled. Possessing a token does not imply permission to read Secrets.

API request with the mounted service-account token
# Point to the internal API server hostname
APISERVER=https://kubernetes.default.svc

# Path to ServiceAccount token
SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount

# Read this Pod's namespace
NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)

# Read the ServiceAccount bearer token
TOKEN=$(cat ${SERVICEACCOUNT}/token)

# Reference the internal certificate authority (CA)
CACERT=${SERVICEACCOUNT}/ca.crt

# Explore the API with TOKEN
curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api

Listing secrets

curl --cacert "$CACERT" -H "Authorization: Bearer $TOKEN" "$APISERVER/api/v1/namespaces/$NAMESPACE/secrets"

Impersonating a privileged account

Impersonation headers only work when the authenticated account already has the corresponding impersonate permissions. Supplying them is not an RBAC bypass.

curl --cacert "$CACERT" -H "Authorization: Bearer $TOKEN" -H "Impersonate-Group: system:masters" -H "Impersonate-User: null" -H "Accept: application/json" "$APISERVER/api/v1/namespaces/kube-system/secrets"

Protection

Detection of anomalous events in Kubernetes:

Resources:

Provenance and confidence
Version
2
Sources reviewed
2026-11-23
Confidence
medium — Legacy RTFM; v2 editorial review on 2026-11-23 corrects object enumeration and clarifies RBAC and allow-all policy limits. Kubernetes object documentation consulted; no cluster test.

Also searched as: k8s, kubernetes, rbac, jeton de service, élévation de privilèges conteneur