Skip to content
Merged
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
82 changes: 5 additions & 77 deletions x-pack/plugins/monitoring/public/alerts/lib/security_toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSpacer, EuiLink, EuiCode, EuiText } from '@elastic/eui';
import { EuiSpacer, EuiLink } from '@elastic/eui';
import { Legacy } from '../../legacy_shims';
import { toMountPoint } from '../../../../../../src/plugins/kibana_react/public';

Expand All @@ -30,11 +30,10 @@ const showTlsAndEncryptionError = () => {
<div>
<p>
{i18n.translate('xpack.monitoring.healthCheck.tlsAndEncryptionError', {
defaultMessage: `You must enable Transport Layer Security between Kibana and Elasticsearch
and configure an encryption key in your kibana.yml file to use the Alerting feature.`,
defaultMessage: `Stack monitoring alerts require Transport Layer Security between Kibana and Elasticsearch, and an encryption key in your kibana.yml file.`,
})}
</p>
<EuiSpacer />
<EuiSpacer size="xs" />
<EuiLink
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/alert-action-settings-kb.html#general-alert-action-settings`}
external
Expand All @@ -49,76 +48,9 @@ const showTlsAndEncryptionError = () => {
});
};

const showEncryptionError = () => {
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = Legacy.shims.docLinks;

Legacy.shims.toastNotifications.addWarning(
{
title: toMountPoint(
<FormattedMessage
id="xpack.monitoring.healthCheck.encryptionErrorTitle"
defaultMessage="You must set an encryption key"
/>
),
text: toMountPoint(
<div role="banner">
{i18n.translate('xpack.monitoring.healthCheck.encryptionErrorBeforeKey', {
defaultMessage: 'To create an alert, set a value for ',
})}
<EuiText size="xs">
<EuiCode>{'xpack.encryptedSavedObjects.encryptionKey'}</EuiCode>
</EuiText>
{i18n.translate('xpack.monitoring.healthCheck.encryptionErrorAfterKey', {
defaultMessage: ' in your kibana.yml file. ',
})}
<EuiLink
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/alert-action-settings-kb.html#general-alert-action-settings`}
external
target="_blank"
>
{i18n.translate('xpack.monitoring.healthCheck.encryptionErrorAction', {
defaultMessage: 'Learn how.',
})}
</EuiLink>
</div>
),
},
{}
);
};

const showTlsError = () => {
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = Legacy.shims.docLinks;

Legacy.shims.toastNotifications.addWarning({
title: toMountPoint(
<FormattedMessage
id="xpack.monitoring.healthCheck.tlsErrorTitle"
defaultMessage="You must enable Transport Layer Security"
/>
),
text: toMountPoint(
<div role="banner">
{i18n.translate('xpack.monitoring.healthCheck.tlsError', {
defaultMessage:
'Alerting relies on API keys, which require TLS between Elasticsearch and Kibana. ',
})}
<EuiLink
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/configuring-tls.html`}
external
target="_blank"
>
{i18n.translate('xpack.monitoring.healthCheck.tlsErrorAction', {
defaultMessage: 'Learn how to enable TLS.',
})}
</EuiLink>
</div>
),
});
};

export const showSecurityToast = (alertingHealth: AlertingFrameworkHealth) => {
const { isSufficientlySecure, hasPermanentEncryptionKey } = alertingHealth;

if (
Array.isArray(alertingHealth) ||
(!alertingHealth.hasOwnProperty('isSufficientlySecure') &&
Expand All @@ -127,11 +59,7 @@ export const showSecurityToast = (alertingHealth: AlertingFrameworkHealth) => {
return;
}

if (!isSufficientlySecure && !hasPermanentEncryptionKey) {
if (!isSufficientlySecure || !hasPermanentEncryptionKey) {
showTlsAndEncryptionError();
} else if (!isSufficientlySecure) {
showTlsError();
} else if (!hasPermanentEncryptionKey) {
showEncryptionError();
}
};