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

[Security Solution][Endpoint] Add API checks to Endpoint Policy create/update for checking endpointPolicyProtections is enabled #163429

Conversation

paul-tavares
Copy link
Contributor

Summary

  • Adds checks to both the Policy Create and Policy Update APIs (Fleet API extension points) and turns off all protections if endpointPolicyProtections appFeature is disabled
  • Adds migration of policies to the Plugin start() that will check if endpointPolicyProtections is disabled and updates all existing policies (if necessary) to disable protections.

Checklist

@paul-tavares paul-tavares added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.10.0 labels Aug 8, 2023
@paul-tavares paul-tavares self-assigned this Aug 8, 2023
@paul-tavares paul-tavares requested review from a team as code owners August 8, 2023 16:13
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

Copy link
Member

@joeypoon joeypoon left a comment

Choose a reason for hiding this comment

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

🙆‍♂️

Copy link
Contributor

@gergoabraham gergoabraham left a comment

Choose a reason for hiding this comment

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

looks great! added some thoughts and questions, please let me know what you think

Comment on lines 169 to 175
export const setPolicyToEventCollectionOnly = (policy: PolicyConfig): PolicyConfig => {
const updatedPolicy = disableProtections(policy);

set(updatedPolicy, 'windows.antivirus_registration.enabled', false);

return updatedPolicy;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering, if disableProtections() should have disabled windows.antivirus_registration.enabled in the first place. Its original goal was to prepare a policy for 'data collection only', see https://github.com/paul-tavares/kibana/blob/eff88cf671eaa498d2d894784e71ab0c795627cc/x-pack/plugins/security_solution/server/fleet_integration/handlers/create_default_policy.ts#L134

I tested it, just created a 'Data collection only' policy, and it has antivirus registration disabled, so I think I accidentally left it out from disableProtections().

what do you think? if you agree, could you add it there? and then there is no need for this function.

otherwise, I suggest another name for this function, because it does not set a policy to event collection only as it doesn't enable any event collection, just disabled protections and antivirus registration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I was not sure about that - thus why I created this one to set it explicitly. I am not familiar with what hte requirement might have been for your other PR, but I would check with Caitlyn and if in fact it should have been disabled in the first place, then we can just add it to disableProtections()

can we maybe follow up on this in a subsequent PR?

Re: name
Yeah you are right. The only reason I named it this way because the Antivirus entry is not a protection. I can change it to ensureOnlyEventCollectionIsAllowed()?? what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the rename, sounds good!

I've created a follow-up issue for this: https://github.com/elastic/security-team/issues/7323, so we can discuss it during grooming

const isEnabled = currentValue !== disableValue;

if (isEnabled) {
message = `property [${fullKeyPathForOs}] is set to [${currentValue}]`;
Copy link
Contributor

Choose a reason for hiding this comment

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

q: do we want to maybe return all protections that are enabled, instead of the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but I was trying to just exit the function as soon as possible rather than to loop through all of them.

});

total = totalPolicies;
hasMoreData = items.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

this causes one additional call for packagePolicy.list() returning zero items. to avoid this, total could be used

update: I see you even have mocks prepared in the tests for the additional call. is it maybe intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its just another way to ensure all policies are covered case policies are added as this function is running. I think I might have picked up this approach from code I saw in fleet.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for nitpicking, but a small optimisation for keeping the startup time a bit lower is still an optimisation. I still don't think the extra fetch is needed, because if a new policy added at this point, it will go through the checks that ensure that no protections are enabled.

(what I don't know: is it even possible for policies to be added during Plugin.start()?)

in case it is possible and the checks are not in place when adding: I think the extra fetch still wouldn't help, only maybe for every N-thousand-and-first-some policies, while still possibly skipping the previous N-thousand minus-some policies (e.g. if the 3992...4016th policies were added after fetching the 4th page, 3992...4000th policies are skipped)

///

independently of the extra fetch, sortOrder: 'asc' and sortField: 'createdAt' should be added to the options for packagePolicy.list() as the default is descending by updated_at.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll make the change to ensure we don't make the additional API call

👍

x-pack/plugins/security_solution/server/plugin.ts Outdated Show resolved Hide resolved
…-for-serverless-policy-protections' into task/olm-7232-api-policy-watcher-for-serverless-policy-protections
Copy link
Contributor

@gergoabraham gergoabraham left a comment

Choose a reason for hiding this comment

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

Thanks for the modifications!

I've extended my nitpicking, but other than that, looks great! 💯

@paul-tavares paul-tavares enabled auto-merge (squash) August 11, 2023 12:26
@paul-tavares paul-tavares merged commit 27c394c into elastic:main Aug 11, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #51 / Index Management app Index template wizard Mappings step "before each" hook for "clearing up the Numeric subtype dropdown doesn't break the page"

Metrics [docs]

Unknown metric groups

ESLint disabled in files

id before after diff
securitySolution 63 64 +1

Total ESLint disabled count

id before after diff
securitySolution 527 528 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @paul-tavares

@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 11, 2023
@paul-tavares paul-tavares deleted the task/olm-7232-api-policy-watcher-for-serverless-policy-protections branch August 11, 2023 13:33
jloleysens added a commit to jloleysens/kibana that referenced this pull request Aug 11, 2023
* main: (64 commits)
  [ML] Transforms: Fix privileges check. (elastic#163687)
  [Log Explorer] Add test suite for Dataset Selector (elastic#163079)
  [Security Solution][Endpoint] Add API checks to Endpoint Policy create/update for checking `endpointPolicyProtections` is enabled (elastic#163429)
  [Security Solution] Fix flaky test: x-pack/test/detection_engine_api_integration/security_and_spaces/update_prebuilt_rules_package/update_prebuilt_rules_package·ts - update_prebuilt_rules_package should allow user to install prebuilt rules from scratch, then install new rules and upgrade existing rules from the new package (elastic#163241)
  [Security Solution] expandable flyout - replace feature flag with advanced settings toggle (elastic#161614)
  [DOCS] Adds the release notes for the 8.9.1 release. (elastic#163578)
  [FTR] Implement browser network condition utils (elastic#163633)
  [Security Solution] Unskip rules table auto-refresh Cypress tests (elastic#163451)
  [Security Solution] Re-enable fixed rule snoozing Cypress test (elastic#160037)
  [Flaky Test elastic#111821] Mock `moment` to avoid midnight TZ issues (elastic#163157)
  Document interactive setup (elastic#163619)
  [Lens] Align decoration color with text color for layer actions (elastic#163630)
  [Lens] Relax counter field checks for saved visualizations with unsupported operations (elastic#163515)
  [Security Solution][Endpoint] Removes pMap and uses a for loop instead (elastic#163509)
  [Enterprise Search] Update Workplace Search connectors doclink (elastic#163676)
  Update APM (main) (elastic#163623)
  [Serverless] Partially fix lens/maps/visualize breadcrumbs missing title  (elastic#163476)
  [Flaky elastic#118272] Unskip tests (elastic#163319)
  [APM] Make service group saved objects exportable (elastic#163569)
  [Observability AI Assistant] Action menu item (elastic#163463)
  ...
benakansara pushed a commit to benakansara/kibana that referenced this pull request Aug 14, 2023
…e/update for checking `endpointPolicyProtections` is enabled (elastic#163429)

## Summary

- Adds checks to both the Policy Create and Policy Update APIs (Fleet
API extension points) and turns off all protections if
`endpointPolicyProtections` appFeature is disabled
- Adds migration of policies to the Plugin `start()` that will check if
`endpointPolicyProtections` is disabled and updates all existing
policies (if necessary) to disable protections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants