This repository is used to conceptualize the automation of detection engineering, in a way that the integration of rulesets such as: decoders and rules to SIEM tools are automated. This approach to detection engineering allows for faster and effective collaboration among security engineers. It also limits access to the SIEM endpoint and reduces collaboration errors in production environments.
This concept can be adapted to work with any SIEM solution by following the guide, even though Wazuh is used to develop and test this concept.
Ensure that the following requirements are met to use this repository with ease:
- Ensure that Git is installed on the SIEM host.
- Ensure that the SIEM host is accessible on the internet by assigning a public IP or NAT if behind a firewall.
- Ensure that port
22or your custom SSH port is open on the public IP address. - Ensure that the SIEM host is provisioned with a public/private key pair, to allow for SSH login.
- Clone the parent DaC repository to use its GitHub Actions workflow file.
Perform the configuration steps after meeting the above requirements.
Perform the following steps on the SIEM endpoint:
- Navigate to the directory where the decoder and rule files are stored. If the decoder and rules files are stored in separate directories, navigate to the parent directory:
cd <FULL_PATH_TO_RULESETS> # Working directory
- Create a
.gitignorefile in the working directory to ignore other files in the directory from being added to Git:
nano .gitignore # Add directories/files to ignore
- Mark the working directory as safe for Git:
git config --global --add safe.directory <FULL_PATH_TO_RULESETS>
- Initialize the working directory as a Git repository:
git init
- Add a remote repository to your local Git to push local changes:
git remote add origin <REMOTE_REPOSITORY>
- Configure your Git user identity:
git config --global user.name <YOUR_NAME>
git config --global user.email <YOUR_EMAIL_ADDRESS>
- Create a new branch
mainand switch to the new branch. Stage the files for commit in your local Git. Make an initial commit to your local Git repository:
git checkout -b main
git add .
git commit -m "Initial commit"
- Push the changes from your local Git repository to the
mainbranch of remote repository:
git pull origin main --no-rebase # Merge remote repo with local repo and resolve any merge conflicts manually if they appear.
git push -u origin main
Perform the following steps on your GitHub repository (remote repository) after pushing local changes:
- Edit the GitHub Actions workflow file
.github/workflows>integrate_rulesets.ymlto adapt it to your SIEM tool. - Navigate to Settings > Secrets and variables > Actions > Secrets to create the following repository secrets to be used by GitHub Actions:
| Name | Secret |
|---|---|
| USERNAME | <USERNAME_OF_SIEM_HOST> |
| HOST | <PUBLIC_IP_OF_SIEM_HOST> |
| SSH_KEY | <PRIVATE_KEY_OF_SIEM_HOST> |
| PORT | <SSH_PORT_OF_SIEM_HOST> |
- Ensure that a
devbranch is created if it does not not already exist. - Create a pull request to merge the changes on the
mainbranch to thedevbranch. This will update thedevbranch with the recent changes from the local Git repository and theautomation.ymlfile.
This guides the use of the repository to create new or modify existing rulesets for automatic integration with the SIEM after completing configuration.
Perform all usage operations in the dev branch for code reviews before merging to the main branch to minimize deployment errors in production.
Create new or modify existing custom decoders in the decoders directory of the repository. This may vary depending on the directory structure of your SIEM.
Create new or modify existing custom rules in the rules directory of the repository. This may vary depending on the directory structure of your SIEM.
- Workflow:
.github/workflows/check_rule_ids.yml - Script:
check_rule_ids.py - Purpose: This repository includes a GitHub Actions workflow and a Python script to automatically check for rule ID conflicts in Wazuh ruleset XML files (
rules/*.xml) whenever a pull request is opened against themainbranch. The workflow ensures that any new or modified rules in pull requests do not reuse rule IDs already present in themainbranch, preventing accidental overwrites and maintaining ruleset integrity.
-
Trigger: The workflow runs on every pull request to the
mainbranch. -
Steps:
- Checks out the PR branch and fetches the latest
mainbranch. - Sets up Python 3.10.
- Runs
check_rule_ids.py, which:- Finds all changed or added
rules/*.xmlfiles in the PR. - Extracts all
<rule id="...">values from these files. - Extracts all rule IDs from
rules/*.xmlfiles in themainbranch. - Checks for any ID overlap (conflicts).
- Fails the workflow if any conflicts are found, listing the conflicting IDs and files.
- Finds all changed or added
- Checks out the PR branch and fetches the latest
🔍 Checking these files for conflicts: ['local_rules.xml']
🔎 Checking file: local_rules.xml
✅ No rule ID conflicts in local_rules.xml.
✅ All checked files are conflict-free.
If a conflict is found:
❌ Conflicting rule IDs in local_rules.xml file. Rule IDs: [100001]
- If you see a ❌ conflict, update your rule IDs to be unique compared to those in the
mainbranch.
- Workflow file:
.github/workflows/integrate_rulesets.yml - Purpose: This repository includes a GitHub Actions workflow to automatically update and apply Wazuh decoders and rules on your SIEM server whenever changes are pushed to the
mainbranch. On every push tomainthat modifies any.xmlfile (typically inrules/ordecoders/), the workflow connects to your SIEM server via SSH and:- Pulls the latest changes.
- Updates file permissions for decoders and rules.
- Restarts the Wazuh manager to apply the new rulesets.
- Prints the status of the Wazuh manager.
-
Trigger:
- On push to
mainbranch affecting any.xmlfile. - Can also be run manually via the GitHub Actions UI (
workflow_dispatch).
- On push to
-
Steps:
- Uses the appleboy/ssh-action to SSH into your SIEM server.
- Runs a script that:
- Changes to
/var/ossec/etc/ - Pulls the latest code from the
mainbranch. - Sets correct ownership and permissions for all decoders and rules.
- Restarts the Wazuh manager.
- Prints the status of the Wazuh manager service.
- Changes to
- SSH credentials (
HOST,USERNAME,SSH_KEY,PORT) are stored as GitHub Actions secrets and never exposed in logs. - Only users with access to your repository and secrets can trigger this workflow.
Ruleset apply SUCCESS!!! - Wazuh manager restarted successfully.
<status output>
or
Ruleset apply FAILURE!!! - Wazuh manager failed to restart, check ruleset for error...
<status output>
- If the workflow fails, check the Actions logs for error messages.
- Ensure your SSH key and user have the necessary permissions on the SIEM server.
- Make sure the SIEM server can pull from your repository (deploy keys, access rights, etc.).