Kubernetes Detection Engineering: Why Volume-Based Alerts Fail and How Baselining Catches Lateral Movement + Video

Listen to this Post

Featured Image

Introduction:

Kubernetes environments generate massive volumes of audit logs, but traditional volume‑based threshold alerts often miss sophisticated attacks where adversaries “live off the land.” By baselining normal user behavior—specifically the namespaces and resource types an engineer typically touches—security teams can detect lateral movement with high fidelity. This article explores practical detection engineering for Kubernetes, drawing on insights from Brandon L.’s recent series and a synthetic 30‑day audit log dataset to illustrate how scope‑based baselining outperforms statistical models.

Learning Objectives:

  • Understand why volume‑based thresholds fail against low‑and‑slow attackers in Kubernetes.
  • Learn to baseline normal user behavior using namespace and resource type footprints.
  • Implement categorical expansion alerts to detect lateral movement and privilege escalation.

1. The Problem with Volume‑Based Detection in Kubernetes

Many detection rules rely on thresholds—e.g., “alert if a user creates more than 50 pods in 5 minutes.” Attackers using compromised credentials often operate within normal business hours and keep their activity volume indistinguishable from everyday traffic. This renders volume‑based alerts useless.

Step‑by‑step: Simulating Normal vs. Attack Traffic

1. Extract a user’s historical pod creation counts:

 Assuming audit logs are in JSON format (e.g., from kube-apiserver)
jq 'select(.user.username=="[email protected]" and .objectRef.resource=="pods" and .verb=="create") | .timestamp' audit.log | wc -l

2. Calculate per‑hour average and standard deviation:

 Group by hour and count
jq -r 'select(.user.username=="[email protected]" and .verb=="create") | .timestamp[0:13]' audit.log | sort | uniq -c

You’ll notice natural fluctuations, but an attacker creating 10 pods per hour (within the 95th percentile) won’t trigger an alert.

3. Why it fails:

Attackers mimic normal patterns. The real signal is not how much but where they operate.

  1. Baselining Normal Behavior: Collecting and Parsing Audit Logs
    Before you can detect anomalies, you need a comprehensive audit log baseline. Kubernetes audit logs record every request to the API server, including user, namespace, resource, verb, and response status.

Step‑by‑step: Enable and Collect Audit Logs

1. Create an audit policy file (`audit-policy.yaml`):

apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
resources:
- group: ""
resources: ["pods", "services", "configmaps"]

2. Pass the policy to the API server (if self‑managed) or enable audit logging in managed clusters (e.g., GKE, EKS).
3. Stream logs to a central location (e.g., using Fluentd to Elasticsearch).
4. Parse logs with `jq` to build user profiles:

jq -r 'select(.user.username) | [.user.username, .objectRef.namespace, .objectRef.resource, .verb] | @csv' audit.log > user_activity.csv
  1. Identifying Scope: Building User Footprints with Namespace and Resource Type
    The key insight: each engineer normally touches a limited set of namespaces (e.g., dev, staging) and resource types (e.g., deployments, pods). Attackers who pivot to production namespaces or create `clusterroles` stand out immediately.

Step‑by‑step: Build a Baseline of Allowed Footprint

1. Aggregate unique (namespace, resource) pairs per user:

jq -r 'select(.user.username=="[email protected]") | "(.objectRef.namespace):(.objectRef.resource)"' audit.log | sort -u > engineer_baseline.txt

2. Example baseline content:

dev:pods
dev:services
staging:deployments

3. Store baseline in a detection rule (e.g., in Falco or a SIEM).

4. Detecting Lateral Movement: Alerting on Scope Expansion

Now that you have a baseline, any activity outside it becomes an alert. This catches attackers even if they keep volume low.

Step‑by‑step: Real‑time Detection with a Custom Script

  1. Write a Python script that consumes live audit logs and checks against the baseline:
    import json
    import sys
    
    Load baseline
    baseline = set()
    with open('engineer_baseline.txt') as f:
    for line in f:
    baseline.add(line.strip())</p></li>
    </ol>
    
    <p>for line in sys.stdin:
    log = json.loads(line)
    user = log.get('user', {}).get('username')
    ns = log.get('objectRef', {}).get('namespace')
    resource = log.get('objectRef', {}).get('resource')
    key = f"{ns}:{resource}"
    if user == "[email protected]" and key not in baseline:
    print(f"ALERT: {user} accessed {key} outside baseline")
    

    2. Pipe live audit logs into the script:

    tail -f /var/log/kubernetes/audit.log | python3 detect_scope.py
    

    3. Integrate with alerting tools (e.g., Slack, PagerDuty).

    5. Attack Scenario: Simulating a Scarleteel‑Style Kubernetes Pivot

    Let’s walk through a realistic attack based loosely on Scarleteel, where an external probe leads to a pod compromise and lateral movement.

    Phase 1: External Probing

    • Attacker scans for exposed Kubernetes API servers. No unusual volume, just a few HTTP requests.
    • Detection via scope: the probing IP is not a known user, but that’s trivial. The real test is after credential compromise.

    Phase 2: Compromised Developer Credentials

    • Attacker uses a stolen service account token from a vulnerable pod. They start by listing pods in the `dev` namespace (normal for that service account).
    • Then they attempt to list secrets in kube-system.
    • Alert: The `kube-system:secrets` pair is not in the service account’s baseline → immediate high‑fidelity alert.

    Phase 3: Pivot and Persistence

    • Even if they create a single pod in `kube-system` (low volume), the namespace is outside the baseline, triggering detection.

    Simulate with `kubectl`:

     Normal activity (within baseline)
    kubectl get pods -n dev
     Anomalous activity (outside baseline)
    kubectl get secrets -n kube-system
    

    6. Advanced: Why Categorical Footprint Beats Statistical Models

    Statistical models like Interquartile Range (IQR) on request counts degrade over time as noise accumulates. Categorical baselines (e.g., sets of allowed namespaces) are immune to volume changes and provide deterministic alerts.

    Step‑by‑step: Compare IQR vs. Categorical Detection

    1. Simulate a year of normal traffic with occasional legitimate namespace additions.

    – IQR on counts will adapt slowly and may miss subtle changes.
    – Categorical detection will alert immediately on any new namespace.
    2. Test with a script that injects a single request to a new namespace:

     IQR-based rule would likely not trigger (single event)
     Categorical rule triggers immediately
    

    3. Result: Categorical footprint expansion is your sharpest tool for infrastructure hardening.

    7. Hardening Kubernetes: Recommendations from Baselining Insights

    Baselining reveals gaps in RBAC and namespace isolation. Here’s how to harden your cluster:

    • Enforce least privilege with RBAC: limit each service account to specific namespaces and resource types.
    • Use Namespace‑Network Policies to prevent lateral pod‑to‑pod communication.
    • Audit frequently to update baselines as teams evolve.
    • Deploy admission controllers (e.g., OPA/Gatekeeper) to block out‑of‑scope resource creation at the API level.

    What Undercode Say

    • Key Takeaway 1: Volume‑based alerts create blind spots; focus on scope—the namespaces and resource types a user or service account should access—to catch lateral movement with near‑zero false positives.
    • Key Takeaway 2: Categorical baselines derived from audit logs are more reliable than statistical models because they ignore traffic volume and concentrate on behavioral footprint.
    • Analysis: While baselining requires initial effort to collect and normalize logs, it pays off by detecting sophisticated attacks that evade traditional rules. Teams should start by auditing high‑privilege users and service accounts, then expand to all identities. Integration with SIEM and automated response (e.g., temporary account lockout) can further reduce dwell time. The challenge lies in maintaining baselines as infrastructure and roles change—but this can be mitigated by periodic reviews and anomaly detection on baseline changes themselves.

    Prediction:

    As Kubernetes adoption grows, detection engineering will shift from signature‑based rules to behavioral baselining powered by machine learning. We will see more tools that automatically build user and workload profiles, alert on footprint deviations, and even proactively adjust RBAC policies. Attackers will respond by attempting to blend into legitimate footprints longer, forcing defenders to adopt continuous verification and zero‑trust principles inside the cluster.

    ▶️ Related Video (82% Match):

    🎯Let’s Practice For Free:

    IT/Security Reporter URL:

    Reported By: Brandon L – Hackers Feeds
    Extra Hub: Undercode MoN
    Basic Verification: Pass ✅

    🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

    💬 Whatsapp | 💬 Telegram

    📢 Follow UndercodeTesting & Stay Tuned:

    𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky