Skip to content

Commit

Permalink
[Search] Fix broken Search plugin on unauthenticated user (elastic#16…
Browse files Browse the repository at this point in the history
…7171)

## Summary

This fixes an issue where the Search plugin was inaccessible for
unauthenticated user, eg. for Kibana in read-only demo setups.

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
sphilipse and kibanamachine authored Sep 26, 2023
1 parent 192bd5a commit 9198475
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const mockKibanaValues = {
setDocTitle: jest.fn(),
share: sharePluginMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
user: {},
};

jest.mock('../../shared/kibana', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useEffect, useState } from 'react';

import { useValues } from 'kea';

Expand All @@ -21,6 +21,8 @@ import { Chat } from '@kbn/cloud-chat-plugin/public';
import { i18n } from '@kbn/i18n';
import { WelcomeBanner } from '@kbn/search-api-panels';

import { AuthenticatedUser } from '@kbn/security-plugin/common';

import { ErrorStateCallout } from '../../../shared/error_state';
import { HttpLogic } from '../../../shared/http';
import { KibanaLogic } from '../../../shared/kibana';
Expand All @@ -40,8 +42,24 @@ import { IngestionSelector } from './ingestion_selector';
import './product_selector.scss';

export const ProductSelector: React.FC = () => {
const { config, user } = useValues(KibanaLogic);
const { config } = useValues(KibanaLogic);
const { errorConnectingMessage } = useValues(HttpLogic);
const { security } = useValues(KibanaLogic);

const [user, setUser] = useState<AuthenticatedUser | null>(null);

useEffect(() => {
try {
security.authc
.getCurrentUser()
.then(setUser)
.catch(() => {
setUser(null);
});
} catch {
setUser(null);
}
}, [security.authc]);

const showErrorConnecting = !!(config.host && errorConnectingMessage);
// The create index flow does not work without ent-search, when content is updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const renderApp = (
const { history } = params;
const { application, chrome, http, uiSettings } = core;
const { capabilities, navigateToUrl } = application;
const { charts, cloud, guidedOnboarding, lens, security, share, user } = plugins;
const { charts, cloud, guidedOnboarding, lens, security, share } = plugins;

const entCloudHost = getCloudEnterpriseSearchHost(plugins.cloud);
externalUrl.enterpriseSearchUrl = publicUrl || entCloudHost || config.host || '';
Expand Down Expand Up @@ -108,7 +108,6 @@ export const renderApp = (
setDocTitle: chrome.docTitle.change,
share,
uiSettings,
user,
});
const unmountLicensingLogic = mountLicensingLogic({
canManageLicense: core.application.capabilities.management?.stack?.license_management,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { AuthenticatedUser } from '@kbn/security-plugin/common';
import { SecurityPluginStart } from '@kbn/security-plugin/public';
import { SharePluginStart } from '@kbn/share-plugin/public';

Expand Down Expand Up @@ -54,7 +53,6 @@ interface KibanaLogicProps {
setDocTitle(title: string): void;
share: SharePluginStart;
uiSettings: IUiSettingsClient;
user: AuthenticatedUser | null;
}

export interface KibanaValues extends Omit<KibanaLogicProps, 'cloud'> {
Expand Down Expand Up @@ -95,7 +93,6 @@ export const KibanaLogic = kea<MakeLogicType<KibanaValues>>({
setDocTitle: [props.setDocTitle, {}],
share: [props.share, {}],
uiSettings: [props.uiSettings, {}],
user: [props.user, {}],
}),
selectors: ({ selectors }) => ({
isCloud: [() => [selectors.cloud], (cloud?: Partial<CloudSetup>) => !!cloud?.isCloudEnabled],
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/publi
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { AuthenticatedUser } from '@kbn/security-plugin/common';
import { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/public';
import { SharePluginStart } from '@kbn/share-plugin/public';

Expand Down Expand Up @@ -66,7 +65,6 @@ export interface PluginsStart {
licensing: LicensingPluginStart;
security: SecurityPluginStart;
share: SharePluginStart;
user: AuthenticatedUser;
}

export class EnterpriseSearchPlugin implements Plugin {
Expand Down Expand Up @@ -102,8 +100,7 @@ export class EnterpriseSearchPlugin implements Plugin {
cloudSetup && (pluginsStart as PluginsStart).cloud
? { ...cloudSetup, ...(pluginsStart as PluginsStart).cloud }
: undefined;
const user = (await (pluginsStart as PluginsStart).security.authc.getCurrentUser()) || null;
const plugins = { ...pluginsStart, cloud, user } as PluginsStart;
const plugins = { ...pluginsStart, cloud } as PluginsStart;

coreStart.chrome
.getChromeStyle$()
Expand Down

0 comments on commit 9198475

Please sign in to comment.