-
Notifications
You must be signed in to change notification settings - Fork 103
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
[KATC] Update config schema #1770
Changes from all commits
88097df
93aa764
77a31a6
b3f251c
5fa2de9
03777f0
4d68485
2367637
479571c
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 |
---|---|---|
|
@@ -16,8 +16,11 @@ import ( | |
// identifier parsed from the JSON KATC config, and the `dataFunc` is the function | ||
// that performs the query against the source. | ||
type katcSourceType struct { | ||
name string | ||
dataFunc func(ctx context.Context, slogger *slog.Logger, sourcePattern string, query string, sourceConstraints *table.ConstraintList) ([]sourceData, error) | ||
name string | ||
// `pathConstraints` comes from the live query or scheduled query, and constrains `sourcePaths` to a particular value. | ||
// For example, `sourcePaths` may allow for querying files belonging to any user ("/Users/%/path/to/file"), and | ||
// `pathConstraints` may narrow the query to a path for a particular user ("/Users/example/path/to/file"). | ||
dataFunc func(ctx context.Context, slogger *slog.Logger, sourcePaths []string, query string, pathConstraints *table.ConstraintList) ([]sourceData, error) | ||
} | ||
|
||
// sourceData holds the result of calling `katcSourceType.dataFunc`. It maps the | ||
|
@@ -101,35 +104,57 @@ func (r *rowTransformStep) UnmarshalJSON(data []byte) error { | |
// katcTableConfig is the configuration for a specific KATC table. The control server | ||
// sends down these configurations. | ||
type katcTableConfig struct { | ||
Name string `json:"name"` | ||
SourceType katcSourceType `json:"source_type"` | ||
Source string `json:"source"` // Describes how to connect to source (e.g. path to db) -- % and _ wildcards supported | ||
Platform string `json:"platform"` | ||
SourcePaths []string `json:"source_paths"` // Describes how to connect to source (e.g. path to db) -- % and _ wildcards supported | ||
Filter string `json:"filter"` | ||
Columns []string `json:"columns"` | ||
Query string `json:"query"` // Query to run against `path` | ||
SourceQuery string `json:"source_query"` // Query to run against each source path | ||
RowTransformSteps []rowTransformStep `json:"row_transform_steps"` | ||
} | ||
|
||
// ConstructKATCTables takes stored configuration of KATC tables, parses the configuration, | ||
// and returns the constructed tables. | ||
func ConstructKATCTables(config map[string]string, slogger *slog.Logger) []osquery.OsqueryPlugin { | ||
plugins := make([]osquery.OsqueryPlugin, 0) | ||
for tableName, tableConfigStr := range config { | ||
|
||
tableConfigs, tableConfigsExist := config["tables"] | ||
if !tableConfigsExist { | ||
slogger.Log(context.TODO(), slog.LevelWarn, | ||
"missing top-level tables key in KATC config, cannot construct tables", | ||
) | ||
|
||
return plugins | ||
} | ||
|
||
// We want to unmarshal each table config separately, so that we don't fail to configure all tables | ||
// if only some are malformed. | ||
var rawTableConfigs []json.RawMessage | ||
if err := json.Unmarshal([]byte(tableConfigs), &rawTableConfigs); err != nil { | ||
slogger.Log(context.TODO(), slog.LevelWarn, | ||
"could not unmarshal tables in KATC config", | ||
"err", err, | ||
) | ||
return plugins | ||
} | ||
|
||
for _, rawTableConfig := range rawTableConfigs { | ||
var cfg katcTableConfig | ||
if err := json.Unmarshal([]byte(tableConfigStr), &cfg); err != nil { | ||
if err := json.Unmarshal(rawTableConfig, &cfg); err != nil { | ||
slogger.Log(context.TODO(), slog.LevelWarn, | ||
"unable to unmarshal config for Kolide ATC table, skipping", | ||
"table_name", tableName, | ||
"unable to unmarshal config for KATC table, skipping", | ||
"err", err, | ||
) | ||
continue | ||
} | ||
|
||
if cfg.Platform != runtime.GOOS { | ||
// For now, the filter is simply the OS | ||
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. I think we probably want to future proof this a little. Brainstorming... We could define a rich DSL with boolean logic. Or maybe we can just have a series of strings? Or maybe a series of K:V pairs? Early use might be 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. What about making {
"name": "kolide_indexeddb_leveldb_test",
"source_type": "indexeddb_leveldb",
"filters": {
"goos": "darwin"
},
"columns": ["data"],
"source_paths": ["/some/path/to/db.indexeddb.leveldb"],
"source_query": "db.store",
"row_transform_steps": ["deserialize_chrome"]
} 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.
I think we should ponder whether that's an 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. I've updated to |
||
if cfg.Filter != runtime.GOOS { | ||
continue | ||
} | ||
|
||
t, columns := newKatcTable(tableName, cfg, slogger) | ||
plugins = append(plugins, table.NewPlugin(tableName, columns, t.generate)) | ||
t, columns := newKatcTable(cfg, slogger) | ||
plugins = append(plugins, table.NewPlugin(cfg.Name, columns, t.generate)) | ||
} | ||
|
||
return plugins | ||
|
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.
I'm a little unsure about how
pathConstraints
will be used. Can you provide an example? (In this comment is fine, doesn't need to be docs)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.
I see what the code is doing, but I'm not sure it adds a lot over a pushing
sourcePath
through `filepath.Glob(...)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.
Added documentation with an example