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] Initiate endpoint package upgrade from security app #77498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1a3506e
Working on package update functionality
jonathan-buttner Sep 14, 2020
5d39443
Correctly installing package
jonathan-buttner Sep 15, 2020
5c3a58f
Moving upgrade component and working upgrade
jonathan-buttner Sep 15, 2020
ebaae00
Doing permissions check
jonathan-buttner Sep 15, 2020
dc9303d
Cleaning up imports
jonathan-buttner Sep 15, 2020
3667f85
Merge branch 'master' of github.com:elastic/kibana into upgrade-endpo…
jonathan-buttner Sep 16, 2020
76df74d
Adding bulk upgrade api
jonathan-buttner Sep 17, 2020
6dea606
Addressing comments
jonathan-buttner Sep 18, 2020
268c526
Removing todo
jonathan-buttner Sep 18, 2020
04a39bd
Resolving conflicts
jonathan-buttner Sep 18, 2020
f3d3979
Merge branch 'master' of github.com:elastic/kibana into upgrade-endpo…
jonathan-buttner Sep 18, 2020
8eb2cea
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner Sep 18, 2020
f111406
Changing body field
jonathan-buttner Sep 18, 2020
5e19070
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner Sep 18, 2020
2846b76
Adding helper for getting the bulk install route
jonathan-buttner Sep 18, 2020
3fffaef
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner Sep 18, 2020
20357fd
Adding request spec
jonathan-buttner Sep 18, 2020
ff0cbce
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner Sep 18, 2020
810b203
Using bulk install endpoint from ingest
jonathan-buttner Sep 18, 2020
3c400fe
Resolving conflicts
jonathan-buttner Sep 22, 2020
b8a9fc7
Moving component to a hook
jonathan-buttner Sep 24, 2020
44c32d9
Fixing merge conflicts
jonathan-buttner Sep 24, 2020
46699bd
Pulling changes from master
jonathan-buttner Sep 28, 2020
fedc630
Addressing feedback
jonathan-buttner Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions x-pack/plugins/security_solution/public/app/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useInitSourcerer, useSourcererScope } from '../../common/containers/sou
import { useKibana } from '../../common/lib/kibana';
import { DETECTIONS_SUB_PLUGIN_ID } from '../../../common/constants';
import { SourcererScopeName } from '../../common/store/sourcerer/model';
import { useUpgradeEndpointPackage } from '../../common/hooks/endpoint/upgrade';
import { useThrottledResizeObserver } from '../../common/components/utils';

const Main = styled.main.attrs<{ paddingTop: number }>(({ paddingTop }) => ({
Expand Down Expand Up @@ -58,6 +59,12 @@ const HomePageComponent: React.FC<HomePageProps> = ({ children }) => {
const [showTimeline] = useShowTimeline();

const { browserFields, indexPattern, indicesExist } = useSourcererScope();
// side effect: this will attempt to upgrade the endpoint package if it is not up to date
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Elaborating to explain when/how often that will happen and why may be helpful to the reader.

// this will run when a user navigates to the Security Solution app and when they navigate between
// tabs in the app. This is useful for keeping the endpoint package as up to date as possible until
// a background task solution can be built on the server side. Once a background task solution is available we
// can remove this.
useUpgradeEndpointPackage();

return (
<SecuritySolutionAppWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { useEffect } from 'react';
import { HttpFetchOptions, HttpStart } from 'src/core/public';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import {
epmRouteService,
appRoutesService,
CheckPermissionsResponse,
BulkInstallPackagesResponse,
} from '../../../../../ingest_manager/common';
import { StartServices } from '../../../types';
import { useIngestEnabledCheck } from './ingest_enabled';

/**
* Requests that the endpoint package be upgraded to the latest version
*
* @param http an http client for sending the request
* @param options an object containing options for the request
*/
const sendUpgradeEndpointPackage = async (
http: HttpStart,
options: HttpFetchOptions = {}
): Promise<BulkInstallPackagesResponse> => {
return http.post<BulkInstallPackagesResponse>(epmRouteService.getBulkInstallPath(), {
...options,
body: JSON.stringify({
packages: ['endpoint'],
}),
});
};

/**
* Checks with the ingest manager if the current user making these requests has the right permissions
* to install the endpoint package.
*
* @param http an http client for sending the request
* @param options an object containing options for the request
*/
const sendCheckPermissions = async (
http: HttpStart,
options: HttpFetchOptions = {}
): Promise<CheckPermissionsResponse> => {
return http.get<CheckPermissionsResponse>(appRoutesService.getCheckPermissionsPath(), {
...options,
});
};

export const useUpgradeEndpointPackage = () => {
const context = useKibana<StartServices>();
const { allEnabled: ingestEnabled } = useIngestEnabledCheck();

useEffect(() => {
const abortController = new AbortController();

// cancel any ongoing requests
const abortRequests = () => {
abortController.abort();
};

if (ingestEnabled) {
const signal = abortController.signal;

(async () => {
try {
// make sure we're a privileged user before trying to install the package
const { success: hasPermissions } = await sendCheckPermissions(context.services.http, {
signal,
});

// if we're not a privileged user then return and don't try to check the status of the endpoint package
if (!hasPermissions) {
return abortRequests;
}

// ignore the response for now since we aren't notifying the user
await sendUpgradeEndpointPackage(context.services.http, { signal });
} catch (error) {
// Ignore Errors, since this should not hinder the user's ability to use the UI

// ignore the error that occurs from aborting a request
if (!abortController.signal.aborted) {
// eslint-disable-next-line no-console
console.error(error);
}
}

return abortRequests;
})();
}
}, [ingestEnabled, context.services.http]);
};