Skip to content
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

[Search Session] Use server-side authc.getCurrentUser from core.security #186919

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/plugins/data/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"management"
],
"optionalPlugins": [
"usageCollection",
"security"
"usageCollection"
],
"requiredBundles": [
"kibanaUtils",
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/data/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { BfetchServerSetup } from '@kbn/bfetch-plugin/server';
import { PluginStart as DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
import { FieldFormatsSetup, FieldFormatsStart } from '@kbn/field-formats-plugin/server';
import type { SecurityPluginSetup } from '@kbn/security-plugin/server';
import { ConfigSchema } from '../config';
import type { ISearchSetup, ISearchStart } from './search';
import { DatatableUtilitiesService } from './datatable_utilities';
Expand Down Expand Up @@ -51,7 +50,6 @@ export interface DataPluginSetupDependencies {
expressions: ExpressionsServerSetup;
usageCollection?: UsageCollectionSetup;
fieldFormats: FieldFormatsSetup;
security?: SecurityPluginSetup;
}

export interface DataPluginStartDependencies {
Expand Down Expand Up @@ -86,7 +84,7 @@ export class DataServerPlugin

public setup(
core: CoreSetup<DataPluginStartDependencies, DataPluginStart>,
{ bfetch, expressions, usageCollection, fieldFormats, security }: DataPluginSetupDependencies
{ bfetch, expressions, usageCollection, fieldFormats }: DataPluginSetupDependencies
) {
this.scriptsService.setup(core);
const querySetup = this.queryService.setup(core);
Expand All @@ -98,7 +96,6 @@ export class DataServerPlugin
bfetch,
expressions,
usageCollection,
security,
});

return {
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { ExpressionsServerSetup } from '@kbn/expressions-plugin/server';
import { FieldFormatsStart } from '@kbn/field-formats-plugin/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
import { KbnServerError } from '@kbn/kibana-utils-plugin/server';
import type { SecurityPluginSetup } from '@kbn/security-plugin/server';
import type { DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import type {
DataRequestHandlerContext,
Expand Down Expand Up @@ -110,7 +109,6 @@ export interface SearchServiceSetupDependencies {
bfetch: BfetchServerSetup;
expressions: ExpressionsServerSetup;
usageCollection?: UsageCollectionSetup;
security?: SecurityPluginSetup;
}

/** @internal */
Expand Down Expand Up @@ -147,7 +145,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {

public setup(
core: CoreSetup<DataPluginStartDependencies, DataPluginStart>,
{ bfetch, expressions, usageCollection, security }: SearchServiceSetupDependencies
{ bfetch, expressions, usageCollection }: SearchServiceSetupDependencies
): ISearchSetup {
core.savedObjects.registerType(searchSessionSavedObjectType);
const usage = usageCollection ? usageProvider(core) : undefined;
Expand All @@ -156,7 +154,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
registerSearchRoute(router);
registerSessionRoutes(router, this.logger);

this.sessionService.setup(core, { security });
this.sessionService.setup(core, {});

core.http.registerRouteHandlerContext<DataRequestHandlerContext, 'search'>(
'search',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createRequestHash } from './utils';
import moment from 'moment';
import { coreMock } from '@kbn/core/server/mocks';
import { ConfigSchema } from '../../../config';
import type { AuthenticatedUser } from '@kbn/security-plugin/common';
import type { AuthenticatedUser } from '@kbn/core/server';
import { SEARCH_SESSION_TYPE, SearchSessionStatus } from '../../../common';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';

Expand Down
15 changes: 5 additions & 10 deletions src/plugins/data/server/search/session/session_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SavedObjectsFindOptions,
ElasticsearchClient,
} from '@kbn/core/server';
import type { AuthenticatedUser, SecurityPluginSetup } from '@kbn/security-plugin/server';
import type { AuthenticatedUser } from '@kbn/core/server';
import { defer } from '@kbn/kibana-utils-plugin/common';
import type { IKibanaSearchRequest, ISearchOptions } from '@kbn/search-types';
import { debounce } from 'lodash';
Expand All @@ -43,10 +43,8 @@ export interface SearchSessionStatusDependencies extends SearchSessionDependenci
internalElasticsearchClient: ElasticsearchClient;
}

interface SetupDependencies {
security?: SecurityPluginSetup;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface SetupDependencies {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface StartDependencies {}

Expand All @@ -68,7 +66,6 @@ interface TrackIdQueueEntry {

export class SearchSessionService implements ISearchSessionService {
private sessionConfig: SearchSessionsConfigSchema;
private security?: SecurityPluginSetup;
private setupCompleted = false;

constructor(
Expand All @@ -80,8 +77,6 @@ export class SearchSessionService implements ISearchSessionService {
}

public setup(core: CoreSetup, deps: SetupDependencies) {
this.security = deps.security;

this.setupCompleted = true;
}

Expand Down Expand Up @@ -419,9 +414,9 @@ export class SearchSessionService implements ISearchSessionService {
return session.attributes.idMapping[requestHash].id;
};

public asScopedProvider = ({ savedObjects, elasticsearch }: CoreStart) => {
public asScopedProvider = ({ security, savedObjects, elasticsearch }: CoreStart) => {
return (request: KibanaRequest) => {
const user = this.security?.authc.getCurrentUser(request) ?? null;
const user = security.authc.getCurrentUser(request) ?? null;
const savedObjectsClient = savedObjects.getScopedClient(request, {
includedHiddenTypes: [SEARCH_SESSION_TYPE],
});
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@kbn/field-formats-plugin",
"@kbn/data-views-plugin",
"@kbn/screenshot-mode-plugin",
"@kbn/security-plugin",
"@kbn/expressions-plugin",
"@kbn/field-types",
"@kbn/es-query",
Expand Down