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

Add mock identity provider for serverless #170852

Merged
merged 31 commits into from
Nov 15, 2023

Conversation

thomheymann
Copy link
Contributor

@thomheymann thomheymann commented Nov 8, 2023

Related to #166340

Summary

Add mock identity provider and utils to test serverless user roles.

Screenshot

1. Login selector

Screenshot 2023-11-08 at 15 18 18

2. Single sign on screen

Screenshot 2023-11-09 at 12 30 46

3. User profile page

Screenshot 2023-11-08 at 17 36 22

Testing

SAML is only supported by ES when running in SSL mode.

  1. To test the mock identity provider run a serverless project in SSL mode using:
yarn es serverless --ssl
yarn start --serverless=es --ssl
  1. Then access Kibana and login in using "Continue as Test User".

@thomheymann thomheymann marked this pull request as ready for review November 9, 2023 15:34
@thomheymann thomheymann requested a review from a team as a code owner November 9, 2023 15:34
@thomheymann thomheymann requested a review from a team November 9, 2023 15:34
@thomheymann thomheymann added the release_note:skip Skip the PR/issue when compiling release notes label Nov 9, 2023
Copy link
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.

Ran locally and working, nice job! Only thing is it would be nice to update the tests for kbn/es. Extending these should be enough since kibanaUrl is set by default.

test('should add SSL args when SSL is passed', () => {

test('should add SSL volumes when ssl is passed', async () => {

packages/kbn-es/tsconfig.json Outdated Show resolved Hide resolved
Copy link
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 adding the tests, lgtm!

@azasypkin azasypkin self-requested a review November 13, 2023 10:33
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
mockIdpPlugin - 19 +19
Unknown metric groups

API count

id before after diff
mockIdpPlugin - 25 +25

History

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

cc @thomheymann

@thomheymann thomheymann merged commit 1fb0313 into elastic:main Nov 15, 2023
26 checks passed
@kibanamachine kibanamachine added v8.12.0 backport:skip This commit does not require backporting labels Nov 15, 2023
delanni added a commit that referenced this pull request Nov 15, 2023
…1275)

## Summary
Fixes type error coming from merge-race:

#170852 - adds a new plugin
#170856 - changes how plugins
should look
Ikuni17 added a commit that referenced this pull request Nov 15, 2023
@Ikuni17
Copy link
Contributor

Ikuni17 commented Nov 15, 2023

@thomheymann thomheymann deleted the serverless-role-selector branch November 20, 2023 10:46
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Nov 23, 2023
Attempting to merge elastic#170852 again now that the release artefact step has
been fixed as part of elastic#171457

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Aleh Zasypkin <[email protected]>
Co-authored-by: Dzmitry Lemechko <[email protected]>
dmlemeshko added a commit that referenced this pull request Dec 4, 2023
## Summary

### This PR enables user roles testing in FTR

We use SAML authentication to get session cookie for user with the
specific role. The cookie is cached on FTR service side so we only make
SAML auth one time per user within FTR config run. For Kibana CI service
relies on changes coming in #170852

In order to run FTR tests locally against existing MKI project:
- add `.ftr/role_users.json` in Kibana root dir
```
{
  "viewer": {
    "email": "...",
    "password": "..."
  },
  "developer": {
    "email": "...",
    "password": "..."
  }
}

```
- set Cloud hostname (!not project hostname!) with TEST_CLOUD_HOST_NAME,
e.g.
`export TEST_CLOUD_HOST_NAME=console.qa.cld.elstc.co`


### How to use:

- functional tests:
```
const svlCommonPage = getPageObject('svlCommonPage');

before(async () => {
  // login with Viewer role  
  await svlCommonPage.loginWithRole('viewer');
  // you are logged in in browser and on project home page, start the test 
});

it('has project header', async () => {
  await svlCommonPage.assertProjectHeaderExists();
});
```

- API integration tests:
```
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let credentials: { Cookie: string };

before(async () => {
  // get auth header for Viewer role  
 credentials = await svlUserManager.getApiCredentialsForRole('viewer');
});

it('returns full status payload for authenticated request', async () => {
    const { body } = await supertestWithoutAuth
    .get('/api/status')
    .set(credentials)
    .set('kbn-xsrf', 'kibana');

    expect(body.name).to.be.a('string');
    expect(body.uuid).to.be.a('string');
    expect(body.version.number).to.be.a('string');
});
```

Flaky-test-runner: 

#1
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4081
#2
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4114

---------

Co-authored-by: Robert Oskamp <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Aleh Zasypkin <[email protected]>
MadameSheema added a commit that referenced this pull request Dec 13, 2023
…ing (#172655)

Relates to:
* #166340
* #170852
* #170417
* #172678

## Summary

In this PR we are using the code implemented on
#170417 and
#172678 to allow SAML and role
testing inside Cypress.

* We are creating a Cypress task to use the above-developed code and be
able to retrieve a session cookie given a role.
* We updated the login task to know how we should perform the login
depending if we are in Serverless (MKI or serverless FTR) or ESS
* In the parallel serverless script:
* We are updating the `BASE_ENV_URL` variable to use the proper QA
environment (pending to be done in follow-up PRs, to extract this value
so it is not hardcoded cc @dkirchan )
* We are adding the `IS_SERVERLESS` environment variable needed for the
logic on the login task. This changed implied to update the
`es_archiver` file to continue work as expected.
* We have added the `TEST_CLOUD_HOST_NAME` environment variable needed
for the code we are reusing to retrieve the session cookie for MKI.
* We have updated the Security Solution quality gate script to set the
`role_users.json` file needed by the code we are reusing to get the
different session cookies on MKI
* We have adjusted the tests because the username now follows the
pattern `test <role>` (@dmlemeshko is it possible to have as username
just the role? Is this something that can impact other tests and teams?)
* We have [skipped](#173168) a
test that got unstable after the changes.

## How to test it in your machine

### Serverless FTR

1. Navigate to `x-pack/test/security_solution_cypress`
2. Execute `yarn cypress:open:qa:serverless`
3. Click on `E2E testing`
4. Click on any test to execute it


### Serverless MKI

Setup a valid Elastic Cloud API key for QA environment:

1. Navigate to QA environment.
2. Click on the `User menu button` located on the top right of the
header.
3. Click on `Organization`.
5. Click on the `API keys` tab.
6. Click on `Create API key` button.
7. Add a name, set an expiration date, assign an organization owner
role.
8. Click on `Create API key`
9. Save the value of the key

Store the saved key on `~/.elastic/cloud.json` using the following
format:

```json
{
  "api_key": {
    "qa": "<API_KEY>"
  }
}
```

Store the email and password of the account you used to login in the QA
Environment at the root directory of your Kibana project on
`.ftr/role_users.json`, using the following format:

```json
{
  "admin": {
    "email": "<email>",
    "password": "<password>"
  }
}
```

If you want to execute a test with a role different from the default
one, make sure you have created the user under your organization and is
added to the above json following the format:

```json
{
  "admin": {
    "email": "<email>",
    "password": "<password>"
  },
  "<roleName>": {
    "email": "<email>",
    "password": "<password>"
  }
}
```

1. Navigate to `x-pack/test/security_solution_cypress`
2. Execute `yarn cypress:open:qa:serverless`
3. Click on `E2E testing`
4. Click on any test to execute it

---------

Co-authored-by: kibanamachine <[email protected]>
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 reverted v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants