Skip to content
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

[Security Solution][Endpoint] Refactor Cypress login task and ensure consistent use of users across ESS and Serverless tests #166958

Merged

Conversation

paul-tavares
Copy link
Contributor

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

Summary

  • Cypress login task refactored:
    • login(user?) : logs use in using the default user or one of the users supported by security solution and endpoint management tests
    • login.with(username, password) : Logs a user in by using username and password
    • login.withCustomRole(role) : creates the provided role, creates a user for it by the same role name and logs in with it
  • The Cypress process for loading users into Kibana only applies to non-serverless (at the moment). For serverless, it only validates that the username being used is one of the approved user names that applies to serverless
    • FYI: the creation/availability of serverless roles/users for testing is an ongoing effort by the kibana ops team
  • New generic RoleAndUserLoader class. Is initialized with an map of Roles and provide a standard interface for loading them.
    • A sub-class (EndpointSecurityTestRolesLoader) was also created for the endpoint security test users, which uses the existing set of role definitions
    • The resolver_generator_script was also updated to use the new EndpointSecurityTestRolesLoader class for handling the --rbacUser argument

@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 21, 2023
@paul-tavares paul-tavares self-assigned this Sep 21, 2023
@paul-tavares paul-tavares marked this pull request as ready for review September 22, 2023 13:19
@paul-tavares paul-tavares requested a review from a team as a code owner September 22, 2023 13:19
@elasticmachine
Copy link
Contributor

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

@paul-tavares paul-tavares requested review from ashokaditya and removed request for gergoabraham September 22, 2023 13:19
Copy link
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.

Thanks for doing this, as usual a piece of good work done 👏
The only thing that comes to my mind is why do we need two approaches to login - login and loginServerless. Please correct me if I got it wrong, but my understanding is that the each test now has to be specific about env's login functionality which makes it not reusable with usage of tags.
What I mean is if we have a spec that should run in two envs (@ess, @serverless) I believe we should ust use 'login' in the spec and somewhere behind the scenes we should login properly.
Does this make sense?
Approved anyway, again it's a great work 👍 Thanks!


export const ROLE = Object.freeze<Record<SecurityTestUser, SecurityTestUser>>({
...ENDPOINT_SECURITY_ROLE_NAMES,
elastic: 'elastic',
Copy link
Contributor

Choose a reason for hiding this comment

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

can we spread KIBANA_KNOWN_DEFAULT_ACCOUNTS here? Or you want to keep it separated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The const is actually an array, thus why I did not use it here... but, thats a good point. I'm going to convert it to an object and then just spread it here so that we keep it centralized.

@paul-tavares
Copy link
Contributor Author

Hey @tomsonpl - thanks for the review.

Re: need for login() and loginServerles()

you are right. I refactored login() to the only one that we will use, but forgot to delete the loginSeverless() task. I will do that now. Thanks for catching that 🙏

Copy link
Member

@ashokaditya ashokaditya 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 the refactor. 🚢

async load(
name: EndpointSecurityRoleNames | KibanaKnownUserAccounts
): Promise<LoadedRoleAndUser> {
// If its a known system account, then just exit here and use the default `changeme` password
Copy link
Member

Choose a reason for hiding this comment

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

nit: If it's...

const KIBANA_USERNAME = 'KIBANA_USERNAME';
const KIBANA_PASSWORD = 'KIBANA_PASSWORD';
export const login: CyLoginTask = (
// FIXME:PT default user to `soc_manager`
Copy link
Member

Choose a reason for hiding this comment

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

Q: Is this something for later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. I did not change it just yet in order to limit the amount of refactor - just in case that changing it to soc_manager requires test changes

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Defend Workflows Cypress Tests #5 / Endpoints page "after all" hook for "Shows endpoint on the list" "after all" hook for "Shows endpoint on the list"
  • [job] [logs] Defend Workflows Cypress Tests #5 / Endpoints page "before all" hook for "Shows endpoint on the list" "before all" hook for "Shows endpoint on the list"
  • [job] [logs] FTR Configs #28 / serverless security UI Case View "before all" hook in "Case View"

Metrics [docs]

Unknown metric groups

ESLint disabled in files

id before after diff
securitySolution 66 67 +1

Total ESLint disabled count

id before after diff
securitySolution 520 521 +1

History

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

cc @paul-tavares

@paul-tavares paul-tavares merged commit 3f03264 into elastic:main Sep 25, 2023
30 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 25, 2023
@paul-tavares paul-tavares deleted the task/olm-7690-cypress-login-task branch September 25, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit 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.

6 participants