forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Obs AI Assistant] Add scoped privileges to readUser and writeUser (e…
…lastic#183592) Related to elastic#183588
- Loading branch information
Showing
14 changed files
with
210 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ck/test/observability_ai_assistant_api_integration/common/users/create_users_and_roles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { InheritedFtrProviderContext } from '../ftr_provider_context'; | ||
import { allUsers } from './users'; | ||
import { allRoles } from './roles'; | ||
|
||
export async function createUsersAndRoles(getService: InheritedFtrProviderContext['getService']) { | ||
const security = getService('security'); | ||
const log = getService('log'); | ||
|
||
// create roles | ||
await Promise.all( | ||
allRoles.map(({ name, privileges }) => { | ||
return security.role.create(name, privileges); | ||
}) | ||
); | ||
|
||
// create users | ||
await Promise.all( | ||
allUsers.map((user) => { | ||
log.info(`Creating user: ${user.username} with roles: ${user.roles.join(', ')}`); | ||
return security.user.create(user.username, { | ||
password: user.password, | ||
roles: user.roles, | ||
}); | ||
}) | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
x-pack/test/observability_ai_assistant_api_integration/common/users/roles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
// Example role: | ||
// export const allAccessRole: Role = { | ||
// name: 'all_access', | ||
// privileges: { | ||
// elasticsearch: { | ||
// indices: [ | ||
// { | ||
// names: ['*'], | ||
// privileges: ['all'], | ||
// }, | ||
// ], | ||
// }, | ||
// kibana: [ | ||
// { | ||
// feature: { | ||
// apm: ['all'], | ||
// actions: ['all'], | ||
// }, | ||
// spaces: ['*'], | ||
// }, | ||
// ], | ||
// }, | ||
// }; | ||
|
||
export interface Role { | ||
name: string; | ||
privileges: { | ||
elasticsearch?: { | ||
cluster?: string[]; | ||
indices?: Array<{ | ||
names: string[]; | ||
privileges: string[]; | ||
}>; | ||
}; | ||
kibana?: Array<{ | ||
spaces: string[]; | ||
base?: string[]; | ||
feature?: { | ||
[featureId: string]: string[]; | ||
}; | ||
}>; | ||
}; | ||
} | ||
|
||
export const allRoles = []; |
29 changes: 29 additions & 0 deletions
29
x-pack/test/observability_ai_assistant_api_integration/common/users/users.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { kbnTestConfig } from '@kbn/test'; | ||
const password = kbnTestConfig.getUrlParts().password!; | ||
|
||
export interface User { | ||
username: 'elastic' | 'editor' | 'viewer'; | ||
password: string; | ||
roles: string[]; | ||
} | ||
|
||
export const editorUser: User = { | ||
username: 'editor', | ||
password, | ||
roles: ['editor'], | ||
}; | ||
|
||
export const viewerUser: User = { | ||
username: 'viewer', | ||
password, | ||
roles: ['viewer'], | ||
}; | ||
|
||
export const allUsers = [editorUser, viewerUser]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.