Skip to content

[8.x] [FTR] support custom native roles in serverless tests (#194677)#196351

Merged
dmlemeshko merged 2 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-194677
Oct 16, 2024
Merged

[8.x] [FTR] support custom native roles in serverless tests (#194677)#196351
dmlemeshko merged 2 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-194677

Conversation

@dmlemeshko
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

## Summary

This PR updates FTR services to support authentication with custom
native role. Few notes:
- for compatibility with MKI we reserve **"customRole"** as a custom
role name used in tests
- test user is **automatically assigned** to this role, but before login
in browser/ generating cookie header or API key in each test suite
**role privileges must me updated according test scenario**

How to test:
I added a new test file for Search project:
`x-pack/test_serverless/functional/test_suites/search/custom_role_access.ts`

It can be run locally with:
```
 node scripts/functional_tests --config=x-pack/test_serverless/functional/test_suites/search/config.ts --grep "With custom role"
```

FTR UI test example:

```ts
// First set privileges for custom role
await samlAuth.setCustomRole({
        elasticsearch: {
          indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],
        },
        kibana: [
          {
            feature: {
              discover: ['read'],
            },
            spaces: ['*'],
          },
        ],
      });
    });

// Then you can login in browser as a user with newly defined privileges
await pageObjects.svlCommonPage.loginWithCustomRole();
```

FTR api_integration test example:

```ts
// First set privileges for custom role
await samlAuth.setCustomRole({
        elasticsearch: {
          indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],
        },
        kibana: [
          {
            feature: {
              discover: ['read'],
            },
            spaces: ['*'],
          },
        ],
      });
    });
// Then you can generate an API key with newly defined privileges
const roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('customRole');
// Don't forget to invalidate the API key in the end
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);
```

(cherry picked from commit f00ac7a)

# Conflicts:
#	packages/kbn-ftr-common-functional-services/services/saml_auth/serverless/auth_provider.ts
#	packages/kbn-ftr-common-functional-services/services/saml_auth/stateful/auth_provider.ts
#	x-pack/test_serverless/api_integration/test_suites/common/platform_security/authorization.ts
#	x-pack/test_serverless/functional/config.base.ts
@dmlemeshko dmlemeshko added the backport This PR is a backport of another PR label Oct 15, 2024
@dmlemeshko dmlemeshko enabled auto-merge (squash) October 15, 2024 15:30
@dmlemeshko dmlemeshko merged commit ddcecd6 into elastic:8.x Oct 16, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 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
@kbn/ftr-common-functional-services 79 82 +3

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
@kbn/ftr-common-functional-services 0 2 +2
Unknown metric groups

API count

id before after diff
@kbn/ftr-common-functional-services 104 107 +3

History

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.

4 participants