en un clic
en un clic
| name | test-rule |
| description | Run Automatus tests for a security rule |
Run Automatus tests for a ComplianceAsCode security rule.
Rule ID: $ARGUMENTS
This skill uses mcp__content-mcp__* tools when available (preferred — deterministic, structured results). When the MCP server is not configured, fall back to filesystem-based alternatives noted as Fallback in each step. See .claude/skills/shared/mcp_fallbacks.md for detailed fallback procedures. The skill must complete successfully either way.
Find the rule using mcp__content-mcp__get_rule_details with rule_id=$ARGUMENTS:
mcp__content-mcp__search_rules with query=$ARGUMENTS to check for similar rule IDs.Glob to find **/$ARGUMENTS/rule.yml, then read the file to extract metadata. For similar rule search, use Grep to search for $ARGUMENTS across rule.yml files.If rule not found:
mcp__content-mcp__list_templates to check if it's a template name instead.
Fallback: Run ls shared/templates/ to check for template names.From the rule details, determine:
template: key)Identify testable products from CCE identifiers:
rhel8, rhel9, rhel10 are supported by Automatuscce@rhel8, cce@rhel9, cce@rhel10Ask user for testing scope using AskUserQuestion:
Question: "Which products do you want to test?"
Options (show only products with CCE identifiers):
Enable multi-select.
Ask for remediation types using AskUserQuestion:
Question: "Which remediation types do you want to test?"
Options:
All virsh and automatus.py commands require dangerouslyDisableSandbox: true on the Bash tool. These commands use libvirt unix sockets and SSH connections to VMs, which are blocked by the default sandbox. Set this flag on every Bash call that runs virsh or automatus.py.
The libvirt connection URI depends on the user's VM setup. Ask the user using AskUserQuestion:
Question: "Which libvirt connection URI does your VM setup use?"
Options:
Store the selected URI as <libvirt_uri> for all subsequent commands.
VM names often differ from product names (e.g., rhel9-test, ssg-rhel9, rhel-9.4). Discover available VMs:
virsh -c <libvirt_uri> list --all 2>/dev/null
For each selected product, ask the user to confirm the VM name:
Question: "Which VM should be used for testing <product>? Available VMs are listed above."
Options (populated from virsh list --all output, filtered to relevant entries):
Store the mapping of product → VM name for Phase 5.
Note on sudo: When using qemu:///system, some operations (starting VMs, creating snapshots) may require sudo. When using qemu:///session, sudo is not needed. Adjust commands accordingly.
Check for existing datastreams:
Use mcp__content-mcp__list_built_products to see which products have been built.
Fallback: Run ls build/ssg-*-ds.xml 2>/dev/null to list built datastreams.
For each selected product, check if datastream exists and get details:
Use mcp__content-mcp__get_datastream_info with product=<product> to verify the datastream exists and get its details.
Fallback: Run ls -la build/ssg-<product>-ds.xml to check if the datastream exists.
Build datastreams if needed:
./build_product --rule-id $ARGUMENTS <product>
Verify VMs are available and running (CRITICAL — Automatus requires the VM to be running):
virsh -c <libvirt_uri> list --all 2>/dev/null | grep -E "rhel[0-9]+"
# For qemu:///system, prefix with sudo if needed
virsh -c <libvirt_uri> start <vm_name>
virsh -c <libvirt_uri> list --all 2>/dev/null | grep <vm_name>
Verify VM has a snapshot (CRITICAL — Automatus reverts to a snapshot between test scenarios):
virsh -c <libvirt_uri> snapshot-list <vm_name>
# For qemu:///system, prefix with sudo if needed
virsh -c <libvirt_uri> snapshot-create-as <vm_name> clean
Run tests for each selected product and remediation type, using the <libvirt_uri> and <vm_name> determined in Phase 3:
Bash remediation:
cd tests
./automatus.py rule --libvirt <libvirt_uri> <vm_name> \
--datastream ../build/ssg-<product>-ds.xml \
$ARGUMENTS
Ansible remediation:
cd tests
./automatus.py rule --libvirt <libvirt_uri> <vm_name> \
--datastream ../build/ssg-<product>-ds.xml \
--remediate-using ansible \
$ARGUMENTS
If testing a template instead of a rule:
cd tests
./automatus.py template --libvirt <libvirt_uri> <vm_name> \
--datastream ../build/ssg-<product>-ds.xml \
$ARGUMENTS
Tests run in foreground - output is streamed
Test phases to expect:
For each test scenario (e.g., correct.pass.sh, wrong.fail.sh):
.pass.sh scenarios: Should pass on initial scan.fail.sh scenarios: Should fail initially, then pass after remediationFind results directory:
ls -td tests/logs/rule-custom-* 2>/dev/null | head -1
Read results.json:
cat tests/logs/rule-custom-*/results.json
Parse and summarize results:
| Scenario | Initial Scan | Remediation | Final Scan | Status |
|---|---|---|---|---|
| wrong.fail | FAIL | APPLIED | PASS | OK |
| correct.pass | PASS | SKIPPED | N/A | OK |
Check for common issues:
Test Results for $ARGUMENTS
==============================
Product: rhel9
Remediation: Bash
Scenarios:
- wrong.fail.sh: PASSED (fail -> remediate -> pass)
- correct.pass.sh: PASSED (already compliant)
Overall: ALL TESTS PASSED
---
Product: rhel9
Remediation: Ansible
Scenarios:
- wrong.fail.sh: PASSED (fail -> remediate -> pass)
- correct.pass.sh: PASSED (already compliant)
Overall: ALL TESTS PASSED
==============================
Summary: 4/4 tests passed across all products and remediation types
Test Results for $ARGUMENTS
==============================
Product: rhel9
Remediation: Bash
Scenarios:
- wrong.fail.sh: FAILED
- Initial scan: FAIL (expected)
- Remediation: APPLIED
- Final scan: FAIL (unexpected!)
- Issue: Remediation did not properly configure the setting
- correct.pass.sh: PASSED
Log files: tests/logs/rule-custom-2024-01-15-1423/
Suggested debugging:
1. Check remediation script: find linux_os/guide -path "*/$ARGUMENTS/bash/*"
2. Review test scenario: find linux_os/guide -path "*/$ARGUMENTS/tests/*"
3. SSH into VM to inspect: virsh console rhel9
==============================
Summary: 1/2 tests failed
Based on results:
If all tests passed:
/build-product <product> to build and /run-tests to validate."If tests failed:
If no tests exist (non-templated rule without tests):
<rule_dir>/tests/".pass.sh and one .fail.sh scenario"VM not found:
Error: VM '<vm_name>' not found
virsh -c <libvirt_uri> list --allDatastream not found:
Error: build/ssg-<product>-ds.xml not found
./build_product --rule-id $ARGUMENTS <product>Permission denied:
qemu:///system, may need sudoqemu:///session for user VMsRule not in datastream:
Test scenario errors:
# packages = <pkg>No snapshot available:
Error: No snapshot found for domain
virsh -c <libvirt_uri> snapshot-create-as <vm_name> clean (prefix with sudo for qemu:///system)Note: Debug mode requires interactive input and must be run manually by the user, not through this skill.
When tests fail, suggest the user run with --debug in their own terminal:
cd tests
./automatus.py rule --libvirt <libvirt_uri> <vm_name> \
--datastream ../build/ssg-<product>-ds.xml \
--debug \
$ARGUMENTS
How --debug works:
ssh root@<vm-ip> # No password required on test VMs
Create a new security rule with all required components
Interactive control-to-rule mapping session. Walk through unmapped requirements, suggest rules using cross-framework analysis, and write selections to control files.
Map rules to a single control file requirement using cross-framework analysis and rule search.
Onboard a new security policy as a control file. Parse the document, create control file structure, and map existing rules to requirements.
Build a ComplianceAsCode product
Draft a PR description based on branch changes and the project PR template