Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(rules): tighten kubernetes-secret-file-read token path patterns

AnandSundar4bfcf42a3695
diff --git a/rules/credential-access/kubernetes-secret-file-read.rule.yaml b/rules/credential-access/kubernetes-secret-file-read.rule.yaml
index f3f19748..84435de0 100644
--- a/rules/credential-access/kubernetes-secret-file-read.rule.yaml
+++ b/rules/credential-access/kubernetes-secret-file-read.rule.yaml
@@ -4,13 +4,15 @@ title: Agent read a Kubernetes secret-bearing file
description: >
The agent read a Kubernetes credential or cluster-admin artifact: a kubeconfig
file under ~/.kube/, a service-account bearer token, or a path bearing the
- kubeconfig / token naming convention. Kubeconfig files hold long-lived
- cluster credentials and are the canonical high-value Kubernetes secret;
- service-account tokens are the canonical runtime bearer secret. An agent
- reading either is almost always a credential-exfiltration or lateral-movement
- signal. The rule is anchored on the path (anchored to a slash or end of
- string, or to specific file names) so unrelated files with "kube" in the
- name (e.g. "kube-prometheus-stack/") do not fire.
+ kubeconfig / k8s-namespaced-token naming convention. Kubeconfig files hold
+ long-lived cluster credentials and are the canonical high-value Kubernetes
+ secret; service-account tokens are the canonical runtime bearer secret. An
+ agent reading either is almost always a credential-exfiltration or
+ lateral-movement signal. The token alternation is anchored to Kubernetes-
+ namespace prefixes (sa-token, service-account-token, kube-token, etc.) or
+ to a path under ~/.kube/ that contains a token-shaped basename, so unrelated
+ files with a generic "token" basename (oauth/token, api/token, auth/token)
+ do not fire.
severity: high
status: experimental
posture: detect
@@ -23,7 +25,8 @@ match: >
e.file.path.matches("(?i)(^|/)\\.kube/config(-[^/]+)?$") ||
e.file.path.matches("(?i)(^|/)kubeconfig(\\.yaml|\\.yml)?$") ||
e.file.path.matches("(?i)(^|/)\\.kube/[^/]*kubeconfig[^/]*$") ||
- e.file.path.matches("(?i)(^|/)(token|sa[-_]?token|service[-_]?account[-_]?token)(\\.csv)?$") ||
+ e.file.path.matches("(?i)(^|/)(sa[-_]?token|service[-_]?account[-_]?token|kube[-_]?token|kubernetes[-_]?token|k8s[-_]?token|cluster[-_]?token|admin[-_]?token|user[-_]?token|deploy[-_]?token|bootstrap[-_]?token)(\\.csv)?$") ||
+ e.file.path.matches("(?i)(^|/)\\.kube/(?:[^/]+/)*[^/]*token[^/]*$") ||
e.file.path.matches("(?i)/var/run/secrets/kubernetes\\.io/serviceaccount/(token|ca\\.crt|namespace)$")
)
@@ -73,3 +76,51 @@ tests:
- event: { action: file.read }
file: { path: "/home/u/.kube/" }
session: { id: s1 }
+ - name: read_kube_token_cache_in_dot_kube
+ verdict: match
+ events:
+ - event: { action: file.read }
+ file: { path: "/home/u/.kube/cache/sa-token-cache" }
+ session: { id: s1 }
+ - name: read_service_account_token_alt_name
+ verdict: match
+ events:
+ - event: { action: file.read }
+ file: { path: "/var/run/secrets/kubernetes.io/serviceaccount/service-account-token" }
+ session: { id: s1 }
+ - name: read_kube_token
+ verdict: match
+ events:
+ - event: { action: file.read }
+ file: { path: "/var/run/secrets/kubernetes.io/serviceaccount/kube-token" }
+ session: { id: s1 }
+ - name: read_oauth_token
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/api/oauth/token" }
+ session: { id: s1 }
+ - name: read_api_token
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/repo/api/token" }
+ session: { id: s1 }
+ - name: read_auth_token
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/repo/auth/token" }
+ session: { id: s1 }
+ - name: read_arbitrary_token_file
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/etc/myapp/token" }
+ session: { id: s1 }
+ - name: read_token_json
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/repo/tokens.json" }
+ session: { id: s1 }