-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Run API tests as restricted user (#70050)
- Loading branch information
1 parent
81022a3
commit dbdc3cd
Showing
9 changed files
with
197 additions
and
25 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
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
102 changes: 102 additions & 0 deletions
102
x-pack/test/apm_api_integration/common/authentication.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,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { PromiseReturnType } from '../../../plugins/apm/typings/common'; | ||
import { SecurityServiceProvider } from '../../../../test/common/services/security'; | ||
|
||
type SecurityService = PromiseReturnType<typeof SecurityServiceProvider>; | ||
|
||
export enum ApmUser { | ||
apmReadUser = 'apm_read_user', | ||
apmWriteUser = 'apm_write_user', | ||
apmAnnotationsWriteUser = 'apm_annotations_write_user', | ||
} | ||
|
||
const roles = { | ||
[ApmUser.apmReadUser]: { | ||
elasticsearch: { | ||
cluster: [], | ||
indices: [ | ||
{ names: ['observability-annotations'], privileges: ['read', 'view_index_metadata'] }, | ||
], | ||
}, | ||
kibana: [ | ||
{ | ||
base: [], | ||
feature: { | ||
apm: ['read'], | ||
}, | ||
spaces: ['*'], | ||
}, | ||
], | ||
}, | ||
[ApmUser.apmWriteUser]: { | ||
elasticsearch: { | ||
cluster: [], | ||
indices: [ | ||
{ names: ['observability-annotations'], privileges: ['read', 'view_index_metadata'] }, | ||
], | ||
}, | ||
kibana: [ | ||
{ | ||
base: [], | ||
feature: { | ||
apm: ['all'], | ||
}, | ||
spaces: ['*'], | ||
}, | ||
], | ||
}, | ||
[ApmUser.apmAnnotationsWriteUser]: { | ||
elasticsearch: { | ||
cluster: [], | ||
indices: [ | ||
{ | ||
names: ['observability-annotations'], | ||
privileges: [ | ||
'read', | ||
'view_index_metadata', | ||
'index', | ||
'manage', | ||
'create_index', | ||
'create_doc', | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
const users = { | ||
[ApmUser.apmReadUser]: { | ||
roles: ['apm_user', ApmUser.apmReadUser], | ||
}, | ||
[ApmUser.apmWriteUser]: { | ||
roles: ['apm_user', ApmUser.apmWriteUser], | ||
}, | ||
[ApmUser.apmAnnotationsWriteUser]: { | ||
roles: ['apm_user', ApmUser.apmWriteUser, ApmUser.apmAnnotationsWriteUser], | ||
}, | ||
}; | ||
|
||
export async function createApmUser(security: SecurityService, apmUser: ApmUser) { | ||
const role = roles[apmUser]; | ||
const user = users[apmUser]; | ||
|
||
if (!role || !user) { | ||
throw new Error(`No configuration found for ${apmUser}`); | ||
} | ||
|
||
await security.role.create(apmUser, role); | ||
|
||
await security.user.create(apmUser, { | ||
full_name: apmUser, | ||
password: APM_TEST_PASSWORD, | ||
roles: user.roles, | ||
}); | ||
} | ||
|
||
export const APM_TEST_PASSWORD = 'changeme'; |
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