fix(api): Attack Paths AWS region fallback and stale SCHEDULED cleanup#10917
Conversation
|
✅ All necessary |
|
✅ Conflict Markers Resolved All conflict markers have been successfully resolved in this pull request. |
There was a problem hiding this comment.
Pull request overview
This PR hardens Attack Paths execution by adding AWS region-resolution fallbacks and expanding periodic cleanup to handle scans stuck before execution, improving reliability when AWS region enumeration fails or Celery messages are lost.
Changes:
- Add
resolve_aws_regions()fallback logic when the SDK can’t enumerate enabled regions. - Persist the Celery task id on
AttackPathsScanat dispatch time and add stale cleanup forSCHEDULEDscans (with worker-side idempotency guard). - Update Attack Paths scan start flow to no longer set task id during the
EXECUTINGtransition.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| api/src/backend/tasks/tests/test_attack_paths_scan.py | Updates unit test expectation for changed starting_attack_paths_scan() call signature. |
| api/src/backend/tasks/tasks.py | Persists the Celery task id on the Attack Paths scan row at dispatch time. |
| api/src/backend/tasks/jobs/attack_paths/scan.py | Adds terminal-state idempotency guard and adjusts scan-start call signature. |
| api/src/backend/tasks/jobs/attack_paths/db_utils.py | Introduces set_attack_paths_scan_task_id() and removes task id persistence from starting_attack_paths_scan(). |
| api/src/backend/tasks/jobs/attack_paths/cleanup.py | Adds cleanup path for stale SCHEDULED scans and refactors stale cleanup helpers. |
| api/src/backend/tasks/jobs/attack_paths/aws.py | Uses new AWS region resolution helper to avoid crashes when enabled regions are unavailable. |
| api/CHANGELOG.md | Adds an UNRELEASED entry documenting the fixes. |
Comments suppressed due to low confidence (1)
api/src/backend/tasks/jobs/attack_paths/scan.py:136
- In the fallback branch where the worker creates the
AttackPathsScanrow, the scan never gets associated to the current Celery task (task_id/taskFK). Sincestarting_attack_paths_scan()no longer sets the task id, this row will remain without a task reference (hurting traceability and preventing queued-task revocation for this path). Consider persisting the currenttask_idto the row when it’s created here (or reintroduce setting it instarting_attack_paths_scanfor the no-row-found case).
if not attack_paths_scan:
# Safety net: the dispatcher normally pre-creates this row buit fall back here for in-flight messages or direct task invocations
logger.warning(
f"No Attack Paths Scan found for scan {scan_id} and tenant {tenant_id}, let's create it then"
)
attack_paths_scan = db_utils.create_attack_paths_scan(
tenant_id, scan_id, prowler_api_provider.id
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔒 Container Security ScanImage: 📊 Vulnerability Summary
4 package(s) affected
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #10917 +/- ##
==========================================
+ Coverage 88.14% 93.63% +5.48%
==========================================
Files 131 230 +99
Lines 5542 33714 +28172
==========================================
+ Hits 4885 31567 +26682
- Misses 657 2147 +1490
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… region order - Fix comment typo
SCHEDULED cleanup
Context
AWS Attack Paths scans were crashing with
TypeError: 'NoneType'object is not iterable whenever the SDK couldn't enumerate enabled regions (missingec2:DescribeRegions, transient AWS error). Separately, Attack Paths rows could sit inSCHEDULEDforever when the parent Prowler scan crashed before dispatch or the broker lost the message.Description
identity.audited_regions, then to all regions in the partition;_excluded_regionsis still subtracted.SCHEDULEDrows: revokes the queued Celery task and marks the rowFAILED. Only triggers when the parent Prowler scan is terminal or missing.task_idis persisted at dispatch time so cleanup can target queued messages.Steps to review
Run tests and a local Attack Paths scan.
Checklist
API
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.