Skip to content
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
23 changes: 10 additions & 13 deletions x-pack/plugins/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { validateConfig } from './server/lib/validate_config';
import { authenticateFactory } from './server/lib/auth_redirect';
import { checkLicense } from './server/lib/check_license';
import { initAuthenticator } from './server/lib/authentication/authenticator';
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { registerPrivilegesIfNecessary } from './server/lib/privileges';
import { initPrivilegesApi } from './server/routes/api/v1/privileges';
import { hasPrivilegesWithServer } from './server/lib/authorization/has_privileges';
import { SecurityAuditLogger } from './server/lib/audit_logger';
import { AuditLogger } from '../../server/lib/audit_logger';
import { SecureSavedObjectsClient } from './server/lib/saved_objects_client/secure_saved_objects_client';
import { registerPrivilegesWithCluster } from './server/lib/privileges';
import { watchStatusAndLicenseToInitialize } from './server/lib/watch_status_and_license_to_initialize';

export const security = (kibana) => new kibana.Plugin({
id: 'security',
Expand Down Expand Up @@ -88,25 +88,22 @@ export const security = (kibana) => new kibana.Plugin({
},

async init(server) {
const pluginId = 'security';
const plugin = this;

const config = server.config();
const xpackMainPlugin = server.plugins.xpack_main;
const xpackInfo = xpackMainPlugin.info;

const plugin = this;

mirrorPluginStatus(xpackMainPlugin, plugin);

const xpackInfoFeature = xpackInfo.feature(this.id);
const xpackInfoFeature = xpackInfo.feature(plugin.id);

// Register a function that is called whenever the xpack info changes,
// to re-compute the license check results for this plugin
xpackInfoFeature.registerLicenseCheckResultsGenerator(checkLicense);

// Register a function to respond to xpack license changes
xpackInfoFeature.registerLicenseChangeCallback(() => {
registerPrivilegesIfNecessary(server, plugin, xpackInfo);
watchStatusAndLicenseToInitialize(xpackMainPlugin, plugin, async (license) => {
if (license.allowRbac) {
await registerPrivilegesWithCluster(server);
}
});

validateConfig(config, message => server.log(['security', 'warning'], message));
Expand All @@ -131,7 +128,7 @@ export const security = (kibana) => new kibana.Plugin({
}) => {
const adminCluster = server.plugins.elasticsearch.getCluster('admin');

if (!xpackInfo.feature(pluginId).getLicenseCheckResults().allowRbac) {
if (!xpackInfoFeature.getLicenseCheckResults().allowRbac) {
const { callWithRequest } = adminCluster;
const callCluster = (...args) => callWithRequest(request, ...args);

Expand Down Expand Up @@ -176,7 +173,7 @@ export const security = (kibana) => new kibana.Plugin({
initLogoutView(server);

server.injectUiAppVars('login', () => {
const { showLogin, loginMessage, allowLogin } = xpackInfo.feature(pluginId).getLicenseCheckResults() || {};
const { showLogin, loginMessage, allowLogin } = xpackInfo.feature(plugin.id).getLicenseCheckResults() || {};

return {
loginState: {
Expand Down
63 changes: 0 additions & 63 deletions x-pack/plugins/security/server/lib/mirror_status_and_initialize.js

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/plugins/security/server/lib/privileges/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { registerPrivilegesIfNecessary } from './privilege_action_registry';
export { registerPrivilegesWithCluster } from './privilege_action_registry';
export { getLoginPrivilege, getVersionPrivilege } from './privileges';
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ import { buildPrivilegeMap } from './privileges';
import { getClient } from '../../../../../server/lib/get_client_shield';
import { equivalentPrivileges } from './equivalent_privileges';

export async function registerPrivilegesIfNecessary(server, plugin, xpackInfo) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad we could get rid of this 👍

const { allowRbac } = xpackInfo.feature('security').getLicenseCheckResults();

if (allowRbac) {
try {
await registerPrivilegesWithCluster(server);
} catch (e) {
plugin.status.red(`Unable to register privileges`);
server.log(['security', 'error'], `Unable to register privileges with cluster: ${e}`);
}
}
}

export async function registerPrivilegesWithCluster(server) {
const config = server.config();
const kibanaVersion = config.get('pkg.version');
Expand Down
Loading