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 secondary authorization header to Transforms in Fleet #154665

Merged
merged 25 commits into from
Apr 20, 2023

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Apr 10, 2023

Summary

The PR updates how credentials are created and managed for packages including Transforms. Previously, everything will be installed as kibana_system user, which has limited permissions to a specific set of indices defined internally. This PR changes so that a secondary authorization is passed to the creation of Transforms, making the permissions/privileges dependent on the logged-in user.

Installing a package containing transforms

  • If the package has transforms assets to be installed, it will show warning/info call out message indicating that the transforms will be created and started with the current user's credentials/roles.
    Screen Shot 2023-04-11 at 17 45 58
    Screen Shot 2023-04-11 at 17 46 03

-It will parse the authorization header (schema and credentials) from the Kibana request to the package handlers.

  • If the package contains transforms, and if run_as_kibana_system: false in the any of the transform yml config , then generate an API key from the above credential (as that Kibana user with the roles and permissions at the time of generation), and use it in transform/_put requests.
  • If user has sufficient permissions:
    • Transforms will be successfully created and started. They will be marked in the saved object reference with deferred: false

    • Transform _meta will have installed_by: {username}
      Screen Shot 2023-04-11 at 14 11 43

    • Package will be successfully installed

  • If user has insufficient permissions:
    • Transforms will be successfully created, but fail to start. They will be marked in the saved object reference with deferred: true
    • Package will still be successfully installed. It will show warning that the package has some deferred installations.

Deferred installations

If a package has deferred installations (a.k.a assets that were included in the package, but require additional permissions to operate correctly), it will:

  • Show a warning on the Installed integrations page:
    Screen Shot 2023-04-06 at 15 59 46

  • Show a warning badge with explanation on the tab:
    Screen Shot 2023-04-10 at 12 17 26

  • Show a new Deferred installations section as well as call out message to prompt user to re-authorize inside the Assets tab:
    Screen Shot 2023-04-06 at 15 59 09

If the currently logged-in user has sufficient permissions (manage_transform ES cluster privilege/transform_admin Kibana role), the Reauthorize buttons will be enabled:

Screen Shot 2023-04-10 at 12 24 18

Reauthorizing installations

  • For transforms:

    • Clicking the Reauthorize button will send an _transform/_update API request with a headers: {es-secondary-authorization: 'ApiKey {encoded_api}' and then a _transform/_start to start operations.
    • Transform _meta will be updated with addition of last_authorized_by: {username}
    Screen Shot 2023-04-11 at 14 12 38
    • If order is specified in _meta of the transform, they will be updated and started sequentially. Else, they will be executed concurrently.

Reviewers note:

-For kibana-core: saved object for Fleet's EsAsset was extended with deferred: boolean, thus changing the hash.

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 changed the title [ML] Add secondary authorization header to Transforms in Fleet [ML] Adds secondary authorization header to Transforms in Fleet Apr 10, 2023
@qn895 qn895 force-pushed the ml-fleet-2nd-auth branch from 5c5f862 to 4086164 Compare April 10, 2023 20:02
@qn895 qn895 force-pushed the ml-fleet-2nd-auth branch from 4086164 to 605b27b Compare April 10, 2023 20:09
Copy link
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

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

Minor suggestions, otherwise UI text LGTM

@qn895 qn895 force-pushed the ml-fleet-2nd-auth branch from b4112ff to 5bb5690 Compare April 13, 2023 04:55
@qn895 qn895 marked this pull request as ready for review April 13, 2023 05:41
@qn895 qn895 requested review from a team as code owners April 13, 2023 05:41
@nchaulet
Copy link
Member

@qn895 Where I can found the hot risk score integration to test this locally?

@nchaulet
Copy link
Member

@qn895 I did some local tests and overall it seems to work well. I may have one suggestion one we click on reauthorize all it could be nice to reload the assets tab what do you think?

transformId: string;
}> | null>(null);

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: do we really need a useEffect here can we call an authorizeTransforms directly from the click events?

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 4e54dee (#154665)

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.

Tested locally and LGTM 🚀

Copy link
Contributor

@szabosteve szabosteve 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 suggestion, otherwise UI text LGTM!

'xpack.fleet.epm.packageDetails.assets.deferredTransformInstallationsDescription',
{
defaultMessage:
'{assetCount, plural, one {Transform was installed but requires} other {# transforms were installed but require}} additional permissions to run. You must have the transform_admin built-in role or manage_transform cluster privileges to start operations.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the discussion here, I suggest slightly modifying this message:

Suggested change
'{assetCount, plural, one {Transform was installed but requires} other {# transforms were installed but require}} additional permissions to run. You must have the transform_admin built-in role or manage_transform cluster privileges to start operations.',
'{assetCount, plural, one {Transform was installed but requires} other {# transforms were installed but require}} additional permissions to run. Contact your administrator to request the required privileges.',

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 4e54dee (#154665)

qn895 added 2 commits April 18, 2023 16:31
- Add comment to route
- Update settings to swallow error without blocking
- Remove redundant update/delete index alias code
- Better error handling, and scenario if security is not defined
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 package and LGTM

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.

Taking a second look I'm wondering if some of the warnings need changes?

@peteharverson peteharverson self-requested a review April 19, 2023 11:37
@hop-dev
Copy link
Contributor

hop-dev commented Apr 19, 2023

@qn895 Where I can found the hot risk score integration to test this locally?

@nchaulet @qn895 same question! I would like to test this locally if possible

@nchaulet
Copy link
Member

@hop-dev you can find the package here https://github.com/qn895/integrations/tree/host_risk_score_versioned

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.

Text changes for the warnings LGTM

Copy link
Contributor

@hop-dev hop-dev left a comment

Choose a reason for hiding this comment

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

Tested locally, looks good to me!

Were you able to test the scenario where the package is reinstalled as system user? Do we retain the previous auth header?


// Extended version of x-pack/plugins/security/server/authentication/http_authentication/http_authorization_header.ts
// to prevent bundle being required in security_solution
// FIXME: Put this in a package
Copy link
Contributor

Choose a reason for hiding this comment

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

For this FIXME comment do we have an issue for the fix? When do we expect to fix it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this FIXME for now as the file is modified from the original copy of security_solution's code 0187c5f (#154665)

count: number;
}> = ({ count }) => {
return (
<EuiCallOut color="primary">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think callouts should always have a title with an icon , check out the EUI examples https://elastic.github.io/eui/#/display/callout

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 0187c5f (#154665)

@@ -432,3 +450,60 @@ export const getVerificationKeyIdHandler: FleetRequestHandler = async (
return defaultFleetErrorHandler({ error, response });
}
};

/**
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 comments here 👍

@qn895
Copy link
Member Author

qn895 commented Apr 20, 2023

Were you able to test the scenario where the package is reinstalled as system user? Do we retain the previous auth header?

As discussed in Slack with you and Nicolas, I'll create a smaller follow-up PR to address force reinstallation of packages containing transforms with the new spec. Thanks all for your help testing and reviewing this PR 🥳

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
fleet 798 803 +5

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 998 1004 +6

Async chunks

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

id before after diff
fleet 945.5KB 954.9KB +9.4KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
fleet 27 28 +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 126.7KB 127.4KB +689.0B

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/saved-objects-service.html#_mappings

id before after diff
epm-packages 22 23 +1
Unknown metric groups

API count

id before after diff
fleet 1103 1109 +6

ESLint disabled line counts

id before after diff
fleet 49 48 -1
securitySolution 394 397 +3
total +2

Total ESLint disabled count

id before after diff
fleet 59 58 -1
securitySolution 474 477 +3
total +2

History

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

cc @qn895

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

LGTM

I'm happy to merge this and fix the inefficiency in a followup.

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 Team:Fleet Team label for Observability Data Collection Fleet team 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.