Kubernetes All Secrets Dumped Across Namespaces


Description

This detection monitors for cluster-wide secret list operations that dump all secrets across all namespaces in a single API call. Attackers with list secrets permissions at the cluster level can trivially access every secret in the cluster using the LIST /api/v1/secrets API, exposing all credentials, tokens, and sensitive configuration data. This is a known attack technique documented by Stratus Red Team and represents mass credential theft.

Query · python

from panther_kubernetes_helpers import is_failed_request, is_system_principal, k8s_alert_context

# System components that legitimately list all secrets cluster-wide
ALLOWED_SECRET_LISTERS = {
    "system:serviceaccount:kube-system:namespace-controller",
    "system:serviceaccount:kube-system:kube-state-metrics",
    "system:apiserver",
}


def rule(event):
    verb = event.udm("verb")
    resource = event.udm("resource")
    namespace = event.udm("namespace")
    username = event.udm("username") or ""
    response_status = event.udm("responseStatus")
    request_uri = event.udm("requestURI") or ""

    # Only check secret list operations that are successful
    if verb != "list" or resource != "secrets" or is_failed_request(response_status):
        return False

    # Key indicator: namespace is empty (cluster-wide list, not namespaced)
    # and requestURI doesn't contain /namespaces/ in path
    if namespace or (request_uri and "/namespaces/" in request_uri):
        return False

    # Exclude system principals and specific components
    if is_system_principal(username) or username in ALLOWED_SECRET_LISTERS:
        return False

    return True


def title(event):
    username = event.udm("username") or "<UNKNOWN_USER>"
    request_uri = event.udm("requestURI") or ""

    return f"[{username}] dumped all secrets across all namespaces (URI: {request_uri})"


def dedup(event):
    username = event.udm("username") or "<UNKNOWN_USER>"
    return f"k8s_secrets_dump_{username}"


def alert_context(event):
    request_uri = event.udm("requestURI") or ""

    # Extract query parameters if present (e.g., limit=500)
    query_params = {}
    if "?" in request_uri:
        query_string = request_uri.split("?", 1)[1]
        for param in query_string.split("&"):
            if "=" in param:
                key, value = param.split("=", 1)
                query_params[key] = value

    return k8s_alert_context(
        event,
        extra_fields={
            "request_uri": request_uri,
            "query_parameters": query_params,
            "operation": "list_all_secrets",
        },
    )

Analyst notes

  1. Immediately investigate the user or service account performing this operation and determine if they are compromised
  2. Review what secrets exist in the cluster to assess the scope of credential exposure and rotate all sensitive credentials
  3. Search for other suspicious API activity by this user in the past 24 hours and check for data exfiltration or lateral movement attempts
Raw source Kubernetes All Secrets Dumped Across Namespaces · Panther Python
Esc
Published by panther-labs/panther-analysis ↗, licensed under Apache 2.0 ↗. Reproduced here unmodified.
AnalysisType: rule
RuleID: "Kubernetes.Secrets.DumpAllNamespaces"
DisplayName: "Kubernetes All Secrets Dumped Across Namespaces"
Enabled: true
Status: Experimental
Filename: k8s_secrets_dump_all_namespaces.py
LogTypes:
  - Amazon.EKS.Audit
  - Azure.MonitorActivity
  - GCP.AuditLog
Tags:
  - Kubernetes
  - Credential Access
  - Mass Exfiltration
  - Secrets Management
  - Unified Detection
Severity: Critical
Description: >
  This detection monitors for cluster-wide secret list operations that dump all secrets across all namespaces in a
  single API call. Attackers with list secrets permissions at the cluster level can trivially access every secret in
  the cluster using the LIST /api/v1/secrets API, exposing all credentials, tokens, and sensitive configuration data.
  This is a known attack technique documented by Stratus Red Team and represents mass credential theft.
Runbook: |
  1. Immediately investigate the user or service account performing this operation and determine if they are compromised
  2. Review what secrets exist in the cluster to assess the scope of credential exposure and rotate all sensitive credentials
  3. Search for other suspicious API activity by this user in the past 24 hours and check for data exfiltration or lateral movement attempts
Reports:
  Stratus Red Team:
    - k8s.credential-access.dump-secrets
  MITRE ATT&CK:
    - TA0006:T1552.007 # Credential Access: Unsecured Credentials - Container API
    - TA0009:T1530 # Collection: Data from Cloud Storage Object
Reference: https://stratus-red-team.cloud/attack-techniques/kubernetes/k8s.credential-access.dump-secrets/
DedupPeriodMinutes: 60
SummaryAttributes:
  - username
  - p_source_label
Tests:
  - Name: EKS cluster-wide secret list
    ExpectedResult: true
    Log:
      {
        "kind": "Event",
        "apiVersion": "audit.k8s.io/v1",
        "stage": "ResponseComplete",
        "verb": "list",
        "user": {"username": "attacker@example.com"},
        "sourceIPs": ["203.0.113.42"],
        "userAgent": "kubectl/v1.28.0",
        "objectRef": {
          "resource": "secrets",
          "apiVersion": "v1"
        },
        "requestURI": "/api/v1/secrets?limit=500",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit",
        "p_source_label": "eks-cluster"
      }
  - Name: AKS cluster-wide secret list
    ExpectedResult: true
    Log:
      {
        "p_log_type": "Azure.MonitorActivity",
        "category": "kube-audit",
        "operationName": "Microsoft.ContainerService/managedClusters/diagnosticLogs/Read",
        "properties": {
          "log": "{\"kind\":\"Event\",\"apiVersion\":\"audit.k8s.io/v1\",\"stage\":\"ResponseComplete\",\"verb\":\"list\",\"user\":{\"username\":\"compromised-user@example.com\"},\"sourceIPs\":[\"1.2.3.4\"],\"objectRef\":{\"resource\":\"secrets\",\"apiVersion\":\"v1\"},\"requestURI\":\"/api/v1/secrets\",\"responseStatus\":{\"code\":200}}"
        },
        "p_source_label": "aks-cluster"
      }
  - Name: GKE cluster-wide secret list
    ExpectedResult: true
    Log:
      {
        "protoPayload": {
          "authenticationInfo": {"principalEmail": "user@company.com"},
          "authorizationInfo": [{
            "granted": true,
            "permission": "io.k8s.core.v1.secrets.list",
            "resource": "core/v1/secrets"
          }],
          "methodName": "io.k8s.core.v1.secrets.list",
          "requestMetadata": {"callerIP": "8.8.8.8"},
          "resourceName": "core/v1/secrets",
          "serviceName": "k8s.io",
          "requestURI": "/api/v1/secrets?limit=500"
        },
        "resource": {
          "type": "k8s_cluster",
          "labels": {"project_id": "test-project"}
        },
        "p_log_type": "GCP.AuditLog",
        "p_source_label": "gke-cluster"
      }
  - Name: EKS cluster-wide secret list with watch parameter
    ExpectedResult: true
    Log:
      {
        "kind": "Event",
        "verb": "list",
        "user": {"username": "attacker@example.com"},
        "objectRef": {"resource": "secrets", "apiVersion": "v1"},
        "requestURI": "/api/v1/secrets?watch=true",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit",
        "p_source_label": "eks-cluster"
      }
  - Name: Namespaced secret list (not cluster-wide)
    ExpectedResult: false
    Log:
      {
        "kind": "Event",
        "verb": "list",
        "user": {"username": "developer@example.com"},
        "objectRef": {
          "resource": "secrets",
          "namespace": "production",
          "apiVersion": "v1"
        },
        "requestURI": "/api/v1/namespaces/production/secrets",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit"
      }
  - Name: Get single secret (not list)
    ExpectedResult: false
    Log:
      {
        "kind": "Event",
        "verb": "get",
        "user": {"username": "admin@example.com"},
        "objectRef": {
          "resource": "secrets",
          "namespace": "default",
          "name": "api-token",
          "apiVersion": "v1"
        },
        "requestURI": "/api/v1/namespaces/default/secrets/api-token",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit"
      }
  - Name: System component listing secrets (excluded)
    ExpectedResult: false
    Log:
      {
        "kind": "Event",
        "verb": "list",
        "user": {"username": "system:serviceaccount:kube-system:namespace-controller"},
        "objectRef": {"resource": "secrets", "apiVersion": "v1"},
        "requestURI": "/api/v1/secrets",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit"
      }
  - Name: Kube-state-metrics listing secrets (excluded)
    ExpectedResult: false
    Log:
      {
        "kind": "Event",
        "verb": "list",
        "user": {"username": "system:serviceaccount:kube-system:kube-state-metrics"},
        "objectRef": {"resource": "secrets", "apiVersion": "v1"},
        "requestURI": "/api/v1/secrets",
        "responseStatus": {"code": 200},
        "p_log_type": "Amazon.EKS.Audit"
      }
  - Name: Failed cluster-wide list (excluded)
    ExpectedResult: false
    Log:
      {
        "kind": "Event",
        "verb": "list",
        "user": {"username": "attacker@example.com"},
        "objectRef": {"resource": "secrets", "apiVersion": "v1"},
        "requestURI": "/api/v1/secrets",
        "responseStatus": {"code": 403},
        "p_log_type": "Amazon.EKS.Audit"
      }


# ------ paired body: k8s_secrets_dump_all_namespaces.py ------

from panther_kubernetes_helpers import is_failed_request, is_system_principal, k8s_alert_context

# System components that legitimately list all secrets cluster-wide
ALLOWED_SECRET_LISTERS = {
    "system:serviceaccount:kube-system:namespace-controller",
    "system:serviceaccount:kube-system:kube-state-metrics",
    "system:apiserver",
}


def rule(event):
    verb = event.udm("verb")
    resource = event.udm("resource")
    namespace = event.udm("namespace")
    username = event.udm("username") or ""
    response_status = event.udm("responseStatus")
    request_uri = event.udm("requestURI") or ""

    # Only check secret list operations that are successful
    if verb != "list" or resource != "secrets" or is_failed_request(response_status):
        return False

    # Key indicator: namespace is empty (cluster-wide list, not namespaced)
    # and requestURI doesn't contain /namespaces/ in path
    if namespace or (request_uri and "/namespaces/" in request_uri):
        return False

    # Exclude system principals and specific components
    if is_system_principal(username) or username in ALLOWED_SECRET_LISTERS:
        return False

    return True


def title(event):
    username = event.udm("username") or "<UNKNOWN_USER>"
    request_uri = event.udm("requestURI") or ""

    return f"[{username}] dumped all secrets across all namespaces (URI: {request_uri})"


def dedup(event):
    username = event.udm("username") or "<UNKNOWN_USER>"
    return f"k8s_secrets_dump_{username}"


def alert_context(event):
    request_uri = event.udm("requestURI") or ""

    # Extract query parameters if present (e.g., limit=500)
    query_params = {}
    if "?" in request_uri:
        query_string = request_uri.split("?", 1)[1]
        for param in query_string.split("&"):
            if "=" in param:
                key, value = param.split("=", 1)
                query_params[key] = value

    return k8s_alert_context(
        event,
        extra_fields={
            "request_uri": request_uri,
            "query_parameters": query_params,
            "operation": "list_all_secrets",
        },
    )

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.