-
Notifications
You must be signed in to change notification settings - Fork 606
osquery_manager: generate ECS section mappings from config #18989
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,61 @@ | ||
| osquery: | ||
| # Exact patch (5.21.0) or prefix (5.21) to auto-pick latest patch. | ||
| version: "5.22.1" | ||
| version: "5.23.0" | ||
| beats: | ||
| # Git ref for elastic/beats osquery extension specs (raw.githubusercontent.com). | ||
| # Precedence: tag > branch > version (semver / prefix resolution). | ||
| # tag: "v9.4.2" | ||
| # branch: "main" | ||
| # Exact patch (9.3.1) or prefix (9.3) to auto-pick latest patch when tag/branch unset: | ||
| version: "9.4.0" | ||
| ecs: | ||
| # ECS field names to include even when they are objects/nested or otherwise | ||
| # filtered out by the default type allow-list. | ||
| keep_fields: | ||
| - dll.pe.sections | ||
| - email.attachments | ||
| - email.attachments.file.extension | ||
| - email.attachments.file.hash.md5 | ||
| - email.attachments.file.hash.sha1 | ||
| - email.attachments.file.hash.sha256 | ||
| - email.attachments.file.hash.sha384 | ||
| - email.attachments.file.hash.sha512 | ||
| - email.attachments.file.hash.ssdeep | ||
| - email.attachments.file.hash.tlsh | ||
| - email.attachments.file.mime_type | ||
| - email.attachments.file.name | ||
| - email.attachments.file.size | ||
| - email.bcc.address | ||
| - email.cc.address | ||
| - email.content_type | ||
| - email.delivery_timestamp | ||
| - email.direction | ||
| - email.from.address | ||
| - email.local_id | ||
| - email.message_id | ||
| - email.origination_timestamp | ||
| - email.reply_to.address | ||
| - email.sender.address | ||
| - email.subject | ||
| - email.to.address | ||
| - email.x_mailer | ||
| - file.elf.sections | ||
| - file.macho.sections | ||
| - file.pe.sections | ||
| - group.id | ||
| - network.iana_number | ||
| - network.type | ||
| - process.elf.sections | ||
| - process.macho.sections | ||
| - process.parent.elf.sections | ||
| - process.parent.macho.sections | ||
| - process.parent.pe.sections | ||
| - process.pe.sections | ||
| - threat.enrichments | ||
| - threat.enrichments.indicator.file.elf.sections | ||
| - threat.enrichments.indicator.file.pe.sections | ||
| - threat.indicator.file.elf.sections | ||
| - threat.indicator.file.pe.sections | ||
| - user.group.id | ||
| - user.id |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ package main | |
|
|
||
| import ( | ||
| "bytes" | ||
| _ "embed" | ||
| "encoding/csv" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
@@ -45,9 +44,6 @@ var ( | |
| ecsRestrictedSet = makeSet(ecsRestrictedFields) | ||
| ) | ||
|
|
||
| //go:embed ecs_keep_fields.txt | ||
| var ecsKeepFieldsContent string | ||
|
|
||
| type kibanaOsqueryTable struct { | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
|
|
@@ -123,7 +119,7 @@ type columnInfo struct { | |
| Column osqueryCol | ||
| } | ||
|
|
||
| func generateArtifacts(outputRoot, osqueryVersion, ecsVersion, beatsRef string, runPackageCheck bool) error { | ||
| func generateArtifacts(outputRoot, osqueryVersion, ecsVersion, beatsRef string, ecsKeepFields []string, runPackageCheck bool) error { | ||
| outFields := filepath.Join(outputRoot, "packages", "osquery_manager", "data_stream", "result", "fields") | ||
| outSchemas := filepath.Join(outputRoot, "packages", "osquery_manager", "schemas") | ||
|
|
||
|
|
@@ -165,7 +161,7 @@ func generateArtifacts(outputRoot, osqueryVersion, ecsVersion, beatsRef string, | |
| if err != nil { | ||
| return fmt.Errorf("download ECS fields: %w", err) | ||
| } | ||
| ecsOut, err := generateECSFieldsYAML(ecsYAML) | ||
| ecsOut, err := generateECSFieldsYAML(ecsYAML, ecsKeepFields) | ||
| if err != nil { | ||
| return fmt.Errorf("generate ecs.yml: %w", err) | ||
| } | ||
|
|
@@ -500,20 +496,8 @@ func marshalYAMLWithIndent(v any, indent int) ([]byte, error) { | |
| return buf.Bytes(), nil | ||
| } | ||
|
|
||
| func loadKeepFields() []string { | ||
| var out []string | ||
| for _, line := range strings.Split(ecsKeepFieldsContent, "\n") { | ||
| line = strings.TrimSpace(line) | ||
| if line == "" || strings.HasPrefix(line, "#") { | ||
| continue | ||
| } | ||
| out = append(out, line) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func generateECSFieldsYAML(ecsBeatsYAML []byte) ([]byte, error) { | ||
| keepFields := makeSet(loadKeepFields()) | ||
| func generateECSFieldsYAML(ecsBeatsYAML []byte, ecsKeepFields []string) ([]byte, error) { | ||
| keepFields := makeSet(ecsKeepFields) | ||
| var root any | ||
| if err := yaml.Unmarshal(ecsBeatsYAML, &root); err != nil { | ||
| return nil, err | ||
|
|
@@ -550,12 +534,16 @@ func collectECSFieldNames(root any, parent string, keepFields map[string]struct{ | |
| if parent == "" && inSet(excludeFromTopLevelSet, name) { | ||
| continue | ||
| } | ||
| fieldName := joinPath(parent, name) | ||
| kept := inSet(keepFields, fieldName) | ||
| if kept && name != "@timestamp" { | ||
| *ecsFields = append(*ecsFields, fieldName) | ||
| } | ||
| if childFields, hasFields := m["fields"]; hasFields { | ||
| collectECSFieldNames(childFields, joinPath(parent, name), keepFields, ecsFields) | ||
| } else { | ||
| fieldName := joinPath(parent, name) | ||
| typ, _ := m["type"].(string) | ||
| if (inSet(keepFields, fieldName) || isAllowedECSType(typ)) && name != "@timestamp" { | ||
| if !kept && isAllowedECSType(typ) && name != "@timestamp" { | ||
| *ecsFields = append(*ecsFields, fieldName) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest adding a unit test for This is the substance of the fix and right now it's only validated indirectly via the regenerated |
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,9 +37,14 @@ type beatsConfig struct { | |
| Version string `yaml:"version"` | ||
| } | ||
|
|
||
| type ecsConfig struct { | ||
| KeepFields []string `yaml:"keep_fields"` | ||
| } | ||
|
|
||
| type config struct { | ||
| Osquery versionConfig `yaml:"osquery"` | ||
| Beats beatsConfig `yaml:"beats"` | ||
| ECS ecsConfig `yaml:"ecs"` | ||
| } | ||
|
|
||
| type packageBuildYAML struct { | ||
|
|
@@ -93,7 +98,7 @@ func main() { | |
| } | ||
|
|
||
| log.Printf("Resolved versions: osquery=%s beats=%s ecs=%s", osqueryVersion, beatsRef, ecsVersion) | ||
| if err := generateArtifacts(outputRoot, osqueryVersion, ecsVersion, beatsRef, !*skipPackageCheck); err != nil { | ||
| if err := generateArtifacts(outputRoot, osqueryVersion, ecsVersion, beatsRef, cfg.ECS.KeepFields, !*skipPackageCheck); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If A |
||
| log.Fatalf("generate artifacts: %v", err) | ||
| } | ||
| log.Println("Done.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| # newer versions go on top | ||
| - version: "1.29.0" | ||
| changes: | ||
| - description: Generate ECS `*.sections` parent mappings from osquery-gen config | ||
| type: bugfix | ||
| link: https://github.com/elastic/integrations/pull/16650 | ||
| - description: Upgrade osquery version to 5.23.0 | ||
| type: enhancement | ||
| link: https://github.com/elastic/integrations/pull/16650 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| - version: "1.28.1" | ||
| changes: | ||
| - description: Update ECS mappings for `*.sections` fields in results dataset | ||
|
|
||
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.
nit: the inverted condition (
!kept && isAllowedECSType(typ)) reads as "skip the type check when kept," but the actual intent is "kept-list takes priority and also emits the parent object node; the leaf type check still applies to non-kept children." A one-line comment above thekeptblock on line 538 would save the next reader from re-deriving this.Also,
name != "@timestamp"is now checked on both branches — minor duplication, harmless, but could be lifted to a single guard at the top of the loop body.