Skip to content

Commit 8384ca1

Browse files
syrulltas50claude
authored
🐛 normalize -k flag into fields array in audtid (#6933)
* fix(auditd): normalize -k flag into fields array The audit rule parser stored -k (key name) only in the 'keyname' field of auditd.rule.syscall, but did not add it to the 'fields' array. This meant -k and -F key= produced different resource representations despite being semantically identical (per auditctl(8), -k is shorthand for -F key=). Policy queries that check fields.where(key == "key") would only match rules using -F key=value, silently missing rules using -k value. Since -k is the standard form used in CIS benchmark remediation steps and most audit rule examples, this caused false failures on correctly configured systems. Fix: when the parser encounters -k, also append "key="+value to rawFields so it appears in the fields array alongside other -F entries. The keyname field is still set for backward compatibility. * chore(os): bump provider version to 13.2.2 * 🟢 add test for -k flag normalization into fields Add a regression test verifying that the -k flag is normalized into the fields array as key=<value>, so queries don't need to check both representations. Update the test recording to match. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Tim Smith <tsmith84@proton.me> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent def874e commit 8384ca1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

providers-sdk/v1/testutils/testdata/arch.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,11 @@
17571757
"key": "auid",
17581758
"op": "!=",
17591759
"value": "unset"
1760+
},
1761+
{
1762+
"key": "key",
1763+
"op": "=",
1764+
"value": "priv_escalation"
17601765
}
17611766
]
17621767
},

providers/os/resources/auditd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func (s *mqlAuditdRules) parse(content string, errors *multierr.Errors) {
303303

304304
case "-k":
305305
args["keyname"] = llx.StringData(v)
306+
// -k is shorthand for -F key=; normalize into fields so queries
307+
// don't need to check both representations.
308+
rawFields = append(rawFields, "key="+v)
306309

307310
case "-p":
308311
args["permissions"] = llx.StringData(v)

providers/os/resources/auditd_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ func TestResource_AuditdRules(t *testing.T) {
7272
})
7373
})
7474

75+
t.Run("-k flag normalized into fields", func(t *testing.T) {
76+
// The -k flag is shorthand for -F key=<value>. Verify that the
77+
// parser normalizes it into the fields array so queries don't
78+
// need to check both representations.
79+
x.TestSimple(t, []testutils.SimpleTest{
80+
{
81+
Code: `auditd.rules.syscalls.where(keyname == "priv_escalation")[0].fields.where(key == "key" && value == "priv_escalation").length`,
82+
ResultIndex: 0,
83+
Expectation: int64(1),
84+
},
85+
})
86+
})
87+
7588
t.Run("auditd comparisons field", func(t *testing.T) {
7689
x.TestSimple(t, []testutils.SimpleTest{
7790
// Test that rules with -C have populated comparisons

0 commit comments

Comments
 (0)