Skip to content

[Security Solution] Supports custom roles in serverless for Cypress tests#206129

Merged
MadameSheema merged 9 commits intoelastic:mainfrom
MadameSheema:cypress/custom-roles
Jan 13, 2025
Merged

[Security Solution] Supports custom roles in serverless for Cypress tests#206129
MadameSheema merged 9 commits intoelastic:mainfrom
MadameSheema:cypress/custom-roles

Conversation

@MadameSheema
Copy link
Copy Markdown
Contributor

@MadameSheema MadameSheema commented Jan 9, 2025

Summary

Solves: https://github.com/elastic/security-team/issues/11464

In this PR we are adding the capability to use custom roles for serverless Cypress tests. To do so, we are leveraging the solution proposed in: #194677, meaning that currently we have the same restrictions, therefore, custom roles cannot be used yet in MKI environments.

Creating a Custom Role

To create a custom role, use the Cypress task createServerlessCustomRole. This task requires two parameters:

  • roleDescriptor: Defines the permissions and access for the role.
  • roleName: A unique name for the custom role.

Example:

const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });

Using a Custom Role

Once the custom role is created, you can log in to the application using your regular `login`` method and passing the name of the role.

login('customRole');

Deleting a Custom Role

After your tests, always delete the custom role to ensure a clean environment. Use the deleteServerlessCustomRole task and provide the name of the role as the parameter.

cy.task('deleteServerlessCustomRole', 'customRole');

Full workflow

Here’s the complete workflow for creating, using, and deleting a custom role:

const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

before(() => {
  cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });
});

beforeEach(() => {
  login('customRole');
});

after(() => {
  cy.task('deleteServerlessCustomRole', 'customRole');
});

@MadameSheema
Copy link
Copy Markdown
Contributor Author

/ci

@MadameSheema MadameSheema changed the title adds task to create a custom serverless role [Security Solution] Supports custom roles in serverless for Cypress tests Jan 10, 2025
@MadameSheema MadameSheema added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.18.0 labels Jan 10, 2025
@MadameSheema MadameSheema marked this pull request as ready for review January 10, 2025 10:31
@MadameSheema MadameSheema requested review from a team as code owners January 10, 2025 10:31
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@MadameSheema MadameSheema added the backport:version Backport to applied version labels label Jan 10, 2025
Copy link
Copy Markdown
Contributor

@janmonschke janmonschke 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 this functionality!

Copy link
Copy Markdown
Contributor

@cavokz cavokz left a comment

Choose a reason for hiding this comment

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

It makes sense and looks good.

I've a comment on a name though, feel free to ignore it :)

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #44 / InfraOps App Metrics UI Hosts View #With data #Permissions: Read Only User - Single Host Flyout Dashboards Tab should render dashboards tab splash screen with disabled option to add dashboard

Metrics [docs]

✅ unchanged

History

@MadameSheema MadameSheema merged commit 255aea7 into elastic:main Jan 13, 2025
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12749350914

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jan 13, 2025
…ests (elastic#206129)

## Summary

Solves: elastic/security-team#11464

In this PR we are adding the capability to use custom roles for
serverless Cypress tests. To do so, we are leveraging the solution
proposed in: elastic#194677, meaning that
currently we have the same restrictions, therefore, custom roles cannot
be used yet in MKI environments.

### Creating a Custom Role

To create a custom role, use the Cypress task
`createServerlessCustomRole`. This task requires two parameters:
- **`roleDescriptor`**: Defines the permissions and access for the role.
- **`roleName`**: A unique name for the custom role.

Example:

```typescript
const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });
```

### Using a Custom Role

Once the custom role is created, you can log in to the application using
your regular `login`` method and passing the name of the role.

```typescript
login('customRole');
```

### Deleting a Custom Role

After your tests, always delete the custom role to ensure a clean
environment. Use the `deleteServerlessCustomRole` task and provide the
name of the role as the parameter.

```typescript
cy.task('deleteServerlessCustomRole', 'customRole');
```

### Full workflow

Here’s the complete workflow for creating, using, and deleting a custom
role:

```typescript
const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

before(() => {
  cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });
});

beforeEach(() => {
  login('customRole');
});

after(() => {
  cy.task('deleteServerlessCustomRole', 'customRole');
});
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 255aea7)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 13, 2025
…ress tests (#206129) (#206451)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Supports custom roles in serverless for Cypress
tests (#206129)](#206129)

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

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

<!--BACKPORT [{"author":{"name":"Gloria
Hornero","email":"gloria.hornero@elastic.co"},"sourceCommit":{"committedDate":"2025-01-13T14:28:30Z","message":"[Security
Solution] Supports custom roles in serverless for Cypress tests
(#206129)\n\n## Summary\r\n\r\nSolves:
https://github.com/elastic/security-team/issues/11464\r\n\r\nIn this PR
we are adding the capability to use custom roles for\r\nserverless
Cypress tests. To do so, we are leveraging the solution\r\nproposed in:
#194677, meaning that\r\ncurrently
we have the same restrictions, therefore, custom roles cannot\r\nbe used
yet in MKI environments.\r\n\r\n\r\n### Creating a Custom Role\r\n\r\nTo
create a custom role, use the Cypress
task\r\n`createServerlessCustomRole`. This task requires two
parameters:\r\n- **`roleDescriptor`**: Defines the permissions and
access for the role.\r\n- **`roleName`**: A unique name for the custom
role.\r\n\r\nExample:\r\n\r\n```typescript\r\nconst roleDescriptor =
{\r\n elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names:
['*'], privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\ncy.task('createServerlessCustomRole', { roleDescriptor,
roleName: 'customRole' });\r\n```\r\n\r\n### Using a Custom
Role\r\n\r\nOnce the custom role is created, you can log in to the
application using\r\nyour regular `login`` method and passing the name
of the
role.\r\n\r\n```typescript\r\nlogin('customRole');\r\n```\r\n\r\n\r\n###
Deleting a Custom Role\r\n\r\nAfter your tests, always delete the custom
role to ensure a clean\r\nenvironment. Use the
`deleteServerlessCustomRole` task and provide the\r\nname of the role as
the
parameter.\r\n\r\n```typescript\r\ncy.task('deleteServerlessCustomRole',
'customRole');\r\n```\r\n\r\n### Full workflow\r\n\r\nHere’s the
complete workflow for creating, using, and deleting a
custom\r\nrole:\r\n\r\n```typescript\r\nconst roleDescriptor = {\r\n
elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names: ['*'],
privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\nbefore(() => {\r\n cy.task('createServerlessCustomRole',
{ roleDescriptor, roleName: 'customRole' });\r\n});\r\n\r\nbeforeEach(()
=> {\r\n login('customRole');\r\n});\r\n\r\nafter(() => {\r\n
cy.task('deleteServerlessCustomRole',
'customRole');\r\n});\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"255aea7adcf196564532df76573814f93097cce6","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","backport:version","v8.18.0"],"title":"[Security
Solution] Supports custom roles in serverless for Cypress
tests","number":206129,"url":"https://github.com/elastic/kibana/pull/206129","mergeCommit":{"message":"[Security
Solution] Supports custom roles in serverless for Cypress tests
(#206129)\n\n## Summary\r\n\r\nSolves:
https://github.com/elastic/security-team/issues/11464\r\n\r\nIn this PR
we are adding the capability to use custom roles for\r\nserverless
Cypress tests. To do so, we are leveraging the solution\r\nproposed in:
#194677, meaning that\r\ncurrently
we have the same restrictions, therefore, custom roles cannot\r\nbe used
yet in MKI environments.\r\n\r\n\r\n### Creating a Custom Role\r\n\r\nTo
create a custom role, use the Cypress
task\r\n`createServerlessCustomRole`. This task requires two
parameters:\r\n- **`roleDescriptor`**: Defines the permissions and
access for the role.\r\n- **`roleName`**: A unique name for the custom
role.\r\n\r\nExample:\r\n\r\n```typescript\r\nconst roleDescriptor =
{\r\n elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names:
['*'], privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\ncy.task('createServerlessCustomRole', { roleDescriptor,
roleName: 'customRole' });\r\n```\r\n\r\n### Using a Custom
Role\r\n\r\nOnce the custom role is created, you can log in to the
application using\r\nyour regular `login`` method and passing the name
of the
role.\r\n\r\n```typescript\r\nlogin('customRole');\r\n```\r\n\r\n\r\n###
Deleting a Custom Role\r\n\r\nAfter your tests, always delete the custom
role to ensure a clean\r\nenvironment. Use the
`deleteServerlessCustomRole` task and provide the\r\nname of the role as
the
parameter.\r\n\r\n```typescript\r\ncy.task('deleteServerlessCustomRole',
'customRole');\r\n```\r\n\r\n### Full workflow\r\n\r\nHere’s the
complete workflow for creating, using, and deleting a
custom\r\nrole:\r\n\r\n```typescript\r\nconst roleDescriptor = {\r\n
elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names: ['*'],
privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\nbefore(() => {\r\n cy.task('createServerlessCustomRole',
{ roleDescriptor, roleName: 'customRole' });\r\n});\r\n\r\nbeforeEach(()
=> {\r\n login('customRole');\r\n});\r\n\r\nafter(() => {\r\n
cy.task('deleteServerlessCustomRole',
'customRole');\r\n});\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"255aea7adcf196564532df76573814f93097cce6"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206129","number":206129,"mergeCommit":{"message":"[Security
Solution] Supports custom roles in serverless for Cypress tests
(#206129)\n\n## Summary\r\n\r\nSolves:
https://github.com/elastic/security-team/issues/11464\r\n\r\nIn this PR
we are adding the capability to use custom roles for\r\nserverless
Cypress tests. To do so, we are leveraging the solution\r\nproposed in:
#194677, meaning that\r\ncurrently
we have the same restrictions, therefore, custom roles cannot\r\nbe used
yet in MKI environments.\r\n\r\n\r\n### Creating a Custom Role\r\n\r\nTo
create a custom role, use the Cypress
task\r\n`createServerlessCustomRole`. This task requires two
parameters:\r\n- **`roleDescriptor`**: Defines the permissions and
access for the role.\r\n- **`roleName`**: A unique name for the custom
role.\r\n\r\nExample:\r\n\r\n```typescript\r\nconst roleDescriptor =
{\r\n elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names:
['*'], privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\ncy.task('createServerlessCustomRole', { roleDescriptor,
roleName: 'customRole' });\r\n```\r\n\r\n### Using a Custom
Role\r\n\r\nOnce the custom role is created, you can log in to the
application using\r\nyour regular `login`` method and passing the name
of the
role.\r\n\r\n```typescript\r\nlogin('customRole');\r\n```\r\n\r\n\r\n###
Deleting a Custom Role\r\n\r\nAfter your tests, always delete the custom
role to ensure a clean\r\nenvironment. Use the
`deleteServerlessCustomRole` task and provide the\r\nname of the role as
the
parameter.\r\n\r\n```typescript\r\ncy.task('deleteServerlessCustomRole',
'customRole');\r\n```\r\n\r\n### Full workflow\r\n\r\nHere’s the
complete workflow for creating, using, and deleting a
custom\r\nrole:\r\n\r\n```typescript\r\nconst roleDescriptor = {\r\n
elasticsearch: {\r\n cluster: ['monitor'],\r\n indices: [{ names: ['*'],
privileges: ['read'] }],\r\n },\r\n kibana: [\r\n {\r\n base:
['all'],\r\n feature: {},\r\n spaces: ['*'],\r\n },\r\n
],\r\n};\r\n\r\nbefore(() => {\r\n cy.task('createServerlessCustomRole',
{ roleDescriptor, roleName: 'customRole' });\r\n});\r\n\r\nbeforeEach(()
=> {\r\n login('customRole');\r\n});\r\n\r\nafter(() => {\r\n
cy.task('deleteServerlessCustomRole',
'customRole');\r\n});\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"255aea7adcf196564532df76573814f93097cce6"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…ests (elastic#206129)

## Summary

Solves: elastic/security-team#11464

In this PR we are adding the capability to use custom roles for
serverless Cypress tests. To do so, we are leveraging the solution
proposed in: elastic#194677, meaning that
currently we have the same restrictions, therefore, custom roles cannot
be used yet in MKI environments.


### Creating a Custom Role

To create a custom role, use the Cypress task
`createServerlessCustomRole`. This task requires two parameters:
- **`roleDescriptor`**: Defines the permissions and access for the role.
- **`roleName`**: A unique name for the custom role.

Example:

```typescript
const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });
```

### Using a Custom Role

Once the custom role is created, you can log in to the application using
your regular `login`` method and passing the name of the role.

```typescript
login('customRole');
```


### Deleting a Custom Role

After your tests, always delete the custom role to ensure a clean
environment. Use the `deleteServerlessCustomRole` task and provide the
name of the role as the parameter.

```typescript
cy.task('deleteServerlessCustomRole', 'customRole');
```

### Full workflow

Here’s the complete workflow for creating, using, and deleting a custom
role:

```typescript
const roleDescriptor = {
  elasticsearch: {
    cluster: ['monitor'],
    indices: [{ names: ['*'], privileges: ['read'] }],
  },
  kibana: [
    {
      base: ['all'],
      feature: {},
      spaces: ['*'],
    },
  ],
};

before(() => {
  cy.task('createServerlessCustomRole', { roleDescriptor, roleName: 'customRole' });
});

beforeEach(() => {
  login('customRole');
});

after(() => {
  cy.task('deleteServerlessCustomRole', 'customRole');
});
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants