Skip to content

[kbn/es serverless] Allow ES serverless resources (ex. users, users_roles, etc) to be overwritten via yarn es serverless command#167087

Merged
paul-tavares merged 23 commits intoelastic:mainfrom
paul-tavares:task/olm-serverless-es-file-realm-users-roles
Sep 27, 2023
Merged

[kbn/es serverless] Allow ES serverless resources (ex. users, users_roles, etc) to be overwritten via yarn es serverless command#167087
paul-tavares merged 23 commits intoelastic:mainfrom
paul-tavares:task/olm-serverless-es-file-realm-users-roles

Conversation

@paul-tavares
Copy link
Copy Markdown
Contributor

@paul-tavares paul-tavares commented Sep 22, 2023

Summary

@kbn/es package

  • Introduces --resources option to the es serverless command

Security Solution Plugin

  • Added customized users, users_roles and roles.yml files that includes:
    • Updated roles.yml file (sync'ed with project controller version)
    • Updated users / users_roles file that includes one one per security project role (name the same as the role)
  • New CLI script - node x-pack/plugins/security_solution/scripts/endpoint/start_es_serverless_with_security_users.js - that will start ES in serverless mode and inject the customized --resources into the command
    • Any existing option that can be passed to es or es serverless can still continue to be passed to this new script. I will pass them along.

closes #167092


➡️ Run example: Override users and users_roles with customized version

yarn es serverless --resources=./relative/path/to/users --resources=/absolute/path/to/users_roles

➡️ yarn es serverless --help

usage: es serverless [<args>]

 Run Serverless Elasticsearch through Docker

 Options:

  --tag               Image tag of ES serverless to run from docker.elastic.co/elasticsearch-ci/elasticsearch-serverless
  --image             Full path of ES serverless image to run, has precedence over tag. [default: docker.elastic.co/kibana-ci/elasticsearch-serverless:latest-verified]
  --background        Start ES serverless without attaching to the first node's logs
  --basePath          Path to the directory where the ES cluster will store data
  --clean             Remove existing file system object store before running
  --kill              Kill running ES serverless nodes if detected on startup
  --port              The port to bind to on 127.0.0.1 [default: 9200]
  --ssl               Enable HTTP SSL on the ES cluster
  --skipTeardown      If this process exits, leave the ES cluster running in the background
  --waitForReady      Wait for the ES cluster to be ready to serve requests
+ --resources         Overrides resources under ES 'config/' directory, which are by default
+                     mounted from 'packages/kbn-es/src/serverless_resources/users'. Value should
+                     be a valid file path (relative or absolute). This option can be used multiple
+                     times if needing to override multiple files. The following files can be overwritten:
+                     operator_users.yml | role_mapping.yml | roles.yml | service_tokens | users | users_roles

  -E                  Additional key=value settings to pass to ES
  -F                  Absolute paths for files to mount into containers

Examples:

  es serverless --tag git-fec36430fba2-x86_64 # loads docker.elastic.co/elasticsearch-ci/elasticsearch-serverless:git-fec36430fba2-x86_64
  es serverless --image docker.elastic.co/kibana-ci/elasticsearch-serverless:latest-verified

➡️ Start ES with Security Roles/Users

node x-pack/plugins/security_solution/scripts/endpoint/start_es_serverless_with_security_users.js --clean --kill -E xpack.security.authc.api_key.enabled=true -E http.host=0.0.0.0

Checklist

@paul-tavares paul-tavares self-assigned this Sep 22, 2023
@paul-tavares paul-tavares changed the title [POC] Add users/roles for serverless for dev [kbn/es serverless] Allow users, user_roles and roles.yml to be overwritten without having to change source code Sep 25, 2023
@paul-tavares paul-tavares added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.11.0 labels Sep 26, 2023
Copy link
Copy Markdown
Contributor

@Ikuni17 Ikuni17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this Paul! The code changes LGTM. I will submit a proper review after it is out of draft and I test locally.

@paul-tavares paul-tavares marked this pull request as ready for review September 26, 2023 17:14
@paul-tavares paul-tavares requested review from a team as code owners September 26, 2023 17:14
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

Copy link
Copy Markdown
Contributor

@Ikuni17 Ikuni17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested OPs changes locally. LGTM, nice work.

@paul-tavares paul-tavares requested a review from a team as a code owner September 26, 2023 20:45
Copy link
Copy Markdown
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@paul-tavares paul-tavares changed the title [kbn/es serverless] Allow users, user_roles and roles.yml to be overwritten without having to change source code [kbn/es serverless] Allow ES serverless resources (ex. users, users_roles, etc) to be overwritten via yarn es serverless command Sep 26, 2023
Copy link
Copy Markdown
Contributor

@tomsonpl tomsonpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, great job 👍

…-es-file-realm-users-roles

# Conflicts:
#	x-pack/plugins/security_solution/public/common/components/markdown_editor/plugins/index.ts
@paul-tavares paul-tavares enabled auto-merge (squash) September 27, 2023 12:54
@paul-tavares paul-tavares merged commit 45a28d4 into elastic:main Sep 27, 2023
@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @paul-tavares

@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Sep 27, 2023
@paul-tavares paul-tavares deleted the task/olm-serverless-es-file-realm-users-roles branch September 27, 2023 19:10
paul-tavares added a commit that referenced this pull request Oct 4, 2023
…oles to cypress e2e test setup (#167446)

## Summary

Goal of this PR is to re-enable the serverless tests that require the
login credentials for users that have the pre-defined roles from
serverless assigned to them.

### `@kbn/test` changes

- Added support for `esServerlessOptions` to FTR config. Currently
allows for `resources` to be defined
- `resources` overrides were introduced [in this
PR](#167087)
- new FTR option will allow for testing serverless with a set of
users/roles that are specific to the project type

### Security Solution Plugin

- Added `esServerlessOptions` to the Defend Workflows cypress
configurations
- Un-skips all serverless specific tests (now that we have support for
users/roles that are specific to the Security project)
- Changed the default username for cypress `login()` task to be
`endpoint_operations_analyst`
- Note that the previously used `endpoint_operations_analyst` role was
also updated to match the definition used for serverless.
- Added new common `fleet_server_services` cli module with reusable
methods for working with fleet server, including generic
`startFleetServer()` method
- New CLI script: `node
x-pack/plugins/security_solution/scripts/endpoint/start_fleet_server.js`
- Starts a fleet server locally (via Docker) and connects it to the
Kibana
    - Supports running fleet server locally for serverless as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.11.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[kbn/es serverless] Allow overriding config files

7 participants