Repository navigation
feat(recommendations): add a Wazuh-derived Linux pattern catalogue and a sources and licensing table - #498
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The extractor emits overlapping same-rule recommendations that consume multiple slots and truncates multi-element descriptions, requiring fixes and catalogue regeneration.
2 open issues
What changed in this PR
Extends Linux recommendations with a Wazuh-derived pattern catalogue, documents catalogue licensing, and makes all catalogue imports manual.
Changes:
- Adds conversion tooling and coverage for 434 Wazuh-derived recommendations.
- Adds licensing metadata, SPDX sidecars, and a packaged NOTICE.
- Removes automatic Cisco catalogue seeding while preserving existing records.
| File | Description |
|---|---|
| tests/Unit/RecommendationsTest.php | Tests Wazuh matching and licensing metadata; removes seed tests. |
| setup.php | Removes automatic recommendation seeding. |
| README.md | Documents Wazuh coverage, manual imports, and licensing. |
| NOTICE | Explains code and catalogue licensing. |
| manifest.json | Includes NOTICE in distribution. |
| includes/recommendations.php | Removes the seed function and constants. |
| docs/RECOMMENDATION_SOURCES.md | Documents Wazuh conversion and metadata builds. |
| docs/paloalto.json.gz.license | Adds Palo Alto licensing tags. |
| docs/nvidia.json.gz.license | Records NVIDIA’s mixed licensing. |
| docs/nokia.json.gz.license | Adds Nokia licensing tags. |
| docs/mikrotik.json.gz.license | Adds MikroTik licensing tags. |
| docs/linux.json.gz.license | Records systemd catalogue licensing. |
| docs/linux-wazuh.json.gz.license | Records Wazuh catalogue licensing. |
| docs/juniper.json.gz.license | Adds Juniper licensing tags. |
| docs/huawei.json.gz.license | Adds Huawei licensing tags. |
| docs/hpe.json.gz.license | Adds HPE licensing tags. |
| docs/fortinet.json.gz.license | Adds Fortinet licensing tags. |
| docs/dell.json.gz.license | Adds Dell licensing tags. |
| docs/cisco.json.gz.license | Adds Cisco licensing tags. |
| docs/arista.json.gz.license | Adds Arista licensing tags. |
| contrib/recommendations/extract_wazuh_rules.py | Converts Wazuh rules into pattern recommendations. |
| contrib/recommendations/build_catalogues.py | Preserves patterns and writes licensing metadata. |
| CHANGELOG.md | Records catalogue, licensing, and import changes. |
Review effort: Balanced
|
Review follow-up, CI now green:
One PHP 8.3 run ran out of memory in the existing Cisco catalogue decode under coverage (256 MB limit). It passed on rerun, and the other versions were unaffected. |
899e392 to
10db933
Compare
somethingwithproof
left a comment
There was a problem hiding this comment.
Blocker: "PHP 8.3 Integration Test" fails on the last two heads (10db933, 10518ac) with the same fatal: Allowed memory size of 268435456 bytes exhausted (tried to allocate 67112960 bytes) at includes/recommendations.php:608. The limit in the message is still 256M after 10518ac set 512M in phpunit.xml, because the test "enforces the expanded import limit and accepts content exactly at that limit" calls ini_set('memory_limit', '256M') itself (tests/Unit/RecommendationsTest.php:418). That test builds a 64 MiB string by appending, so the allocation that fails is the string growing. Raise or drop the limit inside the test, or have it free the earlier payload first. #499 and #500 carry the same commit.
Suggestion: this PR removes syslog_recommendations_seed() and its call in setup.php, so a new install starts with no recommendations. Only the CHANGELOG says so. Put it in the description, since the title reads as an addition.
Suggestion: only level 0 Wazuh rules are skipped, so routine successes get a lightbulb: wazuh-5715 (sshd authentication success) and wazuh-5402 (successful sudo to root) match ordinary log lines. 327 of the 411 records are severity 5 or 6. Consider a severity floor or leaving the informational ones out.
Nit: wazuh-80003 and wazuh-80051 (two leading lookaheads with .*?) reach the backtrack limit on long puppet lines. The limit turns that into no match, so it is cost only.
Not verified here: I did not run the Pest suite or rebuild the catalogue from the Wazuh tag.
10518ac to
789947a
Compare
789947a to
d179c6e
Compare
|
@somethingwithproof thanks, addressed:
|
…d a sources and licensing table Add docs/linux-wazuh.json.gz, a manually importable catalogue of 434 pattern recommendations converted from 315 rules of the Wazuh 4.14.11 ruleset (GPL-2.0): core Linux (syslog, kernel, sshd, PAM, su, sudo, systemd, auditd, AppArmor, firewalld, Docker, USB), mail, network services and databases and applications. contrib/recommendations/extract_wazuh_rules.py reads the release's rule and decoder XML. It combines a rule's own and inherited (if_sid, decoded_as, decoder prematch) OS_Match, OS_Regex and PCRE2 conditions into one PCRE pattern and its program_name into a program glob. Level 0, correlation and decoded-field rules, and the generic rule 1002, are skipped. Records are ordered program-bound and most severe first. build_catalogues.py now keeps the regex and program fields. The README gains a Recommendation sources and licensing table naming, for every bundled catalogue, its vendor, source, copyright holder and license, and how it was obtained. RECOMMENDATION_SOURCES.md documents the Wazuh conversion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… the Cisco catalogue Add a NOTICE file, a SPDX .license file next to every docs/*.json.gz, and copyright, license, license_url and source fields in each catalogue's JSON, from a LICENSING table in build_catalogues.py. Vendor-derived catalogues are marked as separate works aggregated with the plugin, not licensed under the GPL, with LicenseRef- identifiers pointing at each vendor's terms. The Wazuh-derived catalogue is GPL-2.0-only and the systemd one LGPL-2.1-or-later. The NVIDIA catalogue's Cumulus Linux switchd and FRRouting records are identified as CC BY-NC-SA 4.0 (NVIDIA networking documentation license) and its Xid and SXid records as NVIDIA Terms of Service; the README no longer presents its FRRouting records as GPL-licensed. build_catalogues.py --metadata-only <vendor> refreshes only these fields and keeps the shipped records exactly; every catalogue's records are unchanged. The Cisco catalogue is no longer loaded on install or upgrade: syslog_recommendations_seed() and its tests are removed, and every catalogue is imported only on request. Records loaded by an earlier upgrade are kept. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
read_xml() now takes the rules/ or decoders/ directory and a file name, and refuses any resolved path that is not an .xml file directly inside that directory (SonarCloud pythonsecurity:S8707). Also group the component-name regex alternation explicitly (python:S5850). Regenerating linux-wazuh.json.gz from Wazuh v4.14.11 is byte-identical. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The licensing NOTICE added with the catalogue sources table is a top-level file, so validate-manifest.php fails until it is listed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tions Review follow-up for the Wazuh catalogue: - Join all of a rule's <description> elements, as Wazuh does, so rules such as 3102 and 3191 no longer lose the second half of their text. - Emit one record per rule and program: same-program variants become one (?:A)|(?:B) pattern (kept split only beyond the 1,024-character import limit), and a program-bound variant implied by an any-program variant is dropped. wazuh-5760 is now one record instead of two. - Skip a matched pattern record whose vendor, message and explanation repeat an earlier match. A rule can still need an any-program record next to its program-bound ones (Apache 30104 for apache2 and for logs decoded without a program), and they no longer take two of the three recommendation slots. The catalogue is regenerated (411 records from the same 315 rules), and the README, CHANGELOG and RECOMMENDATION_SOURCES.md counts follow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The key only identifies repeated recommendation text, but SHA-256 avoids the weak-hash finding (SonarCloud php:S4790). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The test set memory_limit to a fixed 256M before inflating a 64 MB catalogue, so whatever the suite already held counted against it. Under Xdebug coverage in CI that left too little room once more catalogue tests ran first (Allowed memory size of 268435456 bytes exhausted in syslog_recommendations_read_file()). Set the limit to current usage plus 256M instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d179c6e to
e30fb5e
Compare
|
somethingwithproof
left a comment
There was a problem hiding this comment.
No blockers found at e30fb5e. The import-limit test now sizes memory_limit from current usage, and PHP 8.2 to 8.6 pass on this head. The description now covers the removal of the install-time seed.
The severity floor for routine Wazuh successes (wazuh-5715, wazuh-5402) is still open as a suggestion. It is not a blocker.




Summary
This finishes phase 2 of the Linux recommendations work:
docs/linux-wazuh.json.gz: 411 manually importable pattern recommendations (feat(recommendations): match recommendations by regular expression and program #497) converted from 315 rules of the Wazuh 4.14.11 ruleset (GPL-2.0). They cover the four groups agreed for phase 2:No forwarder change is needed, because records match on message text and program.
README "Recommendation sources and licensing" table: for every bundled
.json.gz, it lists the vendor, file, source, copyright holder and license (with links to the governing terms), and a short sentence on how it was obtained. A paragraph explains that only the systemd, Wazuh and FRRouting-derived data is openly licensed. The remaining catalogues are short factual summaries of proprietary vendor documentation, with references back to it, and are not relicensed under the plugin's GPL.Behaviour change: no catalogue is seeded on install
This PR removes
syslog_recommendations_seed()and its call insetup.php. A new install now starts with no recommendations, and every bundled catalogue, including Cisco's, is imported manually from the Recommendations page. Existing installs keep what they already have. The CHANGELOG records this as well.Conversion (
contrib/recommendations/extract_wazuh_rules.py)<match>/<regex>conditions are combined with those inherited throughif_sidanddecoded_as, including the decoder'sprematchand named child decoders, into one PCRE pattern. Multiple conditions become lookaheads (^(?=.*?A)(?=.*?B)), and negated ones become(?!…).src/analysisd/rules.c), so their conversions start with(?i). OS_Regex classes are expanded and$VARIABLEs substituted. PCRE2 expressions are kept as written.program_namebecomes a program glob:^sshdgivessshd*(which matchessshd-session) and^postfixgivespostfix*(which matchespostfix/smtpd). This uses the*wildcards added to feat(recommendations): match recommendations by regular expression and program #497 in 71130e3.(?:A)|(?:B)pattern, and the plugin skips a pattern record that repeats the vendor, message and explanation of an earlier match, so a rule is never listed twice. A rule's<description>elements are joined as Wazuh does.build_catalogues.pynow keepsregexandprogram, and the build is byte-reproducible. Rebuilding the existing systemd catalogue leaves it unchanged.Testing
The catalogue-load test now covers
linux-wazuh.json.gz. All 411 records import through the plugin's own validation: every pattern compiles under PHP PCRE and none matches an empty message.New end-to-end cases run real syslog lines through the plugin matcher with the full catalogue:
sshd-session"Invalid user" matches rule 5710;postfix/smtpdhostname-resolution warning matches rule 3398;cron, and an ordinary NetworkManager carrier message, match nothing;sshd"Failed password for root" and an Apache segfault each list their Wazuh rule once.Full Pest suite against Cacti 1.2.x: 929 passed. The one warning (
ProcessHelperCompatTest/procprobe) is also present ondevelop.CI memory fix (789947a): the existing test "enforces the expanded import limit and accepts content exactly at that limit" set
memory_limitto a fixed 256M before inflating a 64 MB file, so memory the suite already held counted against it. Under Xdebug coverage on PHP 8.3 and 8.5, that overflowed insyslog_recommendations_read_file(). The test now sets the limit to current usage plus 256M.Licensing sources
The terms linked in the README table were checked against each vendor's published terms-of-use or license pages. Juniper, Dell, HPE and Nokia could only be read through search-result text, and Arista through an archived copy. I found no documentation terms for MikroTik. The table records what the sources say; it is not legal advice.