Skip to content

Commit

Permalink
[Osquery] Fix support for disabled security (#110547)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski authored Sep 6, 2021
1 parent 907a340 commit 4416a31
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 115 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"react-moment-proptypes": "^1.7.0",
"react-monaco-editor": "^0.41.2",
"react-popper-tooltip": "^2.10.1",
"react-query": "^3.21.0",
"react-query": "^3.21.1",
"react-redux": "^7.2.0",
"react-resizable": "^1.7.5",
"react-resize-detector": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@
*/

import { useQuery } from 'react-query';

import { i18n } from '@kbn/i18n';
import { useKibana } from '../common/lib/kibana';
import { useErrorToast } from '../common/hooks/use_error_toast';

export const useActionResultsPrivileges = () => {
const { http } = useKibana().services;
const setErrorToast = useErrorToast();

return useQuery(
['actionResultsPrivileges'],
() => http.get('/internal/osquery/privileges_check'),
{
keepPreviousData: true,
select: (response) => response?.has_all_requested ?? false,
onSuccess: () => setErrorToast(),
onError: (error: Error) =>
setErrorToast(error, {
title: i18n.translate('xpack.osquery.action_results_privileges.fetchError', {
defaultMessage: 'Error while fetching action results privileges',
}),
}),
}
);
};
2 changes: 0 additions & 2 deletions x-pack/plugins/osquery/public/common/page_paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export interface DynamicPagePathValues {
[key: string]: string;
}

export const BASE_PATH = '/app/fleet';

// If routing paths are changed here, please also check to see if
// `pagePathGetters()`, below, needs any modifications
export const PAGE_ROUTING_PATHS = {
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/osquery/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

/* eslint-disable react-hooks/rules-of-hooks */

import React, { useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiTabs, EuiTab } from '@elastic/eui';
Expand All @@ -14,10 +16,17 @@ import { Container, Nav, Wrapper } from './layouts';
import { OsqueryAppRoutes } from '../routes';
import { useRouterNavigate } from '../common/lib/kibana';
import { ManageIntegrationLink } from './manage_integration_link';
import { useOsqueryIntegrationStatus } from '../common/hooks';
import { OsqueryAppEmptyState } from './empty_state';

const OsqueryAppComponent = () => {
const location = useLocation();
const section = useMemo(() => location.pathname.split('/')[1] ?? 'overview', [location.pathname]);
const { data: osqueryIntegration, isFetched } = useOsqueryIntegrationStatus();

if (isFetched && osqueryIntegration.install_status !== 'installed') {
return <OsqueryAppEmptyState />;
}

return (
<Container>
Expand Down
86 changes: 86 additions & 0 deletions x-pack/plugins/osquery/public/components/empty_state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { useCallback, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButton } from '@elastic/eui';

import { KibanaPageTemplate } from '../../../../../src/plugins/kibana_react/public';
import { INTEGRATIONS_PLUGIN_ID } from '../../../fleet/common';
import { pagePathGetters } from '../../../fleet/public';
import { isModifiedEvent, isLeftClickEvent, useKibana } from '../common/lib/kibana';
import { OsqueryIcon } from './osquery_icon';
import { useBreadcrumbs } from '../common/hooks/use_breadcrumbs';
import { OSQUERY_INTEGRATION_NAME } from '../../common';

const OsqueryAppEmptyStateComponent = () => {
useBreadcrumbs('base');

const {
application: { getUrlForApp, navigateToApp },
} = useKibana().services;

const integrationHref = useMemo(() => {
return getUrlForApp(INTEGRATIONS_PLUGIN_ID, {
path: pagePathGetters.integration_details_overview({
pkgkey: OSQUERY_INTEGRATION_NAME,
})[1],
});
}, [getUrlForApp]);

const integrationClick = useCallback(
(event) => {
if (!isModifiedEvent(event) && isLeftClickEvent(event)) {
event.preventDefault();
return navigateToApp(INTEGRATIONS_PLUGIN_ID, {
path: pagePathGetters.integration_details_overview({
pkgkey: OSQUERY_INTEGRATION_NAME,
})[1],
});
}
},
[navigateToApp]
);

const pageHeader = useMemo(
() => ({
iconType: OsqueryIcon,
pageTitle: (
<FormattedMessage
id="xpack.osquery.emptyState.pageTitle"
defaultMessage="Add Osquery Manager"
/>
),
description: (
<FormattedMessage
id="xpack.osquery.emptyState.pageDescription"
defaultMessage="Add this integration to run and schedule queries for Elastic Agent."
/>
),
rightSideItems: [
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiButton
key="button"
fill
href={integrationHref}
onClick={integrationClick}
iconType="plusInCircleFilled"
>
<FormattedMessage
id="xpack.osquery.emptyState.addOsqueryManagerButton"
defaultMessage="Add Osquery Manager"
/>
</EuiButton>,
],
}),
[integrationClick, integrationHref]
);

return <KibanaPageTemplate isEmptyState={true} pageHeader={pageHeader} />;
};

export const OsqueryAppEmptyState = React.memo(OsqueryAppEmptyStateComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ const ManageIntegrationLinkComponent = () => {
const integrationHref = useMemo(() => {
if (osqueryIntegration) {
return getUrlForApp(INTEGRATIONS_PLUGIN_ID, {
path:
'#' +
pagePathGetters.integration_details_policies({
pkgkey: `${osqueryIntegration.name}-${osqueryIntegration.version}`,
})[1],
path: pagePathGetters.integration_details_policies({
pkgkey: `${osqueryIntegration.name}-${osqueryIntegration.version}`,
})[1],
});
}
}, [getUrlForApp, osqueryIntegration]);
Expand All @@ -39,11 +37,9 @@ const ManageIntegrationLinkComponent = () => {
event.preventDefault();
if (osqueryIntegration) {
return navigateToApp(INTEGRATIONS_PLUGIN_ID, {
path:
'#' +
pagePathGetters.integration_details_policies({
pkgkey: `${osqueryIntegration.name}-${osqueryIntegration.version}`,
})[1],
path: pagePathGetters.integration_details_policies({
pkgkey: `${osqueryIntegration.name}-${osqueryIntegration.version}`,
})[1],
});
}
}
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/osquery/public/live_queries/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const LiveQueryFormComponent: React.FC<LiveQueryFormProps> = ({
),
});

const { setFieldValue, submit } = form;
const { setFieldValue, submit, isSubmitting } = form;

const actionId = useMemo(() => data?.actions[0].action_id, [data?.actions]);
const agentIds = useMemo(() => data?.actions[0].agents, [data?.actions]);
Expand Down Expand Up @@ -185,7 +185,10 @@ const LiveQueryFormComponent: React.FC<LiveQueryFormProps> = ({
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiButton disabled={!agentSelected || !queryValueProvided} onClick={submit}>
<EuiButton
disabled={!agentSelected || !queryValueProvided || isSubmitting}
onClick={submit}
>
<FormattedMessage
id="xpack.osquery.liveQueryForm.form.submitButtonLabel"
defaultMessage="Submit"
Expand All @@ -196,13 +199,14 @@ const LiveQueryFormComponent: React.FC<LiveQueryFormProps> = ({
</>
),
[
agentSelected,
permissions.writeSavedQueries,
handleShowSaveQueryFlout,
queryComponentProps,
singleAgentMode,
permissions.writeSavedQueries,
agentSelected,
queryValueProvided,
resultsStatus,
singleAgentMode,
handleShowSaveQueryFlout,
isSubmitting,
submit,
]
);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/osquery/public/packs/common/add_pack_query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const AddPackQueryFormComponent = ({ handleSubmit }) => {
},
},
});
const { submit } = form;
const { submit, isSubmitting } = form;

const createSavedQueryMutation = useMutation(
(payload) => http.post(`/internal/osquery/saved_query`, { body: JSON.stringify(payload) }),
Expand Down Expand Up @@ -108,7 +108,7 @@ const AddPackQueryFormComponent = ({ handleSubmit }) => {
<EuiSpacer />
<CommonUseField path="interval" />
<EuiSpacer />
<EuiButton fill onClick={submit}>
<EuiButton isLoading={isSubmitting} fill onClick={submit}>
{'Add query'}
</EuiButton>
</Form>
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/osquery/public/packs/common/pack_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const PackFormComponent = ({ data, handleSubmit }) => {
},
},
});
const { submit } = form;
const { submit, isSubmitting } = form;

return (
<Form form={form}>
Expand All @@ -50,7 +50,7 @@ const PackFormComponent = ({ data, handleSubmit }) => {
<EuiSpacer />
<CommonUseField path="queries" component={PackQueriesField} />
<EuiSpacer />
<EuiButton fill onClick={submit}>
<EuiButton isLoading={isSubmitting} fill onClick={submit}>
{'Save pack'}
</EuiButton>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const EditSavedQueryFormComponent: React.FC<EditSavedQueryFormProps> = ({
defaultValue,
handleSubmit,
});
const { submit, isSubmitting } = form;

return (
<Form form={form}>
Expand All @@ -58,12 +59,12 @@ const EditSavedQueryFormComponent: React.FC<EditSavedQueryFormProps> = ({
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
// isLoading={isLoading}
isLoading={isSubmitting}
color="primary"
fill
size="m"
iconType="save"
onClick={form.submit}
onClick={submit}
>
<FormattedMessage
id="xpack.osquery.editSavedQuery.form.updateQueryButtonLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const NewSavedQueryFormComponent: React.FC<NewSavedQueryFormProps> = ({
defaultValue,
handleSubmit,
});
const { submit, isSubmitting } = form;

return (
<Form form={form}>
Expand All @@ -54,12 +55,12 @@ const NewSavedQueryFormComponent: React.FC<NewSavedQueryFormProps> = ({
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
// isLoading={isLoading}
isLoading={isSubmitting}
color="primary"
fill
size="m"
iconType="save"
onClick={form.submit}
onClick={submit}
>
<FormattedMessage
id="xpack.osquery.addSavedQuery.form.saveQueryButtonLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const EditScheduledQueryGroupPageComponent = () => {

const { data } = useScheduledQueryGroup({ scheduledQueryGroupId });

useBreadcrumbs('scheduled_query_group_edit', { scheduledQueryGroupName: data?.name ?? '' });
useBreadcrumbs('scheduled_query_group_edit', {
scheduledQueryGroupId: data?.id ?? '',
scheduledQueryGroupName: data?.name ?? '',
});

const LeftColumn = useMemo(
() => (
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/saved_queries/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export const SAVED_QUERIES_ID = 'savedQueryList';
export const SAVED_QUERY_ID = 'savedQuery';
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const SavedQueryFlyoutComponent: React.FC<AddQueryFlyoutProps> = ({ defaultValue
defaultValue,
handleSubmit,
});
const { submit, isSubmitting } = form;

return (
<EuiPortal>
Expand Down Expand Up @@ -72,7 +73,7 @@ const SavedQueryFlyoutComponent: React.FC<AddQueryFlyoutProps> = ({ defaultValue
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton onClick={form.submit} fill>
<EuiButton isLoading={isSubmitting} onClick={submit} fill>
<FormattedMessage
id="xpack.osquery.scheduledQueryGroup.queryFlyoutForm.saveButtonLabel"
defaultMessage="Save"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { useKibana } from '../common/lib/kibana';
import { savedQuerySavedObjectType } from '../../common/types';
import { pagePathGetters } from '../common/page_paths';
import { useErrorToast } from '../common/hooks/use_error_toast';

export const SAVED_QUERY_ID = 'savedQuery';
import { SAVED_QUERY_ID } from './constants';

interface UseSavedQueryProps {
savedQueryId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useKibana } from '../common/lib/kibana';
import { savedQuerySavedObjectType } from '../../common/types';
import { PLUGIN_ID } from '../../common';
import { pagePathGetters } from '../common/page_paths';
import { SAVED_QUERIES_ID } from './constants';
import { SAVED_QUERIES_ID, SAVED_QUERY_ID } from './constants';
import { useErrorToast } from '../common/hooks/use_error_toast';

interface UseUpdateSavedQueryProps {
Expand Down Expand Up @@ -74,6 +74,7 @@ export const useUpdateSavedQuery = ({ savedQueryId }: UseUpdateSavedQueryProps)
},
onSuccess: (payload) => {
queryClient.invalidateQueries(SAVED_QUERIES_ID);
queryClient.invalidateQueries([SAVED_QUERY_ID, { savedQueryId }]);
navigateToApp(PLUGIN_ID, { path: pagePathGetters.saved_queries() });
toasts.addSuccess(
i18n.translate('xpack.osquery.editSavedQuery.successToastMessageText', {
Expand Down
Loading

0 comments on commit 4416a31

Please sign in to comment.