Skip to content

Commit

Permalink
Disable RAC multi-tenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Aug 13, 2021
1 parent ebdda25 commit 51170ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
8 changes: 7 additions & 1 deletion x-pack/plugins/rule_registry/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ export const config = {
write: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
index: schema.string({ defaultValue: '.alerts' }),
unsafe: schema.object({
legacyMultiTenancy: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
}),
};

export type RuleRegistryPluginConfig = TypeOf<typeof config.schema>;

export const INDEX_PREFIX = '.alerts' as const;
29 changes: 24 additions & 5 deletions x-pack/plugins/rule_registry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
KibanaRequest,
CoreStart,
IContextProvider,
SharedGlobalConfig,
} from 'src/core/server';
import { SecurityPluginSetup } from '../../security/server';
import { AlertsClientFactory } from './alert_data_client/alerts_client_factory';
Expand All @@ -20,7 +21,7 @@ import { RacApiRequestHandlerContext, RacRequestHandlerContext } from './types';
import { defineRoutes } from './routes';
import { SpacesPluginStart } from '../../spaces/server';

import { RuleRegistryPluginConfig } from './config';
import { INDEX_PREFIX, RuleRegistryPluginConfig } from './config';
import { RuleDataPluginService } from './rule_data_plugin_service';
import { EventLogService, IEventLogService } from './event_log';
import { AlertsClient } from './alert_data_client/alerts_client';
Expand Down Expand Up @@ -53,6 +54,7 @@ export class RuleRegistryPlugin
RuleRegistryPluginStartDependencies
> {
private readonly config: RuleRegistryPluginConfig;
private readonly legacyConfig: SharedGlobalConfig;
private readonly logger: Logger;
private eventLogService: EventLogService | null;
private readonly alertsClientFactory: AlertsClientFactory;
Expand All @@ -61,6 +63,8 @@ export class RuleRegistryPlugin

constructor(initContext: PluginInitializerContext) {
this.config = initContext.config.get<RuleRegistryPluginConfig>();
// TODO: Can be removed in 8.0.0. Exists to work around multi-tenancy users.
this.legacyConfig = initContext.config.legacy.get();
this.logger = initContext.logger.get();
this.eventLogService = null;
this.ruleDataService = null;
Expand All @@ -82,10 +86,25 @@ export class RuleRegistryPlugin

this.security = plugins.security;

const isWriteEnabled = (config: RuleRegistryPluginConfig, legacyConfig: SharedGlobalConfig) => {
const hasEnabledWrite = config.write.enabled;
const hasSetKibanaIndex = legacyConfig.kibana.index;
const hasSetUnsafeAccess = config.unsafe.legacyMultiTenancy.enabled;

if (!hasEnabledWrite) return false;

// Not using legacy multi-tenancy
if (!hasSetKibanaIndex) {
return hasEnabledWrite;
} else {
return hasSetUnsafeAccess;
}
};

const service = new RuleDataPluginService({
logger: this.logger,
isWriteEnabled: this.config.write.enabled,
index: this.config.index,
isWriteEnabled: isWriteEnabled(this.config, this.legacyConfig),
index: INDEX_PREFIX,
getClusterClient: async () => {
const deps = await startDependencies;
return deps.core.elasticsearch.client.asInternalUser;
Expand All @@ -112,8 +131,8 @@ export class RuleRegistryPlugin

const eventLogService = new EventLogService({
config: {
indexPrefix: this.config.index,
isWriteEnabled: this.config.write.enabled,
indexPrefix: INDEX_PREFIX,
isWriteEnabled: isWriteEnabled(this.config, this.legacyConfig),
},
dependencies: {
clusterClient: startDependencies.then((deps) => deps.core.elasticsearch.client),
Expand Down

0 comments on commit 51170ac

Please sign in to comment.