kibana/scripts
Kibana Machine 9a7dafcf38
[8.x] [CodeQL] Local run script (#194272) (#197989)
# Backport

This will backport the following commits from `main` to `8.x`:
- [[CodeQL] Local run script
(#194272)](https://github.com/elastic/kibana/pull/194272)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Shostak","email":"165678770+elena-shostak@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-28T12:40:27Z","message":"[CodeQL]
Local run script (#194272)\n\n## Summary\r\n\r\nThis PR introduces a
script that allows developers to run CodeQL\r\nanalysis locally. It uses
a Docker container with prebuilt CodeQL\r\nqueries to facilitate easy
setup and execution.\r\nThe script has the following key steps:\r\n-
Creating a CodeQL database from the source code. The database
is\r\nessentially a representation of the codebase that CodeQL uses to
analyze\r\nfor potential issues.\r\n- Running the analysis on the
created database,\r\n`javascript-security-and-quality` suit is
used.\r\n\r\n### Usage\r\n```\r\nbash scripts/codeql/quick_check.sh -s
path/to/your-source-dir\r\n```\r\nFor example\r\n```\r\nbash
scripts/codeql/quick_check.sh -s
./x-pack/plugins/security_solution/public/common/components/ml/conditional_links\r\n```\r\n\r\nThe
`-s` option allows you to specify the path to the source
code\r\ndirectory that you wish to analyze.\r\n\r\n### Why custom Docker
file?\r\nChecked the ability to use MSFT image for local
run\r\nhttps://github.com/microsoft/codeql-container. Turned out it has
several\r\nproblems:\r\n1. The published one has an error with
[execute\r\npermissions](https://github.com/microsoft/codeql-container/issues/53).\r\n2.
Container has outdated nodejs version, so it didn't parse our
syntax\r\n(like `??`) and failed.\r\n3. The technique used in the
repository to download the CodeQL binaries\r\nand precompile the queries
is outdated in the sense that GitHub now\r\noffers pre-compiled queries
you can just download. Follow
this\r\n[comment](https://github.com/microsoft/codeql-container/issues/53#issuecomment-1875879512).\r\n\r\nTaking
this into consideration I have created a lightweight docker
image\r\nwithout extraneous dependencies for go/.net/java.\r\n\r\n##
Context and interdependencies issues\r\nThere are issues sometimes when
analyze run returns no results,\r\nparticularly when analyzing a single
folder.\r\nIt might be due to the missing context for the data flow
graph CodeQL\r\ngenerates or context for interdependencies. This is
actually a trade off\r\nof running it locally for a subset of source
directories. We need to\r\nexplicitly state that in the documentation
and advise to expand the\r\nscope of source code directories involved
for local scan.\r\n\r\nDocumentation for triaging issues will be updated
separately.\r\n\r\n__Closes:
https://github.com/elastic/kibana/issues/195740__","sha":"9dd4205639ed16f9086a7c5d70e077b6db21d73b","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Security","enhancement","release_note:skip","v9.0.0","backport:prev-minor"],"title":"[CodeQL]
Local run
script","number":194272,"url":"https://github.com/elastic/kibana/pull/194272","mergeCommit":{"message":"[CodeQL]
Local run script (#194272)\n\n## Summary\r\n\r\nThis PR introduces a
script that allows developers to run CodeQL\r\nanalysis locally. It uses
a Docker container with prebuilt CodeQL\r\nqueries to facilitate easy
setup and execution.\r\nThe script has the following key steps:\r\n-
Creating a CodeQL database from the source code. The database
is\r\nessentially a representation of the codebase that CodeQL uses to
analyze\r\nfor potential issues.\r\n- Running the analysis on the
created database,\r\n`javascript-security-and-quality` suit is
used.\r\n\r\n### Usage\r\n```\r\nbash scripts/codeql/quick_check.sh -s
path/to/your-source-dir\r\n```\r\nFor example\r\n```\r\nbash
scripts/codeql/quick_check.sh -s
./x-pack/plugins/security_solution/public/common/components/ml/conditional_links\r\n```\r\n\r\nThe
`-s` option allows you to specify the path to the source
code\r\ndirectory that you wish to analyze.\r\n\r\n### Why custom Docker
file?\r\nChecked the ability to use MSFT image for local
run\r\nhttps://github.com/microsoft/codeql-container. Turned out it has
several\r\nproblems:\r\n1. The published one has an error with
[execute\r\npermissions](https://github.com/microsoft/codeql-container/issues/53).\r\n2.
Container has outdated nodejs version, so it didn't parse our
syntax\r\n(like `??`) and failed.\r\n3. The technique used in the
repository to download the CodeQL binaries\r\nand precompile the queries
is outdated in the sense that GitHub now\r\noffers pre-compiled queries
you can just download. Follow
this\r\n[comment](https://github.com/microsoft/codeql-container/issues/53#issuecomment-1875879512).\r\n\r\nTaking
this into consideration I have created a lightweight docker
image\r\nwithout extraneous dependencies for go/.net/java.\r\n\r\n##
Context and interdependencies issues\r\nThere are issues sometimes when
analyze run returns no results,\r\nparticularly when analyzing a single
folder.\r\nIt might be due to the missing context for the data flow
graph CodeQL\r\ngenerates or context for interdependencies. This is
actually a trade off\r\nof running it locally for a subset of source
directories. We need to\r\nexplicitly state that in the documentation
and advise to expand the\r\nscope of source code directories involved
for local scan.\r\n\r\nDocumentation for triaging issues will be updated
separately.\r\n\r\n__Closes:
https://github.com/elastic/kibana/issues/195740__","sha":"9dd4205639ed16f9086a7c5d70e077b6db21d73b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194272","number":194272,"mergeCommit":{"message":"[CodeQL]
Local run script (#194272)\n\n## Summary\r\n\r\nThis PR introduces a
script that allows developers to run CodeQL\r\nanalysis locally. It uses
a Docker container with prebuilt CodeQL\r\nqueries to facilitate easy
setup and execution.\r\nThe script has the following key steps:\r\n-
Creating a CodeQL database from the source code. The database
is\r\nessentially a representation of the codebase that CodeQL uses to
analyze\r\nfor potential issues.\r\n- Running the analysis on the
created database,\r\n`javascript-security-and-quality` suit is
used.\r\n\r\n### Usage\r\n```\r\nbash scripts/codeql/quick_check.sh -s
path/to/your-source-dir\r\n```\r\nFor example\r\n```\r\nbash
scripts/codeql/quick_check.sh -s
./x-pack/plugins/security_solution/public/common/components/ml/conditional_links\r\n```\r\n\r\nThe
`-s` option allows you to specify the path to the source
code\r\ndirectory that you wish to analyze.\r\n\r\n### Why custom Docker
file?\r\nChecked the ability to use MSFT image for local
run\r\nhttps://github.com/microsoft/codeql-container. Turned out it has
several\r\nproblems:\r\n1. The published one has an error with
[execute\r\npermissions](https://github.com/microsoft/codeql-container/issues/53).\r\n2.
Container has outdated nodejs version, so it didn't parse our
syntax\r\n(like `??`) and failed.\r\n3. The technique used in the
repository to download the CodeQL binaries\r\nand precompile the queries
is outdated in the sense that GitHub now\r\noffers pre-compiled queries
you can just download. Follow
this\r\n[comment](https://github.com/microsoft/codeql-container/issues/53#issuecomment-1875879512).\r\n\r\nTaking
this into consideration I have created a lightweight docker
image\r\nwithout extraneous dependencies for go/.net/java.\r\n\r\n##
Context and interdependencies issues\r\nThere are issues sometimes when
analyze run returns no results,\r\nparticularly when analyzing a single
folder.\r\nIt might be due to the missing context for the data flow
graph CodeQL\r\ngenerates or context for interdependencies. This is
actually a trade off\r\nof running it locally for a subset of source
directories. We need to\r\nexplicitly state that in the documentation
and advise to expand the\r\nscope of source code directories involved
for local scan.\r\n\r\nDocumentation for triaging issues will be updated
separately.\r\n\r\n__Closes:
https://github.com/elastic/kibana/issues/195740__","sha":"9dd4205639ed16f9086a7c5d70e077b6db21d73b"}}]}]
BACKPORT-->

Co-authored-by: Elena Shostak <165678770+elena-shostak@users.noreply.github.com>
2024-10-28 09:23:36 -05:00
..
codeql [8.x] [CodeQL] Local run script (#194272) (#197989) 2024-10-28 09:23:36 -05:00
archive_migration_functions.sh [QA] Fixup flaky test (#156373) 2023-05-08 11:32:53 +01:00
backport.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
build.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
build_api_docs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
build_kibana_platform_plugins.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
build_plugin_list_docs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
build_product_doc_artifacts.js [8.x] [KB] create @kbn/product-doc-artifact-builder package (#193847) (#196206) 2024-10-15 08:02:35 +02:00
capture_oas_snapshot.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_file_casing.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_ftr_code_owners.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_ftr_configs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_jest_configs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_licenses.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_mappings_update.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
check_prod_native_modules.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
chromium_version.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
classify_source.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
create_observability_rules.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
delete_kibana_indices.sh Script to delete .kibana indices (#157491) 2023-05-16 14:28:01 +02:00
dev_docs.sh [Docs] Added OAS dev tutorial (#187573) 2024-07-05 08:47:14 +00:00
docs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
download_pr_list.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
enabled_ftr_configs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
es.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
es_archiver.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
eslint.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
eslint_with_types.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
extract_performance_testing_dataset.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
find_babel_runtime_helpers_in_use.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
find_node_libs_browser_polyfills_in_use.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
functional_test_runner.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
functional_tests.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
functional_tests_server.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
generate.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
generate_console_definitions.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
generate_openapi.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
generate_plugin.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
generate_team_assignments.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
i18n_check.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
i18n_extract.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
i18n_integrate.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
ingest_coverage.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
jest.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
jest_integration.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kbn.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kbn_archiver.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana_encryption_keys.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana_keystore.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana_plugin.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana_setup.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana_verification_code.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
licenses_csv_report.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
lint_packages.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
lint_ts_projects.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
makelogs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
manifest.js [8.x] Add ESLINT constraints to detect inter-group dependencies (#194810) (#197670) 2024-10-24 13:20:30 -07:00
notice.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
plugin_check.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
plugin_helpers.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
precommit_hook.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
prettier_topology_check.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
quick_checks.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
read_jest_help.mjs Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
README.md [ftr] automatically determine config run order (#130983) 2022-05-04 17:05:58 -05:00
register_git_hook.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
report_failed_tests.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
report_performance_metrics.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
rewrite_buildkite_definitions.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
run_performance.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
run_scalability.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
saved_objs_info.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
ship_ci_stats.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
snapshot_plugin_types.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
spec_to_console.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
storybook.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
stylelint.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
synthtrace.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
telemetry_check.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
telemetry_extract.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
test_hardening.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
type_check.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
update_prs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
update_vscode_config.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
validate_next_docs.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
whereis_pkg.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
yarn_deduplicate.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00

Kibana Dev Scripts

This directory contains scripts useful for interacting with Kibana tools in development. Use the node executable and --help flag to learn about how they work:

node scripts/{{script name}} --help

For Developers

This directory is excluded from the build and tools within it should help users discover their capabilities. Each script in this directory must:

  • require src/setup_node_env to bootstrap NodeJS environment
  • call out to source code in the src or packages directories
  • react to the --help flag
  • run everywhere OR check and fail fast when a required OS or toolchain is not available

Functional Test Scripts

node scripts/functional_tests [--config test/functional/config.base.js --config test/api_integration/config.js]

Runs all the functional tests: selenium tests and api integration tests. List configs with multiple --config arguments. Uses the @kbn/test library to run Elasticsearch and Kibana servers and tests against those servers, for multiple server+test setups. In particular, calls out to runTests(). Can be run on a single config.

node scripts/functional_tests_server [--config test/functional/config.base.js]

Starts just the Elasticsearch and Kibana servers given a single config, i.e. via --config test/functional/config.base.js or --config test/api_integration/config. Allows the user to start just the servers with this script, and keep them running while running tests against these servers. The idea is that the same config file configures both Elasticsearch and Kibana servers. Uses the startServers() method from @kbn/test library.

Example. Start servers and run tests, separately, but using the same config:

# Just the servers
node scripts/functional_tests_server --config path/to/config

In another terminal:

# Just the tests--against the running servers
node scripts/functional_test_runner --config path/to/config

For details on how the internal methods work, read this readme.

ES archiver

Loading data

If you wish to load up specific es archived data for your test, you can do so via:

node scripts/es_archiver.js load <archive> [--es-url=http://username:password@localhost:9200] [--kibana-url=http://username:password@localhost:5601/{basepath?}]

That will load the specified archive located in the archive directory specified by the default functional config file, located in test/functional/config.base.js. To load archives from other function config files you can pass --config path/to/config.js.

Note: The --es-url and --kibana-url options may or may not be neccessary depending on your current Kibana configuration settings, and their values may also change based on those settings (for example if you are not running with security you will not need the username:password portion).

Saving data

You can save existing data into an archive by using the save command:

node scripts/es_archiver.js save <archive name for kibana data> [space separated list of index patterns to include]

You may want to store the .kibana index separate from data. Since adding a lot of data will bloat our repo size, we have many tests that reuse the same data indices but use their own .kibana index.