-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Detection Engine][FTR] Add prebuilt role tests for rule execution #201509
base: main
Are you sure you want to change the base?
Conversation
@approksiu @caitlinbetz could you confirm the behaviors here? All but the Endpoint Operations Analyst seem to match. The sheet says they're read on rules, but seems they can execute them. |
Pinging @elastic/security-detection-engine (Team:Detection Engine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.buildkite/ftr_security_serverless_configs.yml
/ci |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
History
cc @yctercero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good thank you for adding test suites for this functionality on serverless! This follows the similar pattern for the value list testing with roles. After thinking about this some more I am wondering if we can speed up the test suites a little. I think by iterating over the roles with the same outcome for a given test we remove having to do all the build up and tear down that we would have to do if we used individual test suites for each individual role.
So instead of having a test suite for each role that tests the preview api, we would instead have a singular test suite for the preview api and iterate over all the roles within a singular test item in that suite. For example the following could live within a preview_rule_api
test file and look something like this:
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import TestAgent from 'supertest/lib/agent';
import expect from '@kbn/expect';
import {
QueryRuleCreateProps,
RulePreviewRequestBody,
} from '@kbn/security-solution-plugin/common/api/detection_engine';
import { DETECTION_ENGINE_RULES_PREVIEW } from '@kbn/security-solution-plugin/common/constants';
import { FtrProviderContext } from '../../../../../../../ftr_provider_context';
import { EsArchivePathBuilder } from '../../../../../../../es_archive_path_builder';
import {
deleteAllRules,
deleteAllAlerts,
getRuleForAlertTesting,
} from '../../../../../../../../common/utils/security_solution';
/**
* Specific _id to use for some of the tests. If the archiver changes and you see errors
* here, update this to a new value of a chosen auditbeat record and update the tests values.
*/
const ID = 'BhbXBmkBR346wHgn4PeZ';
export default ({ getService }: FtrProviderContext): void => {
const log = getService('log');
const utils = getService('securitySolutionUtils');
const config = getService('config');
const isServerless = config.get('serverless');
const dataPathBuilder = new EsArchivePathBuilder(isServerless);
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts');
const esArchiver = getService('esArchiver');
const es = getService('es');
const esDeleteAllIndices = getService('esDeleteAllIndices');
let admin: TestAgent;
let endpointPolicyManager: TestAgent;
let socManager: TestAgent;
let viewer: TestAgent;
// ... add other roles as needed
describe('@serverless @serverlessQA roles rule preview execution API behaviors', () => {
before(async () => {
await esArchiver.load(auditbeatPath);
admin = await utils.createSuperTest('admin');
endpointPolicyManager = await utils.createSuperTest('endpoint_policy_manager');
socManager = await utils.createSuperTest('soc_manager');
viewer = await utils.createSuperTest('viewer');
// ... more roles to be tested
});
afterEach(async () => {
await esDeleteAllIndices('.preview.alerts*');
});
after(async () => {
await esArchiver.unload(auditbeatPath);
await deleteAllAlerts(admin, log, es, [
'.preview.alerts-security.alerts-*',
'.alerts-security.alerts-*',
]);
await deleteAllRules(admin, log);
});
// Here we want to test that these two roles can create and run a rule against the preview api
// This will be faster than having to run a full test suite for each individual role.
it('previews rule', async () => {
await Promise.all(
[endpointPolicyManager, socManager].map(async (role) => {
const rule: QueryRuleCreateProps = {
...getRuleForAlertTesting(['auditbeat-*']),
query: `_id:${ID}`,
};
const previewRequest: RulePreviewRequestBody = {
...rule,
invocationCount: 1,
timeframeEnd: new Date().toISOString(),
};
return role
.post(DETECTION_ENGINE_RULES_PREVIEW)
.query({ enable_logged_requests: true })
.set('kbn-xsrf', 'true')
.set('elastic-api-version', '2023-10-31')
.send(previewRequest)
.expect(200);
})
);
});
});
};
Looks like the configuration is indeed set to "all" here. @caitlinbetz could you check the intended definition and comment if it should be changed to read? Thanks! |
Summary
Adds FTR for serverless prebuilt roles around rule execution. Uses the preview API to speed up the tests.