-
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.
Adds read_privileges route for lists and list items
- Loading branch information
1 parent
589a891
commit 9a6f9cf
Showing
7 changed files
with
88 additions
and
2 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
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/lists/server/routes/read_privileges_route.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,60 @@ | ||
/* | ||
* 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 { IRouter } from 'kibana/server'; | ||
import { merge } from 'lodash/fp'; | ||
|
||
import { SecurityPluginSetup } from '../../../security/server'; | ||
import { LIST_PRIVILEGES_URL } from '../../common/constants'; | ||
import { buildSiemResponse, readPrivileges, transformError } from '../siem_server_deps'; | ||
|
||
import { getListClient } from './utils'; | ||
|
||
export const readPrivilegesRoute = ( | ||
router: IRouter, | ||
security: SecurityPluginSetup | null | undefined | ||
): void => { | ||
router.get( | ||
{ | ||
options: { | ||
tags: ['access:lists'], | ||
}, | ||
path: LIST_PRIVILEGES_URL, | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
const siemResponse = buildSiemResponse(response); | ||
try { | ||
const clusterClient = context.core.elasticsearch.legacy.client; | ||
const lists = getListClient(context); | ||
const clusterPrivilegesLists = await readPrivileges( | ||
clusterClient.callAsCurrentUser, | ||
lists.getListIndex() | ||
); | ||
const clusterPrivilegesListItems = await readPrivileges( | ||
clusterClient.callAsCurrentUser, | ||
lists.getListIndex() | ||
); | ||
const privileges = merge( | ||
{ | ||
listItems: clusterPrivilegesListItems, | ||
lists: clusterPrivilegesLists, | ||
}, | ||
{ | ||
is_authenticated: security?.authc.isAuthenticated(request) ?? false, | ||
} | ||
); | ||
return response.ok({ body: privileges }); | ||
} catch (err) { | ||
const error = transformError(err); | ||
return siemResponse.error({ | ||
body: error.message, | ||
statusCode: error.statusCode, | ||
}); | ||
} | ||
} | ||
); | ||
}; |
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,15 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# 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. | ||
# | ||
|
||
set -e | ||
./check_env_variables.sh | ||
|
||
# Example: ./get_privileges.sh | ||
curl -s -k \ | ||
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \ | ||
-X GET ${KIBANA_URL}${SPACE_URL}/api/lists/privileges | jq . |
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