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.
[Upgrade Assistant] Add permissions check to logs step (elastic#112420)
- Loading branch information
1 parent
60f66e9
commit 8de7475
Showing
13 changed files
with
294 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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 { API_BASE_PATH, DEPRECATION_LOGS_INDEX } from '../../common/constants'; | ||
import { versionCheckHandlerWrapper } from '../lib/es_version_precheck'; | ||
import { Privileges } from '../shared_imports'; | ||
import { RouteDependencies } from '../types'; | ||
|
||
const extractMissingPrivileges = ( | ||
privilegesObject: { [key: string]: Record<string, boolean> } = {} | ||
): string[] => | ||
Object.keys(privilegesObject).reduce((privileges: string[], privilegeName: string): string[] => { | ||
if (Object.values(privilegesObject[privilegeName]).some((e) => !e)) { | ||
privileges.push(privilegeName); | ||
} | ||
return privileges; | ||
}, []); | ||
|
||
export function registerAppRoutes({ | ||
router, | ||
lib: { handleEsError }, | ||
config: { isSecurityEnabled }, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: `${API_BASE_PATH}/privileges`, | ||
validate: false, | ||
}, | ||
versionCheckHandlerWrapper( | ||
async ( | ||
{ | ||
core: { | ||
elasticsearch: { client }, | ||
}, | ||
}, | ||
request, | ||
response | ||
) => { | ||
const privilegesResult: Privileges = { | ||
hasAllPrivileges: true, | ||
missingPrivileges: { | ||
index: [], | ||
}, | ||
}; | ||
|
||
if (!isSecurityEnabled()) { | ||
return response.ok({ body: privilegesResult }); | ||
} | ||
|
||
try { | ||
const { | ||
body: { has_all_requested: hasAllPrivileges, index }, | ||
} = await client.asCurrentUser.security.hasPrivileges({ | ||
body: { | ||
index: [ | ||
{ | ||
names: [DEPRECATION_LOGS_INDEX], | ||
privileges: ['read'], | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
if (!hasAllPrivileges) { | ||
privilegesResult.missingPrivileges.index = extractMissingPrivileges(index); | ||
} | ||
|
||
privilegesResult.hasAllPrivileges = hasAllPrivileges; | ||
return response.ok({ body: privilegesResult }); | ||
} catch (error) { | ||
return handleEsError({ error, response }); | ||
} | ||
} | ||
) | ||
); | ||
} |
Oops, something went wrong.