mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Ensure we use the monitoring cluster for retrieving xpack info * Remove unnecessary code
This commit is contained in:
parent
3dc29793d5
commit
4f672d5d4f
6 changed files with 42 additions and 28 deletions
|
@ -25,6 +25,7 @@ export function exposeClient({ elasticsearchConfig, events, log, elasticsearchPl
|
|||
events.on('stop', bindKey(cluster, 'close'));
|
||||
const configSource = isMonitoringCluster ? 'monitoring' : 'production';
|
||||
log([LOGGING_TAG, 'es-client'], `config sourced from: ${configSource} cluster`);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
export function hasMonitoringCluster(config) {
|
||||
|
|
|
@ -7,15 +7,26 @@
|
|||
import { checkLicenseGenerator } from './cluster_alerts/check_license';
|
||||
import { hasMonitoringCluster } from './es_client/instantiate_client';
|
||||
import { LOGGING_TAG } from '../common/constants';
|
||||
import { XPackInfo } from '../../xpack_main/server/lib/xpack_info';
|
||||
|
||||
/*
|
||||
* Expose xpackInfo for the Monitoring cluster as server.plugins.monitoring.info
|
||||
*/
|
||||
export const initMonitoringXpackInfo = async ({ config, xpackMainPlugin, expose, log }) => {
|
||||
export const initMonitoringXpackInfo = async ({
|
||||
config,
|
||||
server,
|
||||
client,
|
||||
xpackMainPlugin,
|
||||
licensing,
|
||||
expose,
|
||||
log,
|
||||
}) => {
|
||||
const xpackInfo = hasMonitoringCluster(config)
|
||||
? xpackMainPlugin.createXPackInfo({
|
||||
clusterSource: 'monitoring',
|
||||
pollFrequencyInMillis: config.get('xpack.monitoring.xpack_api_polling_frequency_millis'),
|
||||
? new XPackInfo(server, {
|
||||
licensing: licensing.createLicensePoller(
|
||||
client,
|
||||
config.get('xpack.monitoring.xpack_api_polling_frequency_millis')
|
||||
),
|
||||
})
|
||||
: xpackMainPlugin.info;
|
||||
|
||||
|
|
|
@ -38,19 +38,29 @@ export async function verifyMonitoringAuth(req) {
|
|||
async function verifyHasPrivileges(req) {
|
||||
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
|
||||
|
||||
const response = await callWithRequest(req, 'transport.request', {
|
||||
method: 'POST',
|
||||
path: '/_security/user/_has_privileges',
|
||||
body: {
|
||||
index: [
|
||||
{
|
||||
names: [INDEX_PATTERN], // uses wildcard
|
||||
privileges: ['read'],
|
||||
},
|
||||
],
|
||||
},
|
||||
ignoreUnavailable: true, // we allow 404 incase the user shutdown security in-between the check and now
|
||||
});
|
||||
let response;
|
||||
try {
|
||||
response = await callWithRequest(req, 'transport.request', {
|
||||
method: 'POST',
|
||||
path: '/_security/user/_has_privileges',
|
||||
body: {
|
||||
index: [
|
||||
{
|
||||
names: [INDEX_PATTERN], // uses wildcard
|
||||
privileges: ['read'],
|
||||
},
|
||||
],
|
||||
},
|
||||
ignoreUnavailable: true, // we allow 404 incase the user shutdown security in-between the check and now
|
||||
});
|
||||
} catch (err) {
|
||||
if (
|
||||
err.message === 'no handler found for uri [/_security/user/_has_privileges] and method [POST]'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// we assume true because, if the response 404ed, then it will not exist but we should try to continue
|
||||
const hasAllRequestedPrivileges = get(response, 'has_all_requested', true);
|
||||
|
|
|
@ -51,7 +51,7 @@ export class Plugin {
|
|||
const uiEnabled = config.get('xpack.monitoring.ui.enabled');
|
||||
|
||||
if (uiEnabled) {
|
||||
await instantiateClient({
|
||||
const client = await instantiateClient({
|
||||
log: core.log,
|
||||
events: core.events,
|
||||
elasticsearchConfig,
|
||||
|
@ -59,6 +59,8 @@ export class Plugin {
|
|||
}); // Instantiate the dedicated ES client
|
||||
await initMonitoringXpackInfo({
|
||||
config,
|
||||
server: core._hapi,
|
||||
client,
|
||||
log: core.log,
|
||||
xpackMainPlugin: plugins.xpack_main,
|
||||
expose: core.expose,
|
||||
|
|
|
@ -19,15 +19,6 @@ export function setupXPackMain(server) {
|
|||
const info = new XPackInfo(server, { licensing: server.newPlatform.setup.plugins.licensing });
|
||||
|
||||
server.expose('info', info);
|
||||
server.expose('createXPackInfo', options => {
|
||||
const client = server.newPlatform.setup.core.elasticsearch.createClient(options.clusterSource);
|
||||
const monitoringLicensing = server.newPlatform.setup.plugins.licensing.createLicensePoller(
|
||||
client,
|
||||
options.pollFrequencyInMillis
|
||||
);
|
||||
|
||||
return new XPackInfo(server, { licensing: monitoringLicensing });
|
||||
});
|
||||
|
||||
server.ext('onPreResponse', (request, h) => injectXPackInfoSignature(info, request, h));
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ export { XPackFeature } from './lib/xpack_info';
|
|||
|
||||
export interface XPackMainPlugin {
|
||||
info: XPackInfo;
|
||||
createXPackInfo(options: XPackInfoOptions): XPackInfo;
|
||||
getFeatures(): Feature[];
|
||||
registerFeature(feature: FeatureWithAllOrReadPrivileges): void;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue