Commit 0e26446
committed
o365: fix error propagation within cel program
The logic for handling error propagation from failed subscriptions
requests was incorrect. The downstream logic was expecting to find the
error in the root of state, but the subscription request block was
leaving it in the work object.
Later error handling was incorrectly leaving any error state in the root
of state, when it should have been placed under events.
In the case that a subscription has failed, there may not be an entry in
the last_for list for the subscription, resulting in a look-up failure
during assessment for completion of the hour-window steps.
Finally, the postamble logic was brittle to failed requests, assuming
that the todo_type and todo_content list would be present, which is not
necessarily the case when a subscription has failed.
This has been manually tested against the mock committed in the deploy
directory (with removal of authentication for convenience) with the
following outcomes:
only one, invalid, subscription:
"""
-- data.json --
{
"url": "http://localhost:9001",
"want_more": false,
"base": {
"tenant_id": "test-cel-tenant-id",
"list_contents_start_time": "12h",
"batch_interval": "1h",
"maximum_age": "167h55m",
"content_types": "Audit.TypeRequiringAdditionalPermissions"
}
}
-- out.json --
{
"base": {
"batch_interval": "1h",
"content_types": "Audit.TypeRequiringAdditionalPermissions",
"list_contents_start_time": "12h",
"maximum_age": "167h55m",
"tenant_id": "test-cel-tenant-id"
},
"events": {
"error": {
"code": "401",
"id": "401 Unauthorized",
"message": "POST /activity/feed/subscriptions/start?contentType=Audit.TypeRequiringAdditionalPermissions: {\"error\":{\"code\":\"AF10001\",\"message\":\"The permission set (...) sent in the request does not include the expected permission.\"}}"
}
},
"url": "http://localhost:9001",
"want_more": false,
"work": {
"curr_type": "Audit.TypeRequiringAdditionalPermissions",
"todo_type": []
}
}
"""
start with an invalid subscription:
"""
-- data.json --
{
"url": "http://localhost:9001",
"want_more": false,
"base": {
"tenant_id": "test-cel-tenant-id",
"list_contents_start_time": "12h",
"batch_interval": "1h",
"maximum_age": "167h55m",
"content_types": "Audit.TypeRequiringAdditionalPermissions, Audit.SharePoint"
}
}
-- out.json --
{
"base": {
"batch_interval": "1h",
"content_types": "Audit.TypeRequiringAdditionalPermissions, Audit.SharePoint",
"list_contents_start_time": "12h",
"maximum_age": "167h55m",
"tenant_id": "test-cel-tenant-id"
},
"events": {
"error": {
"code": "401",
"id": "401 Unauthorized",
"message": "POST /activity/feed/subscriptions/start?contentType=Audit.TypeRequiringAdditionalPermissions: {\"error\":{\"code\":\"AF10001\",\"message\":\"The permission set (...) sent in the request does not include the expected permission.\"}}"
}
},
"url": "http://localhost:9001",
"want_more": true,
"work": {
"curr_type": "Audit.TypeRequiringAdditionalPermissions",
"todo_type": [
"Audit.SharePoint"
]
}
}
{
"base": {
"batch_interval": "1h",
"content_types": "Audit.TypeRequiringAdditionalPermissions, Audit.SharePoint",
"list_contents_start_time": "12h",
"maximum_age": "167h55m",
"tenant_id": "test-cel-tenant-id"
},
"cursor": {
"last_for": {
"audit.sharepoint": "2025-09-23T13:07:36.915764483Z"
}
},
"events": [
{
… more …
"""
end with an invalid subscription:
"""
-- data.json --
{
"url": "http://localhost:9001",
"want_more": false,
"base": {
"tenant_id": "test-cel-tenant-id",
"list_contents_start_time": "12h",
"batch_interval": "1h",
"maximum_age": "167h55m",
"content_types": "Audit.SharePoint, Audit.TypeRequiringAdditionalPermissions"
}
}
-- out.json --
… more before …
"enabled": true,
"type": "Audit.SharePoint"
},
"todo_content": [],
"todo_type": [
"Audit.TypeRequiringAdditionalPermissions"
]
}
}
{
"base": {
"batch_interval": "1h",
"content_types": "Audit.SharePoint, Audit.TypeRequiringAdditionalPermissions",
"list_contents_start_time": "12h",
"maximum_age": "167h55m",
"tenant_id": "test-cel-tenant-id"
},
"cursor": {
"last_for": {
"audit.sharepoint": "2025-09-24T00:10:30.808672557Z"
}
},
"events": {
"error": {
"code": "401",
"id": "401 Unauthorized",
"message": "POST /activity/feed/subscriptions/start?contentType=Audit.TypeRequiringAdditionalPermissions: {\"error\":{\"code\":\"AF10001\",\"message\":\"The permission set (...) sent in the request does not include the expected permission.\"}}"
}
},
"url": "http://localhost:9001",
"want_more": false,
"work": {
"curr_type": "Audit.TypeRequiringAdditionalPermissions",
"todo_type": []
}
}
"""1 parent 024c12d commit 0e26446
File tree
3 files changed
+38
-28
lines changed- packages/o365
- data_stream/audit/agent/stream
3 files changed
+38
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
2 | 7 | | |
3 | 8 | | |
4 | 9 | | |
| |||
Lines changed: 32 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| |||
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
317 | | - | |
| 319 | + | |
318 | 320 | | |
319 | | - | |
| 321 | + | |
320 | 322 | | |
321 | 323 | | |
322 | 324 | | |
| |||
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
452 | 456 | | |
453 | 457 | | |
454 | 458 | | |
| |||
461 | 465 | | |
462 | 466 | | |
463 | 467 | | |
464 | | - | |
465 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
466 | 474 | | |
467 | 475 | | |
468 | 476 | | |
| |||
476 | 484 | | |
477 | 485 | | |
478 | 486 | | |
479 | | - | |
| 487 | + | |
480 | 488 | | |
481 | 489 | | |
482 | 490 | | |
483 | 491 | | |
484 | 492 | | |
485 | 493 | | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 494 | + | |
490 | 495 | | |
491 | 496 | | |
492 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments