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

Migrate privilege/role/user-related operations to a new Elasticsearch client. #84641

Merged
merged 4 commits into from
Dec 4, 2020

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Dec 1, 2020

We should eventually remove all dependencies on the Legacy ES Client, and in this PR I migrated all privilege/role/user-related operations to use a new ES client.

Related to: #83910

@azasypkin azasypkin added chore Feature:New Platform Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 v7.11.0 labels Dec 1, 2020
@azasypkin azasypkin force-pushed the issue-xxx-new-es-client-2 branch from f0b6ff0 to 2104689 Compare December 1, 2020 14:42
@azasypkin azasypkin changed the title Migrate privilege-related methods to a new Elasticsearch client. Migrate privilege/role/user-related operatiosn to a new Elasticsearch client. Dec 1, 2020
@azasypkin azasypkin force-pushed the issue-xxx-new-es-client-2 branch from 2104689 to 9c981cd Compare December 2, 2020 15:51
@azasypkin azasypkin marked this pull request as ready for review December 2, 2020 17:55
@azasypkin azasypkin requested a review from a team as a code owner December 2, 2020 17:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@azasypkin azasypkin added the release_note:skip Skip the PR/issue when compiling release notes label Dec 2, 2020
@azasypkin azasypkin changed the title Migrate privilege/role/user-related operatiosn to a new Elasticsearch client. Migrate privilege/role/user-related operations to a new Elasticsearch client. Dec 3, 2020
@azasypkin azasypkin requested a review from thomheymann December 3, 2020 15:40
Copy link
Contributor

@thomheymann thomheymann left a comment

Choose a reason for hiding this comment

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

One small nit but otherwise LGTM! 👍

@@ -47,9 +47,9 @@ export function checkPrivilegesWithRequestFactory(
: [];
const allApplicationPrivileges = uniq([actions.version, actions.login, ...kibanaPrivileges]);

const hasPrivilegesResponse = (await clusterClient
const { body: hasPrivilegesResponse } = await (await getClusterClient())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would try and avoid double await as it's quite hard to read and understand what's going on.

const startServicesPromise = core.getStartServices().then(([coreServices, depsServices]) => ({
elasticsearch: coreServices.elasticsearch,
features: depsServices.features,
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

I have no idea yet how we're going to solve this but I had to do the same for audit logging and it's a bit of an architectural smell. Lifecycles should flow in one direction. A lifecycle can certainly have access to a previous phase but not the other way around. If we need access to a start contract in the setup phase then either the setup contract we're depending on isn't exposing everything it should or the lifecycles themselves aren't really separate lifecycles.

Would love to start thinking about improving this. (Obviously not as part of this PR)

@elastic/kibana-core Are you guys aware this is happening throughout the codebase? Any ideas or plans how this situation could be avoided in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a bit of an architectural smell.

It's! And one of the main reasons why we still use this "trick", in Security at least, is that we need all of that stuff in the HTTP routes and we can only register them at the setup stage right now. Would definitely love to get rid of this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you guys aware this is happening throughout the codebase?

We are.

Any ideas or plans how this situation could be avoided in the future?

Using context-based wrapper around all APIs that might require start contract when registered in setup would be a solution. (such as what is done with RouteHandlerContext for http handler for example). This is some heavy code restructuring though, and is not planned atm.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@azasypkin azasypkin merged commit 0a42b65 into elastic:master Dec 4, 2020
@azasypkin azasypkin deleted the issue-xxx-new-es-client-2 branch December 4, 2020 13:24
azasypkin added a commit to azasypkin/kibana that referenced this pull request Dec 4, 2020
@azasypkin
Copy link
Member Author

7.x/7.11.0: b710b81

jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 4, 2020
…fields

* 'master' of github.com:elastic/kibana:
  [ILM] Fix delete phase serialization bug (elastic#84870)
  chore(NA): removes auto install of pre-commit hook (elastic#83566)
  chore(NA): upgrade node-sass into last v4.14.1 to stop shipping old node-gyp (elastic#84935)
  [Alerting] Enables AlertTypes to define the custom recovery action groups (elastic#84408)
  [ML] Functional tests - add missing test data cleanup (elastic#84998)
  Migrate privilege/role/user-related operations to a new Elasticsearch client. (elastic#84641)

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants