Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to serve YARA rules via authenticated Fleet endpoints #23343

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zwass
Copy link
Member

@zwass zwass commented Oct 29, 2024

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.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • 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.
  • Added/updated tests
  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes
  • If database migrations are included, checked table schema to confirm autoupdate
  • For database migrations:
    • 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.
    • Ensured the correct collation is explicitly set for character columns (COLLATE utf8mb4_unicode_ci).
  • Manual QA for all new/changed functionality

Part of #14899, this implements the ability for Fleet to server up yara rules with the usual osquery (node key) authentication. The relevant changes to allow authentication via osquery are shipped in osquery 5.14.
@zwass zwass requested a review from a team as a code owner October 29, 2024 17:10
@zwass
Copy link
Member Author

zwass commented Oct 29, 2024

@sharon-fdm IIRC we had discussed the endpoint ops team helping out with a code review for this one. Can you please tag the appropriate person for review? Thanks!

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 35.82090% with 86 lines in your changes missing coverage. Please review.

Project coverage is 53.45%. Comparing base (12b2914) to head (0171efb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/service/client.go 16.00% 39 Missing and 3 partials ⚠️
server/service/osquery.go 0.00% 15 Missing ⚠️
server/datastore/mysql/app_configs.go 72.22% 7 Missing and 3 partials ⚠️
...rations/tables/20241025141856_AddYaraRulesTable.go 70.58% 4 Missing and 1 partial ⚠️
server/fleet/app.go 0.00% 4 Missing and 1 partial ⚠️
server/service/mock/service_osquery.go 0.00% 5 Missing ⚠️
server/service/appconfig.go 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23343      +/-   ##
==========================================
- Coverage   63.09%   53.45%   -9.64%     
==========================================
  Files        1555     1556       +1     
  Lines      147014   147147     +133     
  Branches     3666     3666              
==========================================
- Hits        92754    78654   -14100     
- Misses      46924    62036   +15112     
+ Partials     7336     6457     -879     
Flag Coverage Δ
backend 53.42% <35.82%> (-10.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sharon-fdm
Copy link
Collaborator

@zwass, sorry, this fell between the cracks.
Will take care of it.

@zwass
Copy link
Member Author

zwass commented Oct 29, 2024

No worries I only just put it up an hour ago!

@lucasmrod lucasmrod self-assigned this Oct 29, 2024
Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Left a few questions.

Also (from Noah comments on the issue):

  • Let's add yara_rules to https://fleetdm.com/docs/configuration/yaml-files.
  • Add API changes to PATCH/GET /api/latest/fleet/config endpoints.
  • CI failures:
    • Maybe reorder migrations yet again and run make dump-test-schema?
    • lint checks 🙈
    • test-native-packaging can be ignored (was fixed on main)
    • Go tests seem a-ok, failures are known flaky tests.

(We usually do a separate PR for the docs to not block the merge on docs changes.)

@@ -0,0 +1 @@
* Add capability for Fleet to serve yara rules to agents over HTTPS authenticated via node key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use past tense.

@@ -0,0 +1 @@
* Add capability for Fleet to serve yara rules to agents over HTTPS authenticated via node key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clarify it needs osquery 5.14.X on the hosts.

@@ -115,6 +115,7 @@ type osqueryOptions struct {
TlsDisableStatusLog bool `json:"tls_disable_status_log"`
Verbose bool `json:"verbose"`
YaraDelay uint32 `json:"yara_delay"`
YaraSigurlAuthenticate bool `json:"yara_sigurl_authenticate"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should also be added to osqueryCommandLineFlags (was this edited manually or did auto generation not add it?)

CREATE TABLE yara_rules (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
contents TEXT NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How big can these get?

https://github.com/Yara-Rules/rules/blob/master/crypto/crypto_signatures.yar listed in the osquery docs https://osquery.readthedocs.io/en/stable/deployment/yara/#continuous-monitoring-using-the-yara_events-table is ~76KB.

Eventually if customers/users need bigger rules we can migrate and store them in S3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file.

rules, ok := asMap["yara_rules"]
if !ok {
// yara_rules is not present
return nil, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return []fleet.YaraRuleSpec{}, nil

GitOps mode is so that if it's not defined or set then the settings are removed/cleared.

That is,

org_settings:

(without putting yara_rules:) should also clear yara rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants