Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Filter out security realm deprecations on Cloud (#30018) #30039

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions x-pack/plugins/cloud/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export interface CloudPlugin {
isCloudEnabled: boolean;
}
7 changes: 7 additions & 0 deletions x-pack/plugins/cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ export const cloud = kibana => {
}).default(),
}).default();
},

init(server) {
const config = server.config().get(`xpack.cloud`);
server.expose('config', {
isCloudEnabled: !!config.id
});
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,32 @@ describe('getUpgradeAssistantStatus', () => {
deprecationsResponse = _.cloneDeep(fakeDeprecations);
});

it('calls /_xpack/migration/deprecations', async () => {
await getUpgradeAssistantStatus(callWithRequest, {} as any);
it('calls /_migration/deprecations', async () => {
await getUpgradeAssistantStatus(callWithRequest, {} as any, false);
expect(callWithRequest).toHaveBeenCalledWith({}, 'transport.request', {
path: '/_xpack/migration/deprecations',
method: 'GET',
});
});

it('returns the correct shape of data', async () => {
const resp = await getUpgradeAssistantStatus(callWithRequest, {} as any);
const resp = await getUpgradeAssistantStatus(callWithRequest, {} as any, false);
expect(resp).toMatchSnapshot();
});

it('returns readyForUpgrade === false when critical issues found', async () => {
deprecationsResponse = {
cluster_settings: [{ level: 'critical', message: 'Do count me', url: 'https://...' }],
node_settings: [],
ml_settings: [],
index_settings: {},
};

await expect(
getUpgradeAssistantStatus(callWithRequest, {} as any, false)
).resolves.toHaveProperty('readyForUpgrade', false);
});

it('returns readyForUpgrade === true when no critical issues found', async () => {
deprecationsResponse = {
cluster_settings: [{ level: 'warning', message: 'Do not count me', url: 'https://...' }],
Expand All @@ -46,9 +59,28 @@ describe('getUpgradeAssistantStatus', () => {
index_settings: {},
};

await expect(getUpgradeAssistantStatus(callWithRequest, {} as any)).resolves.toHaveProperty(
'readyForUpgrade',
true
);
await expect(
getUpgradeAssistantStatus(callWithRequest, {} as any, false)
).resolves.toHaveProperty('readyForUpgrade', true);
});

it('filters out security realm deprecation on Cloud', async () => {
deprecationsResponse = {
cluster_settings: [
{
level: 'critical',
message: 'Security realm settings structure changed',
url: 'https://...',
},
],
node_settings: [],
ml_settings: [],
index_settings: {},
};

const result = await getUpgradeAssistantStatus(callWithRequest, {} as any, true);

expect(result).toHaveProperty('readyForUpgrade', true);
expect(result).toHaveProperty('cluster', []);
});
});
24 changes: 17 additions & 7 deletions x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ export interface UpgradeAssistantStatus {

export async function getUpgradeAssistantStatus(
callWithRequest: CallClusterWithRequest,
req: Request
req: Request,
isCloudEnabled: boolean
): Promise<UpgradeAssistantStatus> {
const deprecations = await callWithRequest(req, 'transport.request', {
path: '/_xpack/migration/deprecations',
method: 'GET',
});

const cluster = deprecations.cluster_settings
.concat(deprecations.ml_settings)
.concat(deprecations.node_settings);
const cluster = getClusterDeprecations(deprecations, isCloudEnabled);
const indices = getCombinedIndexInfos(deprecations);

const criticalWarnings = cluster.concat(indices).filter(d => d.level === 'critical');
Expand All @@ -47,9 +46,7 @@ export async function getUpgradeAssistantStatus(
};
}

// Combines the information from the migration assistance api and the deprecation api into a single array.
// Enhances with information about which index the deprecation applies to and adds buttons for accessing the
// reindex UI.
// Reformats the index deprecations to an array of deprecation warnings extended with an index field.
const getCombinedIndexInfos = (deprecations: DeprecationAPIResponse) =>
Object.keys(deprecations.index_settings).reduce(
(indexDeprecations, indexName) => {
Expand All @@ -61,3 +58,16 @@ const getCombinedIndexInfos = (deprecations: DeprecationAPIResponse) =>
},
[] as EnrichedDeprecationInfo[]
);

const getClusterDeprecations = (deprecations: DeprecationAPIResponse, isCloudEnabled: boolean) => {
const combined = deprecations.cluster_settings
.concat(deprecations.ml_settings)
.concat(deprecations.node_settings);

if (isCloudEnabled) {
// In Cloud, this is changed at upgrade time. Filter it out to improve upgrade UX.
return combined.filter(d => d.message !== 'Security realm settings structure changed');
} else {
return combined;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('cluster checkup API', () => {
elasticsearch: {
getCluster: () => ({ callWithRequest: jest.fn() } as any),
} as any,
cloud: {
isCloudEnabled: false,
},
} as any;
server.config = () => ({ get: () => '' } as any);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { getUpgradeAssistantStatus } from '../lib/es_migration_apis';

export function registerClusterCheckupRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const { isCloudEnabled } = server.plugins.cloud;

server.route({
path: '/api/upgrade_assistant/status',
method: 'GET',
async handler(request) {
try {
return await getUpgradeAssistantStatus(callWithRequest, request);
return await getUpgradeAssistantStatus(callWithRequest, request, isCloudEnabled);
} catch (e) {
if (e.status === 403) {
return Boom.forbidden(e.message);
Expand Down
3 changes: 3 additions & 0 deletions x-pack/typings/hapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
*/

import 'hapi';

import { CloudPlugin } from 'x-pack/plugins/cloud';
import { XPackMainPlugin } from 'x-pack/plugins/xpack_main/xpack_main';

declare module 'hapi' {
interface PluginProperties {
cloud: CloudPlugin;
xpack_main: XPackMainPlugin;
}
}