-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[APM] Show missing permissions message to the user on the Services overview #56374
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4dc9dc
creating permission page
cauemarcondes d16a813
pr comments
cauemarcondes 22b03ee
creating permission page
cauemarcondes e680a83
fixing pr comments
cauemarcondes ac6ab86
removing breadcrumb and adding static label to dismiss the permission…
cauemarcondes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import { getConfigFromInjectedMetadata } from './getConfigFromInjectedMetadata'; | |
| import { setHelpExtension } from './setHelpExtension'; | ||
| import { toggleAppLinkInNav } from './toggleAppLinkInNav'; | ||
| import { setReadonlyBadge } from './updateBadge'; | ||
| import { Permission } from '../components/app/Permission'; | ||
|
|
||
| export const REACT_APP_ROOT_ID = 'react-apm-root'; | ||
|
|
||
|
|
@@ -51,11 +52,14 @@ const App = () => { | |
| <MainContainer data-test-subj="apmMainContainer" role="main"> | ||
| <UpdateBreadcrumbs routes={routes} /> | ||
| <Route component={ScrollToTopOnPathChange} /> | ||
| <Switch> | ||
| {routes.map((route, i) => ( | ||
| <ApmRoute key={i} {...route} /> | ||
| ))} | ||
| </Switch> | ||
| {/* Check if user has the appropriate permissions to use the APM UI. */} | ||
| <Permission> | ||
|
||
| <Switch> | ||
| {routes.map((route, i) => ( | ||
| <ApmRoute key={i} {...route} /> | ||
| ))} | ||
| </Switch> | ||
| </Permission> | ||
| </MainContainer> | ||
| ); | ||
| }; | ||
|
|
||
32 changes: 32 additions & 0 deletions
32
x-pack/legacy/plugins/apm/server/lib/security/getPermissions.ts
This file contains hidden or 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 hidden or 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 hidden or 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); | ||
| } | ||
| })); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.