fleet/server/service/mock/service_osquery.go
Zach Wasserman 8c21dff636
Add capability to serve YARA rules via authenticated Fleet endpoints (#23343)
Implements the Fleet side of #14899

- Add new endpoints to update and retrieve yara rules
- Add support in fleetctl for applying the rules

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`.
  See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information.
- [x] 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
- [ ] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes
- [x] If database migrations are included, checked table schema to confirm autoupdate
- For database migrations:
  - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration.
  - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects.
  - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Manual QA for all new/changed functionality
2024-11-13 09:01:08 -08:00

113 lines
3.9 KiB
Go

// Automatically generated by mockimpl. DO NOT EDIT!
package mock
import (
"context"
"encoding/json"
"sync"
"github.com/fleetdm/fleet/v4/server/fleet"
)
var _ fleet.OsqueryService = (*TLSService)(nil)
type EnrollAgentFunc func(ctx context.Context, enrollSecret string, hostIdentifier string, hostDetails map[string](map[string]string)) (nodeKey string, err error)
type AuthenticateHostFunc func(ctx context.Context, nodeKey string) (host *fleet.Host, debug bool, err error)
type GetClientConfigFunc func(ctx context.Context) (config map[string]interface{}, err error)
type GetDistributedQueriesFunc func(ctx context.Context) (queries map[string]string, discovery map[string]string, accelerate uint, err error)
type SubmitDistributedQueryResultsFunc func(ctx context.Context, results fleet.OsqueryDistributedQueryResults, statuses map[string]fleet.OsqueryStatus, messages map[string]string, stats map[string]*fleet.Stats) (err error)
type SubmitStatusLogsFunc func(ctx context.Context, logs []json.RawMessage) (err error)
type SubmitResultLogsFunc func(ctx context.Context, logs []json.RawMessage) (err error)
type YaraRuleByNameFunc func(ctx context.Context, name string) (*fleet.YaraRule, error)
type TLSService struct {
EnrollAgentFunc EnrollAgentFunc
EnrollAgentFuncInvoked bool
AuthenticateHostFunc AuthenticateHostFunc
AuthenticateHostFuncInvoked bool
GetClientConfigFunc GetClientConfigFunc
GetClientConfigFuncInvoked bool
GetDistributedQueriesFunc GetDistributedQueriesFunc
GetDistributedQueriesFuncInvoked bool
SubmitDistributedQueryResultsFunc SubmitDistributedQueryResultsFunc
SubmitDistributedQueryResultsFuncInvoked bool
SubmitStatusLogsFunc SubmitStatusLogsFunc
SubmitStatusLogsFuncInvoked bool
SubmitResultLogsFunc SubmitResultLogsFunc
SubmitResultLogsFuncInvoked bool
YaraRuleByNameFunc YaraRuleByNameFunc
YaraRuleByNameFuncInvoked bool
mu sync.Mutex
}
func (s *TLSService) EnrollAgent(ctx context.Context, enrollSecret string, hostIdentifier string, hostDetails map[string](map[string]string)) (nodeKey string, err error) {
s.mu.Lock()
s.EnrollAgentFuncInvoked = true
s.mu.Unlock()
return s.EnrollAgentFunc(ctx, enrollSecret, hostIdentifier, hostDetails)
}
func (s *TLSService) AuthenticateHost(ctx context.Context, nodeKey string) (host *fleet.Host, debug bool, err error) {
s.mu.Lock()
s.AuthenticateHostFuncInvoked = true
s.mu.Unlock()
return s.AuthenticateHostFunc(ctx, nodeKey)
}
func (s *TLSService) GetClientConfig(ctx context.Context) (config map[string]interface{}, err error) {
s.mu.Lock()
s.GetClientConfigFuncInvoked = true
s.mu.Unlock()
return s.GetClientConfigFunc(ctx)
}
func (s *TLSService) GetDistributedQueries(ctx context.Context) (queries map[string]string, discovery map[string]string, accelerate uint, err error) {
s.mu.Lock()
s.GetDistributedQueriesFuncInvoked = true
s.mu.Unlock()
return s.GetDistributedQueriesFunc(ctx)
}
func (s *TLSService) SubmitDistributedQueryResults(ctx context.Context, results fleet.OsqueryDistributedQueryResults, statuses map[string]fleet.OsqueryStatus, messages map[string]string, stats map[string]*fleet.Stats) (err error) {
s.mu.Lock()
s.SubmitDistributedQueryResultsFuncInvoked = true
s.mu.Unlock()
return s.SubmitDistributedQueryResultsFunc(ctx, results, statuses, messages, stats)
}
func (s *TLSService) SubmitStatusLogs(ctx context.Context, logs []json.RawMessage) (err error) {
s.mu.Lock()
s.SubmitStatusLogsFuncInvoked = true
s.mu.Unlock()
return s.SubmitStatusLogsFunc(ctx, logs)
}
func (s *TLSService) SubmitResultLogs(ctx context.Context, logs []json.RawMessage) (err error) {
s.mu.Lock()
s.SubmitResultLogsFuncInvoked = true
s.mu.Unlock()
return s.SubmitResultLogsFunc(ctx, logs)
}
func (s *TLSService) YaraRuleByName(ctx context.Context, name string) (*fleet.YaraRule, error) {
s.mu.Lock()
s.YaraRuleByNameFuncInvoked = true
s.mu.Unlock()
return s.YaraRuleByNameFunc(ctx, name)
}