Skip to content

Instantly share code, notes, and snippets.

@indradhanush
Last active October 30, 2025 13:16
Show Gist options
  • Select an option

  • Save indradhanush/454a2babad32ce20227b584fa0be9904 to your computer and use it in GitHub Desktop.

Select an option

Save indradhanush/454a2babad32ce20227b584fa0be9904 to your computer and use it in GitHub Desktop.
Privilege escalation on kubernetes node
apiVersion: v1
kind: Pod
metadata:
name: debug-pod
namespace: default
labels:
app: debug-pod
spec:
hostNetwork: true
hostPID: true
hostIPC: true
containers:
- name: debug
image: ubuntu:22.04
command: ["/bin/bash"]
args: ["-c", "apt-get update && apt-get install -y curl wget net-tools procps util-linux && sleep infinity"]
securityContext:
privileged: true
allowPrivilegeEscalation: true
runAsUser: 0
capabilities:
add:
- SYS_ADMIN
- SYS_PTRACE
- SYS_TIME
- NET_ADMIN
- IPC_LOCK
volumeMounts:
- name: host-root
mountPath: /host
readOnly: false
- name: host-var-log
mountPath: /host/var/log
readOnly: true
- name: host-dev
mountPath: /dev
readOnly: false
- name: host-proc
mountPath: /host/proc
readOnly: true
- name: host-sys
mountPath: /host/sys
readOnly: true
- name: host-run
mountPath: /host/run
readOnly: false
- name: host-var-run
mountPath: /host/var/run
readOnly: false
env:
- name: DEBIAN_FRONTEND
value: noninteractive
volumes:
- name: host-root
hostPath:
path: /
type: Directory
- name: host-var-log
hostPath:
path: /var/log
type: Directory
- name: host-dev
hostPath:
path: /dev
type: Directory
- name: host-proc
hostPath:
path: /proc
type: Directory
- name: host-sys
hostPath:
path: /sys
type: Directory
- name: host-run
hostPath:
path: /run
type: Directory
- name: host-var-run
hostPath:
path: /var/run
type: Directory
restartPolicy: Never
tolerations:
- operator: Exists
effect: NoSchedule
- operator: Exists
effect: NoExecute
@mridulgain

mridulgain commented Oct 30, 2025

Copy link
Copy Markdown

Same concept but daemonset & updated image

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: debug-daemon
  namespace: default
spec:
  selector:
    matchLabels:
      app: debug-pod
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: debug-pod
    spec:
      hostNetwork: true
      hostPID: true
      hostIPC: true
      tolerations:
      - operator: Exists
        effect: NoSchedule
      - operator: Exists
        effect: NoExecute
      containers:
      - name: debug
        image: quay.io/platform9/ubuntu:netshoot
        command: ["/bin/bash"]
        args: ["-c", "sleep infinity"]
        securityContext:
          privileged: true
          allowPrivilegeEscalation: true
          runAsUser: 0
          capabilities:
            add:
            - SYS_ADMIN
            - SYS_PTRACE
            - SYS_TIME
            - NET_ADMIN
            - IPC_LOCK
        env:
        - name: DEBIAN_FRONTEND
          value: noninteractive
        volumeMounts:
        - name: host-root
          mountPath: /host
          readOnly: false
        - name: host-var-log
          mountPath: /host/var/log
          readOnly: true
        - name: host-dev
          mountPath: /dev
          readOnly: false
        - name: host-proc
          mountPath: /host/proc
          readOnly: true
        - name: host-sys
          mountPath: /host/sys
          readOnly: true
        - name: host-run
          mountPath: /host/run
          readOnly: false
        - name: host-var-run
          mountPath: /host/var/run
          readOnly: false
      volumes:
      - name: host-root
        hostPath:
          path: /
          type: Directory
      - name: host-var-log
        hostPath:
          path: /var/log
          type: Directory
      - name: host-dev
        hostPath:
          path: /dev
          type: Directory
      - name: host-proc
        hostPath:
          path: /proc
          type: Directory
      - name: host-sys
        hostPath:
          path: /sys
          type: Directory
      - name: host-run
        hostPath:
          path: /run
          type: Directory
      - name: host-var-run
        hostPath:
          path: /var/run
          type: Directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment