-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EDR Workflows][MKI][Osquery] Osquery Cypress tests in MKI (#190675)
This PR introduces osquery Cypress tests to the MKI environment. These tests will be executed within the **Kibana / Serverless / Security Solution Quality Gate / Defend Workflows** scope. You can find an example of the build here: [Buildkite Example](https://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-defend-workflows/builds/1049). The main challenge with running osquery tests in MKI is that we cannot continuously log in users as we do in other environments. This is due to an issue where users are logged out when switching apps. To address this, I've added a simple check in the login method to prevent the login function from being called unnecessarily in MKI. This is a temporary solution until we can properly log in users via API calls using authentication tokens. All the `chalk` & `log.indent` changes were made to make logs more beautiful 😸 ![Screenshot 2024-08-09 at 13 00 50](https://github.com/user-attachments/assets/a113e2a2-7e9c-42f0-800d-4883de8a34d2) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
69a842e
commit 7027b0b
Showing
24 changed files
with
320 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ity_solution_quality_gate/edr_workflows/mki_security_solution_defend_workflows_osquery.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo "No target script from the package.json file, is supplied" | ||
exit 1 | ||
fi | ||
|
||
|
||
source .buildkite/scripts/common/util.sh | ||
.buildkite/scripts/bootstrap.sh | ||
|
||
export JOB=kibana-defend-workflows-osquery-serverless-cypress | ||
|
||
buildkite-agent meta-data set "${BUILDKITE_JOB_ID}_is_test_execution_step" "true" | ||
|
||
source .buildkite/scripts/pipelines/security_solution_quality_gate/prepare_vault_entries.sh | ||
|
||
cd x-pack/plugins/osquery | ||
set +e | ||
|
||
export BK_ANALYTICS_API_KEY=$(vault_get security-solution-quality-gate serverless-cypress-defend-workflows) | ||
|
||
echo "--- Running the tests for target $1" | ||
BK_ANALYTICS_API_KEY=$BK_ANALYTICS_API_KEY yarn $1; status=$?; yarn junit:merge || :; exit $status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 { merge } from 'lodash'; | ||
import path from 'path'; | ||
import { safeLoad as loadYaml } from 'js-yaml'; | ||
import { readFileSync } from 'fs'; | ||
import type { YamlRoleDefinitions } from '@kbn/test-suites-serverless/shared/lib'; | ||
import { setupUserDataLoader } from '@kbn/test-suites-serverless/functional/test_suites/security/cypress/support/setup_data_loader_tasks'; | ||
import { samlAuthentication } from '@kbn/security-solution-plugin/public/management/cypress/support/saml_authentication'; | ||
import { getFailedSpecVideos } from './support/filter_videos'; | ||
|
||
const ROLES_YAML_FILE_PATH = path.join( | ||
`${__dirname}/support`, | ||
'project_controller_osquery_roles.yml' | ||
); | ||
const roleDefinitions = loadYaml(readFileSync(ROLES_YAML_FILE_PATH, 'utf8')) as YamlRoleDefinitions; | ||
|
||
export const getCypressBaseConfig = ( | ||
overrides: Cypress.ConfigOptions = {} | ||
): Cypress.ConfigOptions => | ||
merge( | ||
{ | ||
reporter: '../../../node_modules/cypress-multi-reporters', | ||
reporterOptions: { | ||
configFile: './cypress/reporter_config.json', | ||
}, | ||
|
||
defaultCommandTimeout: 60000, | ||
execTimeout: 120000, | ||
pageLoadTimeout: 12000, | ||
screenshotsFolder: '../../../target/kibana-osquery/cypress/screenshots', | ||
trashAssetsBeforeRuns: false, | ||
video: true, | ||
videosFolder: '../../../target/kibana-osquery/cypress/videos', | ||
|
||
retries: { | ||
runMode: 1, | ||
openMode: 0, | ||
}, | ||
videoCompression: 15, | ||
viewportHeight: 900, | ||
viewportWidth: 1440, | ||
experimentalStudio: true, | ||
|
||
env: { | ||
grepFilterSpecs: true, | ||
grepOmitFiltered: true, | ||
}, | ||
|
||
e2e: { | ||
specPattern: './cypress/e2e/**/*.cy.ts', | ||
experimentalRunAllSpecs: true, | ||
experimentalMemoryManagement: true, | ||
numTestsKeptInMemory: 3, | ||
setupNodeEvents(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { | ||
setupUserDataLoader(on, config, { roleDefinitions, additionalRoleName: 'viewer' }); | ||
samlAuthentication(on, config); | ||
on('after:spec', getFailedSpecVideos); | ||
|
||
return config; | ||
}, | ||
}, | ||
}, | ||
overrides | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.