diff --git a/.eslintrc.js b/.eslintrc.js index ea61de23f2402..9da7404b0e6a4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -832,48 +832,12 @@ module.exports = { // typescript only for front and back end files: ['x-pack/plugins/security_solution/**/*.{ts,tsx}'], rules: { - // This will be turned on after bug fixes are complete - // '@typescript-eslint/explicit-member-accessibility': 'warn', '@typescript-eslint/no-this-alias': 'error', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-useless-constructor': 'error', - // This will be turned on after bug fixes are complete - // '@typescript-eslint/no-object-literal-type-assertion': 'warn', '@typescript-eslint/unified-signatures': 'error', - - // eventually we want this to be a warn and then an error since this is a recommended linter rule - // for now, keeping it commented out to avoid too much IDE noise until the other linter issues - // are fixed in the next release or two - // '@typescript-eslint/explicit-function-return-type': 'warn', - - // these rules cannot be turned on and tested at the moment until this issue is resolved: - // https://github.com/prettier/prettier-eslint/issues/201 - // '@typescript-eslint/await-thenable': 'error', - // '@typescript-eslint/no-non-null-assertion': 'error' - // '@typescript-eslint/no-unnecessary-type-assertion': 'error', - // '@typescript-eslint/no-unused-vars': 'error', - // '@typescript-eslint/prefer-includes': 'error', - // '@typescript-eslint/prefer-string-starts-ends-with': 'error', - // '@typescript-eslint/promise-function-async': 'error', - // '@typescript-eslint/prefer-regexp-exec': 'error', - // '@typescript-eslint/promise-function-async': 'error', - // '@typescript-eslint/require-array-sort-compare': 'error', - // '@typescript-eslint/restrict-plus-operands': 'error', - // '@typescript-eslint/unbound-method': 'error', }, }, - // { - // // will introduced after the other warns are fixed - // // typescript and javascript for front end react performance - // files: ['x-pack/plugins/security_solution/public/**/!(*.test).{js,mjs,ts,tsx}'], - // plugins: ['react-perf'], - // rules: { - // // 'react-perf/jsx-no-new-object-as-prop': 'error', - // // 'react-perf/jsx-no-new-array-as-prop': 'error', - // // 'react-perf/jsx-no-new-function-as-prop': 'error', - // // 'react/jsx-no-bind': 'error', - // }, - // }, { // typescript and javascript for front and back end files: ['x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}'], @@ -886,21 +850,6 @@ module.exports = { 'array-callback-return': 'error', 'no-array-constructor': 'error', complexity: 'warn', - // This will be turned on after bug fixes are mostly completed - // 'consistent-return': 'warn', - // This will be turned on after bug fixes are mostly completed - // 'func-style': ['warn', 'expression'], - // These will be turned on after bug fixes are mostly completed and we can - // run a fix-lint - /* - 'import/order': [ - 'warn', - { - groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], - 'newlines-between': 'always', - }, - ], - */ 'node/no-deprecated-api': 'error', 'no-bitwise': 'error', 'no-continue': 'error', @@ -940,12 +889,8 @@ module.exports = { 'no-useless-catch': 'error', 'no-useless-concat': 'error', 'no-useless-computed-key': 'error', - // This will be turned on after bug fixes are mostly complete - // 'no-useless-escape': 'warn', 'no-useless-rename': 'error', 'no-useless-return': 'error', - // This will be turned on after bug fixers are mostly complete - // 'no-void': 'warn', 'one-var-declaration-per-line': 'error', 'prefer-object-spread': 'error', 'prefer-promise-reject-errors': 'error', @@ -961,9 +906,6 @@ module.exports = { 'react/no-danger-with-children': 'error', 'react/no-deprecated': 'error', 'react/no-did-mount-set-state': 'error', - // Re-enable once we have better options per this issue: - // https://github.com/airbnb/javascript/issues/1875 - // 'react/no-did-update-set-state': 'error', 'react/no-direct-mutation-state': 'error', 'react/no-find-dom-node': 'error', 'react/no-redundant-should-component-update': 'error', @@ -975,8 +917,6 @@ module.exports = { 'react/no-unsafe': 'error', 'react/no-unused-prop-types': 'error', 'react/no-unused-state': 'error', - // will introduced after the other warns are fixed - // 'react/sort-comp': 'error', 'react/void-dom-elements-no-children': 'error', 'react/jsx-no-comment-textnodes': 'error', 'react/jsx-no-literals': 'error', diff --git a/x-pack/plugins/security_solution/scripts/convert_saved_search_to_rules.js b/x-pack/plugins/security_solution/scripts/convert_saved_search_to_rules.js deleted file mode 100644 index 33968849fdb91..0000000000000 --- a/x-pack/plugins/security_solution/scripts/convert_saved_search_to_rules.js +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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. - */ - -require('../../../../src/setup_node_env'); - -const fs = require('fs'); -const path = require('path'); -// eslint-disable-next-line import/no-extraneous-dependencies -const uuid = require('uuid'); - -/* - * This script is used to parse a set of saved searches on a file system - * and output rule data compatible json files. - * Example: - * node saved_query_to_rules.js ${HOME}/saved_searches ${HOME}/saved_rules - * - * After editing any changes in the files of ${HOME}/saved_rules/*.json - * you can then post the rules with a CURL post script such as: - * - * ./post_rule.sh ${HOME}/saved_rules/*.json - * - * Note: This script is recursive and but does not preserve folder structure - * when it outputs the saved rules. - */ - -// Defaults of the outputted rules since the saved KQL searches do not have -// this type of information. You usually will want to make any hand edits after -// doing a search to KQL conversion before posting it as a rule or checking it -// into another repository. -const INTERVAL = '5m'; -const SEVERITY = 'low'; -const TYPE = 'query'; -const FROM = 'now-6m'; -const TO = 'now'; -const IMMUTABLE = true; -const RISK_SCORE = 50; -const ENABLED = false; - -// For converting, if you want to use these instead of rely on the defaults then -// comment these in and use them for the script. Otherwise this is commented out -// so we can utilize the defaults of input and output which are based on saved objects -// of securitySolution:defaultIndex and your kibana.dev.yml setting of xpack.securitySolution.signalsIndex. If -// the setting of xpack.securitySolution.signalsIndex is not set it defaults to .siem-signals -// const INDEX = ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*']; -// const OUTPUT_INDEX = '.siem-signals-some-other-index'; - -const walk = (dir) => { - const list = fs.readdirSync(dir); - return list.reduce((accum, file) => { - const fileWithDir = `${dir}/${file}`; - const stat = fs.statSync(fileWithDir); - if (stat && stat.isDirectory()) { - return [...accum, ...walk(fileWithDir)]; - } else { - return [...accum, fileWithDir]; - } - }, []); -}; - -//clean up the file system characters -const cleanupFileName = (file) => { - const fileWithoutSpecialChars = file - .trim() - .replace(/\./g, '') - .replace(/\//g, '') - .replace(/\s+/g, '_') - .replace(/,/g, '') - .replace(/\[/g, '') - .replace(/\]/g, '') - .replace(/\(/g, '') - .replace(/\)/g, '') - .replace(/\@/g, '') - .replace(/\:/g, '') - .replace(/\+s/g, '') - .replace(/-/g, '') - .replace(/__/g, '_') - .toLowerCase(); - return path.basename( - fileWithoutSpecialChars.trim(), - path.extname(fileWithoutSpecialChars.trim()) - ); -}; - -async function main() { - if (process.argv.length !== 4) { - throw new Error( - 'usage: saved_query_to_rules [input directory with saved searches] [output directory]' - ); - } - - const files = process.argv[2]; - const outputDir = process.argv[3]; - - const savedSearchesJson = walk(files).filter((file) => { - return !path.basename(file).startsWith('.') && file.endsWith('.ndjson'); - }); - - const savedSearchesParsed = savedSearchesJson.reduce((accum, json) => { - const jsonFile = fs.readFileSync(json, 'utf8'); - const jsonLines = jsonFile.split(/\r{0,1}\n/); - const parsedLines = jsonLines.reduce((accum, line) => { - try { - const parsedLine = JSON.parse(line); - // don't try to parse out any exported count records - if (parsedLine.exportedCount != null) { - return accum; - } - parsedLine._file = parsedLine.attributes.title; - parsedLine.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.parse( - parsedLine.attributes.kibanaSavedObjectMeta.searchSourceJSON - ); - return [...accum, parsedLine]; - } catch (err) { - return accum; - } - }, []); - return [...accum, ...parsedLines]; - }, []); - - savedSearchesParsed.forEach( - ({ - _file, - attributes: { - description, - title, - kibanaSavedObjectMeta: { - searchSourceJSON: { - query: { query, language }, - filter, - }, - }, - }, - }) => { - const fileToWrite = cleanupFileName(_file); - - // remove meta value from the filter - const filterWithoutMeta = filter.map((filterValue) => { - filterValue.$state; - return filterValue; - }); - const outputMessage = { - description: description || title, - enabled: ENABLED, - filters: filterWithoutMeta, - from: FROM, - immutable: IMMUTABLE, - interval: INTERVAL, - language, - name: title, - query, - risk_score: RISK_SCORE, - rule_id: uuid.v4(), - severity: SEVERITY, - to: TO, - type: TYPE, - version: 1, - // comment these in if you want to use these for input output, otherwise - // with these two commented out, we will use the default saved objects from spaces. - // index: INDEX, - // output_index: OUTPUT_INDEX, - }; - - fs.writeFileSync( - `${outputDir}/${fileToWrite}.json`, - `${JSON.stringify(outputMessage, null, 2)}\n` - ); - } - ); -} - -if (require.main === module) { - main(); -} diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig.js b/x-pack/plugins/security_solution/scripts/optimize_tsconfig.js deleted file mode 100644 index e8fda71d8b7db..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ - -const { optimizeTsConfig } = require('./optimize_tsconfig/optimize'); - -optimizeTsConfig().catch((err) => { - console.error(err); - // eslint-disable-next-line no-process-exit - process.exit(1); -}); diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/README.md b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/README.md deleted file mode 100644 index b711b8bf1dbc2..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/README.md +++ /dev/null @@ -1,16 +0,0 @@ -Hard forked from here: -x-pack/plugins/apm/scripts/optimize-tsconfig.js - - -#### Optimizing TypeScript - -Kibana and X-Pack are very large TypeScript projects, and it comes at a cost. Editor responsiveness is not great, and the CLI type check for X-Pack takes about a minute. To get faster feedback, we create a smaller SIEM TypeScript project that only type checks the SIEM project and the files it uses. This optimization consists of creating a `tsconfig.json` in SIEM that includes the Kibana/X-Pack typings, and editing the Kibana/X-Pack configurations to not include any files, or removing the configurations altogether. The script configures git to ignore any changes in these files, and has an undo script as well. - -To run the optimization: - -`$ node x-pack/plugins/security_solution/scripts/optimize_tsconfig` - -To undo the optimization: - -`$ node x-pack/plugins/security_solution/scripts/unoptimize_tsconfig` - diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/optimize.js b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/optimize.js deleted file mode 100644 index 9bea8c93ed52c..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/optimize.js +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable import/no-extraneous-dependencies */ - -const fs = require('fs'); -const { promisify } = require('util'); -const path = require('path'); -const json5 = require('json5'); -const execa = require('execa'); - -const readFile = promisify(fs.readFile); -const writeFile = promisify(fs.writeFile); - -const { xpackRoot, kibanaRoot, tsconfigTpl, filesToIgnore } = require('./paths'); -const { unoptimizeTsConfig } = require('./unoptimize'); - -function prepareParentTsConfigs() { - return Promise.all( - [path.resolve(xpackRoot, 'tsconfig.json'), path.resolve(kibanaRoot, 'tsconfig.json')].map( - async (filename) => { - const config = json5.parse(await readFile(filename, 'utf-8')); - - await writeFile( - filename, - JSON.stringify( - { - ...config, - include: [], - }, - null, - 2 - ), - { encoding: 'utf-8' } - ); - } - ) - ); -} - -async function addFilesToXpackTsConfig() { - const template = json5.parse(await readFile(tsconfigTpl, 'utf-8')); - const xpackTsConfig = path.join(xpackRoot, 'tsconfig.json'); - const config = json5.parse(await readFile(xpackTsConfig, 'utf-8')); - - await writeFile(xpackTsConfig, JSON.stringify({ ...config, ...template }, null, 2), { - encoding: 'utf-8', - }); -} - -async function setIgnoreChanges() { - for (const filename of filesToIgnore) { - await execa('git', ['update-index', '--skip-worktree', filename]); - } -} - -async function optimizeTsConfig() { - await unoptimizeTsConfig(); - - await prepareParentTsConfigs(); - - await addFilesToXpackTsConfig(); - - await setIgnoreChanges(); - // eslint-disable-next-line no-console - console.log( - 'Created an optimized tsconfig.json for SIEM. To undo these changes, run `./scripts/unoptimize_tsconfig.js`' - ); -} - -module.exports = { - optimizeTsConfig, -}; diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/paths.js b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/paths.js deleted file mode 100644 index ac32739627935..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/paths.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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. - */ - -const path = require('path'); - -const xpackRoot = path.resolve(__dirname, '../../../..'); -const kibanaRoot = path.resolve(xpackRoot, '..'); - -const tsconfigTpl = path.resolve(__dirname, './tsconfig.json'); - -const filesToIgnore = [ - path.resolve(xpackRoot, 'tsconfig.json'), - path.resolve(kibanaRoot, 'tsconfig.json'), -]; - -module.exports = { - xpackRoot, - kibanaRoot, - tsconfigTpl, - filesToIgnore, -}; diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json deleted file mode 100644 index ac56a6af31c72..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "include": [ - "typings/**/*", - "plugins/lists/**/*", - "plugins/security_solution/**/*", - "plugins/apm/typings/numeral.d.ts", - "plugins/canvas/types/webpack.d.ts", - "plugins/triggers_actions_ui/**/*" - ], - "exclude": [ - "test/**/*", - "**/__fixtures__/**/*", - "plugins/security_solution/cypress/**/*" - ] -} diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/unoptimize.js b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/unoptimize.js deleted file mode 100644 index 58bd5d526a638..0000000000000 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/unoptimize.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable import/no-extraneous-dependencies */ - -const execa = require('execa'); - -const { filesToIgnore } = require('./paths'); - -async function unoptimizeTsConfig() { - for (const filename of filesToIgnore) { - await execa('git', ['update-index', '--no-skip-worktree', filename]); - await execa('git', ['checkout', filename]); - } -} - -module.exports = { - unoptimizeTsConfig: async () => { - await unoptimizeTsConfig(); - // eslint-disable-next-line no-console - console.log('Removed SIEM TypeScript optimizations'); - }, -}; diff --git a/x-pack/plugins/security_solution/scripts/unoptimize_tsconfig.js b/x-pack/plugins/security_solution/scripts/unoptimize_tsconfig.js deleted file mode 100644 index f7f6e7936fbbc..0000000000000 --- a/x-pack/plugins/security_solution/scripts/unoptimize_tsconfig.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ - -const { unoptimizeTsConfig } = require('./optimize_tsconfig/unoptimize'); - -unoptimizeTsConfig().catch((err) => { - console.error(err); - // eslint-disable-next-line no-process-exit - process.exit(1); -}); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/scripts/convert_saved_search_to_rules.sh b/x-pack/plugins/security_solution/server/lib/detection_engine/scripts/convert_saved_search_to_rules.sh deleted file mode 100755 index 65f27647fd43a..0000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/scripts/convert_saved_search_to_rules.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# -# 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. -# - -set -e -./check_env_variables.sh - -OUTPUT=${2:-../rules/prepackaged_rules} - -node ../../../../scripts/convert_saved_search_to_rules.js $1 $OUTPUT