Found these bugs while testing the extensions feature for #13287. - [X] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - ~[ ] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)~ - ~[ ] Documented any permissions changes (docs/Using Fleet/manage-access.md)~ - ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements)~ - ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features.~ - [x] Added/updated tests - [X] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [x] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
|
"github.com/osquery/osquery-go"
|
|
"github.com/osquery/osquery-go/plugin/table"
|
|
)
|
|
|
|
var (
|
|
socket = flag.String("socket", "", "Path to the extensions UNIX domain socket")
|
|
timeout = flag.Int("timeout", 3, "Seconds to wait for autoloaded extensions")
|
|
interval = flag.Int("interval", 3, "Seconds delay between connectivity checks")
|
|
// verbose must be set because osqueryd will set it on the extension when running in verbose mode.
|
|
_ = flag.Bool("verbose", false, "Enable verbose informational messages")
|
|
|
|
extensionName = "test_extensions.hello_world"
|
|
tableName = "hello_world"
|
|
columnName = "hello"
|
|
columnValue = "world"
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *socket == "" {
|
|
log.Fatalf(`Usage: %s -socket SOCKET_PATH`, os.Args[0])
|
|
}
|
|
|
|
serverTimeout := osquery.ServerTimeout(
|
|
time.Second * time.Duration(*timeout),
|
|
)
|
|
serverPingInterval := osquery.ServerPingInterval(
|
|
time.Second * time.Duration(*interval),
|
|
)
|
|
|
|
var server *osquery.ExtensionManagerServer
|
|
backOff := backoff.WithMaxRetries(backoff.NewConstantBackOff(time.Millisecond*200), 25) // retry once per 200ms for 25 times == 5 seconds
|
|
op := func() error {
|
|
s, err := osquery.NewExtensionManagerServer(extensionName, *socket, serverTimeout, serverPingInterval)
|
|
if err != nil {
|
|
return fmt.Errorf("error creating extension: %w", err)
|
|
}
|
|
server = s
|
|
return nil
|
|
}
|
|
|
|
err := backoff.Retry(op, backOff)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
server.RegisterPlugin(
|
|
table.NewPlugin(
|
|
tableName,
|
|
[]table.ColumnDefinition{
|
|
table.TextColumn(columnName),
|
|
},
|
|
func(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
|
|
return []map[string]string{
|
|
{
|
|
columnName: columnValue,
|
|
},
|
|
}, nil
|
|
},
|
|
),
|
|
)
|
|
if err := server.Run(); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
}
|