Skip to content

Commit

Permalink
Adding manage_own_api_key privilege to apiKey creation validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn committed Jun 8, 2023
1 parent 8d4a710 commit a552963
Showing 1 changed file with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,17 @@
*/

import { ElasticsearchClient } from '@kbn/core/server';
import { every } from 'lodash';
import { cluster, indices, privileges } from './monitoring_config';
import { cluster, indices } from './monitoring_config';

export async function hasLogMonitoringPrivileges(
esClient: ElasticsearchClient
) {
const { index, cluster: clusterMonitor } =
await esClient.security.hasPrivileges({
body: {
index: indices,
cluster,
},
});
const res = await esClient.security.hasPrivileges({
body: {
index: indices,
cluster: [...cluster, 'manage_own_api_key'],
},
});

const hasPrivileges =
clusterMonitor.monitor &&
every(
index,
privileges.reduce(
(result, privilege) => ({
...result,
[privilege]: true,
}),
{}
)
);

return hasPrivileges;
return res.has_all_requested;
}

0 comments on commit a552963

Please sign in to comment.