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

[RAC] Disable RAC multi-tenancy #108506

Merged
merged 5 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 3 deletions packages/kbn-rule-data-utils/src/alerts_as_data_rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import type { EsQueryConfig } from '@kbn/es-query';
* registering a new instance of the rule data client
* in a new plugin will require updating the below data structure
* to include the index name where the alerts as data will be written to.
*
* This doesn't work in combination with the `xpack.ruleRegistry.index`
* setting, with which the user can change the index prefix.
*/

export const AlertConsumers = {
Expand Down
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 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we change xpack.ruleRegistry.write.enabled to true by default now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll happen as part of #105237 and the "final wrap up" 👍

}),
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 hasSetCustomKibanaIndex = legacyConfig.kibana.index !== '.kibana';
const hasSetUnsafeAccess = config.unsafe.legacyMultiTenancy.enabled;

if (!hasEnabledWrite) return false;

// Not using legacy multi-tenancy
if (!hasSetCustomKibanaIndex) {
return hasEnabledWrite;
} else {
return hasSetUnsafeAccess;
}
Comment on lines +90 to +97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe this could be easier to grasp (totally subjective)

if (hasEnabledWrite) {
  return hasSetCustomKibanaIndex ? hasSetUnsafeAccess : true;
}

return false;

};

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
1 change: 0 additions & 1 deletion x-pack/test/apm_api_integration/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const apmFtrConfigs = {
license: 'trial' as const,
kibanaConfig: {
'migrations.enableV2': 'false',
'xpack.ruleRegistry.index': '.kibana-alerts',
'xpack.ruleRegistry.write.enabled': 'true',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const BULK_INDEX_DELAY = 1000;
const INDEXING_DELAY = 5000;

const ALERTS_INDEX_TARGET = '.kibana-alerts-*-apm*';
const ALERTS_INDEX_TARGET = '.alerts-*-apm*';
const APM_TRANSACTION_INDEX_NAME = 'apm-8.0.0-transaction';

const createTransactionEvent = (override: Record<string, any>) => {
Expand Down