-
Notifications
You must be signed in to change notification settings - Fork 2
build: enforce README.md presence on every rule #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Agent Instructions for rulelibrary | ||
|
|
||
| When you add, modify, or delete a rule under `pkg/rules/`: | ||
|
|
||
| 1. Each rule directory MUST contain a non-empty `README.md` that follows | ||
| the template used by sibling rules (see any existing rule's README.md | ||
| for the structure: metadata table + Description, Attack Technique, How | ||
| It Works, Investigation Steps, Remediation, False Positives). | ||
| 2. If you add a new rule, generate its `README.md` in the same commit. | ||
| 3. If you modify a rule's YAML (CEL expression, severity, MITRE fields, | ||
| profileDependency), update the affected sections of its `README.md` | ||
| in the same commit. | ||
| 4. Do not commit a rule change without its corresponding README update — | ||
| the release build will fail. | ||
|
|
||
| The release build's `gen.sh` invokes `scripts/check_readmes.sh`, which | ||
| exits non-zero if any rule under `pkg/rules/` is missing or has an empty | ||
| `README.md`. The README content is consumed downstream by the | ||
| `armo-rulelibrary` build (which embeds this repo as a submodule) and | ||
| shipped as the `documentation` field on each rule. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| # Verify every rule directory under the given path has a non-empty README.md. | ||
| # Used by the release build as a hard gate. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| RULES_DIR="${1:-pkg/rules}" | ||
|
|
||
| if [ ! -d "$RULES_DIR" ]; then | ||
| echo "check_readmes: directory not found: $RULES_DIR" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| failed=0 | ||
| while IFS= read -r -d '' rule_dir; do | ||
| readme="$rule_dir/README.md" | ||
| if [ ! -f "$readme" ]; then | ||
| echo "check_readmes: missing README.md in $(basename "$rule_dir")" >&2 | ||
| failed=1 | ||
| continue | ||
| fi | ||
| if [ ! -s "$readme" ]; then | ||
| echo "check_readmes: empty README.md in $(basename "$rule_dir")" >&2 | ||
| failed=1 | ||
| fi | ||
| done < <(find "$RULES_DIR" -mindepth 1 -maxdepth 1 -type d -name 'r[0-9]*' -print0) | ||
|
|
||
| if [ "$failed" -ne 0 ]; then | ||
| echo "check_readmes: one or more rules are missing or have empty README.md" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "check_readmes: OK" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| setup() { | ||
| TEST_DIR=$(mktemp -d) | ||
| export RULES_DIR="$TEST_DIR/pkg/rules" | ||
| mkdir -p "$RULES_DIR/r0001-good" "$RULES_DIR/r0002-bad" | ||
| echo "# Rule" > "$RULES_DIR/r0001-good/README.md" | ||
| # r0002-bad has no README | ||
| } | ||
|
|
||
| teardown() { | ||
| rm -rf "$TEST_DIR" | ||
| } | ||
|
|
||
| @test "check_readmes.sh fails when a rule directory is missing README.md" { | ||
| run bash "$BATS_TEST_DIRNAME/check_readmes.sh" "$RULES_DIR" | ||
| [ "$status" -ne 0 ] | ||
| [[ "$output" == *"r0002-bad"* ]] | ||
| } | ||
|
|
||
| @test "check_readmes.sh passes when all rule directories have README.md" { | ||
| echo "# Rule 2" > "$RULES_DIR/r0002-bad/README.md" | ||
| run bash "$BATS_TEST_DIRNAME/check_readmes.sh" "$RULES_DIR" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "check_readmes.sh fails when README.md exists but is empty" { | ||
| echo "# Rule 2" > "$RULES_DIR/r0002-bad/README.md" | ||
| : > "$RULES_DIR/r0001-good/README.md" | ||
| run bash "$BATS_TEST_DIRNAME/check_readmes.sh" "$RULES_DIR" | ||
| [ "$status" -ne 0 ] | ||
| [[ "$output" == *"r0001-good"* ]] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Policy bypass risk: validation only targets
r[0-9]*directory names.Line 26 scopes checks to a naming pattern, so a rule directory with a different name can skip README enforcement.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents