Skip to content

Commit a861300

Browse files
authored
[Osquery] PR - A: rrule scheduling foundation (flag off) (elastic#269730)
1 parent 3f2b1fb commit a861300

22 files changed

Lines changed: 1672 additions & 25 deletions

File tree

packages/kbn-check-saved-objects-cli/current_fields.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@
10641064
"created_by_profile_uid",
10651065
"description",
10661066
"enabled",
1067+
"interval",
10671068
"name",
10681069
"queries",
10691070
"queries.ecs_mapping",
@@ -1073,6 +1074,8 @@
10731074
"queries.query",
10741075
"queries.timeout",
10751076
"queries.version",
1077+
"rrule_schedule",
1078+
"schedule_type",
10761079
"shards",
10771080
"updated_at",
10781081
"updated_by",

packages/kbn-check-saved-objects-cli/current_mappings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
"createdBy": {
338338
"type": "keyword"
339339
},
340-
341340
"description": {
342341
"fields": {
343342
"keyword": {
@@ -3550,6 +3549,9 @@
35503549
"enabled": {
35513550
"type": "boolean"
35523551
},
3552+
"interval": {
3553+
"type": "integer"
3554+
},
35533555
"name": {
35543556
"type": "text"
35553557
},
@@ -3580,6 +3582,14 @@
35803582
}
35813583
}
35823584
},
3585+
"rrule_schedule": {
3586+
"dynamic": false,
3587+
"properties": {}
3588+
},
3589+
"schedule_type": {
3590+
"ignore_above": 1024,
3591+
"type": "keyword"
3592+
},
35833593
"shards": {
35843594
"dynamic": false,
35853595
"properties": {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"10.2.0": [
3+
{
4+
"name": "test-pack-1",
5+
"description": "A test pack",
6+
"queries": {
7+
"query1": {
8+
"id": "query1",
9+
"query": "select * from processes;",
10+
"interval": 3600,
11+
"timeout": 300
12+
}
13+
},
14+
"enabled": true,
15+
"created_at": "2024-01-01T00:00:00.000Z",
16+
"created_by": "elastic",
17+
"updated_at": "2024-01-01T00:00:00.000Z",
18+
"updated_by": "elastic"
19+
}
20+
],
21+
"10.3.0": [
22+
{
23+
"name": "test-pack-1",
24+
"description": "A test pack",
25+
"queries": {
26+
"query1": {
27+
"id": "query1",
28+
"query": "select * from processes;",
29+
"interval": 3600,
30+
"timeout": 300
31+
}
32+
},
33+
"enabled": true,
34+
"created_at": "2024-01-01T00:00:00.000Z",
35+
"created_by": "elastic",
36+
"updated_at": "2024-01-01T00:00:00.000Z",
37+
"updated_by": "elastic"
38+
}
39+
]
40+
}

src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
150150
"oauth_state": "4d7f9d29a0d49146a54cbc7580fbd317ad709048a79cc994c7e83d84ebfc9a85",
151151
"observability-onboarding-state": "2495563e6b20ce1be160ec0c3143a4aee920cad1d6e5c478452470ccb7bd2753",
152152
"osquery-manager-usage-metric": "8833b9f812e9179897444c395761f9911945cfb77de9869c4e9b6ee6eeb0f573",
153-
"osquery-pack": "9cb5096182b6490fe2364d740cf9a23fa5562153d8c4a416303b7a82b9d37f21",
153+
"osquery-pack": "ed35a71e98489dd9a5acc476188648c7280deedb55fd596aa6a53d40d587678d",
154154
"osquery-pack-asset": "fb48358a1ecbe00b7a4e670b47e301e86f9fdc392f403a64dbe207b1884e8784",
155155
"osquery-saved-query": "a66139a460e1fc80611ffe392fab4db7db48e5a81691ba306a258bd70008a6d1",
156156
"policy-settings-protection-updates-note": "d91301a012aa934229958cbbb2bffa72c9ce2532fbe67fa00a6f255ff60571b6",
@@ -1092,9 +1092,10 @@ describe('checking migration metadata changes on all registered SO types', () =>
10921092
"osquery-manager-usage-metric|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
10931093
"==============================================================================",
10941094
"osquery-pack|global: 2d5e5413c0bdbc80e7127c3a57f6be15e5078dbe",
1095-
"osquery-pack|mappings: bce366d537668509ca94beac2250664b3a6b62ea",
1095+
"osquery-pack|mappings: 78077a573dfb4f0d6c42c6c02ae5fe3a5bacb4b7",
10961096
"osquery-pack|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
1097-
"osquery-pack|10.2.0: 3814752beb1760b29d858991c55e488b0005166668cd51dd61a806359236d04b",
1097+
"osquery-pack|10.3.0: 80c6ea83536c342f97734b289264bf74e457b2f6f604a596d6857d161416d018",
1098+
"osquery-pack|10.2.0: fcd4b94ad161b8463b4de2f15fc2a7dae820dc84878db67e25b7261892432706",
10981099
"osquery-pack|10.1.0: 98a6593772eecbe42b9dd8d007af5fbcaf6cd7adbf037857f9686307cdb771c1",
10991100
"=====================================================================================",
11001101
"osquery-pack-asset|global: 6ae0ad3ceac166af2a7b4d9b0b0afffd2d315cda",
@@ -1568,7 +1569,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
15681569
"oauth_state": "10.1.0",
15691570
"observability-onboarding-state": "10.2.0",
15701571
"osquery-manager-usage-metric": "10.0.0",
1571-
"osquery-pack": "10.2.0",
1572+
"osquery-pack": "10.3.0",
15721573
"osquery-pack-asset": "10.1.0",
15731574
"osquery-saved-query": "10.2.0",
15741575
"policy-settings-protection-updates-note": "10.0.0",
@@ -1741,7 +1742,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
17411742
"oauth_state": "10.1.0",
17421743
"observability-onboarding-state": "10.2.0",
17431744
"osquery-manager-usage-metric": "0.0.0",
1744-
"osquery-pack": "10.2.0",
1745+
"osquery-pack": "10.3.0",
17451746
"osquery-pack-asset": "10.1.0",
17461747
"osquery-saved-query": "10.2.0",
17471748
"policy-settings-protection-updates-note": "0.0.0",

x-pack/platform/plugins/shared/osquery/common/experimental_features.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ export const allowedExperimentalValues = Object.freeze({
3030
* for downloading osquery results as NDJSON, JSON, or CSV files.
3131
*/
3232
exportResults: false,
33+
/**
34+
* Enables RFC 5545 RRULE-based recurrence scheduling for packs and pack queries
35+
* as an alternative to native interval-based scheduling. When enabled, the
36+
* pack form and pack query flyout expose a Schedule section, the API accepts
37+
* `schedule_type` / `interval` (pack-level) / `rrule_schedule` fields, and the
38+
* Fleet config fans the pack-level schedule onto each query that doesn't have
39+
* its own override. Requires osquerybeat with RRULE support.
40+
*/
41+
rruleScheduling: false,
3342
});
3443

3544
type ExperimentalFeatures = { [K in keyof typeof allowedExperimentalValues]: boolean };

x-pack/platform/plugins/shared/osquery/common/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export {
1212
getExperimentalAllowedValues,
1313
} from './experimental_features';
1414
export type { ExperimentalFeatures } from './experimental_features';
15+
export type { ScheduleType, RRuleScheduleConfig } from './schedule';
16+
export { MAX_SPLAY_SECONDS } from './schedule';
1517

1618
export const PLUGIN_ID = 'osquery';
1719
export const PLUGIN_NAME = 'Osquery';
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
/**
9+
* Maximum allowed splay duration in seconds (12 hours). Aligned with osquerybeat's
10+
* `MaxSplay = 12 * time.Hour` constant.
11+
*/
12+
export const MAX_SPLAY_SECONDS = 43200;
13+
14+
/**
15+
* Discriminator for which scheduling mode a pack or pack query uses.
16+
*
17+
* - `'interval'`: native osqueryd interval scheduling (seconds). Mutually
18+
* exclusive with `rrule_schedule`.
19+
* - `'rrule'`: osquerybeat RRULE-based recurrence scheduling. Mutually
20+
* exclusive with `interval`.
21+
*
22+
* Absence of the field on a pack means no pack-level schedule is set: each
23+
* query uses its own per-query `interval` and there is no default to inherit.
24+
*/
25+
export type ScheduleType = 'interval' | 'rrule';
26+
27+
/**
28+
* RRULE schedule configuration consumed by osquerybeat. The `rrule` field is
29+
* the fully serialized RFC 5545 string (e.g. `"FREQ=WEEKLY;BYDAY=MO,WE,FR"`),
30+
* not a structured object — osquerybeat's `teambition/rrule-go` parser speaks
31+
* strings directly. DTSTART is NOT included in the RRULE string; osquerybeat
32+
* uses the separate `start_date` field.
33+
*/
34+
export interface RRuleScheduleConfig {
35+
/** RFC 5545 RRULE string. */
36+
rrule: string;
37+
/** RFC 3339 datetime string for the schedule's start. Required. */
38+
start_date: string;
39+
/** Optional RFC 3339 datetime string for the schedule's end. */
40+
end_date?: string;
41+
/**
42+
* Optional Go duration string for splay (random execution delay).
43+
* Single-unit only on write: suffix `s` (seconds), `m` (minutes), or `h`
44+
* (hours) — e.g. `"30s"`, `"5m"`, `"1h"`. Compound durations like `"1h30m"`
45+
* are tolerated only on read (osquerybeat parses via `time.ParseDuration`
46+
* and may emit compound strings). Maximum 12 hours ({@link MAX_SPLAY_SECONDS}).
47+
*/
48+
splay?: string;
49+
/**
50+
* Optional query execution timeout, in **seconds**. Field name is `timeout`
51+
* to match osquerybeat's wire field (`RRuleScheduleConfig.Timeout int`
52+
* in `elastic/beats#48767`). Default in beats is 60s when absent.
53+
*/
54+
timeout?: number;
55+
}

0 commit comments

Comments
 (0)