Skip to content

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

fix(rules): match gpg2 and --export-secret-key in gpg-keyring-access (#1044)

Rudy Mizrahi Celeklicec58be39f9a
diff --git a/rules/credential-access/gpg-keyring-access.rule.yaml b/rules/credential-access/gpg-keyring-access.rule.yaml
index 714058be..519a16fe 100644
--- a/rules/credential-access/gpg-keyring-access.rule.yaml
+++ b/rules/credential-access/gpg-keyring-access.rule.yaml
@@ -1,12 +1,12 @@
id: gpg-keyring-access
-version: 1
+version: 2
title: Agent read a GPG private key or exported a secret key
description: >
The agent either read a file under the GnuPG private-key directory
(private-keys-v1.d/, secring.gpg, .gnupg/openpgp-revocs.d/ certificate
revocation, .gnupg/trustdb.gpg trust database, .gnupg/gpg-control files) OR
- invoked gpg with --export-secret-keys, --export-secret-subkeys, or
- --gen-key. Private GPG keys sign commits and decrypt sensitive mail; an
+ invoked gpg or gpg2 with --export-secret-key(s), --export-secret-subkey(s),
+ or --gen-key. Private GPG keys sign commits and decrypt sensitive mail; an
agent touching a private keyring is a high-value exfil signal. The rule
is anchored on the path or on a gpg subcommand, and explicitly excludes
the public keyring (pubring.gpg, *.asc public keys) since reading public
@@ -27,9 +27,9 @@ match: >
e.file.path.matches("(?i)(^|/)\\.gnupg/[^/]+\\.key$")
)) || (
e.event.action == "command.executed" && (
- e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg\\b[^;&|]*--export-secret-(keys|subkeys)\\b") ||
- e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg\\b[^;&|]*--gen-key\\b") ||
- e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg\\b[^;&|]*--card-status\\b[^;&|]*--with-keygrip\\b")
+ e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg2?\\b[^;&|]*--export-secret-(k|sub)\\w*\\b") ||
+ e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg2?\\b[^;&|]*--gen-key\\b") ||
+ e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*gpg2?\\b[^;&|]*--card-status\\b[^;&|]*--with-keygrip\\b")
)
)
@@ -67,6 +67,36 @@ tests:
- event: { action: command.executed }
command: { command: "gpg --export-secret-subkeys 0xCAFEBABE > /tmp/keys.asc" }
session: { id: s1 }
+ - name: gpg_export_secret_key_singular
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "gpg --armor --export-secret-key ABCDEF12 > key.asc" }
+ session: { id: s1 }
+ - name: gpg2_export_secret_keys
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "gpg2 --export-secret-keys --armor > all.asc" }
+ session: { id: s1 }
+ - name: gpg_export_secret_abbreviated
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "gpg --armor --export-secret-k ABCDEF12" }
+ session: { id: s1 }
+ - name: gpg_export_secret_sub_abbreviated
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "gpg --export-secret-sub ABCDEF12! > sub.asc" }
+ session: { id: s1 }
+ - name: gpg_export_public_key
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "gpg --armor --export ABCDEF12 > pub.asc" }
+ session: { id: s1 }
- name: read_public_keyring
verdict: no_match
events: