Skip to content

[Fleet][Endpoint][RBAC V2] Update fleet router and config to allow API access via RBAC controls#145361

Merged
ashokaditya merged 68 commits intoelastic:mainfrom
ashokaditya:task/olm-policy-list-api-rbac-4926
Dec 14, 2022
Merged

[Fleet][Endpoint][RBAC V2] Update fleet router and config to allow API access via RBAC controls#145361
ashokaditya merged 68 commits intoelastic:mainfrom
ashokaditya:task/olm-policy-list-api-rbac-4926

Conversation

@ashokaditya
Copy link
Member

@ashokaditya ashokaditya commented Nov 16, 2022

Summary

Note

This PR is adding changes only to some of api/fleet/package_policies
API routes, there will be subsequent PRs after this to update
api/fleet/epm/packages, api/fleet/agent_policeis and,
api/fleet/agent_status.

This PR introduces the framework needed in fleet in order to be able to
support Package level Privileges - meaning: if a user does not have
authorization granted via Fleet and/or Integration privileges, then
package level privileges are check and API access granted. When access
is granted based on Package Privileges, the data is also validated to
ensure that it is limited to the integration package names that were
given authorization to the API.

The following APIs were updated to leverage this new framework:

  • Integration Package Policy list API
  • Integration Package Policy get one API
  • Integration Package Policy update one API
  • Integration Package Policy bulk get API

ℹ️ these API were updated in support of Endpoint use cases needed for
v8.7.

Example of API error for Package policies api:

{
    "statusCode": 403,
    "error": "Forbidden",
    "message": "Authorization denied to [package.name=fleet_server]. Allowed package.name's: endpoint"
}

To test:

  1. Log in as elastic/superuser and create some agent policies.

  2. Under Stack Management, create a role policy_role with the
    following RBAC settings. DO NOT select Fleet -> All or toggle
    Integrations. Leave those RBAC toggles set to None
    Screenshot 2022-11-16 at 14 45 15

  3. Create a user e.g. policy_user and assign them only the above
    role. NOT superuser.

  4. Login with this user and navigate to
    app/security/administration/policy or curl/postman.

  5. Expect to see the following:

  • GET api/fleet/epm/packages?category=security should return a 403
    status.
  • GET
    api/fleet/package_policies?page=1&perPage=10&kuery=ingest-package-policies.package.name%3A%20endpoint
    should return a list of policies.
  • GET /api/fleet/package_policies/<packagePolicyId> should return a
    200 and a signle item that has the policie's details. Note that the
    package name of this item is endpoint.
  • there should be a POST API request matching
    api/fleet/agent_policies/_bulk_get, and should return a 403.
  1. With Policy Management RBAC set to All
  • PUT
    http://localhost:5601/api/fleet/package_policies/<packagePolicyId>
    should return a 200 with the updated policy details as response

Checklist

Co-authored-by: Paul Tavares paul.tavares@elastic.co

@ashokaditya ashokaditya self-assigned this Nov 16, 2022
@ashokaditya ashokaditya added Team:Defend Workflows “EDR Workflows” sub-team of Security Solution OLM Sprint 8.7 candidate release_note:feature Makes this part of the condensed release notes labels Nov 16, 2022
@ashokaditya ashokaditya force-pushed the task/olm-policy-list-api-rbac-4926 branch 9 times, most recently from 020caa1 to b29cd19 Compare November 21, 2022 14:02
@ashokaditya ashokaditya force-pushed the task/olm-policy-list-api-rbac-4926 branch 3 times, most recently from c01607f to b82e709 Compare November 23, 2022 07:43
gergoabraham added a commit that referenced this pull request Nov 23, 2022
## Summary

RBAC UI features for Trusted Applications. To test, enable
`endpointRbacEnabled` feature-flag, create a non-superuser user with
_Security: ALL_ privilege and (All | Read | None) sub-privilege for
_Trusted Applications_.
<img width="541" alt="image"
src="https://user-images.githubusercontent.com/39014407/203073992-fb71e293-2cd8-4639-8d61-4867e39ef071.png">

The modification should:
- hide Trusted Apps from Manage navigation items if privilege is NONE,
(note: it is still displayed for non-superusers, if the feature flag is
disabled)
- disable add/edit/delete for Trusted Applications if privilege is READ.

## ⚠️  Note
This PR focuses on _Read_ and _None_. The sub-privilege _All_ does not
work perfectly at the moment, because of unauthorised API calls. A
follow-up PR will fix this, after this PR is merged:
#145361

### Checklist

Delete any items that are not applicable to this PR.
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
@ashokaditya ashokaditya force-pushed the task/olm-policy-list-api-rbac-4926 branch 5 times, most recently from e2d3807 to e7a4db3 Compare November 29, 2022 12:38
@ashokaditya ashokaditya changed the title [Security Solution][Endpoint][RBAC V2] Policy list management RBAC v2 [Security Solution][Fleet][Endpoint][RBAC V2] Update fleet API route config to allow route access via RBAC controls Nov 29, 2022
@ashokaditya ashokaditya force-pushed the task/olm-policy-list-api-rbac-4926 branch from e7a4db3 to 7f5102a Compare November 29, 2022 13:30
@paul-tavares
Copy link
Contributor

@juliaElastic ,

Re:

Is the agent policy API going to filter out the package policies that do not belong to endpoint package?

I'm not sure yet about how this one should be implemented and it warrants some discussions. Our Endpoint use cases don't need update/create/delete access, so for us, it would be ok to filter out any package policy that does not match the authz package names. But for cases (in the future or for other integrations) where Update/Delete is needed, that gets more complicated.

@ashokaditya,
we need to explore each one of these individually and see if we can come up with good suggestions on the approach. We should use the tracking issues you created to expand upon this.

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

@ashokaditya ,
I took a look through and am good with the changes. I'm not going to approve it just because I worked with you on this. I'll defer approval to the Fleet team

@juliaElastic
Copy link
Contributor

The code looks good to me, I'll do a few manual tests locally before I approve.

@juliaElastic
Copy link
Contributor

juliaElastic commented Dec 14, 2022

I noticed something strange, I created a role that has access to Fleet:All and Integrations:Read, and I'm getting a permission denied error on Fleet/Agents screen.
The same role has access on the dev-oblt cluster, so might be a regression from this pr.

Though it might be a difference between environments, as the dev-oblt doesn't use the fleetServerSetup=true param in the check-permissions request

EDIT: seeing the same behavior on main branch, so it is not caused by this pr.

image

Copy link
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally with the endpoint role and existing fleet/integrations role

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@ashokaditya ashokaditya enabled auto-merge (squash) December 14, 2022 14:26
@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 923 922 -1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fleet 120.8KB 120.8KB +1.0B
Unknown metric groups

API count

id before after diff
fleet 1028 1027 -1

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 61 67 +6
osquery 109 115 +6
securitySolution 445 451 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 70 76 +6
osquery 110 117 +7
securitySolution 521 527 +6
total +21

History

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

cc @ashokaditya

@ashokaditya ashokaditya merged commit b1a75ae into elastic:main Dec 14, 2022
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Dec 14, 2022
jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 14, 2022
* main: (21 commits)
  [Profiling] Remove link to 'Other' bucket (elastic#147523)
  [Synthetics UI] Add missing configuration options to the add/edit monitor forms (elastic#147265)
  [DOCS] Updates what's new pages (elastic#147483)
  [Fleet][Endpoint][RBAC V2] Update fleet router and config to allow API access via RBAC controls (elastic#145361)
  [Guided onboarding] Update guide IDs (elastic#147348)
  [Synthetics] Add synthetics settings alerting default (elastic#147339)
  [Security Solution][Endpoint] Fix Policy form being displayed as Read Only when displayed in Fleet pages (elastic#147212)
  [Cases] Save draft user comment (elastic#146327)
  [API Docs] Fix `--plugin` filter (elastic#147500)
  [Fleet] added a logic to use `destinationId` when tagging imported SOs (elastic#147439)
  Do not skip UPDATE_TARGET_MAPPINGS if upgrading to a newer stack version (elastic#147503)
  [Discover] Validate if Data View time field exists on Alert creation / editing (elastic#146324)
  [Discover] Fix Discover navigation from Lens embeddable (elastic#147000)
  Allow users to Update API Keys (elastic#146237)
  Update dependency xstate to ^4.35.0 (main) (elastic#147463)
  [Behavioral Analytics] Remove feature flag to hide functionality (elastic#147429)
  [Fleet] Add agent policy `inactivity_timeout`experimental setting (elastic#147432)
  [APM] Switching service groups from grid to flex layout (elastic#147448)
  [Fleet] Add missing endpoints to openApi specs (elastic#147452)
  [AO] Allow providing custom time range for Alert Summary Widget (elastic#147253)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting OLM Sprint release_note:feature Makes this part of the condensed release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution Team:Fleet Team label for Observability Data Collection Fleet team v8.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants