Skip to content

Default Ruleset

Default Ruleset #25

name: Default Ruleset
on:
workflow_dispatch: # Manually
schedule: # Every Monday at 06:00 UTC
- cron: '0 6 * * 1'
permissions: read-all
jobs:
update:
runs-on: ubuntu-latest
name: Update
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: oldstable
cache-dependency-path: _tools/ruleset-updater/go.mod
- name: Generate a GitHub token (DataDog/appsec-event-rules)
id: generate-token
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
with:
app-id: ${{ vars.DD_K9_LIBRARY_GO_APP_ID }}
private-key: ${{ secrets.DD_K9_LIBRARY_GO_APP_PRIVATE_KEY }}
owner: DataDog
repositories: appsec-event-rules
permission-contents: read
- name: Update Default Ruleset
id: ruleset
run: |-
go -C _tools/ruleset-updater run . -output="${{ github.workspace }}/internal/ruleset/recommended.json.gz"
echo "version=$(jq -r '.metadata.rules_version' <(gunzip --to-stdout ${GITHUB_WORKSPACE}/internal/ruleset/recommended.json.gz))" >> "${GITHUB_OUTPUT}"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Detect Mutation
id: detect
run: |-
git add .
mutated='false'
git diff --staged --patch --exit-code || mutated='true'
echo "mutation-happened=${mutated}" >> "${GITHUB_OUTPUT}"
##########################################################################
# Creating a PR with the changes if there are any
- name: Create PR Branch
if: fromJson(steps.detect.outputs.mutation-happened)
id: create-branch
run: |-
branch="automation/default-ruleset-update/${VERSION}"
git push --force origin "${{ github.sha }}":"refs/heads/${branch}"
echo "branch=${branch}" >> "${GITHUB_OUTPUT}"
git fetch origin "${branch}"
env:
VERSION: ${{ steps.ruleset.outputs.version }}
- name: Generate a GitHub token (${{ github.repository_owner }}/go-libddwaf)
if: fromJson(steps.detect.outputs.mutation-happened)
id: generate-token-pr
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
with:
app-id: ${{ vars.DD_K9_LIBRARY_GO_APP_ID }}
private-key: ${{ secrets.DD_K9_LIBRARY_GO_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: go-libddwaf
# We use ghcommit to create signed commits directly using the GitHub API
- name: Create Commit on PR Branch
if: fromJson(steps.detect.outputs.mutation-happened)
uses: planetscale/ghcommit-action@6a383e778f6620afde4bf4b45069d3c6983c1ae2 # v0.2.15
with:
commit_message: "chore: update default ruleset to ${{ steps.ruleset.outputs.version }}"
branch: ${{ steps.create-branch.outputs.branch }}
repo: ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ steps.generate-token-pr.outputs.token }}
- name: Create PR
if: fromJson(steps.detect.outputs.mutation-happened)
run: |-
git fetch origin "${{ steps.create-branch.outputs.branch }}"
git reset --hard HEAD
git switch "${{ steps.create-branch.outputs.branch }}"
gh pr create --title "chore: update default ruleset to ${VERSION}" \
--body "Updated default ruleset to ${VERSION}." \
--head="${{ steps.create-branch.outputs.branch }}"
env:
GITHUB_TOKEN: ${{ steps.generate-token-pr.outputs.token }}
VERSION: ${{ steps.ruleset.outputs.version }}