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

[ML] Adds option to Reauthorize transform in Management page #154736

Merged
merged 24 commits into from
Apr 20, 2023

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Apr 11, 2023

Summary

Part of #151186. Follow up of #154665. This PR adds the ability to Reauthorize transforms with a secondary authorization so that it can start operating correctly.

If the transform was originally created with insufficient permission

  • It will be created successfully, but fail to start, and show a warning:

Screen Shot 2023-04-20 at 09 41 00

  • It will show an option to Reauthorize transform for both individual and bulk:
    Screen Shot 2023-04-11 at 21 00 03
    Screen Shot 2023-04-11 at 21 00 49
    Screen Shot 2023-04-11 at 21 00 37

  • Reauthorizing transform will create an API key using the user's credential, call transform/_update with the es-secondary-authorization: 'ApiKey {encoded_api_key} in the headers, and start the transform.

If the transform was originally created with sufficient permission:

  • No Reauthorize option will be shown:
    Screen Shot 2023-04-10 at 22 16 26

This PR also updates the behavior of the tooltip message when a bulk action should be disabled.
Screen Shot 2023-04-11 at 21 02 11

WIP:

  • API integration test
  • Functional test (follow up PR)

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@qn895 qn895 self-assigned this Apr 11, 2023
@qn895
Copy link
Member Author

qn895 commented Apr 12, 2023

@elasticmachine merge upstream

@qn895 qn895 marked this pull request as ready for review April 12, 2023 14:07
@qn895 qn895 requested a review from a team as a code owner April 12, 2023 14:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@lcawl lcawl added the ui-copy Review of UI copy with docs team is recommended label Apr 12, 2023

export function isTransformApiKey(arg: any): arg is TransformAPIKey {
return (
arg &&
Copy link
Contributor

Choose a reason for hiding this comment

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

You could do isPopulated(arg, ['api_key', 'encoded']) && typeof arg.encoded === string here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 3f64b1f (#154736)

@@ -295,6 +303,66 @@ export function registerTransformsRoutes(routeDependencies: RouteDependencies) {
)
);

/**
* @apiGroup Reauthorize transforms with API key generated from currently logged in suer
Copy link
Contributor

Choose a reason for hiding this comment

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

Type suer -> user

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 3f64b1f (#154736)

@@ -5,14 +5,14 @@
* 2.0.
*/

import type { IRouter, CoreStart } from '@kbn/core/server';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep the type exports here or is there a reason to remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 3f64b1f (#154736)

'xpack.transform.transformList.needsReauthorizationBadgeTooltip',
{
defaultMessage:
'This transform was created with insufficient permissions. You must have manage_transform cluster privileges to reauthorize and start it.',
Copy link
Contributor

Choose a reason for hiding this comment

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

@szabosteve @lcawl is it common practice to mention specific cluster privileges that are required? Wondering as in other places we aren't so specific:

image

Copy link
Contributor

@szabosteve szabosteve Apr 17, 2023

Choose a reason for hiding this comment

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

After a quick check, I found that although we rarely mention specific cluster privileges in the UI, there is precedent for doing it, for example in the APM app when you don't have the correct privileges to create anomaly detection jobs. While there is precedent, I would go without mentioning the privileges specifically. The docs mention the correct privileges and we consider them as the source of truth, so it might make sense to keep only the docs up-to-date – even if the name of the privileges is unlikely to change.
@peteharverson @lcawl WDYT?

Suggested change
'This transform was created with insufficient permissions. You must have manage_transform cluster privileges to reauthorize and start it.',
'This transform was created with insufficient permissions. Contact your administrator to request the required privileges.',

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to your suggestion @szabosteve to not mention the privileges specifically.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here (1a8969a)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that's even better, thanks!

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested with your example Host Risk Score packages and overall looks good.

A couple of the warning messages probably need a further edit.

'xpack.transform.transformList.needsReauthorizationBadgeTooltip',
{
defaultMessage:
'This transform was created with insufficient permissions. Contact your administrator to request the required privileges.',
Copy link
Contributor

Choose a reason for hiding this comment

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

This message should be adjusted if logging in as a user with the correct permissions, otherwise it gives the impression that the current user does not have the required permissions.

Something along the lines of

This transform was installed by a user who did not have the permissions required to run it. Select Reauthorize in the Actions menu to reauthorize.

(too many 'reauthorize's! Any suggestions @szabosteve ?

Copy link
Contributor

@szabosteve szabosteve Apr 19, 2023

Choose a reason for hiding this comment

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

How about This transform was installed by a user who did not have the permissions required to run it. Reauthorize it in the Actions menu.?

In the case of the user without proper permissions, I propose to use the following: This transform was created with insufficient permissions. Contact your administrator to request the required permissions. So we can use a single term instead of permissions and privileges.

(I don't use suggesting mode because it would be more confusing.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 1775dd0 (#154736)

For when user has permissions:
Screen Shot 2023-04-19 at 15 54 01

color="warning"
title={i18n.translate('xpack.transform.transformList.unauthorizedTransformsCallout', {
defaultMessage:
'{unauthorizedCnt, plural, one {A transform was installed but requires more permissions to run.} other {# transforms were installed but require more permissions to run.}} Contact your administrator to request the required privileges.',
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, this message should be adjusted if logging back in as a user with the correct permissions.

Nit - the text refers to both 'permissions' and 'privileges'. Should we use a single term here @szabosteve?

Copy link
Contributor

@szabosteve szabosteve Apr 19, 2023

Choose a reason for hiding this comment

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

We can use the same string as above if the user has correct permissions: A transform was installed by a user who did not have the permissions required to run it. Reauthorize it in the Actions menu.

In the case of the user without proper permissions, I propose to use the following: This transform was created with insufficient permissions. Contact your administrator to request the required permissions. So we can use a single term instead of permissions and privileges.

(I don't use suggesting mode because it would be more confusing.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 1775dd0 (#154736)

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Latest text edits LGTM.

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Latest changes code LGTM.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
transform 318 325 +7

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
transform 376.3KB 383.0KB +6.8KB
Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 394 397 +3

Total ESLint disabled count

id before after diff
securitySolution 474 477 +3

History

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

cc @qn895

@qn895 qn895 merged commit dd46350 into elastic:main Apr 20, 2023
@qn895 qn895 deleted the ml-transform-management-reauthorize branch April 20, 2023 18:16
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 20, 2023
@szabosteve szabosteve changed the title [ML] Add option to Reauthorize transform in Management page [ML] Adds option to Reauthorize transform in Management page Apr 21, 2023
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 Feature:Transforms ML transforms :ml release_note:enhancement ui-copy Review of UI copy with docs team is recommended v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants