From 2d5b4de163d0adf6db5651e68ad04b3f410f34a4 Mon Sep 17 00:00:00 2001 From: mohamedhamed-ahmed Date: Tue, 1 Oct 2024 12:38:16 +0100 Subject: [PATCH] [Logs Explorer] Fix Privileges Accessibility (#193894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/elastic/kibana/issues/192062 ## 📝 Summary This PR adds privileges checks for `Logs Explorerer` it checks for `Discover & Fleet` privileges before allowing the user access to `Logs Explorer`. Clicking on the `Logs` tab from the side nav defaults to `Stream`, as long as its not depricated, in case the user doesn't have access to `Logs Explorer` ## 🎥 Demo https://github.com/user-attachments/assets/a4105ec0-7681-40ee-b2fd-e39b9c178dcf (cherry picked from commit dbfd4f0879aa89c49b379cc2c6c5feb74f5c16c7) --- .../infra/public/apps/logs_app.tsx | 26 ++++++++++--------- .../infra/public/pages/logs/page_content.tsx | 1 + .../infra/public/plugin.ts | 21 +++++++++------ .../public/plugin.ts | 16 +++++++++++- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx b/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx index 8bd243b0723d5..329e059288e3e 100644 --- a/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx +++ b/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx @@ -57,7 +57,7 @@ const LogsApp: React.FC<{ storage: Storage; theme$: AppMountParameters['theme$']; }> = ({ core, history, pluginStart, plugins, setHeaderActionMenu, storage, theme$ }) => { - const uiCapabilities = core.application.capabilities; + const { logs, discover, fleet } = core.application.capabilities; return ( @@ -74,19 +74,21 @@ const LogsApp: React.FC<{ toastsService={core.notifications.toasts} > - { - plugins.share.url.locators - .get(ALL_DATASETS_LOCATOR_ID) - ?.navigate({}); + {Boolean(discover?.show && fleet?.read) && ( + { + plugins.share.url.locators + .get(ALL_DATASETS_LOCATOR_ID) + ?.navigate({}); - return null; - }} - /> + return null; + }} + /> + )} - {uiCapabilities?.logs?.show && } + {logs?.show && } diff --git a/x-pack/plugins/observability_solution/infra/public/pages/logs/page_content.tsx b/x-pack/plugins/observability_solution/infra/public/pages/logs/page_content.tsx index 056c98513c244..5b5965bb2d5ec 100644 --- a/x-pack/plugins/observability_solution/infra/public/pages/logs/page_content.tsx +++ b/x-pack/plugins/observability_solution/infra/public/pages/logs/page_content.tsx @@ -113,6 +113,7 @@ export const LogsPageContent: React.FunctionComponent = () => { )} + ( { + const { infrastructure, logs, discover, fleet } = capabilities; return [ - ...(capabilities.logs.show + ...(logs.show ? [ { label: 'Logs', sortKey: 200, entries: [ - { - label: 'Explorer', - app: 'observability-logs-explorer', - path: '/', - isBetaFeature: true, - }, + ...(discover?.show && fleet?.read + ? [ + { + label: 'Explorer', + app: 'observability-logs-explorer', + path: '/', + isBetaFeature: true, + }, + ] + : []), ...(this.config.featureFlags.logsUIEnabled ? [ { label: 'Stream', app: 'logs', path: '/stream' }, @@ -161,7 +166,7 @@ export class Plugin implements InfraClientPluginClass { }, ] : []), - ...(capabilities.infrastructure.show + ...(infrastructure.show ? [ { label: metricsTitle, diff --git a/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts b/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts index 906caf72a450a..798a03da0ebdf 100644 --- a/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts +++ b/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts @@ -7,6 +7,8 @@ import { AppMountParameters, + AppStatus, + AppUpdater, CoreSetup, CoreStart, DEFAULT_APP_CATEGORIES, @@ -14,6 +16,7 @@ import { PluginInitializerContext, } from '@kbn/core/public'; import { OBSERVABILITY_LOGS_EXPLORER_APP_ID } from '@kbn/deeplinks-observability'; +import { BehaviorSubject } from 'rxjs'; import { AllDatasetsLocatorDefinition, ObservabilityLogsExplorerLocators, @@ -35,6 +38,7 @@ export class ObservabilityLogsExplorerPlugin { private config: ObservabilityLogsExplorerConfig; private locators?: ObservabilityLogsExplorerLocators; + private appStateUpdater = new BehaviorSubject(() => ({})); constructor(context: PluginInitializerContext) { this.config = context.config.get(); @@ -56,6 +60,7 @@ export class ObservabilityLogsExplorerPlugin ? ['globalSearch', 'sideNav'] : ['globalSearch'], keywords: ['logs', 'log', 'explorer', 'logs explorer'], + updater$: this.appStateUpdater, mount: async (appMountParams: ObservabilityLogsExplorerAppMountParameters) => { const [coreStart, pluginsStart, ownPluginStart] = await core.getStartServices(); const { renderObservabilityLogsExplorer } = await import( @@ -123,7 +128,16 @@ export class ObservabilityLogsExplorerPlugin }; } - public start(_core: CoreStart, _pluginsStart: ObservabilityLogsExplorerStartDeps) { + public start(core: CoreStart, _pluginsStart: ObservabilityLogsExplorerStartDeps) { + const { discover, fleet, logs } = core.application.capabilities; + + if (!(discover?.show && fleet?.read && logs?.show)) { + this.appStateUpdater.next(() => ({ + status: AppStatus.inaccessible, + visibleIn: [], + })); + } + return {}; } }