Skip to content
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

THREAT-395 Correlation Rule Style Guide in repo #1376

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

akozlovets098
Copy link
Contributor

Changes

  • Added Correlation Rule Style Guide in repo

@akozlovets098 akozlovets098 requested a review from a team as a code owner October 3, 2024 14:25
@arielkr256 arielkr256 added the documentation Improvements or additions to documentation label Oct 3, 2024
@arielkr256
Copy link
Contributor

Should we create a /style_guides directory to put this and STYLE_GUIDE.md?


This style guide highlights essential best practices for writing correlation rules. For a more detailed guide, visit [Correlation Rules](https://docs.panther.com/detections/correlation-rules) in the Panther documentation.

## General advises

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe use "guidelines" instead of "advises"


## General advises

- Transition names in rule IDs, and transition IDs should be all caps.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • comma not necessary
  • "be in all-caps"
  • this might be just my personal preference, but using "Transition names" here is a little confusing because it makes me wonder whether Transition.Name is an actual Transition field, like ID. you could rephrase to say, "In a rule ID or transition ID, when describing a transition, put that portion of the ID in all-caps."

@@ -0,0 +1,70 @@
# panther-analysis Correlation Rule (CR) Style Guide and Best Practices

This style guide highlights essential best practices for writing correlation rules. For a more detailed guide, visit [Correlation Rules](https://docs.panther.com/detections/correlation-rules) in the Panther documentation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I loved that you added the acronym "(CR)," but we typically don't add those in titles. so like the title would just say Correlation Rule, and the first use of it (in this sentence) would have (CR) after

- e.g. `"GitHub Advanced Security Change NOT FOLLOWED BY repo archived"`
- Boilerplate comments from the CR template in the UI should be removed before committing to PA.
- e.g. remove `# Create a list of rules to correlate`
- Sequence, Group, and Transition IDs should have meaningful names.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the docs, we don't capitalize group or transition (or sequence). the more important thing, though, is consistency—if you are capitalizing transition here, e.g., be sure to do it everywhere

- e.g. remove `# Create a list of rules to correlate`
- Sequence, Group, and Transition IDs should have meaningful names.
- e.g. `- ID: GHASChange` instead of `- ID: TR.1`
- Check for Signal rules that already exist.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a top-level bullet instead of a sub-bullet of line 11?


### Testing

You must run `pat validate` against a live Panther instance to test, `pat test` is not sufficient.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test your correlation rules before uploading them, run pat validate against a live Panther instance. Running pat test is not sufficient.

- Guidance for multi-logtype pack is do not enable the pack, just enable the individual detections you have logs for
- A pack with CRs should also contain the sub-rules referenced by those CRs
- AND any globals, data models, etc. that the sub-rules reference
- can the pack-checker be updated to check for these dependencies?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this question be here?


### Placing CRs in packs

- If a CR only references 1 LogType it can go in that LogType’s pack

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of "it can go in" maybe say "store it in"

### WithinTimeFrameMinutes

- `WithinTimeFrameMinutes` is not required and defaults to `LookbackWindowMinutes`.
- Omit `WithinTimeFrameMinutes` in Sequences with only 2 rules

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lower-case sequences, spell out two


### Match On

- `Match On` fields are not required to be `p_` fields. Especially for CRs where each subrule is for the same LogType, use the regular field instead of the alert context field.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other places you included a dash in "sub-rules"


- If a CR only references 1 LogType it can go in that LogType’s pack
- If a CR spans multiple LogTypes, put it in the multi-logtype pack
- Guidance for multi-logtype pack is do not enable the pack, just enable the individual detections you have logs for

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make clearer here that you are sharing guidance for end-users, not p-a contributors

like "Customers are advised not to enable multi-LogType packs, and to instead enable the individual detections within them that they have log sources set up for."


### MinMatchCount

`MinMatchCount: 1` is the default value, this can be omitted.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other sections within "Correlation rule fields," the body is formatted as bullets. I would suggest making this line a bullet, too

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested rewrite: If you are setting MinMatchCount to 1, you can omit it completely, as 1 is the default value.


### LookbackWindowMinutes

- `LookbackWindowMinutes: 15` is the default value, but this feels valuable to keep.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested rewrite: For ease of understanding, it's valuable to include LookbackWindowMinutes even if you are setting it to 15, which is the default value.

@cara-panther
Copy link

Should we create a /style_guides directory to put this and STYLE_GUIDE.md?

I would say: yes!

I also want to advocate for each guide linking to one another. because even if I know both guides exist, if I'm writing a CR, I might think oh, I only have to reference/abide by the CR guide. so it would be nice to have something near the top of the CR guide that says, like, "This guide provides specialized guidelines on writing CRs, which build upon the general detection writing best practices outlined in /regular-style-guide."

and then in the regular guide, I would love to see like "For specialized guidelines on writing correlation rules, see /cr_guide." or whatever

@akozlovets098
Copy link
Contributor Author

@cara-panther Thank you for your comments!
They made the guide look a lot better!

@arielkr256 arielkr256 enabled auto-merge (squash) October 15, 2024 03:34
Copy link

😱
looks like some things could be wrong with the packs

Copy link

😱
looks like some things could be wrong with the packs

@arielkr256 arielkr256 merged commit f64ef48 into develop Oct 17, 2024
9 checks passed
@arielkr256 arielkr256 deleted the THREAT-395-Correlation-Rule-Style-Guide-in-repo branch October 17, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants