|
| 1 | +name: ES|QL Validation |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [ "main", "7.*", "8.*", "9.*" ] |
| 5 | + pull_request: |
| 6 | + branches: [ "*" ] |
| 7 | + paths: |
| 8 | + - 'rules/**/*.toml' |
| 9 | +jobs: |
| 10 | + build-and-validate: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Check out repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + path: elastic-container |
| 18 | + repository: eric-forte-elastic/elastic-container |
| 19 | + |
| 20 | + - name: Build and run containers |
| 21 | + run: | |
| 22 | + cd elastic-container |
| 23 | + GENERATED_PASSWORD=$(openssl rand -base64 16) |
| 24 | + sed -i 's/changeme/$GENERATED_PASSWORD/' .env |
| 25 | + echo "GENERATED_PASSWORD=$GENERATED_PASSWORD" >> $GITHUB_ENV |
| 26 | + set -x |
| 27 | + bash elastic-container.sh start |
| 28 | + |
| 29 | +
|
| 30 | + - name: Setup Detection Rules |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Set up Python 3.13 |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: '3.13' |
| 39 | + |
| 40 | + - name: Get API Key and setup auth |
| 41 | + env: |
| 42 | + DR_KIBANA_URL: "https://localhost:5601" |
| 43 | + DR_ELASTICSEARCH_URL: "https://localhost:9200" |
| 44 | + ES_USER: "elastic" |
| 45 | + ES_PASSWORD: ${{ env.GENERATED_PASSWORD }} |
| 46 | + run: | |
| 47 | + cd detection-rules |
| 48 | + response=$(curl -k -X POST -u "$ES_USER:$ES_PASSWORD" -H "Content-Type: application/json" -d '{ |
| 49 | + "name": "tmp-api-key", |
| 50 | + "expiration": "1d" |
| 51 | + }' "$ELASTICSEARCH_URL/_security/api_key") |
| 52 | +
|
| 53 | + DR_API_KEY=$(echo "$response" | jq -r '.api_key') |
| 54 | + echo "DR_API_KEY=$DR_API_KEY" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Install dependencies |
| 57 | + run: | |
| 58 | + cd detection-rules |
| 59 | + python -m pip install --upgrade pip |
| 60 | + pip cache purge |
| 61 | + pip install .[dev] |
| 62 | +
|
| 63 | + - name: Validate Test ESQL Rule |
| 64 | + env: |
| 65 | + DR_KIBANA_URL: "https://localhost:5601" |
| 66 | + DR_ES_USER: "elastic" |
| 67 | + DR_API_KEY: ${{ env.DR_API_KEY }} |
| 68 | + run: | |
| 69 | + cd detection-rules |
| 70 | + python -m pytest tests/test_rules_remote.py::TestRemoteRules::test_esql_rules |
0 commit comments