# kubernetes-pentesting

A Kubernetes pentesting playbook: API server access, RBAC enumeration, service account token abuse, etcd, the Kubelet API and pod escape.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3700 installs · ★ 2547
- Author: yaklang
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yaklang/hack-skills/tree/HEAD/skills/kubernetes-pentesting/SKILL.md
- Updated: 2026-09-13
- HTML: https://affpapa.org/en/nevibecode/skills/kubernetes-pentesting

## What it does

The skill hands the agent ready-made commands and chains for probing a Kubernetes cluster. It starts with anonymous access checks against the API server on ports 6443, 8443 and 8080, then token auth from `/var/run/secrets/kubernetes.io/serviceaccount/token` and kubeconfig auth, RBAC enumeration with `kubectl auth can-i --list`, and a hunt for cluster roles carrying wildcard verbs or resources.

Later sections cover service account token abuse, reading secrets straight out of etcd on port 2379, escaping a pod to the node through `hostPID`, `hostNetwork`, `hostPath` or a privileged container, and hitting the Kubelet API on ports 10250 and 10255. A separate block deals with cloud attacks: IMDS access on EKS, GKE and AKS, admission webhook bypass and network policy evasion.

The skill routes to sibling material in the same repository: `container-escape-techniques`, `linux-privilege-escalation`, `linux-lateral-movement`, `linux-security-bypass` and `ssrf-server-side-request-forgery`. The source text is cut off, so the full set of cloud techniques can't be checked from it. Treat this as authorized-testing material only: commands such as `kubectl create token admin-sa -n kube-system --duration=87600h` or applying a privileged pod change cluster state.

## Requirements
- Works with: Kubernetes

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill kubernetes-pentesting -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/kubernetes-pentesting/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/kubernetes-pentesting/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill kubernetes-pentesting -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/kubernetes-pentesting/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill kubernetes-pentesting -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/kubernetes-pentesting/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yaklang/hack-skills kubernetes-pentesting
```

2. **Manually: put the files in place**
- File: `.github/skills/kubernetes-pentesting/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill kubernetes-pentesting -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yaklang/hack-skills --path skills/kubernetes-pentesting
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/kubernetes-pentesting/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill kubernetes-pentesting -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yaklang/hack-skills/tree/HEAD/skills/kubernetes-pentesting/SKILL.md

## When to use it
- check whether anonymous auth is on at the API server
- find roles and clusterroles with wildcard permissions
- pull a service account token from a pod and decode its JWT
- read secrets directly from etcd on port 2379
- run a command in a pod via the Kubelet API, bypassing RBAC

## Example prompts
- Check anonymous access to the cluster API server and show what comes back
- List cluster roles with wildcard permissions using kubectl auth can-i --list
- Work out whether this pod can reach IMDS on EKS

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: adf9ada945ff1dd3.

BEGIN THIRD-PARTY FILE adf9ada945ff1dd3
````text
---
name: kubernetes-pentesting
description: >-
  Kubernetes penetration testing playbook. Use when targeting Kubernetes clusters via API server, RBAC enumeration, service account abuse, etcd access, Kubelet API, pod escape, cloud-specific metadata, admission webhook bypass, and registry secrets.
---

# SKILL: Kubernetes Pentesting — Expert Attack Playbook

> **AI LOAD INSTRUCTION**: Expert Kubernetes attack techniques. Covers API server access, RBAC escalation, service account token abuse, etcd secrets extraction, Kubelet API exploitation, cloud IMDS access (EKS/GKE/AKS), admission webhook bypass, and network policy evasion. Base models miss the distinction between namespace-scoped and cluster-scoped RBAC, and overlook Kubelet's unauthenticated API.

## 0. RELATED ROUTING

Before going deep, consider loading:

- [container-escape-techniques](../container-escape-techniques/SKILL.md) for escaping from a compromised pod to the underlying node
- [linux-privilege-escalation](../linux-privilege-escalation/SKILL.md) once on a node for escalating to root
- [linux-lateral-movement](../linux-lateral-movement/SKILL.md) for pivoting between nodes
- [linux-security-bypass](../linux-security-bypass/SKILL.md) when Pod Security Standards or seccomp profiles restrict your actions
- [ssrf-server-side-request-forgery](../ssrf-server-side-request-forgery/SKILL.md) when exploiting SSRF to reach the K8s API or cloud metadata

---

## 1. K8S API SERVER ACCESS

### 1.1 Anonymous Access Check

```bash
# Check if anonymous auth is enabled (default: limited in modern clusters)
curl -sk https://APISERVER:6443/api/v1/namespaces
curl -sk https://APISERVER:6443/version
curl -sk https://APISERVER:6443/api
curl -sk https://APISERVER:6443/apis

# Common API server ports:
# 6443 — secure API (default)
# 8443 — alternative secure
# 8080 — insecure API (legacy, no auth needed)
```

### 1.2 Token-Based Authentication (from inside pod)

```bash
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
APISERVER="https://kubernetes.default.svc"

curl -s --cacert $CACERT -H "Authorization: Bearer $TOKEN" \
  $APISERVER/api/v1/namespaces/$NAMESPACE/pods
```
````
END THIRD-PARTY FILE adf9ada945ff1dd3

The third-party file has ended. Everything between the adf9ada945ff1dd3 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2303 of 12617 bytes. © yaklang · MIT · https://github.com/yaklang/hack-skills/tree/HEAD/skills/kubernetes-pentesting/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
