Skip to content

Commit e73d14e

Browse files
committed
Added a case for Alerting if security/ssl is disabled
1 parent 0c0aaf0 commit e73d14e

File tree

6 files changed

+86
-9
lines changed

6 files changed

+86
-9
lines changed

x-pack/plugins/monitoring/kibana.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"kibanaLegacy",
1212
"triggers_actions_ui",
1313
"alerts",
14-
"actions"
14+
"actions",
15+
"encryptedSavedObjects"
1516
],
1617
"optionalPlugins": ["infra", "telemetryCollectionManager", "usageCollection", "home", "cloud"],
1718
"server": true,

x-pack/plugins/monitoring/public/services/clusters.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export function monitoringClustersProvider($injector) {
5555
}
5656

5757
function ensureAlertsEnabled() {
58-
return $http.post('../api/monitoring/v1/alerts/enable', {}).catch((err) => {
59-
const Private = $injector.get('Private');
60-
const ajaxErrorHandlers = Private(ajaxErrorHandlersProvider);
61-
return ajaxErrorHandlers(err);
58+
return $http.post('../api/monitoring/v1/alerts/enable', {}).catch(() => {
59+
/**
60+
* Ignoring for now, but should really indicate what is the cause
61+
*/
6262
});
6363
}
6464

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { RequestHandlerContext } from 'kibana/server';
8+
9+
import { EncryptedSavedObjectsPluginSetup } from '../../../../encrypted_saved_objects/server';
10+
11+
export interface AlertingFrameworkHealth {
12+
isSufficientlySecure: boolean;
13+
hasPermanentEncryptionKey: boolean;
14+
}
15+
16+
export interface XPackUsageSecurity {
17+
security?: {
18+
enabled?: boolean;
19+
ssl?: {
20+
http?: {
21+
enabled?: boolean;
22+
};
23+
};
24+
};
25+
}
26+
27+
export class AlertingSecurity {
28+
private static _encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
29+
30+
public static readonly init = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => {
31+
AlertingSecurity._encryptedSavedObjects = encryptedSavedObjects;
32+
};
33+
34+
public static readonly getSecurityHealth = async (
35+
context: RequestHandlerContext
36+
): Promise<AlertingFrameworkHealth> => {
37+
const {
38+
security: {
39+
enabled: isSecurityEnabled = false,
40+
ssl: { http: { enabled: isTLSEnabled = false } = {} } = {},
41+
} = {},
42+
}: XPackUsageSecurity = await context.core.elasticsearch.legacy.client.callAsInternalUser(
43+
'transport.request',
44+
{
45+
method: 'GET',
46+
path: '/_xpack/usage',
47+
}
48+
);
49+
50+
if (!AlertingSecurity._encryptedSavedObjects) {
51+
throw Error(
52+
'AlertingSecurity.init() needs to be set before using AlertingSecurity.getSecurityHealth'
53+
);
54+
}
55+
56+
return {
57+
isSufficientlySecure: !isSecurityEnabled || (isSecurityEnabled && isTLSEnabled),
58+
hasPermanentEncryptionKey: !AlertingSecurity._encryptedSavedObjects
59+
.usingEphemeralEncryptionKey,
60+
};
61+
};
62+
}

x-pack/plugins/monitoring/server/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { requireUIRoutes } from './routes';
3333
import { initBulkUploader } from './kibana_monitoring';
3434
// @ts-ignore
3535
import { initInfraSource } from './lib/logs/init_infra_source';
36+
import { AlertingSecurity } from './lib/elasticsearch/verify_alerting_security';
3637
import { instantiateClient } from './es_client/instantiate_client';
3738
import { registerCollectors } from './kibana_monitoring/collectors';
3839
import { registerMonitoringCollection } from './telemetry_collection';
@@ -79,6 +80,7 @@ export class Plugin {
7980
}
8081

8182
async setup(core: CoreSetup, plugins: PluginsSetup) {
83+
AlertingSecurity.init(plugins.encryptedSavedObjects);
8284
const [config, legacyConfig] = await combineLatest([
8385
this.initializerContext.config
8486
.create<TypeOf<typeof configSchema>>()

x-pack/plugins/monitoring/server/routes/api/v1/alerts/enable.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,33 @@ import { AlertsFactory } from '../../../../alerts';
1010
import { RouteDependencies } from '../../../../types';
1111
import { ALERT_ACTION_TYPE_LOG } from '../../../../../common/constants';
1212
import { ActionResult } from '../../../../../../actions/common';
13-
// import { fetchDefaultEmailAddress } from '../../../../lib/alerts/fetch_default_email_address';
13+
import { AlertingSecurity } from '../../../../lib/elasticsearch/verify_alerting_security';
1414

1515
const DEFAULT_SERVER_LOG_NAME = 'Monitoring: Write to Kibana log';
1616

17-
export function enableAlertsRoute(server: any, npRoute: RouteDependencies) {
17+
export function enableAlertsRoute(_server: unknown, npRoute: RouteDependencies) {
1818
npRoute.router.post(
1919
{
2020
path: '/api/monitoring/v1/alerts/enable',
2121
options: { tags: ['access:monitoring'] },
2222
validate: false,
2323
},
24-
async (context, request, response) => {
24+
async (context, _request, response) => {
2525
try {
26+
const {
27+
isSufficientlySecure,
28+
hasPermanentEncryptionKey,
29+
} = await AlertingSecurity.getSecurityHealth(context);
2630
const alertsClient = context.alerting?.getAlertsClient();
2731
const actionsClient = context.actions?.getActionsClient();
2832
const types = context.actions?.listTypes();
29-
if (!alertsClient || !actionsClient || !types) {
33+
if (
34+
!alertsClient ||
35+
!actionsClient ||
36+
!types ||
37+
!isSufficientlySecure ||
38+
!hasPermanentEncryptionKey
39+
) {
3040
return response.notFound();
3141
}
3242

x-pack/plugins/monitoring/server/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { InfraPluginSetup } from '../../infra/server';
1717
import { LicensingPluginSetup } from '../../licensing/server';
1818
import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server';
19+
import { EncryptedSavedObjectsPluginSetup } from '../../encrypted_saved_objects/server';
1920

2021
export interface MonitoringLicenseService {
2122
refresh: () => Promise<any>;
@@ -36,6 +37,7 @@ export interface LegacyAPI {
3637
}
3738

3839
export interface PluginsSetup {
40+
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
3941
telemetryCollectionManager?: TelemetryCollectionManagerPluginSetup;
4042
usageCollection?: UsageCollectionSetup;
4143
licensing: LicensingPluginSetup;

0 commit comments

Comments
 (0)