mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.11`: - [[Synthetics] Improve reading user permissions (#169601)](https://github.com/elastic/kibana/pull/169601) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Abdul Wahab Zahid","email":"awahab07@yahoo.com"},"sourceCommit":{"committedDate":"2023-10-31T18:45:32Z","message":"[Synthetics] Improve reading user permissions (#169601)\n\n## Summary\r\n\r\nThe PR improves the way to determine what permissions user has.","sha":"fce380dadbf156d8f24f919c1bd680548653ce27","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:uptime","release_note:skip","v8.11.0","v8.12.0"],"number":169601,"url":"https://github.com/elastic/kibana/pull/169601","mergeCommit":{"message":"[Synthetics] Improve reading user permissions (#169601)\n\n## Summary\r\n\r\nThe PR improves the way to determine what permissions user has.","sha":"fce380dadbf156d8f24f919c1bd680548653ce27"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/169601","number":169601,"mergeCommit":{"message":"[Synthetics] Improve reading user permissions (#169601)\n\n## Summary\r\n\r\nThe PR improves the way to determine what permissions user has.","sha":"fce380dadbf156d8f24f919c1bd680548653ce27"}}]}] BACKPORT--> Co-authored-by: Abdul Wahab Zahid <awahab07@yahoo.com>
This commit is contained in:
parent
ba8198f29a
commit
679541d52e
4 changed files with 71 additions and 4 deletions
|
@ -19,6 +19,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
|
|||
import { css } from '@emotion/react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { selectOverviewStatus } from '../state/overview_status';
|
||||
import { useCanReadSyntheticsIndex } from '../../../hooks/use_capabilities';
|
||||
import {
|
||||
LICENSE_MISSING_ERROR,
|
||||
LICENSE_NOT_ACTIVE_ERROR,
|
||||
|
@ -28,9 +29,11 @@ import {
|
|||
import { useSyntheticsSettingsContext } from '../contexts';
|
||||
|
||||
export const useSyntheticsPrivileges = () => {
|
||||
const { canRead: canReadSyntheticsIndex, loading: isCanReadLoading } =
|
||||
useCanReadSyntheticsIndex();
|
||||
const { error } = useSelector(selectOverviewStatus);
|
||||
|
||||
if (error?.body?.message?.startsWith('MissingIndicesPrivileges:')) {
|
||||
if (!isCanReadLoading && !canReadSyntheticsIndex) {
|
||||
return (
|
||||
<EuiFlexGroup
|
||||
alignItems="center"
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { useFetcher } from '@kbn/observability-shared-plugin/public';
|
||||
import { SYNTHETICS_INDEX_PATTERN } from '../../common/constants';
|
||||
import { MonitorLocations } from '../../common/runtime_types';
|
||||
|
||||
export const useCanEditSynthetics = () => {
|
||||
|
@ -23,3 +26,48 @@ export const useCanUsePublicLocations = (monLocations?: MonitorLocations) => {
|
|||
|
||||
return !!canUsePublicLocations;
|
||||
};
|
||||
|
||||
export const useCanReadSyntheticsIndex = () => {
|
||||
const {
|
||||
services: { data: dataPublicPluginStart },
|
||||
} = useKibana<{ data: DataPublicPluginStart }>();
|
||||
|
||||
const { data, loading, status } = useFetcher<
|
||||
Promise<{ canRead: boolean; error: undefined | unknown }>
|
||||
>(() => {
|
||||
return new Promise((resolve) => {
|
||||
dataPublicPluginStart.search
|
||||
.search(
|
||||
{
|
||||
terminate_after: 1,
|
||||
params: {
|
||||
index: SYNTHETICS_INDEX_PATTERN,
|
||||
size: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
legacyHitsTotal: false,
|
||||
}
|
||||
)
|
||||
.subscribe({
|
||||
next: (_) => {
|
||||
resolve({ canRead: true, error: undefined });
|
||||
},
|
||||
error: (error: { err: { statusCode: number } }) => {
|
||||
if (error.err?.statusCode >= 400 && error.err?.statusCode < 500) {
|
||||
resolve({ canRead: false, error });
|
||||
} else {
|
||||
resolve({ canRead: true, error });
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
return {
|
||||
canRead: data?.canRead,
|
||||
error: data?.error,
|
||||
loading,
|
||||
status,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -16,7 +16,9 @@ interface EmptyStateErrorProps {
|
|||
|
||||
export const EmptyStateError = ({ errors }: EmptyStateErrorProps) => {
|
||||
const unauthorized = errors.find(
|
||||
(error) => error.message && error.message.includes('unauthorized')
|
||||
(error) =>
|
||||
(error.message && error.message.includes('unauthorized')) ||
|
||||
(error.body?.message && error.body.message.includes('unauthorized'))
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
|
@ -19,8 +19,22 @@ export const createGetIndexStatusRoute: UMRestApiRouteFactory = (libs: UMServerL
|
|||
to: schema.maybe(schema.string()),
|
||||
}),
|
||||
},
|
||||
handler: async ({ uptimeEsClient, request }): Promise<any> => {
|
||||
handler: async ({ uptimeEsClient, request, response }): Promise<any> => {
|
||||
const { from, to } = request.query;
|
||||
return await libs.requests.getIndexStatus({ uptimeEsClient, range: { from, to } });
|
||||
try {
|
||||
return await libs.requests.getIndexStatus({ uptimeEsClient, range: { from, to } });
|
||||
} catch (e) {
|
||||
if (e.meta?.statusCode === 403) {
|
||||
return response.customError({
|
||||
statusCode: 403,
|
||||
body: {
|
||||
message:
|
||||
'unauthorized: You do not have the required permissions to read uptime indices',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue