Skip to content

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

feat(rules): add 3 sensitive-edit rules — SSH keys, /etc/hosts, container/IaC

AnandSundar42924b0aa7b2
diff --git a/rules/sensitive-edit/container-or-iac-file-modified.rule.yaml b/rules/sensitive-edit/container-or-iac-file-modified.rule.yaml
new file mode 100644
index 00000000..9713ad5c
--- /dev/null
+++ b/rules/sensitive-edit/container-or-iac-file-modified.rule.yaml
@@ -0,0 +1,111 @@
+id: container-or-iac-file-modified
+version: 1
+title: Container or IaC file modified (Dockerfile / compose / Terraform / K8s / Helm)
+description: >
+ The agent modified a container, orchestration, or infrastructure-as-code
+ file: a Dockerfile, a docker-compose YAML, a Terraform .tf / .tfstate,
+ a Kubernetes manifest (kubernetes*.yaml / k8s*.yaml / kustomization.yaml),
+ or a Helm values.yaml. A modified IaC file is a supply-chain /
+ lateral-movement primitive — an attacker can add a privileged
+ container, a host-path mount, an exec into a running pod, or a
+ wide-permission IAM role that gets applied on the next apply. The rule
+ matches the well-known file names (anchored on `Dockerfile` as a
+ whole word, anchored on `.tf` / `.tfstate` suffixes, anchored on
+ `values.yaml` as a leaf, and anchored on the k8s file-naming
+ convention), so random .yaml files in a repo are not flagged.
+severity: medium
+status: experimental
+posture: detect
+taxonomy:
+ owasp_llm: LLM03
+ mitre_atlas: AML.T0011
+
+match: >
+ e.event.action == "file.modified" && (
+ e.file.path.matches("(?i)(^|/)dockerfile(\\.prod|\\.dev|\\.local|\\.test|\\.staging|\\.debug|\\.alpine|\\.nginx|\\.node|\\.python|\\.go|\\.rust|\\.java|\\.base|\\.builder|\\.runtime|\\.ci|\\.prod|\\.pr[a-z0-9]+)?$") ||
+ e.file.path.matches("(?i)(^|/)containerfile(\\.prod|\\.dev|\\.local|\\.test|\\.staging|\\.debug|\\.alpine|\\.nginx|\\.node|\\.python|\\.go|\\.rust|\\.java|\\.base|\\.builder|\\.runtime|\\.ci|\\.pr[a-z0-9]+)?$") ||
+ e.file.path.matches("(?i)(^|/)docker-compose(-[^/]+)?\\.(yml|yaml)$") ||
+ e.file.path.matches("(?i)(^|/)[^/]+\\.tf$") ||
+ e.file.path.matches("(?i)(^|/)[^/]+\\.tfstate(\\.[0-9]+)?$") ||
+ e.file.path.matches("(?i)(^|/)kubernetes(-[^/]+)?\\.(yml|yaml)$") ||
+ e.file.path.matches("(?i)(^|/)k8s(-[^/]+)?\\.(yml|yaml)$") ||
+ e.file.path.matches("(?i)(^|/)kustomization\\.(yml|yaml)$") ||
+ e.file.path.matches("(?i)(^|/)values\\.(yml|yaml)$")
+ )
+
+emit:
+ reason: "Container or IaC file modified (Dockerfile / compose / Terraform / K8s manifest / Helm values)"
+
+tests:
+ - name: modify_dockerfile
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "app/Dockerfile" }
+ session: { id: s1 }
+ - name: modify_dockerfile_prod_variant
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "app/Dockerfile.prod" }
+ session: { id: s1 }
+ - name: modify_docker_compose
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "deploy/docker-compose.yaml" }
+ session: { id: s1 }
+ - name: modify_terraform_main
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "infra/prod/main.tf" }
+ session: { id: s1 }
+ - name: modify_terraform_state
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "infra/prod/terraform.tfstate" }
+ session: { id: s1 }
+ - name: modify_kubernetes_manifest
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "deploy/kubernetes-prod.yaml" }
+ session: { id: s1 }
+ - name: modify_helm_values
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "charts/api/values.yaml" }
+ session: { id: s1 }
+ - name: modify_kustomization
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "deploy/kustomization.yaml" }
+ session: { id: s1 }
+ - name: modify_ordinary_source
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "src/main.go" }
+ session: { id: s1 }
+ - name: modify_unrelated_yaml
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "config/api.yaml" }
+ session: { id: s1 }
+ - name: read_dockerfile
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "app/Dockerfile" }
+ session: { id: s1 }
+ - name: modify_dockerfile_backup
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "app/Dockerfile.bak" }
+ session: { id: s1 }
diff --git a/rules/sensitive-edit/etc-hosts-modified.rule.yaml b/rules/sensitive-edit/etc-hosts-modified.rule.yaml
new file mode 100644
index 00000000..38769ad6
--- /dev/null
+++ b/rules/sensitive-edit/etc-hosts-modified.rule.yaml
@@ -0,0 +1,67 @@
+id: etc-hosts-modified
+version: 1
+title: /etc/hosts or hosts.allow/deny modified
+description: >
+ The agent modified a system name resolution file: /etc/hosts (the
+ primary local DNS override), /etc/hosts.allow, or /etc/hosts.deny
+ (the TCP-wrappers access control list). Modifying /etc/hosts is a
+ local DNS-hijack primitive — an attacker can redirect a known
+ hostname (e.g. github.com, an internal package registry) to an
+ attacker-controlled IP and exfiltrate credentials on the next
+ connection. Modifying hosts.allow / hosts.deny changes the
+ network-access ACL for the system. The rule matches the well-known
+ paths and excludes generic "hosts" mentions (e.g. a file named
+ "hosts" in a project tree).
+severity: high
+status: experimental
+posture: detect
+taxonomy:
+ owasp_llm: LLM06
+ mitre_atlas: AML.T0011
+
+match: >
+ e.event.action == "file.modified" && (
+ e.file.path.matches("(?i)(^|/)etc/hosts$") ||
+ e.file.path.matches("(?i)(^|/)etc/hosts\\.(allow|deny)$")
+ )
+
+emit:
+ reason: "/etc/hosts or hosts.allow/deny modified (local DNS hijack or ACL change)"
+
+tests:
+ - name: modify_etc_hosts
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/hosts" }
+ session: { id: s1 }
+ - name: modify_etc_hosts_allow
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/hosts.allow" }
+ session: { id: s1 }
+ - name: modify_etc_hosts_deny
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/hosts.deny" }
+ session: { id: s1 }
+ - name: read_etc_hosts
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/etc/hosts" }
+ session: { id: s1 }
+ - name: modify_project_hosts_file
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/repo/ops/hosts" }
+ session: { id: s1 }
+ - name: modify_etc_hosts_backup
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/hosts.bak" }
+ session: { id: s1 }
diff --git a/rules/sensitive-edit/ssh-authorized-keys-modified.rule.yaml b/rules/sensitive-edit/ssh-authorized-keys-modified.rule.yaml
new file mode 100644
index 00000000..4b76b9bf
--- /dev/null
+++ b/rules/sensitive-edit/ssh-authorized-keys-modified.rule.yaml
@@ -0,0 +1,82 @@
+id: ssh-authorized-keys-modified
+version: 1
+title: SSH authorized_keys or sshd_config modified
+description: >
+ The agent modified an SSH trust file: a user authorized_keys
+ (~/.ssh/authorized_keys or the legacy authorized_keys2), the
+ system-wide sshd_config (/etc/ssh/sshd_config and any
+ sshd_config.d/* drop-in), or a known_hosts file. Modifying
+ authorized_keys adds a new persistent SSH login key for the
+ account — a strong persistence signal — and modifying sshd_config
+ can change the server's permitted auth methods (e.g. enabling
+ PermitRootLogin, PasswordAuthentication, or AuthorizedKeysFile to
+ a writable path). The rule matches the well-known paths only, so
+ benign edits to other ~/.ssh/* files (config, environment) do not
+ fire.
+severity: high
+status: experimental
+posture: detect
+taxonomy:
+ owasp_llm: LLM06
+ mitre_atlas: AML.T0011
+
+match: >
+ e.event.action == "file.modified" && (
+ e.file.path.matches("(?i)(^|/)\\.ssh/authorized_keys(2)?$") ||
+ e.file.path.matches("(?i)(^|/)\\.ssh/known_hosts(2)?$") ||
+ e.file.path.matches("(?i)(^|/)etc/ssh/sshd_config$") ||
+ e.file.path.matches("(?i)(^|/)etc/ssh/sshd_config\\.d/[^/]+\\.conf$")
+ )
+
+emit:
+ reason: "SSH authorized_keys, known_hosts, or sshd_config modified (persistence or auth bypass)"
+
+tests:
+ - name: modify_authorized_keys
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/home/u/.ssh/authorized_keys" }
+ session: { id: s1 }
+ - name: modify_authorized_keys2
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/home/u/.ssh/authorized_keys2" }
+ session: { id: s1 }
+ - name: modify_sshd_config
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/ssh/sshd_config" }
+ session: { id: s1 }
+ - name: modify_sshd_config_d_dropin
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/etc/ssh/sshd_config.d/99-override.conf" }
+ session: { id: s1 }
+ - name: modify_known_hosts
+ verdict: match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/home/u/.ssh/known_hosts" }
+ session: { id: s1 }
+ - name: modify_ssh_config
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/home/u/.ssh/config" }
+ session: { id: s1 }
+ - name: read_authorized_keys
+ verdict: no_match
+ events:
+ - event: { action: file.read }
+ file: { path: "/home/u/.ssh/authorized_keys" }
+ session: { id: s1 }
+ - name: modify_authorized_keys_dotbak
+ verdict: no_match
+ events:
+ - event: { action: file.modified }
+ file: { path: "/home/u/.ssh/authorized_keys.bak" }
+ session: { id: s1 }