Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
apmRulesTransactionDuration: `${ELASTIC_DOCS}solutions/observability/incident-management/create-latency-threshold-rule`,
apmRulesTransactionError: `${ELASTIC_DOCS}solutions/observability/incident-management/create-failed-transaction-rate-threshold-rule`,
apmRulesAnomaly: `${ELASTIC_DOCS}solutions/observability/incident-management/create-an-apm-anomaly-rule`,
authorization: `${KIBANA_DOCS}alerting-setup.html#alerting-authorization`,
emailAction: `${ELASTIC_DOCS}reference/kibana/connectors-kibana/email-action-type`,
emailActionConfig: `${ELASTIC_DOCS}reference/kibana/connectors-kibana/email-action-type`,
emailExchangeClientSecretConfig: `${ELASTIC_DOCS}reference/kibana/connectors-kibana/email-action-type#exchange-client-secret`,
Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export interface DocLinks {
aiAssistant: string;
}>;
readonly alerting: Readonly<{
authorization: string;
guide: string;
actionTypes: string;
apmRulesErrorCount: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
({
lists,
actions,
docLinks,
logger,
config,
publicBaseUrl,
Expand Down Expand Up @@ -306,6 +307,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
privileges,
ruleExecutionLogger,
uiSettingsClient,
docLinks,
});

if (readIndexWarningMessage != null) {
Expand Down Expand Up @@ -537,7 +539,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
// as the current status of the rule.
await ruleExecutionLogger.logStatusChange({
newStatus: RuleExecutionStatusEnum['partial failure'],
message: truncateList(result.warningMessages.concat(wrapperWarnings)).join(', '),
message: truncateList(result.warningMessages.concat(wrapperWarnings)).join('\n\n'),
metrics: {
searchDurations: result.searchAfterTimes,
indexingDurations: result.bulkCreateTimes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { sampleDocNoSortId } from '../__mocks__/es_results';
import { getQueryRuleParams } from '../../rule_schema/mocks';
import { licensingMock } from '@kbn/licensing-plugin/server/mocks';
import { QUERY_RULE_TYPE_ID } from '@kbn/securitysolution-rules';
import { docLinksServiceMock } from '@kbn/core/server/mocks';
import { hasTimestampFields } from '../utils/utils';
import { RuleExecutionStatusEnum } from '../../../../../common/api/detection_engine';

Expand All @@ -44,6 +45,7 @@ jest.mock('../utils/get_list_client', () => ({
describe('Custom Query Alerts', () => {
const mocks = createRuleTypeMocks();
const licensing = licensingMock.createSetup();
const docLinks = docLinksServiceMock.createSetupContract();
const publicBaseUrl = 'http://somekibanabaseurl.com';
const mockedStatusLogger = ruleExecutionLogMock.forExecutors.create();
const ruleStatusLogger = () => Promise.resolve(mockedStatusLogger);
Expand All @@ -52,6 +54,7 @@ describe('Custom Query Alerts', () => {
const { actions, alerting, lists, logger, ruleDataClient } = dependencies;
const securityRuleTypeWrapper = createSecurityRuleTypeWrapper({
actions,
docLinks,
lists,
logger,
config: createMockConfig(),
Expand Down Expand Up @@ -282,7 +285,9 @@ describe('Custom Query Alerts', () => {
expect.objectContaining({
newStatus: RuleExecutionStatusEnum['partial failure'],
message:
"Check privileges failed to execute Error: hastTimestampFields test error, The rule's max alerts per run setting (10000) is greater than the Kibana alerting limit (1000). The rule will only write a maximum of 1000 alerts per rule run.",
'Check privileges failed to execute Error: hastTimestampFields test error\n' +
'\n' +
"The rule's max alerts per run setting (10000) is greater than the Kibana alerting limit (1000). The rule will only write a maximum of 1000 alerts per rule run.",
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { TypeOfFieldMap } from '@kbn/rule-registry-plugin/common/field_map'
import type { Filter } from '@kbn/es-query';

import type { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
import type { DocLinksServiceSetup } from '@kbn/core/server';
import type { RulePreviewLoggedRequest } from '../../../../common/api/detection_engine/rule_preview/rule_preview.gen';
import type { RuleResponseAction } from '../../../../common/api/detection_engine/model/rule_response_actions';
import type { ConfigType } from '../../../config';
Expand Down Expand Up @@ -139,6 +140,7 @@ export type SecurityAlertType<
export interface CreateSecurityRuleTypeWrapperProps {
lists: SetupPlugins['lists'];
actions: SetupPlugins['actions'];
docLinks: DocLinksServiceSetup;
logger: Logger;
config: ConfigType;
publicBaseUrl: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
} from '@kbn/securitysolution-io-ts-list-types';

import type {
DocLinksServiceSetup,
ElasticsearchClient,
IUiSettingsClient,
SavedObjectsClientContract,
Expand Down Expand Up @@ -105,35 +106,32 @@ export const hasReadIndexPrivileges = async (args: {
privileges: Privilege;
ruleExecutionLogger: IRuleExecutionLogForExecutors;
uiSettingsClient: IUiSettingsClient;
docLinks: DocLinksServiceSetup;
}): Promise<string | undefined> => {
const { privileges, ruleExecutionLogger, uiSettingsClient } = args;

const { privileges, ruleExecutionLogger, uiSettingsClient, docLinks } = args;
const apiKeyDocs = docLinks.links.alerting.authorization;
const isCcsPermissionWarningEnabled = await uiSettingsClient.get(ENABLE_CCS_READ_WARNING_SETTING);

const indexNames = Object.keys(privileges.index);
const filteredIndexNames = isCcsPermissionWarningEnabled
? indexNames
: indexNames.filter((indexName) => {
return !isCCSRemoteIndexName(indexName);
});

const [, indexesWithNoReadPrivileges] = partition(
filteredIndexNames,
(indexName) => privileges.index[indexName].read
);

let warningStatusMessage;

// Some indices have read privileges others do not.
if (indexesWithNoReadPrivileges.length > 0) {
const indexesString = JSON.stringify(indexesWithNoReadPrivileges);
warningStatusMessage = `This rule may not have the required read privileges to the following index patterns: ${indexesString}`;
warningStatusMessage = `This rule's API key is unable to access all indices that match the ${indexesString} pattern. To learn how to update and manage API keys, refer to ${apiKeyDocs}.`;
await ruleExecutionLogger.logStatusChange({
newStatus: RuleExecutionStatusEnum['partial failure'],
message: warningStatusMessage,
});
}

return warningStatusMessage;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class Plugin implements ISecuritySolutionPlugin {

const securityRuleTypeOptions = {
lists: plugins.lists,
docLinks: core.docLinks,
actions: plugins.actions,
logger: this.logger,
config: this.config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default ({ getService }: FtrProviderContext) => {

// TODO: https://github.com/elastic/kibana/pull/121644 clean up, make type-safe
expect(body?.execution_summary?.last_execution.message).to.contain(
`This rule may not have the required read privileges to the following index patterns: ["${index[0]}"]`
`This rule's API key is unable to access all indices that match the ["${index[0]}"] pattern. To learn how to update and manage API keys, refer to https://www.elastic.co/guide/en/kibana/9.0/alerting-setup.html#alerting-authorization.`
);

await deleteUserAndRole(getService, ROLES.detections_admin);
Expand Down Expand Up @@ -166,7 +166,7 @@ export default ({ getService }: FtrProviderContext) => {

// TODO: https://github.com/elastic/kibana/pull/121644 clean up, make type-safe
expect(body?.execution_summary?.last_execution.message).to.eql(
`This rule may not have the required read privileges to the following index patterns: ["${index[0]}"]`
`This rule's API key is unable to access all indices that match the ["${index[0]}"] pattern. To learn how to update and manage API keys, refer to https://www.elastic.co/guide/en/kibana/9.0/alerting-setup.html#alerting-authorization.`
);

await deleteUserAndRole(getService, ROLES.detections_admin);
Expand Down