feat: enforce incident trigger CEL in insert_incident - #6657
Open
ausias-armesto wants to merge 1 commit into
Open
feat: enforce incident trigger CEL in insert_incident#6657ausias-armesto wants to merge 1 commit into
ausias-armesto wants to merge 1 commit into
Conversation
insert_incident() only checked whether the trigger's event name matched (created/updated) but never compiled or evaluated the trigger's "cel" expression, unlike insert_events() which enforces it for alert triggers. This meant any cel on an incident trigger (e.g. a guard like `!has(incident_id)` to prevent re-running after a workflow already succeeded) was silently ignored and the workflow ran on every matching event regardless.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #6656
Problem
WorkflowManager.insert_incident()only checked whether the incoming eventname (
created/updated) was declared on the trigger. It never compiledor evaluated the trigger's
celexpression, unlikeinsert_events(), whichdoes this for alert triggers. As a result, a
celguard on an incidenttrigger — e.g.
!has(incident_id), meant to stop a workflow from re-runningonce it has already completed and enriched the incident — had no effect at
all. The workflow ran on every matching event regardless.
Change
insert_incident()now:eventslist containsthe incoming event name, instead of only checking membership across a
flattened list of all incident triggers' events.
IncidentDto(asbefore), so fields set by a prior successful run (e.g.
incident_id) arevisible.
cel, compiles and evaluates it viathe same
celpyenvironmentinsert_events()uses, and skips schedulingthe workflow when it evaluates to
false. Evaluation errors are caught,logged, and treated as "don't run" rather than raised.
incident.dict()leaves UUID fields (likeincident.id) as native Pythonobjects, which
celpy.json_to_celrejects. The activation payload is builtfrom
json.loads(incident.json())instead, so pydantic's own JSON encodershandle that conversion first.