-
Notifications
You must be signed in to change notification settings - Fork 600
feat: ESQL query validation against Elastic cluster #4955
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
Open
traut
wants to merge
87
commits into
main
Choose a base branch
from
esql-field-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,346
−178
Open
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
1a8f552
Style fixes
traut aa21e96
Typo fix
traut 46248f7
Initial logic
traut 08b0c15
Comments and small fixes
traut 03c4bd6
Merge branch 'main' into esql-field-validation
eric-forte-elastic 65e5eda
Add initial dynamic field validation
eric-forte-elastic 2046d63
Update dynamic field validation
eric-forte-elastic 5a2e81c
Remove sub query ecs enforcement
eric-forte-elastic 0cc5443
Add initial non ecs support
eric-forte-elastic 6f018b5
Add initial workflow
eric-forte-elastic 01191d2
Merge branch 'main' into esql-field-validation
eric-forte-elastic f95d70b
Merge branch 'main' into esql-field-validation
eric-forte-elastic e86a807
Merge branch 'main' into esql-field-validation
eric-forte-elastic 6329493
Add optional multi index method
eric-forte-elastic fd67c65
Code cleanup
eric-forte-elastic 1cf9367
Reduce function complexity
eric-forte-elastic d17d377
Minor Version Bump
eric-forte-elastic e84e563
Linting
eric-forte-elastic f827f91
Add connection retry handling
eric-forte-elastic 34cfb33
Switch to encoded var
eric-forte-elastic bf3955d
comment cleanup
eric-forte-elastic a38b195
Skip internal fields on validation
eric-forte-elastic 0b61ca7
Fix typo in internal fields
eric-forte-elastic b0d3fb8
Handle ECS mappings like fleet
eric-forte-elastic 8f58df6
Add validate support via env var
eric-forte-elastic 90793e4
Add unique field support
eric-forte-elastic f7c1476
Update with DR_REMOTE_ESQL_VALIDATION
eric-forte-elastic 9e1150c
Merge branch 'main' into esql-field-validation
eric-forte-elastic d18b493
Update to use remote validation logic
eric-forte-elastic b6aac59
Merge branch 'esql-field-validation' of https://github.com/elastic/de…
eric-forte-elastic 6456cbc
Add index_replacement option
eric-forte-elastic a0798aa
Add docstring
eric-forte-elastic 252aafa
minor bump
eric-forte-elastic 2599c6b
Merge branch 'main' into esql-field-validation
eric-forte-elastic df33505
Merge branch 'main' into esql-field-validation
eric-forte-elastic edd18ee
Remove excess function
eric-forte-elastic f21442d
Add support for event.dataset
eric-forte-elastic e17ab0e
Update related integrations
eric-forte-elastic 676503e
Cleanup
eric-forte-elastic bf21646
Add view rule flag
eric-forte-elastic 2a6b0ef
Linting
eric-forte-elastic 391eafb
Merge branch 'main' into esql-field-validation
eric-forte-elastic 9246c16
Fix unit test bug
eric-forte-elastic 86cb0a4
explicit raw string
eric-forte-elastic d973bd1
Merge branch 'main' into esql-field-validation
eric-forte-elastic 526567f
Merge branch 'main' into esql-field-validation
eric-forte-elastic c25d18d
CI updates
eric-forte-elastic b6e83bd
fix typo
eric-forte-elastic f23d839
Initial Error Classes
eric-forte-elastic 013ad5f
Update Error Types
eric-forte-elastic f9d4dba
Update Validation Errors for Index handling
eric-forte-elastic bdd7ed4
Formatting
eric-forte-elastic 84e36a5
Add license
eric-forte-elastic 39116a1
Re order error classes
eric-forte-elastic 4d3de2e
Handle nested flattened fields
eric-forte-elastic ae7e7a3
Handle cases where ESQL validator is not fully initialized
eric-forte-elastic 1c87dc6
Making package/integrations consistent
eric-forte-elastic afd9cef
Add note
eric-forte-elastic ace3950
Add FIXME
eric-forte-elastic e82d412
Remove Note
eric-forte-elastic 2ce790b
Update ESQL class with a base error class
eric-forte-elastic b3df752
Remove event.module from parsing
eric-forte-elastic 0fa8c0f
Prevent double validation on view rule
eric-forte-elastic 289bbef
Move functions out of utils for clarity
eric-forte-elastic db963ff
Merge branch 'main' into esql-field-validation
eric-forte-elastic 5942aeb
Cleanup Esql Error Types
eric-forte-elastic 2aaeae6
Add explicit deepcopy
eric-forte-elastic 2ee3f67
Ignore Kibana long vs schema integer mismatch
eric-forte-elastic a513c0a
can now enforce length with proper schemas
eric-forte-elastic fdbb483
Add remote testing dev command
eric-forte-elastic 5ae9937
Get latest instead of least for this validation
eric-forte-elastic 5e58418
TODO items
eric-forte-elastic a368516
Add validation for all stacks in schema map
eric-forte-elastic a24b50c
Merge branch 'main' into esql-field-validation
eric-forte-elastic 3f04c44
Merge branch 'main' into esql-field-validation
eric-forte-elastic dd64521
Update function name
eric-forte-elastic 8b37fc7
Merge branch 'esql-field-validation' of https://github.com/elastic/de…
eric-forte-elastic df9e285
Use env rather than variables
eric-forte-elastic 269795a
Switch if logic to env
eric-forte-elastic 2746b00
Handle empty strings as None
eric-forte-elastic 76b33d7
Add comment
eric-forte-elastic a07c7f5
Add failed rules output for CI
eric-forte-elastic e55c593
Add env masking
eric-forte-elastic 827937a
Only run on modified esql rules or push to main
eric-forte-elastic c077219
Update to main elastic-container
eric-forte-elastic 244226f
Add index validation and unsupported type checking
eric-forte-elastic cc768b2
Add index validation
eric-forte-elastic 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: ES|QL Validation | ||
on: | ||
push: | ||
branches: [ "main", "8.*", "9.*" ] | ||
pull_request: | ||
branches: [ "*" ] | ||
paths: | ||
- 'rules/**/*.toml' | ||
jobs: | ||
build-and-validate: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup Detection Rules | ||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | ||
with: | ||
fetch-depth: 0 | ||
path: detection-rules | ||
|
||
- name: Check if new or modified rule files are ESQL rules | ||
id: check-esql | ||
run: | | ||
cd detection-rules | ||
|
||
# Check if the event is a push | ||
if [ "${{ github.event_name }}" = "push" ]; then | ||
echo "Triggered by a push event. Setting run_esql=true." | ||
echo "run_esql=true" >> $GITHUB_ENV | ||
exit 0 | ||
fi | ||
|
||
MODIFIED_FILES=$(git diff --name-only --diff-filter=AM HEAD~1 | grep '^rules/.*\.toml$' || true) | ||
if [ -z "$MODIFIED_FILES" ]; then | ||
echo "No modified or new .toml files found. Skipping workflow." | ||
echo "run_esql=false" >> $GITHUB_ENV | ||
exit 0 | ||
fi | ||
|
||
if ! grep -q 'type = "esql"' $MODIFIED_FILES; then | ||
echo "No 'type = \"esql\"' found in the modified .toml files. Skipping workflow." | ||
echo "run_esql=false" >> $GITHUB_ENV | ||
exit 0 | ||
fi | ||
|
||
echo "run_esql=true" >> $GITHUB_ENV | ||
|
||
- name: Check out repository | ||
env: | ||
DR_CLOUD_ID: ${{ secrets.cloud_id }} | ||
DR_API_KEY: ${{ secrets.api_key }} | ||
if: ${{ !env.DR_CLOUD_ID && !env.DR_API_KEY && env.run_esql == 'true' }} | ||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | ||
with: | ||
path: elastic-container | ||
repository: peasead/elastic-container | ||
|
||
- name: Build and run containers | ||
env: | ||
DR_CLOUD_ID: ${{ secrets.cloud_id }} | ||
DR_API_KEY: ${{ secrets.api_key }} | ||
if: ${{ !env.DR_CLOUD_ID && !env.DR_API_KEY && env.run_esql == 'true' }} | ||
run: | | ||
cd elastic-container | ||
GENERATED_PASSWORD=$(openssl rand -base64 16) | ||
sed -i "s|changeme|$GENERATED_PASSWORD|" .env | ||
echo "::add-mask::$GENERATED_PASSWORD" | ||
echo "GENERATED_PASSWORD=$GENERATED_PASSWORD" >> $GITHUB_ENV | ||
set -x | ||
bash elastic-container.sh start | ||
|
||
- name: Get API Key and setup auth | ||
env: | ||
DR_CLOUD_ID: ${{ secrets.cloud_id }} | ||
DR_API_KEY: ${{ secrets.api_key }} | ||
DR_ELASTICSEARCH_URL: "https://localhost:9200" | ||
ES_USER: "elastic" | ||
ES_PASSWORD: ${{ env.GENERATED_PASSWORD }} | ||
if: ${{ !env.DR_CLOUD_ID && !env.DR_API_KEY && env.run_esql == 'true' }} | ||
run: | | ||
cd detection-rules | ||
response=$(curl -k -X POST -u "$ES_USER:$ES_PASSWORD" -H "Content-Type: application/json" -d '{ | ||
"name": "tmp-api-key", | ||
"expiration": "1d" | ||
}' "$DR_ELASTICSEARCH_URL/_security/api_key") | ||
|
||
DR_API_KEY=$(echo "$response" | jq -r '.encoded') | ||
echo "::add-mask::$DR_API_KEY" | ||
echo "DR_API_KEY=$DR_API_KEY" >> $GITHUB_ENV | ||
|
||
- name: Set up Python 3.13 | ||
if: ${{ env.run_esql == 'true' }} | ||
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6 | ||
with: | ||
python-version: '3.13' | ||
|
||
- name: Install dependencies | ||
if: ${{ env.run_esql == 'true' }} | ||
run: | | ||
cd detection-rules | ||
python -m pip install --upgrade pip | ||
pip cache purge | ||
pip install .[dev] | ||
|
||
- name: Remote Test ESQL Rules | ||
if: ${{ env.run_esql == 'true' }} | ||
env: | ||
DR_CLOUD_ID: ${{ secrets.cloud_id || '' }} | ||
DR_KIBANA_URL: ${{ secrets.cloud_id == '' && 'https://localhost:5601' || '' }} | ||
DR_ELASTICSEARCH_URL: ${{ secrets.cloud_id == '' && 'https://localhost:9200' || '' }} | ||
DR_API_KEY: ${{ secrets.api_key || env.DR_API_KEY }} | ||
DR_IGNORE_SSL_ERRORS: ${{ secrets.cloud_id == '' && 'true' || '' }} | ||
run: | | ||
cd detection-rules | ||
python -m detection_rules dev test esql-remote-validation |
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
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
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.
Im not sure we want this to run outside of PRs because its expensive.
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.
That makes sense. I think my only concern would be backport testing then, but given that we are checking everything in the stack schema map anyway each time, I think it would be unlikely that we would miss something. The case I can think of would be when we introduce a min-stack and then have a case where the fork is no longer tested.
Again I agree it is probably not worth the expense, just adding context.