Skip to content

[8.x] [Security Solution] Supports custom roles in serverless for Cypress tests (#206129)#206451

Merged
kibanamachine merged 1 commit intoelastic:8.xfrom
kibanamachine:backport/8.x/pr-206129
Jan 13, 2025
Merged

[8.x] [Security Solution] Supports custom roles in serverless for Cypress tests (#206129)#206451
kibanamachine merged 1 commit intoelastic:8.xfrom
kibanamachine:backport/8.x/pr-206129

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

…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 kibanamachine merged commit 067942b into elastic:8.x Jan 13, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

cc @MadameSheema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants