diff --git a/cmd/launcher/interactive.go b/cmd/launcher/interactive.go index 2b69cea44..99f3d4869 100644 --- a/cmd/launcher/interactive.go +++ b/cmd/launcher/interactive.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + "log/slog" "os" "strings" @@ -14,6 +15,7 @@ import ( "github.com/kolide/launcher/ee/tuf" "github.com/kolide/launcher/pkg/autoupdate" "github.com/kolide/launcher/pkg/launcher" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/kolide/launcher/pkg/osquery/interactive" ) @@ -34,6 +36,15 @@ func runInteractive(args []string) error { logger := logutil.NewServerLogger(*flDebug) + slogLevel := slog.LevelInfo + if *flDebug { + slogLevel = slog.LevelDebug + } + + slogger := multislogger.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ + Level: slogLevel, + })).Logger + osquerydPath := *flOsquerydPath if osquerydPath == "" { latestOsquerydBinary, err := tuf.CheckOutLatestWithoutConfig("osqueryd", logger) @@ -80,7 +91,7 @@ func runInteractive(args []string) error { flOsqueryFlags = append(flOsqueryFlags, fmt.Sprintf("tls_server_certs=%s", certs)) } - osqueryProc, extensionsServer, err := interactive.StartProcess(logger, rootDir, osquerydPath, flOsqueryFlags) + osqueryProc, extensionsServer, err := interactive.StartProcess(slogger, rootDir, osquerydPath, flOsqueryFlags) if err != nil { return fmt.Errorf("error starting osqueryd: %s", err) } diff --git a/ee/dataflatten/examples/flatten/main.go b/ee/dataflatten/examples/flatten/main.go index 6f214f523..04d63f250 100644 --- a/ee/dataflatten/examples/flatten/main.go +++ b/ee/dataflatten/examples/flatten/main.go @@ -7,8 +7,8 @@ import ( "strings" "text/tabwriter" - "github.com/kolide/kit/logutil" "github.com/kolide/launcher/ee/dataflatten" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/peterbourgon/ff/v3" ) @@ -40,13 +40,14 @@ func main() { checkError(fmt.Errorf("parsing flags: %w", err)) } - logger := logutil.NewCLILogger(*flDebug) - opts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(logger), + dataflatten.WithSlogger(multislogger.New().Logger), dataflatten.WithNestedPlist(), dataflatten.WithQuery(strings.Split(*flQuery, `/`)), } + if *flDebug { + opts = append(opts, dataflatten.WithDebugLogging()) + } rows := []dataflatten.Row{} diff --git a/ee/dataflatten/flatten.go b/ee/dataflatten/flatten.go index f269a015a..6d1346782 100644 --- a/ee/dataflatten/flatten.go +++ b/ee/dataflatten/flatten.go @@ -39,16 +39,17 @@ package dataflatten import ( "bytes" + "context" "encoding/base64" "fmt" + "log/slog" "strconv" "strings" "time" "unicode/utf8" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/groob/plist" + "github.com/kolide/launcher/pkg/log/multislogger" howett "howett.net/plist" ) @@ -66,16 +67,21 @@ import ( // It can optionally filtering and rewriting. type Flattener struct { debugLogging bool + logLevel slog.Level // the level that logs should be logged at expandNestedPlist bool includeNestedRaw bool includeNils bool - logger log.Logger + slogger *slog.Logger query []string queryKeyDenoter string queryWildcard string rows []Row } +// levelFlattenDebug is a log level below debug, so that we discard debugging logs +// that we only want for development purposes. +const levelFlattenDebug = slog.LevelDebug - 1 + type FlattenOpts func(*Flattener) // IncludeNulls indicates that Flatten should return null values, @@ -93,21 +99,21 @@ func WithNestedPlist() FlattenOpts { } } -// WithLogger sets the logger to use -func WithLogger(logger log.Logger) FlattenOpts { - if logger == nil { +// WithSlogger sets the slogger to use +func WithSlogger(slogger *slog.Logger) FlattenOpts { + if slogger == nil { return func(_ *Flattener) {} } return func(fl *Flattener) { - fl.logger = logger + fl.slogger = slogger } } -// WithDebugLogging enables debug logging. With debug logs, -// dataflatten is very verbose. This can overwhelm the other launcher -// logs. As we're not generally debugging this library, the default is -// to not enable debug logging. +// WithDebugLogging enables debug logging intended for development use. +// With debug logs, dataflatten is very verbose. This can overwhelm the +// other launcher logs. As we're not generally debugging this library, +// the default is to not enable debug logging. func WithDebugLogging() FlattenOpts { return func(fl *Flattener) { fl.debugLogging = true @@ -131,7 +137,8 @@ func WithQuery(q []string) FlattenOpts { func Flatten(data interface{}, opts ...FlattenOpts) ([]Row, error) { fl := &Flattener{ rows: []Row{}, - logger: log.NewNopLogger(), + logLevel: levelFlattenDebug, // by default, log at a level below debug + slogger: multislogger.New().Logger, queryWildcard: `*`, queryKeyDenoter: `#`, } @@ -140,8 +147,8 @@ func Flatten(data interface{}, opts ...FlattenOpts) ([]Row, error) { opt(fl) } - if !fl.debugLogging { - fl.logger = level.NewFilter(fl.logger, level.AllowInfo()) + if fl.debugLogging { + fl.logLevel = slog.LevelDebug } if err := fl.descend([]string{}, data, 0); err != nil { @@ -155,10 +162,10 @@ func Flatten(data interface{}, opts ...FlattenOpts) ([]Row, error) { func (fl *Flattener) descend(path []string, data interface{}, depth int) error { queryTerm, isQueryMatched := fl.queryAtDepth(depth) - logger := log.With(fl.logger, + slogger := fl.slogger.With( "caller", "descend", "depth", depth, - "rows-so-far", len(fl.rows), + "rows_so_far", len(fl.rows), "query", queryTerm, "path", strings.Join(path, "/"), ) @@ -167,7 +174,10 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { case []interface{}: for i, e := range v { pathKey := strconv.Itoa(i) - level.Debug(logger).Log("msg", "checking an array", "indexStr", pathKey) + slogger.Log(context.TODO(), fl.logLevel, + "checking an array", + "index_str", pathKey, + ) // If the queryTerm starts with // queryKeyDenoter, then we want to rewrite @@ -183,25 +193,34 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { keyQuery := strings.SplitN(strings.TrimPrefix(queryTerm, fl.queryKeyDenoter), "=>", 2) keyName := keyQuery[0] - innerlogger := log.With(logger, "arraykeyname", keyName) - level.Debug(logger).Log("msg", "attempting to coerce array into map") + innerslogger := slogger.With("array_key_name", keyName) + innerslogger.Log(context.TODO(), fl.logLevel, + "attempting to coerce array into map", + ) e, ok := e.(map[string]interface{}) if !ok { - level.Debug(innerlogger).Log("msg", "can't coerce into map") + innerslogger.Log(context.TODO(), fl.logLevel, + "can't coerce into map", + ) continue } // Is keyName in this array? val, ok := e[keyName] if !ok { - level.Debug(innerlogger).Log("msg", "keyName not in map") + innerslogger.Log(context.TODO(), fl.logLevel, + "keyName not in map", + "key_name", keyName, + ) continue } pathKey, ok = val.(string) if !ok { - level.Debug(innerlogger).Log("msg", "can't coerce pathKey val into string") + innerslogger.Log(context.TODO(), fl.logLevel, + "can't coerce pathKey val into string", + ) continue } @@ -209,7 +228,9 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { } if !(isQueryMatched || fl.queryMatchArrayElement(e, i, queryTerm)) { - level.Debug(logger).Log("msg", "query not matched") + slogger.Log(context.TODO(), fl.logLevel, + "query not matched", + ) continue } @@ -218,7 +239,9 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { } } case map[string]interface{}: - level.Debug(logger).Log("msg", "checking a map") + slogger.Log(context.TODO(), fl.logLevel, + "checking a map", + ) for k, e := range v { // Check that the key name matches. If not, skip this entire // branch of the map @@ -231,7 +254,9 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { } } case []map[string]interface{}: - level.Debug(logger).Log("msg", "checking an array of maps") + slogger.Log(context.TODO(), fl.logLevel, + "checking an array of maps", + ) for i, e := range v { if err := fl.descend(append(path, strconv.Itoa(i)), e, depth+1); err != nil { return fmt.Errorf("flattening array of maps: %w", err) @@ -240,7 +265,9 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { case nil: // Because we want to filter nils out, we do _not_ examine isQueryMatched here if !(fl.queryMatchNil(queryTerm)) { - level.Debug(logger).Log("msg", "query not matched") + slogger.Log(context.TODO(), fl.logLevel, + "query not matched", + ) return nil } fl.rows = append(fl.rows, NewRow(path, "")) @@ -250,7 +277,7 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { // Most string like data comes in this way return fl.descendMaybePlist(path, v, depth) default: - if err := fl.handleStringLike(logger, path, v, depth); err != nil { + if err := fl.handleStringLike(slogger, path, v, depth); err != nil { return fmt.Errorf("flattening at path %v: %w", path, err) } } @@ -260,7 +287,7 @@ func (fl *Flattener) descend(path []string, data interface{}, depth int) error { // handleStringLike is called when we finally have an object we think // can be converted to a string. It uses the depth to compare against // the query, and returns a stringify'ed value -func (fl *Flattener) handleStringLike(logger log.Logger, path []string, v interface{}, depth int) error { +func (fl *Flattener) handleStringLike(slogger *slog.Logger, path []string, v interface{}, depth int) error { queryTerm, isQueryMatched := fl.queryAtDepth(depth) stringValue, err := stringify(v) @@ -269,7 +296,9 @@ func (fl *Flattener) handleStringLike(logger log.Logger, path []string, v interf } if !(isQueryMatched || fl.queryMatchString(stringValue, queryTerm)) { - level.Debug(logger).Log("msg", "query not matched") + slogger.Log(context.TODO(), fl.logLevel, + "query not matched", + ) return nil } @@ -281,37 +310,45 @@ func (fl *Flattener) handleStringLike(logger log.Logger, path []string, v interf // embedded plist. In the case of failures, it falls back to treating // it like a plain string. func (fl *Flattener) descendMaybePlist(path []string, data []byte, depth int) error { - logger := log.With(fl.logger, + slogger := fl.slogger.With( "caller", "descendMaybePlist", "depth", depth, - "rows-so-far", len(fl.rows), + "rows_so_far", len(fl.rows), "path", strings.Join(path, "/"), ) // Skip if we're not expanding nested plists if !fl.expandNestedPlist { - return fl.handleStringLike(logger, path, data, depth) + return fl.handleStringLike(slogger, path, data, depth) } // Skip if this doesn't look like a plist. if !isPlist(data) { - return fl.handleStringLike(logger, path, data, depth) + return fl.handleStringLike(slogger, path, data, depth) } // Looks like a plist. Try parsing it - level.Debug(logger).Log("msg", "Parsing inner plist") + slogger.Log(context.TODO(), fl.logLevel, + "parsing inner plist", + ) var innerData interface{} if err := plist.Unmarshal(data, &innerData); err != nil { - level.Info(logger).Log("msg", "plist parsing failed", "err", err) - return fl.handleStringLike(logger, path, data, depth) + slogger.Log(context.TODO(), slog.LevelInfo, + "plist parsing failed", + "err", err, + ) + return fl.handleStringLike(slogger, path, data, depth) } // have a parsed plist. Descend and return from here. if fl.includeNestedRaw { - if err := fl.handleStringLike(logger, append(path, "_raw"), data, depth); err != nil { - level.Error(logger).Log("msg", "Failed to add _raw key", "err", err) + if err := fl.handleStringLike(slogger, append(path, "_raw"), data, depth); err != nil { + slogger.Log(context.TODO(), slog.LevelError, + "failed to add _raw key", + "err", err, + ) } } @@ -337,9 +374,9 @@ func (fl *Flattener) queryMatchNil(queryTerm string) bool { // We use `=>` as something that is reasonably intuitive, and not very // likely to occur on it's own. Unfortunately, `==` shows up in base64 func (fl *Flattener) queryMatchArrayElement(data interface{}, arrIndex int, queryTerm string) bool { - logger := log.With(fl.logger, + slogger := fl.slogger.With( "caller", "queryMatchArrayElement", - "rows-so-far", len(fl.rows), + "rows_so_far", len(fl.rows), "query", queryTerm, "arrIndex", arrIndex, ) @@ -353,11 +390,15 @@ func (fl *Flattener) queryMatchArrayElement(data interface{}, arrIndex int, quer // If the queryTerm is an int, then we expect to match the index if queryIndex, err := strconv.Atoi(queryTerm); err == nil { - level.Debug(logger).Log("msg", "using numeric index comparison") + slogger.Log(context.TODO(), fl.logLevel, + "using numeric index comparison", + ) return queryIndex == arrIndex } - level.Debug(logger).Log("msg", "checking data type") + slogger.Log(context.TODO(), fl.logLevel, + "checking data type", + ) switch dataCasted := data.(type) { case []interface{}: diff --git a/ee/tables/airport/table_darwin.go b/ee/tables/airport/table_darwin.go index f7c216a19..4c0bb6890 100644 --- a/ee/tables/airport/table_darwin.go +++ b/ee/tables/airport/table_darwin.go @@ -12,7 +12,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -27,12 +26,11 @@ var ( type Table struct { name string slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec } const tableName = "kolide_airport_util" -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("option"), ) @@ -40,7 +38,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ name: tableName, slogger: slogger.With("name", tableName), - logger: logger, } return table.NewPlugin(t.name, columns, t.generate) @@ -49,11 +46,10 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { type airportExecutor struct { ctx context.Context // nolint:containedctx slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec } func (a *airportExecutor) Exec(option string) ([]byte, error) { - return tablehelpers.Exec(a.ctx, a.logger, 30, allowedcmd.Airport, []string{"--" + option}, false) + return tablehelpers.Exec(a.ctx, a.slogger, 30, allowedcmd.Airport, []string{"--" + option}, false) } type executor interface { @@ -65,13 +61,12 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( airportExecutor := &airportExecutor{ ctx: ctx, slogger: t.slogger, - logger: t.logger, } - return generateAirportData(queryContext, airportExecutor, t.slogger, t.logger) + return generateAirportData(queryContext, airportExecutor, t.slogger) } -func generateAirportData(queryContext table.QueryContext, airportExecutor executor, slogger *slog.Logger, logger log.Logger) ([]map[string]string, error) { +func generateAirportData(queryContext table.QueryContext, airportExecutor executor, slogger *slog.Logger) ([]map[string]string, error) { options := tablehelpers.GetConstraints(queryContext, "option", tablehelpers.WithAllowedValues(allowedOptions)) if len(options) == 0 { @@ -90,7 +85,7 @@ func generateAirportData(queryContext table.QueryContext, airportExecutor execut continue } - optionResult, err := processAirportOutput(bytes.NewReader(airportOutput), option, queryContext, slogger, logger) + optionResult, err := processAirportOutput(bytes.NewReader(airportOutput), option, queryContext, slogger) if err != nil { slogger.Log(context.TODO(), slog.LevelDebug, "error processing airport output", @@ -105,7 +100,7 @@ func generateAirportData(queryContext table.QueryContext, airportExecutor execut return results, nil } -func processAirportOutput(airportOutput io.Reader, option string, queryContext table.QueryContext, slogger *slog.Logger, logger log.Logger) ([]map[string]string, error) { +func processAirportOutput(airportOutput io.Reader, option string, queryContext table.QueryContext, slogger *slog.Logger) ([]map[string]string, error) { var results []map[string]string var unmarshalledOutput []map[string]interface{} @@ -123,7 +118,7 @@ func processAirportOutput(airportOutput io.Reader, option string, queryContext t for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - flattened, err := dataflatten.Flatten(unmarshalledOutput, dataflatten.WithLogger(logger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) + flattened, err := dataflatten.Flatten(unmarshalledOutput, dataflatten.WithSlogger(slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) if err != nil { return nil, err } diff --git a/ee/tables/airport/table_darwin_test.go b/ee/tables/airport/table_darwin_test.go index b28a00fe1..eac09f8a1 100644 --- a/ee/tables/airport/table_darwin_test.go +++ b/ee/tables/airport/table_darwin_test.go @@ -11,7 +11,6 @@ import ( "strings" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/airport/mocks" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/pkg/log/multislogger" @@ -101,7 +100,7 @@ func Test_generateAirportData_HappyPath(t *testing.T) { constraints["query"] = []string{tt.query} } - got, err := generateAirportData(tablehelpers.MockQueryContext(constraints), executor, multislogger.New().Logger, log.NewNopLogger()) + got, err := generateAirportData(tablehelpers.MockQueryContext(constraints), executor, multislogger.New().Logger) require.NoError(t, err) executor.AssertExpectations(t) @@ -219,7 +218,7 @@ func Test_generateAirportData_EdgeCases(t *testing.T) { executor.On("Exec", mock.Anything).Return(tt.execReturn()).Once() - got, err := generateAirportData(tt.args.queryContext, executor, multislogger.New().Logger, log.NewNopLogger()) + got, err := generateAirportData(tt.args.queryContext, executor, multislogger.New().Logger) tt.assertion(t, err) assert.Equal(t, tt.want, got) }) diff --git a/ee/tables/apple_silicon_security_policy/table.go b/ee/tables/apple_silicon_security_policy/table.go index 75ef84383..386ebae9d 100644 --- a/ee/tables/apple_silicon_security_policy/table.go +++ b/ee/tables/apple_silicon_security_policy/table.go @@ -9,7 +9,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -20,18 +19,16 @@ import ( const bootPolicyUtilArgs = "--display-all-policies" type Table struct { - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec slogger *slog.Logger } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() tableName := "kolide_apple_silicon_security_policy" t := &Table{ slogger: slogger.With("table", tableName), - logger: log.With(logger, "table", tableName), } return table.NewPlugin(tableName, columns, t.generate) @@ -40,7 +37,7 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) { var results []map[string]string - output, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Bputil, []string{bootPolicyUtilArgs}, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 30, allowedcmd.Bputil, []string{bootPolicyUtilArgs}, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "bputil failed", @@ -59,7 +56,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( data := parseBootPoliciesOutput(bytes.NewReader(output)) for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - flattened, err := dataflatten.Flatten(data, dataflatten.WithLogger(t.logger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) + flattened, err := dataflatten.Flatten(data, dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "error flattening data", diff --git a/ee/tables/crowdstrike/falcon_kernel_check/table.go b/ee/tables/crowdstrike/falcon_kernel_check/table.go index ac12f3055..a9dc39128 100644 --- a/ee/tables/crowdstrike/falcon_kernel_check/table.go +++ b/ee/tables/crowdstrike/falcon_kernel_check/table.go @@ -9,7 +9,6 @@ import ( "log/slog" "regexp" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/osquery/osquery-go/plugin/table" @@ -17,10 +16,9 @@ import ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := []table.ColumnDefinition{ table.TextColumn("kernel"), table.IntegerColumn("supported"), @@ -31,14 +29,13 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", tableName), - logger: log.With(logger, "table", tableName), } return table.NewPlugin(tableName, columns, t.generate) } func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) { - output, err := tablehelpers.Exec(ctx, t.logger, 5, allowedcmd.FalconKernelCheck, []string{}, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 5, allowedcmd.FalconKernelCheck, []string{}, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "exec failed", diff --git a/ee/tables/crowdstrike/falconctl/table.go b/ee/tables/crowdstrike/falconctl/table.go index 1153bf03b..67215e298 100644 --- a/ee/tables/crowdstrike/falconctl/table.go +++ b/ee/tables/crowdstrike/falconctl/table.go @@ -10,7 +10,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -39,23 +38,21 @@ var ( defaultOption = strings.Join(allowedOptions, " ") ) -type execFunc func(context.Context, log.Logger, int, allowedcmd.AllowedCommand, []string, bool) ([]byte, error) +type execFunc func(context.Context, *slog.Logger, int, allowedcmd.AllowedCommand, []string, bool) ([]byte, error) type falconctlOptionsTable struct { slogger *slog.Logger - logger log.Logger // preserved temporarily for use in dataflattentables/tablehelpers tableName string execFunc execFunc } -func NewFalconctlOptionTable(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func NewFalconctlOptionTable(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("options"), ) t := &falconctlOptionsTable{ slogger: slogger.With("table", "kolide_falconctl_options"), - logger: log.With(logger, "table", "kolide_falconctl_options"), tableName: "kolide_falconctl_options", execFunc: tablehelpers.Exec, } @@ -95,7 +92,7 @@ OUTER: // then the list of options to fetch. Set the command line thusly. args := append([]string{"-g"}, options...) - output, err := t.execFunc(ctx, t.logger, 30, allowedcmd.Falconctl, args, false) + output, err := t.execFunc(ctx, t.slogger, 30, allowedcmd.Falconctl, args, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "exec failed", @@ -131,7 +128,7 @@ OUTER: for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/crowdstrike/falconctl/table_test.go b/ee/tables/crowdstrike/falconctl/table_test.go index ba59cb866..a1f618ec4 100644 --- a/ee/tables/crowdstrike/falconctl/table_test.go +++ b/ee/tables/crowdstrike/falconctl/table_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/pkg/log/multislogger" @@ -68,7 +67,6 @@ func TestOptionRestrictions(t *testing.T) { testTable := &falconctlOptionsTable{ slogger: multislogger.New(slog.NewJSONHandler(&logBytes, &slog.HandlerOptions{Level: slog.LevelDebug})).Logger, - logger: log.NewLogfmtLogger(&logBytes), execFunc: noopExec, } @@ -88,7 +86,7 @@ func TestOptionRestrictions(t *testing.T) { } } -func noopExec(_ context.Context, log log.Logger, _ int, _ allowedcmd.AllowedCommand, args []string, _ bool) ([]byte, error) { - log.Log("exec", "exec-in-test", "args", strings.Join(args, " ")) +func noopExec(ctx context.Context, slogger *slog.Logger, _ int, _ allowedcmd.AllowedCommand, args []string, _ bool) ([]byte, error) { + slogger.Log(ctx, slog.LevelInfo, "exec-in-test", "args", strings.Join(args, " ")) return []byte{}, nil } diff --git a/ee/tables/cryptoinfotable/table.go b/ee/tables/cryptoinfotable/table.go index ec414e3ae..781bb480a 100644 --- a/ee/tables/cryptoinfotable/table.go +++ b/ee/tables/cryptoinfotable/table.go @@ -10,7 +10,6 @@ import ( "path/filepath" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/cryptoinfo" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -19,19 +18,17 @@ import ( ) type Table struct { - logger log.Logger // preserved only temporarily for dataflattentable usage slogger *slog.Logger } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("passphrase"), table.TextColumn("path"), ) t := &Table{ - slogger: slogger, - logger: logger, + slogger: slogger.With("table", "kolide_cryptinfo"), } return table.NewPlugin("kolide_cryptoinfo", columns, t.generate) @@ -62,7 +59,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, passphrase := range tablehelpers.GetConstraints(queryContext, "passphrase", tablehelpers.WithDefaults("")) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithNestedPlist(), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/cryptsetup/table.go b/ee/tables/cryptsetup/table.go index ad08bb8b5..8ffbe32e4 100644 --- a/ee/tables/cryptsetup/table.go +++ b/ee/tables/cryptsetup/table.go @@ -9,7 +9,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -21,18 +20,16 @@ const allowedNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for use in dataflattentable/tablehelpers.Exec temporarily name string } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("name"), ) t := &Table{ slogger: slogger.With("table", "kolide_cryptsetup_status"), - logger: logger, name: "kolide_cryptsetup_status", } @@ -44,7 +41,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( requestedNames := tablehelpers.GetConstraints(queryContext, "name", tablehelpers.WithAllowedCharacters(allowedNameCharacters), - tablehelpers.WithLogger(t.logger), + tablehelpers.WithSlogger(t.slogger), ) if len(requestedNames) == 0 { @@ -52,7 +49,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( } for _, name := range requestedNames { - output, err := tablehelpers.Exec(ctx, t.logger, 15, allowedcmd.Cryptsetup, []string{"--readonly", "status", name}, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 15, allowedcmd.Cryptsetup, []string{"--readonly", "status", name}, false) if err != nil { t.slogger.Log(ctx, slog.LevelDebug, "error execing for status", @@ -93,7 +90,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( func (t *Table) flattenOutput(dataQuery string, status map[string]interface{}) ([]dataflatten.Row, error) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/dataflattentable/exec.go b/ee/tables/dataflattentable/exec.go index a37e9f7f2..39f63847c 100644 --- a/ee/tables/dataflattentable/exec.go +++ b/ee/tables/dataflattentable/exec.go @@ -2,12 +2,11 @@ package dataflattentable import ( "context" + "log/slog" "os" "strings" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -25,11 +24,11 @@ func WithKVSeparator(separator string) ExecTableOpt { } } -func TablePluginExec(logger log.Logger, tableName string, dataSourceType DataSourceType, cmdGen allowedcmd.AllowedCommand, execArgs []string, opts ...ExecTableOpt) *table.Plugin { +func TablePluginExec(slogger *slog.Logger, tableName string, dataSourceType DataSourceType, cmdGen allowedcmd.AllowedCommand, execArgs []string, opts ...ExecTableOpt) *table.Plugin { columns := Columns() t := &Table{ - logger: level.NewFilter(logger, level.AllowInfo()), + slogger: slogger.With("table", tableName), tableName: tableName, cmdGen: cmdGen, execArgs: execArgs, @@ -61,7 +60,7 @@ func TablePluginExec(logger log.Logger, tableName string, dataSourceType DataSou func (t *Table) generateExec(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) { var results []map[string]string - execBytes, err := tablehelpers.Exec(ctx, t.logger, 50, t.cmdGen, t.execArgs, false) + execBytes, err := tablehelpers.Exec(ctx, t.slogger, 50, t.cmdGen, t.execArgs, false) if err != nil { // exec will error if there's no binary, so we never want to record that if os.IsNotExist(errors.Cause(err)) { @@ -70,19 +69,25 @@ func (t *Table) generateExec(ctx context.Context, queryContext table.QueryContex // If the exec failed for some reason, it's probably better to return no results, and log the, // error. Returning an error here will cause a table failure, and thus break joins - level.Info(t.logger).Log("msg", "failed to exec", "err", err) + t.slogger.Log(ctx, slog.LevelInfo, + "failed to exec", + "err", err, + ) return nil, nil } for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } flattened, err := t.flattenBytesFunc(execBytes, flattenOpts...) if err != nil { - level.Info(t.logger).Log("msg", "failure flattening output", "err", err) + t.slogger.Log(ctx, slog.LevelInfo, + "failure flattening output", + "err", err, + ) continue } diff --git a/ee/tables/dataflattentable/exec_and_parse.go b/ee/tables/dataflattentable/exec_and_parse.go index 30c54dbb3..6d87fd603 100644 --- a/ee/tables/dataflattentable/exec_and_parse.go +++ b/ee/tables/dataflattentable/exec_and_parse.go @@ -2,11 +2,10 @@ package dataflattentable import ( "context" + "log/slog" "os" "strings" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -21,7 +20,7 @@ type bytesFlattener interface { // execTableV2 is the next iteration of the dataflattentable wrapper. Aim to migrate exec based tables to this. type execTableV2 struct { - logger log.Logger + slogger *slog.Logger tableName string flattener bytesFlattener timeoutSeconds int @@ -51,9 +50,9 @@ func WithIncludeStderr() execTableV2Opt { } } -func NewExecAndParseTable(logger log.Logger, tableName string, p parser, cmd allowedcmd.AllowedCommand, execArgs []string, opts ...execTableV2Opt) *table.Plugin { +func NewExecAndParseTable(slogger *slog.Logger, tableName string, p parser, cmd allowedcmd.AllowedCommand, execArgs []string, opts ...execTableV2Opt) *table.Plugin { t := &execTableV2{ - logger: level.NewFilter(log.With(logger, "table", tableName), level.AllowInfo()), + slogger: slogger.With("table", tableName), tableName: tableName, flattener: flattenerFromParser(p), timeoutSeconds: 30, @@ -65,10 +64,6 @@ func NewExecAndParseTable(logger log.Logger, tableName string, p parser, cmd all opt(t) } - if t.tabledebug { - level.NewFilter(log.With(logger, "table", tableName), level.AllowDebug()) - } - return table.NewPlugin(t.tableName, Columns(), t.generate) } @@ -78,26 +73,35 @@ func (t *execTableV2) generate(ctx context.Context, queryContext table.QueryCont var results []map[string]string - execOutput, err := tablehelpers.Exec(ctx, t.logger, t.timeoutSeconds, t.cmd, t.execArgs, t.includeStderr) + execOutput, err := tablehelpers.Exec(ctx, t.slogger, t.timeoutSeconds, t.cmd, t.execArgs, t.includeStderr) if err != nil { // exec will error if there's no binary, so we never want to record that if os.IsNotExist(errors.Cause(err)) { return nil, nil } traces.SetError(span, err) - level.Info(t.logger).Log("msg", "exec failed", "err", err) + t.slogger.Log(ctx, slog.LevelInfo, + "exec failed", + "err", err, + ) return nil, nil } for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } + if t.tabledebug { + flattenOpts = append(flattenOpts, dataflatten.WithDebugLogging()) + } flattened, err := t.flattener.FlattenBytes(execOutput, flattenOpts...) if err != nil { - level.Info(t.logger).Log("msg", "failure flattening output", "err", err) + t.slogger.Log(ctx, slog.LevelInfo, + "failure flattening output", + "err", err, + ) continue } diff --git a/ee/tables/dataflattentable/tables.go b/ee/tables/dataflattentable/tables.go index a098aced8..0f8804193 100644 --- a/ee/tables/dataflattentable/tables.go +++ b/ee/tables/dataflattentable/tables.go @@ -3,11 +3,10 @@ package dataflattentable import ( "context" "fmt" + "log/slog" "path/filepath" "strings" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -29,7 +28,7 @@ const ( ) type Table struct { - logger log.Logger + slogger *slog.Logger tableName string flattenFileFunc func(string, ...dataflatten.FlattenOpts) ([]dataflatten.Row, error) @@ -42,23 +41,21 @@ type Table struct { } // AllTablePlugins is a helper to return all the expected flattening tables. -func AllTablePlugins(logger log.Logger) []osquery.OsqueryPlugin { +func AllTablePlugins(slogger *slog.Logger) []osquery.OsqueryPlugin { return []osquery.OsqueryPlugin{ - TablePlugin(logger, JsonType), - TablePlugin(logger, XmlType), - TablePlugin(logger, IniType), - TablePlugin(logger, PlistType), - TablePlugin(logger, JsonlType), - TablePlugin(logger, JWTType), + TablePlugin(slogger, JsonType), + TablePlugin(slogger, XmlType), + TablePlugin(slogger, IniType), + TablePlugin(slogger, PlistType), + TablePlugin(slogger, JsonlType), + TablePlugin(slogger, JWTType), } } -func TablePlugin(logger log.Logger, dataSourceType DataSourceType) osquery.OsqueryPlugin { +func TablePlugin(slogger *slog.Logger, dataSourceType DataSourceType) osquery.OsqueryPlugin { columns := Columns(table.TextColumn("path")) - t := &Table{ - logger: logger, - } + t := &Table{} switch dataSourceType { case PlistType: @@ -83,6 +80,8 @@ func TablePlugin(logger log.Logger, dataSourceType DataSourceType) osquery.Osque panic("Unknown data source type") } + t.slogger = slogger.With("table", t.tableName) + return table.NewPlugin(t.tableName, columns, t.generate) } @@ -105,10 +104,10 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, filePath := range filePaths { for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - subresults, err := t.generatePath(filePath, dataQuery) + subresults, err := t.generatePath(ctx, filePath, dataQuery) if err != nil { - level.Info(t.logger).Log( - "msg", "failed to get data for path", + t.slogger.Log(ctx, slog.LevelInfo, + "failed to get data for path", "path", filePath, "err", err, ) @@ -122,16 +121,19 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( return results, nil } -func (t *Table) generatePath(filePath string, dataQuery string) ([]map[string]string, error) { +func (t *Table) generatePath(ctx context.Context, filePath string, dataQuery string) ([]map[string]string, error) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithNestedPlist(), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } data, err := t.flattenFileFunc(filePath, flattenOpts...) if err != nil { - level.Info(t.logger).Log("msg", "failure parsing file", "file", filePath) + t.slogger.Log(ctx, slog.LevelInfo, + "failure parsing file", + "file", filePath, + ) return nil, fmt.Errorf("parsing data: %w", err) } diff --git a/ee/tables/dataflattentable/tables_test.go b/ee/tables/dataflattentable/tables_test.go index d3d4f4671..0537a4111 100644 --- a/ee/tables/dataflattentable/tables_test.go +++ b/ee/tables/dataflattentable/tables_test.go @@ -8,9 +8,9 @@ import ( "sort" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/tablehelpers" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/require" ) @@ -20,13 +20,13 @@ import ( func TestDataFlattenTablePlist_Animals(t *testing.T) { t.Parallel() - logger := log.NewNopLogger() + slogger := multislogger.New().Logger // Test plist parsing both the json and xml forms testTables := map[string]Table{ - "plist": {logger: logger, flattenFileFunc: dataflatten.PlistFile}, - "xml": {logger: logger, flattenFileFunc: dataflatten.PlistFile}, - "json": {logger: logger, flattenFileFunc: dataflatten.JsonFile}, + "plist": {slogger: slogger, flattenFileFunc: dataflatten.PlistFile}, + "xml": {slogger: slogger, flattenFileFunc: dataflatten.PlistFile}, + "json": {slogger: slogger, flattenFileFunc: dataflatten.JsonFile}, } var tests = []struct { @@ -85,7 +85,7 @@ func TestDataFlattenTablePlist_Animals(t *testing.T) { func TestDataFlattenTables(t *testing.T) { t.Parallel() - logger := log.NewNopLogger() + slogger := multislogger.New().Logger var tests = []struct { testTables map[string]Table @@ -96,18 +96,18 @@ func TestDataFlattenTables(t *testing.T) { }{ // xml { - testTables: map[string]Table{"xml": {logger: logger, flattenFileFunc: dataflatten.XmlFile}}, + testTables: map[string]Table{"xml": {slogger: slogger, flattenFileFunc: dataflatten.XmlFile}}, testFile: path.Join("testdata", "simple.xml"), expectedRows: 6, }, { - testTables: map[string]Table{"xml": {logger: logger, flattenFileFunc: dataflatten.XmlFile}}, + testTables: map[string]Table{"xml": {slogger: slogger, flattenFileFunc: dataflatten.XmlFile}}, testFile: path.Join("testdata", "simple.xml"), queries: []string{"simple/Items"}, expectedRows: 3, }, { - testTables: map[string]Table{"xml": {logger: logger, flattenFileFunc: dataflatten.XmlFile}}, + testTables: map[string]Table{"xml": {slogger: slogger, flattenFileFunc: dataflatten.XmlFile}}, testFile: path.Join("testdata", "simple.xml"), queries: []string{"this/does/not/exist"}, expectNoData: true, @@ -115,18 +115,18 @@ func TestDataFlattenTables(t *testing.T) { // ini { - testTables: map[string]Table{"ini": {logger: logger, flattenFileFunc: dataflatten.IniFile}}, + testTables: map[string]Table{"ini": {slogger: slogger, flattenFileFunc: dataflatten.IniFile}}, testFile: path.Join("testdata", "secdata.ini"), expectedRows: 87, }, { - testTables: map[string]Table{"ini": {logger: logger, flattenFileFunc: dataflatten.IniFile}}, + testTables: map[string]Table{"ini": {slogger: slogger, flattenFileFunc: dataflatten.IniFile}}, testFile: path.Join("testdata", "secdata.ini"), queries: []string{"Registry Values"}, expectedRows: 59, }, { - testTables: map[string]Table{"ini": {logger: logger, flattenFileFunc: dataflatten.IniFile}}, + testTables: map[string]Table{"ini": {slogger: slogger, flattenFileFunc: dataflatten.IniFile}}, testFile: path.Join("testdata", "secdata.ini"), queries: []string{"this/does/not/exist"}, expectNoData: true, diff --git a/ee/tables/dev_table_tooling/table.go b/ee/tables/dev_table_tooling/table.go index 9e5b04284..4e468b641 100644 --- a/ee/tables/dev_table_tooling/table.go +++ b/ee/tables/dev_table_tooling/table.go @@ -6,7 +6,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/osquery/osquery-go/plugin/table" @@ -20,11 +19,10 @@ type allowedCommand struct { } type Table struct { - logger log.Logger // preserved temporarily only for tablehelpers.Exec usage slogger *slog.Logger } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := []table.ColumnDefinition{ table.TextColumn("name"), table.TextColumn("args"), @@ -36,7 +34,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", tableName), - logger: log.With(logger, "table", tableName), } return table.NewPlugin(tableName, columns, t.generate) @@ -70,7 +67,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( "error": "", } - if output, err := tablehelpers.Exec(ctx, t.logger, 30, cmd.bin, cmd.args, false); err != nil { + if output, err := tablehelpers.Exec(ctx, t.slogger, 30, cmd.bin, cmd.args, false); err != nil { t.slogger.Log(ctx, slog.LevelInfo, "execution failed", "name", name, diff --git a/ee/tables/dev_table_tooling/table_test.go b/ee/tables/dev_table_tooling/table_test.go index d69d729f6..4c8909eb2 100644 --- a/ee/tables/dev_table_tooling/table_test.go +++ b/ee/tables/dev_table_tooling/table_test.go @@ -7,7 +7,6 @@ import ( "encoding/base64" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/assert" @@ -35,7 +34,7 @@ func Test_generate(t *testing.T) { }, } - table := Table{logger: log.NewNopLogger(), slogger: multislogger.New().Logger} + table := Table{slogger: multislogger.New().Logger} for _, tt := range tests { tt := tt diff --git a/ee/tables/dsim_default_associations/dsim_default_associations.go b/ee/tables/dsim_default_associations/dsim_default_associations.go index 57b362d75..ae0527190 100644 --- a/ee/tables/dsim_default_associations/dsim_default_associations.go +++ b/ee/tables/dsim_default_associations/dsim_default_associations.go @@ -13,7 +13,6 @@ import ( "strings" "time" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" @@ -24,16 +23,14 @@ import ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() t := &Table{ slogger: slogger.With("table", "kolide_dsim_default_associations"), - logger: logger, } return table.NewPlugin("kolide_dsim_default_associations", columns, t.generate) @@ -53,7 +50,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/filevault/filevault.go b/ee/tables/filevault/filevault.go index 0d85e869b..63cff7694 100644 --- a/ee/tables/filevault/filevault.go +++ b/ee/tables/filevault/filevault.go @@ -10,7 +10,6 @@ import ( "os" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/osquery/osquery-go/plugin/table" @@ -19,24 +18,22 @@ import ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := []table.ColumnDefinition{ table.TextColumn("status"), } t := &Table{ slogger: slogger.With("table", "kolide_filevault"), - logger: logger, } return table.NewPlugin("kolide_filevault", columns, t.generate) } func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) { - output, err := tablehelpers.Exec(ctx, t.logger, 10, allowedcmd.Fdesetup, []string{"status"}, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 10, allowedcmd.Fdesetup, []string{"status"}, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "fdesetup failed", diff --git a/ee/tables/firmwarepasswd/firmwarepasswd.go b/ee/tables/firmwarepasswd/firmwarepasswd.go index 3c35f6ea1..b41d7b428 100644 --- a/ee/tables/firmwarepasswd/firmwarepasswd.go +++ b/ee/tables/firmwarepasswd/firmwarepasswd.go @@ -11,37 +11,36 @@ import ( "bytes" "context" "fmt" + "log/slog" "os" "strings" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/allowedcmd" "github.com/osquery/osquery-go/plugin/table" ) type Table struct { - logger log.Logger - parser *OutputParser + slogger *slog.Logger + parser *OutputParser } -func TablePlugin(logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := []table.ColumnDefinition{ table.IntegerColumn("option_roms_allowed"), table.IntegerColumn("password_enabled"), table.TextColumn("mode"), } - t := New(logger) + t := New(slogger.With("table", "kolide_firmwarepasswd")) return table.NewPlugin("kolide_firmwarepasswd", columns, t.generate) } -func New(logger log.Logger) *Table { - parser := NewParser(logger, +func New(slogger *slog.Logger) *Table { + parser := NewParser(slogger, []Matcher{ { Match: func(in string) bool { return strings.HasPrefix(in, "Password Enabled: ") }, @@ -61,8 +60,8 @@ func New(logger log.Logger) *Table { }) return &Table{ - logger: level.NewFilter(logger, level.AllowInfo()), - parser: parser, + slogger: slogger, + parser: parser, } } @@ -73,8 +72,8 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, mode := range []string{"-check", "-mode"} { output := new(bytes.Buffer) if err := t.runFirmwarepasswd(ctx, mode, output); err != nil { - level.Info(t.logger).Log( - "msg", "Error running firmware password", + t.slogger.Log(ctx, slog.LevelInfo, + "error running firmware password", "command", mode, "err", err, ) @@ -118,8 +117,8 @@ func (t *Table) runFirmwarepasswd(ctx context.Context, subcommand string, output cmd.Stdout = output if err := cmd.Run(); err != nil { - level.Debug(t.logger).Log( - "msg", "Error running firmwarepasswd", + t.slogger.Log(ctx, slog.LevelDebug, + "error running firmwarepasswd", "stderr", strings.TrimSpace(stderr.String()), "stdout", strings.TrimSpace(output.String()), "err", err, diff --git a/ee/tables/firmwarepasswd/firmwarepasswd_test.go b/ee/tables/firmwarepasswd/firmwarepasswd_test.go index fd6cdef28..403b87992 100644 --- a/ee/tables/firmwarepasswd/firmwarepasswd_test.go +++ b/ee/tables/firmwarepasswd/firmwarepasswd_test.go @@ -9,7 +9,7 @@ import ( "path/filepath" "testing" - "github.com/go-kit/kit/log" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/require" ) @@ -50,7 +50,7 @@ func TestParser(t *testing.T) { for _, tt := range tests { tt := tt - parser := New(log.NewNopLogger()).parser + parser := New(multislogger.New().Logger).parser t.Run(tt.input, func(t *testing.T) { t.Parallel() diff --git a/ee/tables/firmwarepasswd/parser.go b/ee/tables/firmwarepasswd/parser.go index 34a5a85ac..39714ad78 100644 --- a/ee/tables/firmwarepasswd/parser.go +++ b/ee/tables/firmwarepasswd/parser.go @@ -6,9 +6,8 @@ package firmwarepasswd import ( "bufio" "bytes" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "context" + "log/slog" ) type Matcher struct { @@ -19,13 +18,13 @@ type Matcher struct { type OutputParser struct { matchers []Matcher - logger log.Logger + slogger *slog.Logger } -func NewParser(logger log.Logger, matchers []Matcher) *OutputParser { +func NewParser(slogger *slog.Logger, matchers []Matcher) *OutputParser { p := &OutputParser{ matchers: matchers, - logger: logger, + slogger: slogger, } return p } @@ -48,8 +47,8 @@ func (p *OutputParser) Parse(input *bytes.Buffer) []map[string]string { if m.Match(line) { key, err := m.KeyFunc(line) if err != nil { - level.Debug(p.logger).Log( - "msg", "key match failed", + p.slogger.Log(context.TODO(), slog.LevelDebug, + "key match failed", "line", line, "err", err, ) @@ -58,8 +57,8 @@ func (p *OutputParser) Parse(input *bytes.Buffer) []map[string]string { val, err := m.ValFunc(line) if err != nil { - level.Debug(p.logger).Log( - "msg", "value match failed", + p.slogger.Log(context.TODO(), slog.LevelDebug, + "value match failed", "line", line, "err", err, ) @@ -72,14 +71,20 @@ func (p *OutputParser) Parse(input *bytes.Buffer) []map[string]string { } if len(row) == 0 { - level.Debug(p.logger).Log("msg", "No matched keys", "line", line) + p.slogger.Log(context.TODO(), slog.LevelDebug, + "no matched keys", + "line", line, + ) continue } results = append(results, row) } if err := scanner.Err(); err != nil { - level.Debug(p.logger).Log("msg", "scanner error", "err", err) + p.slogger.Log(context.TODO(), slog.LevelDebug, + "scanner error", + "err", err, + ) } return results } diff --git a/ee/tables/ioreg/ioreg.go b/ee/tables/ioreg/ioreg.go index 84416178a..3ea251810 100644 --- a/ee/tables/ioreg/ioreg.go +++ b/ee/tables/ioreg/ioreg.go @@ -14,7 +14,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -26,11 +25,10 @@ const allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0 type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec tableName string } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( // ioreg input options. These match the ioreg @@ -45,7 +43,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_ioreg"), - logger: logger, tableName: "kolide_ioreg", } @@ -58,7 +55,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( gcOpts := []tablehelpers.GetConstraintOpts{ tablehelpers.WithDefaults(""), tablehelpers.WithAllowedCharacters(allowedCharacters), - tablehelpers.WithLogger(t.logger), + tablehelpers.WithSlogger(t.slogger), } for _, ioC := range tablehelpers.GetConstraints(queryContext, "c", gcOpts...) { @@ -105,7 +102,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { // Finally, an inner loop - ioregOutput, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Ioreg, ioregArgs, false) + ioregOutput, err := tablehelpers.Exec(ctx, t.slogger, 30, allowedcmd.Ioreg, ioregArgs, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "ioreg failed", @@ -146,7 +143,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( func (t *Table) flattenOutput(dataQuery string, systemOutput []byte) ([]dataflatten.Row, error) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/macos_software_update/available_products_table.go b/ee/tables/macos_software_update/available_products_table.go index acec9ac94..74ffcd973 100644 --- a/ee/tables/macos_software_update/available_products_table.go +++ b/ee/tables/macos_software_update/available_products_table.go @@ -17,7 +17,6 @@ import ( "strings" "time" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -27,14 +26,13 @@ import ( var productsData []map[string]interface{} var cachedTime time.Time -func AvailableProducts(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func AvailableProducts(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() tableName := "kolide_macos_available_products" t := &Table{ slogger: slogger.With("table", tableName), - logger: log.With(logger, "table", tableName), } return table.NewPlugin(tableName, columns, t.generateAvailableProducts) @@ -46,7 +44,7 @@ func (t *Table) generateAvailableProducts(ctx context.Context, queryContext tabl data := getProducts() for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - flattened, err := dataflatten.Flatten(data, dataflatten.WithLogger(t.logger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) + flattened, err := dataflatten.Flatten(data, dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "error flattening data", diff --git a/ee/tables/macos_software_update/recommended_updates_table.go b/ee/tables/macos_software_update/recommended_updates_table.go index 68963ebaf..646d0cb02 100644 --- a/ee/tables/macos_software_update/recommended_updates_table.go +++ b/ee/tables/macos_software_update/recommended_updates_table.go @@ -16,7 +16,6 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -27,17 +26,15 @@ var updatesData []map[string]interface{} type Table struct { slogger *slog.Logger - logger log.Logger // preserved only temporarily for dataflattentable } -func RecommendedUpdates(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func RecommendedUpdates(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() tableName := "kolide_macos_recommended_updates" t := &Table{ slogger: slogger.With("table", tableName), - logger: log.With(logger, "table", tableName), } return table.NewPlugin(tableName, columns, t.generate) @@ -49,7 +46,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( data := getUpdates() for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - flattened, err := dataflatten.Flatten(data, dataflatten.WithLogger(t.logger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) + flattened, err := dataflatten.Flatten(data, dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/"))) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "error flattening data", diff --git a/ee/tables/macos_software_update/recommended_updates_table_test.go b/ee/tables/macos_software_update/recommended_updates_table_test.go index 558161c5a..7c77c5384 100644 --- a/ee/tables/macos_software_update/recommended_updates_table_test.go +++ b/ee/tables/macos_software_update/recommended_updates_table_test.go @@ -7,14 +7,14 @@ import ( "context" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/tablehelpers" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/require" ) func Test_generateRecommendedUpdatesHappyPath(t *testing.T) { t.Parallel() - table := Table{logger: log.NewNopLogger()} + table := Table{slogger: multislogger.New().Logger} _, err := table.generate(context.Background(), tablehelpers.MockQueryContext(nil)) diff --git a/ee/tables/mdmclient/mdmclient.go b/ee/tables/mdmclient/mdmclient.go index ac456712c..5464489c9 100644 --- a/ee/tables/mdmclient/mdmclient.go +++ b/ee/tables/mdmclient/mdmclient.go @@ -14,7 +14,6 @@ import ( "regexp" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -50,18 +49,16 @@ var lengthBytesRegex = regexp.MustCompile(`{length = (\d+,) bytes = (0[xX][0-9a- type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec tableName string } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("command"), ) t := &Table{ slogger: slogger.With("table", "kolide_mdmclient"), - logger: logger, tableName: "kolide_mdmclient", } @@ -73,7 +70,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( gcOpts := []tablehelpers.GetConstraintOpts{ tablehelpers.WithAllowedCharacters(allowedCharacters), - tablehelpers.WithLogger(t.logger), + tablehelpers.WithSlogger(t.slogger), tablehelpers.WithDefaults(""), } @@ -94,7 +91,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) { - mdmclientOutput, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Mdmclient, []string{mdmclientCommand}, false) + mdmclientOutput, err := tablehelpers.Exec(ctx, t.slogger, 30, allowedcmd.Mdmclient, []string{mdmclientCommand}, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "mdmclient failed", @@ -133,7 +130,7 @@ func (t *Table) flattenOutput(ctx context.Context, dataQuery string, systemOutpu } flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/mdmclient/mdmclient_test.go b/ee/tables/mdmclient/mdmclient_test.go index c9fa315c8..f4e1bf1ad 100644 --- a/ee/tables/mdmclient/mdmclient_test.go +++ b/ee/tables/mdmclient/mdmclient_test.go @@ -9,7 +9,7 @@ import ( "path/filepath" "testing" - "github.com/go-kit/kit/log" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/require" ) @@ -42,7 +42,7 @@ func TestTransformOutput(t *testing.T) { }, } - table := Table{logger: log.NewNopLogger()} + table := Table{slogger: multislogger.New().Logger} for _, tt := range tests { tt := tt diff --git a/ee/tables/nix_env/upgradeable/upgradeable.go b/ee/tables/nix_env/upgradeable/upgradeable.go index c73865f2c..129481c99 100644 --- a/ee/tables/nix_env/upgradeable/upgradeable.go +++ b/ee/tables/nix_env/upgradeable/upgradeable.go @@ -14,7 +14,6 @@ import ( "strings" "syscall" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -26,18 +25,16 @@ const allowedCharacters = "0123456789" type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable/etc execCC allowedcmd.AllowedCommand } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("uid"), ) t := &Table{ slogger: slogger.With("table", "kolide_nix_upgradeable"), - logger: logger, execCC: allowedcmd.NixEnv, } @@ -65,7 +62,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( } flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/profiles/profiles.go b/ee/tables/profiles/profiles.go index db34200ce..f7f9a5b57 100644 --- a/ee/tables/profiles/profiles.go +++ b/ee/tables/profiles/profiles.go @@ -18,7 +18,6 @@ import ( "path/filepath" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" @@ -38,11 +37,10 @@ var ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec tableName string } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { // profiles options. See `man profiles`. These may not be needed, // we use `show -all` as the default, and it probably covers // everything. @@ -54,7 +52,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_profiles"), - logger: logger, tableName: "kolide_profiles", } @@ -104,7 +101,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( return nil, fmt.Errorf("Unknown user argument: %s", user) } - output, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Profiles, profileArgs, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 30, allowedcmd.Profiles, profileArgs, false) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, "ioreg exec failed", @@ -121,7 +118,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( } flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/pwpolicy/pwpolicy.go b/ee/tables/pwpolicy/pwpolicy.go index a48a5afc2..f5d3a8963 100644 --- a/ee/tables/pwpolicy/pwpolicy.go +++ b/ee/tables/pwpolicy/pwpolicy.go @@ -17,7 +17,6 @@ import ( "strings" "time" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" @@ -29,12 +28,11 @@ const pwpolicyCmd = "getaccountpolicies" type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec tableName string execCC allowedcmd.AllowedCommand } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("username"), @@ -42,7 +40,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_pwpolicy"), - logger: logger, tableName: "kolide_pwpolicy", execCC: allowedcmd.Pwpolicy, } @@ -71,7 +68,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( } flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/pwpolicy/pwpolicy_test.go b/ee/tables/pwpolicy/pwpolicy_test.go index a0424167c..f337c37f7 100644 --- a/ee/tables/pwpolicy/pwpolicy_test.go +++ b/ee/tables/pwpolicy/pwpolicy_test.go @@ -9,7 +9,6 @@ import ( "path" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/assert" @@ -46,7 +45,6 @@ func TestQueries(t *testing.T) { tt := tt testTable := &Table{ slogger: multislogger.New().Logger, - logger: log.NewNopLogger(), execCC: execFaker(tt.file), } diff --git a/ee/tables/secedit/secedit.go b/ee/tables/secedit/secedit.go index e36c9ead2..c3ea6a54d 100644 --- a/ee/tables/secedit/secedit.go +++ b/ee/tables/secedit/secedit.go @@ -13,7 +13,6 @@ import ( "strconv" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" @@ -27,17 +26,15 @@ import ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("mergedpolicy"), ) t := &Table{ slogger: slogger.With("table", "kolide_secedit"), - logger: logger, } return table.NewPlugin("kolide_secedit", columns, t.generate) @@ -87,7 +84,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( func (t *Table) flattenOutput(dataQuery string, systemOutput []byte) ([]dataflatten.Row, error) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } @@ -111,7 +108,7 @@ func (t *Table) execSecedit(ctx context.Context, mergedPolicy bool) ([]byte, err args = append(args, "/mergedpolicy") } - if out, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Secedit, args, true); err != nil { + if out, err := tablehelpers.Exec(ctx, t.slogger, 30, allowedcmd.Secedit, args, true); err != nil { return nil, fmt.Errorf("calling secedit. Got: %s: %w", string(out), err) } diff --git a/ee/tables/spotlight/spotlight.go b/ee/tables/spotlight/spotlight.go index ec0115f50..da02eb7af 100644 --- a/ee/tables/spotlight/spotlight.go +++ b/ee/tables/spotlight/spotlight.go @@ -13,14 +13,12 @@ import ( "log/slog" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/osquery/osquery-go/plugin/table" ) type spotlightTable struct { - logger log.Logger // preserved only temporarily for tablehelpers.Exec usage slogger *slog.Logger } @@ -32,14 +30,13 @@ Example Query: AS f JOIN kolide_spotlight ON spotlight.path = f.path AND spotlight.query = "kMDItemKint = 'Agile Keychain'"; */ -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := []table.ColumnDefinition{ table.TextColumn("query"), table.TextColumn("path"), } t := &spotlightTable{ - logger: logger, slogger: slogger.With("table", "kolide_spotlight"), } @@ -60,7 +57,7 @@ func (t *spotlightTable) generate(ctx context.Context, queryContext table.QueryC query = []string{where} } - out, err := tablehelpers.Exec(ctx, t.logger, 120, allowedcmd.Mdfind, query, false) + out, err := tablehelpers.Exec(ctx, t.slogger, 120, allowedcmd.Mdfind, query, false) if err != nil { return nil, fmt.Errorf("call mdfind: %w", err) } diff --git a/ee/tables/systemprofiler/systemprofiler.go b/ee/tables/systemprofiler/systemprofiler.go index 89217288a..c2a76d16d 100644 --- a/ee/tables/systemprofiler/systemprofiler.go +++ b/ee/tables/systemprofiler/systemprofiler.go @@ -44,8 +44,6 @@ import ( "strings" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/groob/plist" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" @@ -79,11 +77,10 @@ type Result struct { type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec tableName string } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("parentdatatype"), table.TextColumn("datatype"), @@ -92,7 +89,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_system_profiler"), - logger: level.NewFilter(logger, level.AllowInfo()), tableName: "kolide_system_profiler", } @@ -159,7 +155,7 @@ func (t *Table) getRowsFromOutput(ctx context.Context, dataQuery, detailLevel st var results []map[string]string flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/tablehelpers/exec.go b/ee/tables/tablehelpers/exec.go index 32944cf6d..50b86876b 100644 --- a/ee/tables/tablehelpers/exec.go +++ b/ee/tables/tablehelpers/exec.go @@ -4,12 +4,11 @@ import ( "bytes" "context" "fmt" + "log/slog" "os" "path/filepath" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/pkg/traces" "go.opentelemetry.io/otel/attribute" @@ -27,7 +26,7 @@ import ( // `possibleBins` can be either a list of command names, or a list of paths to commands. // Where reasonable, `possibleBins` should be command names only, so that we can perform // lookup against PATH. -func Exec(ctx context.Context, logger log.Logger, timeoutSeconds int, execCmd allowedcmd.AllowedCommand, args []string, includeStderr bool) ([]byte, error) { +func Exec(ctx context.Context, slogger *slog.Logger, timeoutSeconds int, execCmd allowedcmd.AllowedCommand, args []string, includeStderr bool) ([]byte, error) { ctx, span := traces.StartSpan(ctx) defer span.End() @@ -53,8 +52,8 @@ func Exec(ctx context.Context, logger log.Logger, timeoutSeconds int, execCmd al cmd.Stderr = &stderr } - level.Debug(logger).Log( - "msg", "execing", + slogger.Log(ctx, slog.LevelDebug, + "execing", "cmd", cmd.String(), ) diff --git a/ee/tables/tablehelpers/exec_test.go b/ee/tables/tablehelpers/exec_test.go index 619d285e0..a135abd22 100644 --- a/ee/tables/tablehelpers/exec_test.go +++ b/ee/tables/tablehelpers/exec_test.go @@ -7,8 +7,8 @@ import ( "context" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/assert" ) @@ -32,7 +32,7 @@ func TestExec(t *testing.T) { } ctx := context.Background() - logger := log.NewNopLogger() + slogger := multislogger.New().Logger for _, tt := range tests { tt := tt @@ -42,7 +42,7 @@ func TestExec(t *testing.T) { if tt.timeout == 0 { tt.timeout = 30 } - output, err := Exec(ctx, logger, tt.timeout, tt.bin, tt.args, false) + output, err := Exec(ctx, slogger, tt.timeout, tt.bin, tt.args, false) if tt.err { assert.Error(t, err) assert.Empty(t, output) diff --git a/ee/tables/tablehelpers/getconstraints.go b/ee/tables/tablehelpers/getconstraints.go index 1dcd8ea41..326236778 100644 --- a/ee/tables/tablehelpers/getconstraints.go +++ b/ee/tables/tablehelpers/getconstraints.go @@ -1,10 +1,11 @@ package tablehelpers import ( + "context" + "log/slog" "strings" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/osquery/osquery-go/plugin/table" ) @@ -12,15 +13,15 @@ type constraintOptions struct { allowedCharacters string allowedValues []string defaults []string - logger log.Logger + slogger *slog.Logger } type GetConstraintOpts func(*constraintOptions) // WithLogger sets the logger to use -func WithLogger(logger log.Logger) GetConstraintOpts { +func WithSlogger(slogger *slog.Logger) GetConstraintOpts { return func(co *constraintOptions) { - co.logger = logger + co.slogger = slogger } } @@ -50,7 +51,7 @@ func WithAllowedValues(allowed []string) GetConstraintOpts { func GetConstraints(queryContext table.QueryContext, columnName string, opts ...GetConstraintOpts) []string { co := &constraintOptions{ - logger: log.NewNopLogger(), + slogger: multislogger.New().Logger, } for _, opt := range opts { @@ -67,11 +68,12 @@ func GetConstraints(queryContext table.QueryContext, columnName string, opts ... for _, c := range q.Constraints { // No point in checking allowed characters, if we have an allowedValues. Just use it. if len(co.allowedValues) == 0 && !co.OnlyAllowedCharacters(c.Expression) { - level.Info(co.logger).Log( - "msg", "Disallowed character in expression", + co.slogger.Log(context.TODO(), slog.LevelInfo, + "disallowed character in expression", "column", columnName, "expression", c.Expression, ) + continue } @@ -85,8 +87,8 @@ func GetConstraints(queryContext table.QueryContext, columnName string, opts ... } if skip { - level.Info(co.logger).Log( - "msg", "Disallowed value in expression", + co.slogger.Log(context.TODO(), slog.LevelInfo, + "disallowed character in expression", "column", columnName, "expression", c.Expression, ) diff --git a/ee/tables/tdebug/gc.go b/ee/tables/tdebug/gc.go index 25c848a80..61e6472a1 100644 --- a/ee/tables/tdebug/gc.go +++ b/ee/tables/tdebug/gc.go @@ -8,7 +8,6 @@ import ( "runtime/debug" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -20,16 +19,14 @@ const ( ) type gcTable struct { - logger log.Logger // preserved only for temporary dataflattentable use slogger *slog.Logger stats debug.GCStats } -func LauncherGcInfo(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func LauncherGcInfo(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() t := &gcTable{ - logger: logger, slogger: slogger.With("table", gcTableName), } @@ -58,7 +55,7 @@ func (t *gcTable) generate(ctx context.Context, queryContext table.QueryContext) flatData, err := dataflatten.Json( jsonBytes, - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), ) if err != nil { diff --git a/ee/tables/wifi_networks/wifi_networks.go b/ee/tables/wifi_networks/wifi_networks.go index 41c7a7f4c..2a839855e 100644 --- a/ee/tables/wifi_networks/wifi_networks.go +++ b/ee/tables/wifi_networks/wifi_networks.go @@ -13,7 +13,6 @@ import ( "path/filepath" "time" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/dataflatten" @@ -38,16 +37,14 @@ type execer func(ctx context.Context, buf *bytes.Buffer) error type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for use in dataflattentable temporarily getBytes execer } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns() t := &Table{ slogger: slogger.With("table", "kolide_wifi_networks"), - logger: logger, getBytes: execPwsh(slogger), } @@ -63,7 +60,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( if err := t.getBytes(ctx, &output); err != nil { return results, fmt.Errorf("getting raw data: %w", err) } - rows, err := dataflatten.Json(output.Bytes(), dataflatten.WithLogger(t.logger)) + rows, err := dataflatten.Json(output.Bytes(), dataflatten.WithSlogger(t.slogger)) if err != nil { return results, fmt.Errorf("flattening json output: %w", err) } diff --git a/ee/tables/windowsupdatetable/windowsupdate.go b/ee/tables/windowsupdatetable/windowsupdate.go index d4c097673..f761e386a 100644 --- a/ee/tables/windowsupdatetable/windowsupdate.go +++ b/ee/tables/windowsupdatetable/windowsupdate.go @@ -11,7 +11,6 @@ import ( "strconv" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -29,21 +28,18 @@ const ( type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable queryFunc queryFuncType name string } -func TablePlugin(mode tableMode, slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(mode tableMode, slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("locale"), table.IntegerColumn("is_default"), ) - t := &Table{ - logger: logger, - } + t := &Table{} switch mode { case UpdatesTable: @@ -129,7 +125,7 @@ func (t *Table) searchLocale(ctx context.Context, locale string, queryContext ta func (t *Table) flattenOutput(dataQuery string, searchResults interface{}) ([]dataflatten.Row, error) { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/windowsupdatetable/windowsupdate_test.go b/ee/tables/windowsupdatetable/windowsupdate_test.go index 2e636eb66..aa0e5f180 100644 --- a/ee/tables/windowsupdatetable/windowsupdate_test.go +++ b/ee/tables/windowsupdatetable/windowsupdate_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/tablehelpers" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/require" ) @@ -30,7 +30,7 @@ func TestTable(t *testing.T) { t.Parallel() table := Table{ - logger: log.NewNopLogger(), + slogger: multislogger.New().Logger, queryFunc: tt.queryFunc, } diff --git a/ee/tables/wmitable/wmitable.go b/ee/tables/wmitable/wmitable.go index 6315d14a0..2953eb9da 100644 --- a/ee/tables/wmitable/wmitable.go +++ b/ee/tables/wmitable/wmitable.go @@ -10,13 +10,10 @@ import ( "strings" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/ee/wmi" - "github.com/kolide/launcher/pkg/contexts/ctxlog" "github.com/osquery/osquery-go/plugin/table" ) @@ -24,10 +21,9 @@ const allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0 type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in dataflattentable and tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { columns := dataflattentable.Columns( table.TextColumn("namespace"), @@ -37,7 +33,6 @@ func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { ) t := &Table{ - logger: level.NewFilter(logger), slogger: slogger.With("table", "kolide_wmi"), } @@ -94,9 +89,6 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( ctx, cancel := context.WithTimeout(ctx, 120*time.Second) defer cancel() - // Add a logger in - ctx = ctxlog.NewContext(ctx, t.logger) - wmiResults, err := wmi.Query(ctx, class, properties, wmi.ConnectUseMaxWait(), wmi.ConnectNamespace(ns), wmi.WithWhere(whereClause)) if err != nil { t.slogger.Log(ctx, slog.LevelInfo, @@ -123,7 +115,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( func (t *Table) flattenRowsFromWmi(ctx context.Context, dataQuery string, wmiResults []map[string]interface{}, wmiClass, wmiProperties, wmiNamespace, whereClause string) []map[string]string { flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/wmitable/wmitable_test.go b/ee/tables/wmitable/wmitable_test.go index 9cd7f0372..04d8f7592 100644 --- a/ee/tables/wmitable/wmitable_test.go +++ b/ee/tables/wmitable/wmitable_test.go @@ -7,7 +7,6 @@ import ( "context" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/stretchr/testify/assert" @@ -17,7 +16,7 @@ import ( func TestQueries(t *testing.T) { t.Parallel() - wmiTable := Table{logger: log.NewNopLogger(), slogger: multislogger.New().Logger} + wmiTable := Table{slogger: multislogger.New().Logger} var tests = []struct { name string diff --git a/ee/tables/xfconf/xfconf.go b/ee/tables/xfconf/xfconf.go index f7f8c1759..01df43df9 100644 --- a/ee/tables/xfconf/xfconf.go +++ b/ee/tables/xfconf/xfconf.go @@ -13,7 +13,6 @@ import ( "path/filepath" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/dataflatten" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/tablehelpers" @@ -29,13 +28,11 @@ var xfconfChannelXmlPath string = filepath.Join("xfce4", "xfconf", "xfce-perchan type xfconfTable struct { slogger *slog.Logger - logger log.Logger // preserved temporarily for use in dataflattentable and tablehelpers.Exec } -func TablePlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func TablePlugin(slogger *slog.Logger) *table.Plugin { t := &xfconfTable{ slogger: slogger.With("table", "kolide_xfconf"), - logger: logger, } return table.NewPlugin("kolide_xfconf", dataflattentable.Columns(table.TextColumn("username"), table.TextColumn("path")), t.generate) @@ -191,7 +188,7 @@ func (t *xfconfTable) getCombinedFlattenedConfig(u *user.User, userConfig map[st var results []map[string]string flattenOpts := []dataflatten.FlattenOpts{ - dataflatten.WithLogger(t.logger), + dataflatten.WithSlogger(t.slogger), dataflatten.WithQuery(strings.Split(dataQuery, "/")), } diff --git a/ee/tables/xfconf/xfconf_test.go b/ee/tables/xfconf/xfconf_test.go index 88e86c032..083c7ffc5 100644 --- a/ee/tables/xfconf/xfconf_test.go +++ b/ee/tables/xfconf/xfconf_test.go @@ -11,7 +11,6 @@ import ( "strings" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/kit/fsutil" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/osquery/osquery-go/plugin/table" @@ -24,7 +23,6 @@ func Test_getUserConfig(t *testing.T) { tmpDefaultDir, tmpUserDir := setUpConfigFiles(t) xfconf := xfconfTable{ - logger: log.NewNopLogger(), slogger: multislogger.New().Logger, } diff --git a/ee/tables/zfs/tables.go b/ee/tables/zfs/tables.go index 73882f167..e323e80d8 100644 --- a/ee/tables/zfs/tables.go +++ b/ee/tables/zfs/tables.go @@ -12,7 +12,6 @@ import ( "os" "strings" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/tablehelpers" "github.com/osquery/osquery-go/plugin/table" @@ -23,7 +22,6 @@ const allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0 type Table struct { slogger *slog.Logger - logger log.Logger // preserved only for temporary use in tablehelpers.Exec cmd allowedcmd.AllowedCommand } @@ -36,20 +34,18 @@ func columns() []table.ColumnDefinition { } } -func ZfsPropertiesPlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func ZfsPropertiesPlugin(slogger *slog.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_zfs_properties"), - logger: logger, cmd: allowedcmd.Zfs, } return table.NewPlugin("kolide_zfs_properties", columns(), t.generate) } -func ZpoolPropertiesPlugin(slogger *slog.Logger, logger log.Logger) *table.Plugin { +func ZpoolPropertiesPlugin(slogger *slog.Logger) *table.Plugin { t := &Table{ slogger: slogger.With("table", "kolide_zpool_properties"), - logger: logger, cmd: allowedcmd.Zpool, } @@ -77,7 +73,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ( args = append(args, names...) - output, err := tablehelpers.Exec(ctx, t.logger, 15, t.cmd, args, false) + output, err := tablehelpers.Exec(ctx, t.slogger, 15, t.cmd, args, false) if err != nil { // exec will error if there's no binary, so we never want to record that if os.IsNotExist(errors.Cause(err)) { diff --git a/pkg/osquery/interactive/interactive.go b/pkg/osquery/interactive/interactive.go index 8618891ba..874743a8d 100644 --- a/pkg/osquery/interactive/interactive.go +++ b/pkg/osquery/interactive/interactive.go @@ -2,15 +2,14 @@ package interactive import ( "fmt" + "log/slog" "os" "path/filepath" "runtime" "time" - "github.com/go-kit/kit/log" "github.com/kolide/kit/fsutil" "github.com/kolide/launcher/pkg/augeas" - "github.com/kolide/launcher/pkg/log/multislogger" osqueryRuntime "github.com/kolide/launcher/pkg/osquery/runtime" "github.com/kolide/launcher/pkg/osquery/table" osquery "github.com/osquery/osquery-go" @@ -18,7 +17,7 @@ import ( const extensionName = "com.kolide.launcher_interactive" -func StartProcess(logger log.Logger, rootDir, osquerydPath string, osqueryFlags []string) (*os.Process, *osquery.ExtensionManagerServer, error) { +func StartProcess(slogger *slog.Logger, rootDir, osquerydPath string, osqueryFlags []string) (*os.Process, *osquery.ExtensionManagerServer, error) { if err := os.MkdirAll(rootDir, fsutil.DirMode); err != nil { return nil, nil, fmt.Errorf("creating root dir for interactive mode: %w", err) @@ -59,7 +58,7 @@ func StartProcess(logger log.Logger, rootDir, osquerydPath string, osqueryFlags return nil, nil, fmt.Errorf("error waiting for osquery to create socket: %w", err) } - extensionServer, err := loadExtensions(logger, socketPath, osquerydPath) + extensionServer, err := loadExtensions(slogger, socketPath, osquerydPath) if err != nil { err = fmt.Errorf("error loading extensions: %w", err) @@ -101,7 +100,7 @@ func buildOsqueryFlags(socketPath, augeasLensesPath string, osqueryFlags []strin return flags } -func loadExtensions(logger log.Logger, socketPath string, osquerydPath string) (*osquery.ExtensionManagerServer, error) { +func loadExtensions(slogger *slog.Logger, socketPath string, osquerydPath string) (*osquery.ExtensionManagerServer, error) { client, err := osquery.NewClient(socketPath, 10*time.Second, osquery.MaxWaitTime(10*time.Second)) if err != nil { return nil, fmt.Errorf("error creating osquery client: %w", err) @@ -118,7 +117,7 @@ func loadExtensions(logger log.Logger, socketPath string, osquerydPath string) ( return extensionManagerServer, fmt.Errorf("error creating extension manager server: %w", err) } - extensionManagerServer.RegisterPlugin(table.PlatformTables(multislogger.New().Logger, logger, osquerydPath)...) + extensionManagerServer.RegisterPlugin(table.PlatformTables(slogger, osquerydPath)...) if err := extensionManagerServer.Start(); err != nil { return nil, fmt.Errorf("error starting extension manager server: %w", err) diff --git a/pkg/osquery/interactive/interactive_test.go b/pkg/osquery/interactive/interactive_test.go index 40d677653..f0cb97f82 100644 --- a/pkg/osquery/interactive/interactive_test.go +++ b/pkg/osquery/interactive/interactive_test.go @@ -14,8 +14,8 @@ import ( "runtime" "testing" - "github.com/go-kit/kit/log" "github.com/kolide/kit/fsutil" + "github.com/kolide/launcher/pkg/log/multislogger" "github.com/kolide/launcher/pkg/packaging" "github.com/stretchr/testify/require" ) @@ -84,7 +84,7 @@ func TestProc(t *testing.T) { require.NoError(t, downloadOsquery(rootDir)) osquerydPath := filepath.Join(rootDir, "osqueryd") - proc, _, err := StartProcess(log.NewNopLogger(), rootDir, osquerydPath, tt.osqueryFlags) + proc, _, err := StartProcess(multislogger.New().Logger, rootDir, osquerydPath, tt.osqueryFlags) if tt.errContainsStr != "" { require.Error(t, err) diff --git a/pkg/osquery/runtime/runner.go b/pkg/osquery/runtime/runner.go index d2cce377d..0f0eece90 100644 --- a/pkg/osquery/runtime/runner.go +++ b/pkg/osquery/runtime/runner.go @@ -528,7 +528,7 @@ func (r *Runner) launchOsqueryInstance() error { "errgroup", "kolide extension manager server launch", ) - plugins := table.PlatformTables(r.knapsack.Slogger().With("component", "platform_tables"), o.logger, currentOsquerydBinaryPath) + plugins := table.PlatformTables(r.knapsack.Slogger().With("component", "platform_tables"), currentOsquerydBinaryPath) if len(plugins) == 0 { return nil diff --git a/pkg/osquery/table/platform_tables_darwin.go b/pkg/osquery/table/platform_tables_darwin.go index 68f6ee837..110187bfb 100644 --- a/pkg/osquery/table/platform_tables_darwin.go +++ b/pkg/osquery/table/platform_tables_darwin.go @@ -6,7 +6,6 @@ package table import ( "log/slog" - "github.com/go-kit/kit/log" "github.com/knightsc/system_policy/osquery/table/kextpolicy" "github.com/knightsc/system_policy/osquery/table/legacyexec" "github.com/kolide/launcher/ee/allowedcmd" @@ -40,7 +39,7 @@ const ( screenlockQuery = "select enabled, grace_period from screenlock" ) -func platformSpecificTables(slogger *slog.Logger, logger log.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { +func platformSpecificTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { munki := munki.New() // This table uses undocumented APIs, There is some discussion at the @@ -83,49 +82,49 @@ func platformSpecificTables(slogger *slog.Logger, logger log.Logger, currentOsqu keychainItemsTable, appicons.AppIcons(), ChromeLoginKeychainInfo(slogger), - firmwarepasswd.TablePlugin(logger), + firmwarepasswd.TablePlugin(slogger), GDriveSyncConfig(slogger), GDriveSyncHistoryInfo(slogger), MDMInfo(), macos_software_update.MacOSUpdate(), - macos_software_update.RecommendedUpdates(slogger, logger), - macos_software_update.AvailableProducts(slogger, logger), + macos_software_update.RecommendedUpdates(slogger), + macos_software_update.AvailableProducts(slogger), MachoInfo(), - spotlight.TablePlugin(slogger, logger), + spotlight.TablePlugin(slogger), TouchIDUserConfig(slogger), TouchIDSystemConfig(slogger), UserAvatar(slogger), - ioreg.TablePlugin(slogger, logger), - profiles.TablePlugin(slogger, logger), - airport.TablePlugin(slogger, logger), + ioreg.TablePlugin(slogger), + profiles.TablePlugin(slogger), + airport.TablePlugin(slogger), kextpolicy.TablePlugin(), - filevault.TablePlugin(slogger, logger), - mdmclient.TablePlugin(slogger, logger), - apple_silicon_security_policy.TablePlugin(slogger, logger), + filevault.TablePlugin(slogger), + mdmclient.TablePlugin(slogger), + apple_silicon_security_policy.TablePlugin(slogger), legacyexec.TablePlugin(), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_diskutil_list", dataflattentable.PlistType, allowedcmd.Diskutil, []string{"list", "-plist"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_falconctl_stats", dataflattentable.PlistType, allowedcmd.Falconctl, []string{"stats", "-p"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_apfs_list", dataflattentable.PlistType, allowedcmd.Diskutil, []string{"apfs", "list", "-plist"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_apfs_users", dataflattentable.PlistType, allowedcmd.Diskutil, []string{"apfs", "listUsers", "/", "-plist"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_tmutil_destinationinfo", dataflattentable.PlistType, allowedcmd.Tmutil, []string{"destinationinfo", "-X"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_powermetrics", dataflattentable.PlistType, allowedcmd.Powermetrics, []string{"-n", "1", "-f", "plist"}), screenlockTable, - pwpolicy.TablePlugin(slogger, logger), - systemprofiler.TablePlugin(slogger, logger), + pwpolicy.TablePlugin(slogger), + systemprofiler.TablePlugin(slogger), munki.ManagedInstalls(), munki.MunkiReport(), - dataflattentable.TablePluginExec(logger, "kolide_nix_upgradeable", dataflattentable.XmlType, allowedcmd.NixEnv, []string{"--query", "--installed", "-c", "--xml"}), - dataflattentable.NewExecAndParseTable(logger, "kolide_remotectl", remotectl.Parser, allowedcmd.Remotectl, []string{`dumpstate`}), - dataflattentable.NewExecAndParseTable(logger, "kolide_softwareupdate", softwareupdate.Parser, allowedcmd.Softwareupdate, []string{`--list`, `--no-scan`}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_softwareupdate_scan", softwareupdate.Parser, allowedcmd.Softwareupdate, []string{`--list`}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_carbonblack_repcli_status", repcli.Parser, allowedcmd.Repcli, []string{"status"}, dataflattentable.WithIncludeStderr()), - zfs.ZfsPropertiesPlugin(slogger, logger), - zfs.ZpoolPropertiesPlugin(slogger, logger), + dataflattentable.TablePluginExec(slogger, "kolide_nix_upgradeable", dataflattentable.XmlType, allowedcmd.NixEnv, []string{"--query", "--installed", "-c", "--xml"}), + dataflattentable.NewExecAndParseTable(slogger, "kolide_remotectl", remotectl.Parser, allowedcmd.Remotectl, []string{`dumpstate`}), + dataflattentable.NewExecAndParseTable(slogger, "kolide_softwareupdate", softwareupdate.Parser, allowedcmd.Softwareupdate, []string{`--list`, `--no-scan`}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_softwareupdate_scan", softwareupdate.Parser, allowedcmd.Softwareupdate, []string{`--list`}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_carbonblack_repcli_status", repcli.Parser, allowedcmd.Repcli, []string{"status"}, dataflattentable.WithIncludeStderr()), + zfs.ZfsPropertiesPlugin(slogger), + zfs.ZpoolPropertiesPlugin(slogger), } } diff --git a/pkg/osquery/table/platform_tables_linux.go b/pkg/osquery/table/platform_tables_linux.go index 52abc88ff..569766adb 100644 --- a/pkg/osquery/table/platform_tables_linux.go +++ b/pkg/osquery/table/platform_tables_linux.go @@ -6,7 +6,6 @@ package table import ( "log/slog" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/crowdstrike/falcon_kernel_check" "github.com/kolide/launcher/ee/tables/crowdstrike/falconctl" @@ -31,41 +30,41 @@ import ( osquery "github.com/osquery/osquery-go" ) -func platformSpecificTables(slogger *slog.Logger, logger log.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { +func platformSpecificTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { return []osquery.OsqueryPlugin{ - cryptsetup.TablePlugin(slogger, logger), + cryptsetup.TablePlugin(slogger), gsettings.Settings(slogger), gsettings.Metadata(slogger), - nix_env_upgradeable.TablePlugin(slogger, logger), + nix_env_upgradeable.TablePlugin(slogger), secureboot.TablePlugin(slogger), xrdb.TablePlugin(slogger), fscrypt_info.TablePlugin(slogger), - falcon_kernel_check.TablePlugin(slogger, logger), - falconctl.NewFalconctlOptionTable(slogger, logger), - xfconf.TablePlugin(slogger, logger), + falcon_kernel_check.TablePlugin(slogger), + falconctl.NewFalconctlOptionTable(slogger), + xfconf.TablePlugin(slogger), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_nmcli_wifi", dataflattentable.KeyValueType, allowedcmd.Nmcli, []string{"--mode=multiline", "--fields=all", "device", "wifi", "list"}, dataflattentable.WithKVSeparator(":")), - dataflattentable.TablePluginExec(logger, "kolide_lsblk", dataflattentable.JsonType, + dataflattentable.TablePluginExec(slogger, "kolide_lsblk", dataflattentable.JsonType, allowedcmd.Lsblk, []string{"-fJp"}, ), - dataflattentable.TablePluginExec(logger, "kolide_wsone_uem_status_enroll", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--enroll"}), - dataflattentable.TablePluginExec(logger, "kolide_wsone_uem_status_dependency", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--dependency"}), - dataflattentable.TablePluginExec(logger, "kolide_wsone_uem_status_profile", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--profile"}), - dataflattentable.NewExecAndParseTable(logger, "kolide_falconctl_systags", simple_array.New("systags"), allowedcmd.Falconctl, []string{"-g", "--systags"}), - dataflattentable.NewExecAndParseTable(logger, "kolide_apt_upgradeable", apt.Parser, allowedcmd.Apt, []string{"list", "--upgradeable"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_dnf_upgradeable", dnf.Parser, allowedcmd.Dnf, []string{"check-update"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_dpkg_version_info", dpkg.Parser, allowedcmd.Dpkg, []string{"-p"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_pacman_group", pacman_group.Parser, allowedcmd.Pacman, []string{"-Qg"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_pacman_version_info", pacman_info.Parser, allowedcmd.Pacman, []string{"-Qi"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_pacman_upgradeable", pacman_upgradeable.Parser, allowedcmd.Pacman, []string{"-Qu"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_rpm_version_info", rpm.Parser, allowedcmd.Rpm, []string{"-qai"}, dataflattentable.WithIncludeStderr()), - dataflattentable.NewExecAndParseTable(logger, "kolide_carbonblack_repcli_status", repcli.Parser, allowedcmd.Repcli, []string{"status"}, dataflattentable.WithIncludeStderr()), - dataflattentable.TablePluginExec(logger, "kolide_nftables", dataflattentable.JsonType, allowedcmd.Nftables, []string{"-jat", "list", "ruleset"}), // -j (json) -a (show object handles) -t (terse, omit set contents) - zfs.ZfsPropertiesPlugin(slogger, logger), - zfs.ZpoolPropertiesPlugin(slogger, logger), + dataflattentable.TablePluginExec(slogger, "kolide_wsone_uem_status_enroll", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--enroll"}), + dataflattentable.TablePluginExec(slogger, "kolide_wsone_uem_status_dependency", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--dependency"}), + dataflattentable.TablePluginExec(slogger, "kolide_wsone_uem_status_profile", dataflattentable.JsonType, allowedcmd.Ws1HubUtil, []string{"status", "--profile"}), + dataflattentable.NewExecAndParseTable(slogger, "kolide_falconctl_systags", simple_array.New("systags"), allowedcmd.Falconctl, []string{"-g", "--systags"}), + dataflattentable.NewExecAndParseTable(slogger, "kolide_apt_upgradeable", apt.Parser, allowedcmd.Apt, []string{"list", "--upgradeable"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_dnf_upgradeable", dnf.Parser, allowedcmd.Dnf, []string{"check-update"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_dpkg_version_info", dpkg.Parser, allowedcmd.Dpkg, []string{"-p"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_pacman_group", pacman_group.Parser, allowedcmd.Pacman, []string{"-Qg"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_pacman_version_info", pacman_info.Parser, allowedcmd.Pacman, []string{"-Qi"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_pacman_upgradeable", pacman_upgradeable.Parser, allowedcmd.Pacman, []string{"-Qu"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_rpm_version_info", rpm.Parser, allowedcmd.Rpm, []string{"-qai"}, dataflattentable.WithIncludeStderr()), + dataflattentable.NewExecAndParseTable(slogger, "kolide_carbonblack_repcli_status", repcli.Parser, allowedcmd.Repcli, []string{"status"}, dataflattentable.WithIncludeStderr()), + dataflattentable.TablePluginExec(slogger, "kolide_nftables", dataflattentable.JsonType, allowedcmd.Nftables, []string{"-jat", "list", "ruleset"}), // -j (json) -a (show object handles) -t (terse, omit set contents) + zfs.ZfsPropertiesPlugin(slogger), + zfs.ZpoolPropertiesPlugin(slogger), } } diff --git a/pkg/osquery/table/platform_tables_windows.go b/pkg/osquery/table/platform_tables_windows.go index 049d2b276..f41e336e4 100644 --- a/pkg/osquery/table/platform_tables_windows.go +++ b/pkg/osquery/table/platform_tables_windows.go @@ -6,7 +6,6 @@ package table import ( "log/slog" - "github.com/go-kit/kit/log" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/dataflattentable" "github.com/kolide/launcher/ee/tables/dsim_default_associations" @@ -18,15 +17,15 @@ import ( osquery "github.com/osquery/osquery-go" ) -func platformSpecificTables(slogger *slog.Logger, logger log.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { +func platformSpecificTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { return []osquery.OsqueryPlugin{ ProgramIcons(), - dsim_default_associations.TablePlugin(slogger, logger), - secedit.TablePlugin(slogger, logger), - wifi_networks.TablePlugin(slogger, logger), - windowsupdatetable.TablePlugin(windowsupdatetable.UpdatesTable, slogger, logger), - windowsupdatetable.TablePlugin(windowsupdatetable.HistoryTable, slogger, logger), - wmitable.TablePlugin(slogger, logger), - dataflattentable.NewExecAndParseTable(logger, "kolide_dsregcmd", dsregcmd.Parser, allowedcmd.Dsregcmd, []string{`/status`}), + dsim_default_associations.TablePlugin(slogger), + secedit.TablePlugin(slogger), + wifi_networks.TablePlugin(slogger), + windowsupdatetable.TablePlugin(windowsupdatetable.UpdatesTable, slogger), + windowsupdatetable.TablePlugin(windowsupdatetable.HistoryTable, slogger), + wmitable.TablePlugin(slogger), + dataflattentable.NewExecAndParseTable(slogger, "kolide_dsregcmd", dsregcmd.Parser, allowedcmd.Dsregcmd, []string{`/status`}), } } diff --git a/pkg/osquery/table/table.go b/pkg/osquery/table/table.go index 8b8e27f68..aa5007ceb 100644 --- a/pkg/osquery/table/table.go +++ b/pkg/osquery/table/table.go @@ -15,7 +15,6 @@ import ( "github.com/kolide/launcher/ee/tables/tdebug" "github.com/kolide/launcher/ee/tables/tufinfo" - "github.com/go-kit/kit/log" osquery "github.com/osquery/osquery-go" ) @@ -37,7 +36,7 @@ func LauncherTables(k types.Knapsack) []osquery.OsqueryPlugin { } // PlatformTables returns all tables for the launcher build platform. -func PlatformTables(slogger *slog.Logger, logger log.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { +func PlatformTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { // Common tables to all platforms tables := []osquery.OsqueryPlugin{ ChromeLoginDataEmails(slogger), @@ -46,23 +45,23 @@ func PlatformTables(slogger *slog.Logger, logger log.Logger, currentOsquerydBina OnePasswordAccounts(slogger), SlackConfig(slogger), SshKeys(slogger), - cryptoinfotable.TablePlugin(slogger, logger), - dev_table_tooling.TablePlugin(slogger, logger), + cryptoinfotable.TablePlugin(slogger), + dev_table_tooling.TablePlugin(slogger), firefox_preferences.TablePlugin(slogger), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_zerotier_info", dataflattentable.JsonType, allowedcmd.ZerotierCli, []string{"info"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_zerotier_networks", dataflattentable.JsonType, allowedcmd.ZerotierCli, []string{"listnetworks"}), - dataflattentable.TablePluginExec(logger, + dataflattentable.TablePluginExec(slogger, "kolide_zerotier_peers", dataflattentable.JsonType, allowedcmd.ZerotierCli, []string{"listpeers"}), - tdebug.LauncherGcInfo(slogger, logger), + tdebug.LauncherGcInfo(slogger), } // The dataflatten tables - tables = append(tables, dataflattentable.AllTablePlugins(logger)...) + tables = append(tables, dataflattentable.AllTablePlugins(slogger)...) // add in the platform specific ones (as denoted by build tags) - tables = append(tables, platformSpecificTables(slogger, logger, currentOsquerydBinaryPath)...) + tables = append(tables, platformSpecificTables(slogger, currentOsquerydBinaryPath)...) return tables }