forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Show missing permissions message to the user on the Services ov…
…erview (elastic#56374) * creating permission page * pr comments * creating permission page * fixing pr comments * removing breadcrumb and adding static label to dismiss the permission page
- Loading branch information
1 parent
05574a9
commit 56ef098
Showing
6 changed files
with
208 additions
and
8 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
x-pack/legacy/plugins/apm/public/components/app/Permission/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* 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 { | ||
EuiButton, | ||
EuiEmptyPrompt, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiLink, | ||
EuiPanel, | ||
EuiTitle | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { FETCH_STATUS, useFetcher } from '../../../hooks/useFetcher'; | ||
import { fontSize, pct, px, units } from '../../../style/variables'; | ||
import { ElasticDocsLink } from '../../shared/Links/ElasticDocsLink'; | ||
import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink'; | ||
|
||
export const Permission: React.FC = ({ children }) => { | ||
const [isPermissionPageEnabled, setIsPermissionsPageEnabled] = useState(true); | ||
|
||
const { data, status } = useFetcher(callApmApi => { | ||
return callApmApi({ | ||
pathname: '/api/apm/security/permissions' | ||
}); | ||
}, []); | ||
|
||
// Return null until receive the reponse of the api. | ||
if (status === FETCH_STATUS.LOADING || status === FETCH_STATUS.PENDING) { | ||
return null; | ||
} | ||
// When the user doesn't have the appropriate permissions and they | ||
// did not use the escape hatch, show the missing permissions page | ||
if (data?.hasPermission === false && isPermissionPageEnabled) { | ||
return ( | ||
<PermissionPage | ||
onEscapeHatchClick={() => setIsPermissionsPageEnabled(false)} | ||
/> | ||
); | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
const CentralizedContainer = styled.div` | ||
height: ${pct(100)}; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
const EscapeHatch = styled.div` | ||
width: ${pct(100)}; | ||
margin-top: ${px(units.plus)}; | ||
justify-content: center; | ||
display: flex; | ||
`; | ||
|
||
interface Props { | ||
onEscapeHatchClick: () => void; | ||
} | ||
|
||
const PermissionPage = ({ onEscapeHatchClick }: Props) => { | ||
return ( | ||
<div style={{ height: pct(95) }}> | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiTitle size="l"> | ||
<h1> | ||
{i18n.translate('xpack.apm.permission.apm', { | ||
defaultMessage: 'APM' | ||
})} | ||
</h1> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<SetupInstructionsLink /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<CentralizedContainer> | ||
<div> | ||
<EuiPanel paddingSize="none"> | ||
<EuiEmptyPrompt | ||
iconType="apmApp" | ||
iconColor={''} | ||
title={ | ||
<h2> | ||
{i18n.translate('xpack.apm.permission.title', { | ||
defaultMessage: 'Missing permissions to access APM' | ||
})} | ||
</h2> | ||
} | ||
body={ | ||
<p> | ||
{i18n.translate('xpack.apm.permission.description', { | ||
defaultMessage: | ||
"We've detected your current role in Kibana does not grant you access to the APM data. Please check with your Kibana administrator to get the proper privileges granted in order to start using APM." | ||
})} | ||
</p> | ||
} | ||
actions={ | ||
<> | ||
<ElasticDocsLink | ||
section="/apm/server" | ||
path="/feature-roles.html" | ||
> | ||
{(href: string) => ( | ||
<EuiButton color="primary" fill href={href}> | ||
{i18n.translate('xpack.apm.permission.learnMore', { | ||
defaultMessage: 'Learn more about APM permissions' | ||
})} | ||
</EuiButton> | ||
)} | ||
</ElasticDocsLink> | ||
|
||
<EscapeHatch> | ||
<EuiLink | ||
color="subdued" | ||
onClick={onEscapeHatchClick} | ||
style={{ fontSize }} | ||
> | ||
{i18n.translate('xpack.apm.permission.dismissWarning', { | ||
defaultMessage: 'Dismiss warning' | ||
})} | ||
</EuiLink> | ||
</EscapeHatch> | ||
</> | ||
} | ||
/> | ||
</EuiPanel> | ||
</div> | ||
</CentralizedContainer> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
x-pack/legacy/plugins/apm/server/lib/security/getPermissions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 { Setup } from '../helpers/setup_request'; | ||
|
||
export async function getPermissions(setup: Setup) { | ||
const { client, indices } = setup; | ||
|
||
const params = { | ||
index: Object.values(indices), | ||
body: { | ||
size: 0, | ||
query: { | ||
match_all: {} | ||
} | ||
} | ||
}; | ||
|
||
try { | ||
await client.search(params); | ||
return { hasPermission: true }; | ||
} catch (e) { | ||
// If 403, it means the user doesnt have permission. | ||
if (e.status === 403) { | ||
return { hasPermission: false }; | ||
} | ||
// if any other error happens, throw it. | ||
throw e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 { createRoute } from './create_route'; | ||
import { setupRequest } from '../lib/helpers/setup_request'; | ||
import { getPermissions } from '../lib/security/getPermissions'; | ||
|
||
export const permissionsRoute = createRoute(() => ({ | ||
path: '/api/apm/security/permissions', | ||
handler: async ({ context, request }) => { | ||
const setup = await setupRequest(context, request); | ||
return getPermissions(setup); | ||
} | ||
})); |