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

macOS: fix EndpointSecurity FIM mute inversion for file paths #8166

Merged
merged 1 commit into from
Oct 22, 2023

Conversation

sharvilshah
Copy link
Member

@sharvilshah sharvilshah commented Oct 19, 2023

Slack conversation: https://osquery.slack.com/archives/C08VA3XQU/p1697483297449949

tl;dr: the bug was that we were inadvertently calling the ES mute inversion APIs on each config refresh, causing us to actually lose the mute inversion for file paths and cause a surge of events.

The fix is to check the ES mute inversion state, and call those APIs only if we are not currently "mute inverted" ( in ES parlance ES_MUTE_NOT_INVERTED). This essentially gates the existing code with:

if (es_muting_inverted(es_file_client_, ES_MUTE_INVERSION_TYPE_TARGET_PATH) == ES_MUTE_NOT_INVERTED) {
...
}

@sharvilshah
Copy link
Member Author

closing and reopening to trigger latest CI

@sharvilshah sharvilshah reopened this Oct 20, 2023
Copy link
Member

@Smjert Smjert left a comment

Choose a reason for hiding this comment

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

A part from the inversion logic, something else I noticed is that the flags we are using here, are only evaluated once, when the publisher starts (which basically means when osquery starts).

I would define those as CLI_FLAG instead of FLAG to reflect that.

EDIT: Nevermind, I noticed things late and what I suggested is a breaking change. Nonetheless I think that we should remember to mark flags whose effect cannot (or must not) change at runtime as CLI_FLAG to reflect that to users.

@Smjert
Copy link
Member

Smjert commented Oct 21, 2023

@directionless sorry if I caused confusion, but when I wrote "this is a breaking change" I meant my suggestion, not the PR here.

@sharvilshah
Copy link
Member Author

@directionless I don't think this is a breaking/API change, so I am removing that label. Please feel free to add it if you think it requires one.

@sharvilshah sharvilshah added bug macOS events Related to osquery's evented tables or eventing subsystem ready for review Pull requests that are ready to be reviewed by a maintainer and removed API change labels Oct 22, 2023
Copy link
Member

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I'm not really following this, and I haven't absorbed this PR (pr the feature it's adjusting) but the conversation here makes me think you're dealing with cases around config changes and how it impacts the FIM subscriptions and mutes. Yes? If so, that leads me to questions... I won't be offended if I'm offbase, or y'all have covered/dismissed/whatever this direction.

  1. Is the underlying issue that unrelated config changes causes spurious reprocessing of the FIM directives, which then cause things to get messed up?
  2. Or that reprocessing the FIM directives is hard because of how it's layered together?
  3. both?

I think one way to address (1) would be to keep some hash of the FIM config and early return if it's unchanged. This wouldn't address (2) but it might be part of it.

If I think about that kind of complex processing, I think it's very hard to do stateless. I'd end up tracking state, so that subsequent config parses could correlate with the state of what's already configured.

@Smjert
Copy link
Member

Smjert commented Oct 22, 2023

I'm not really following this, and I haven't absorbed this PR (pr the feature it's adjusting) but the conversation here makes me think you're dealing with cases around config changes and how it impacts the FIM subscriptions and mutes. Yes? If so, that leads me to questions... I won't be offended if I'm offbase, or y'all have covered/dismissed/whatever this direction.

1. Is the underlying issue that unrelated config changes causes spurious reprocessing of the FIM directives, which then cause things to get messed up?

2. Or that reprocessing the FIM directives is hard because of how it's layered together?

3. both?

I think one way to address (1) would be to keep some hash of the FIM config and early return if it's unchanged. This wouldn't address (2) but it might be part of it.

If I think about that kind of complex processing, I think it's very hard to do stateless. I'd end up tracking state, so that subsequent config parses could correlate with the state of what's already configured.

At every config refresh osquery calls the configure function of a publisher. Publishers for FIM normally parse the file_paths config and re-apply it.
This is what this feature was originally attempting to do; due to issues with how the ES API works and how they were used, it was incorrectly inverting the filtering, basically filtering nothing.

The PR here fixes that behavior making so that the inversion happens only once (the inversion is necessary because you don't have 2 APIs, one for including a path and another for excluding it, so you need to use es_mute_path to do both, but for one of the two behaviors you need to call another API to invert the es_mute_path behavior).

This was working ok, but what I noticed was that we were not reacting to file_paths changes anymore. Then there has been some confusion on my part on the intentions, and now we are back to the original state of this PR, because Sharvil would like to address the "reacting to file_paths changes" later.

So no, the issue was not detecting when things change, but what and how to apply it correctly.

EDIT: Also to be extra clear, this is not a regression on some behavior that was present in previous releases. The support for file_paths has been added in this release; simply it will not be full featured.

Copy link
Member

@Smjert Smjert left a comment

Choose a reason for hiding this comment

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

As discussed I think this is acceptable, improvements (reacting to file_paths changes) will come in another PR.

I'm approving but lets leave @directionless time to look at it.

@directionless
Copy link
Member

If you two are happy, I don't feel like I need to stick my nose in. I'll merge

@directionless directionless merged commit 9db9952 into osquery:master Oct 22, 2023
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug events Related to osquery's evented tables or eventing subsystem macOS ready for review Pull requests that are ready to be reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants