Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#196351) # Backport This will backport the following commits from `main` to `8.x`: - [[FTR] support custom native roles in serverless tests (#194677)](#194677) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Dzmitry Lemechko","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-11T15:11:23Z","message":"[FTR] support custom native roles in serverless tests (#194677)\n\n## Summary\r\n\r\nThis PR updates FTR services to support authentication with custom\r\nnative role. Few notes:\r\n- for compatibility with MKI we reserve **\"customRole\"** as a custom\r\nrole name used in tests\r\n- test user is **automatically assigned** to this role, but before login\r\nin browser/ generating cookie header or API key in each test suite\r\n**role privileges must me updated according test scenario**\r\n\r\nHow to test:\r\nI added a new test file for Search project:\r\n`x-pack/test_serverless/functional/test_suites/search/custom_role_access.ts`\r\n\r\nIt can be run locally with:\r\n```\r\n node scripts/functional_tests --config=x-pack/test_serverless/functional/test_suites/search/config.ts --grep \"With custom role\"\r\n```\r\n\r\nFTR UI test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n\r\n// Then you can login in browser as a user with newly defined privileges\r\nawait pageObjects.svlCommonPage.loginWithCustomRole();\r\n```\r\n\r\nFTR api_integration test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n// Then you can generate an API key with newly defined privileges\r\nconst roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('customRole');\r\n// Don't forget to invalidate the API key in the end\r\nawait samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);\r\n```","sha":"f00ac7a8a21463e6bb4a2784c3a3884f36c62900","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","FTR","v8.16.0","backport:version"],"number":194677,"url":"https://github.com/elastic/kibana/pull/194677","mergeCommit":{"message":"[FTR] support custom native roles in serverless tests (#194677)\n\n## Summary\r\n\r\nThis PR updates FTR services to support authentication with custom\r\nnative role. Few notes:\r\n- for compatibility with MKI we reserve **\"customRole\"** as a custom\r\nrole name used in tests\r\n- test user is **automatically assigned** to this role, but before login\r\nin browser/ generating cookie header or API key in each test suite\r\n**role privileges must me updated according test scenario**\r\n\r\nHow to test:\r\nI added a new test file for Search project:\r\n`x-pack/test_serverless/functional/test_suites/search/custom_role_access.ts`\r\n\r\nIt can be run locally with:\r\n```\r\n node scripts/functional_tests --config=x-pack/test_serverless/functional/test_suites/search/config.ts --grep \"With custom role\"\r\n```\r\n\r\nFTR UI test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n\r\n// Then you can login in browser as a user with newly defined privileges\r\nawait pageObjects.svlCommonPage.loginWithCustomRole();\r\n```\r\n\r\nFTR api_integration test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n// Then you can generate an API key with newly defined privileges\r\nconst roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('customRole');\r\n// Don't forget to invalidate the API key in the end\r\nawait samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);\r\n```","sha":"f00ac7a8a21463e6bb4a2784c3a3884f36c62900"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194677","number":194677,"mergeCommit":{"message":"[FTR] support custom native roles in serverless tests (#194677)\n\n## Summary\r\n\r\nThis PR updates FTR services to support authentication with custom\r\nnative role. Few notes:\r\n- for compatibility with MKI we reserve **\"customRole\"** as a custom\r\nrole name used in tests\r\n- test user is **automatically assigned** to this role, but before login\r\nin browser/ generating cookie header or API key in each test suite\r\n**role privileges must me updated according test scenario**\r\n\r\nHow to test:\r\nI added a new test file for Search project:\r\n`x-pack/test_serverless/functional/test_suites/search/custom_role_access.ts`\r\n\r\nIt can be run locally with:\r\n```\r\n node scripts/functional_tests --config=x-pack/test_serverless/functional/test_suites/search/config.ts --grep \"With custom role\"\r\n```\r\n\r\nFTR UI test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n\r\n// Then you can login in browser as a user with newly defined privileges\r\nawait pageObjects.svlCommonPage.loginWithCustomRole();\r\n```\r\n\r\nFTR api_integration test example:\r\n\r\n```ts\r\n// First set privileges for custom role\r\nawait samlAuth.setCustomRole({\r\n elasticsearch: {\r\n indices: [{ names: ['logstash-*'], privileges: ['read', 'view_index_metadata'] }],\r\n },\r\n kibana: [\r\n {\r\n feature: {\r\n discover: ['read'],\r\n },\r\n spaces: ['*'],\r\n },\r\n ],\r\n });\r\n });\r\n// Then you can generate an API key with newly defined privileges\r\nconst roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('customRole');\r\n// Don't forget to invalidate the API key in the end\r\nawait samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);\r\n```","sha":"f00ac7a8a21463e6bb4a2784c3a3884f36c62900"}},{"branch":"8.x","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
- Loading branch information