-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Migrate security chromeless views to Kibana Platform plugin #54021
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
Changes from 7 commits
0619274
826b327
7707b8b
86cc53e
7c3de89
86aff5e
db9c2cd
321a4cf
f6cc830
3710751
0822ae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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 { Root } from 'joi'; | ||
| import { resolve } from 'path'; | ||
| import { Server } from 'src/legacy/server/kbn_server'; | ||
| import { KibanaRequest, LegacyRequest } from '../../../../src/core/server'; | ||
| // @ts-ignore | ||
| import { AuditLogger } from '../../server/lib/audit_logger'; | ||
| // @ts-ignore | ||
| import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize'; | ||
| import { AuthenticatedUser, SecurityPluginSetup } from '../../../plugins/security/server'; | ||
|
|
||
| /** | ||
| * Public interface of the security plugin. | ||
| */ | ||
| export interface SecurityPlugin { | ||
| getUser: (request: LegacyRequest) => Promise<AuthenticatedUser>; | ||
| } | ||
|
|
||
| function getSecurityPluginSetup(server: Server) { | ||
| const securityPlugin = server.newPlatform.setup.plugins.security as SecurityPluginSetup; | ||
| if (!securityPlugin) { | ||
| throw new Error('Kibana Platform Security plugin is not available.'); | ||
| } | ||
|
|
||
| return securityPlugin; | ||
| } | ||
|
|
||
| export const security = (kibana: Record<string, any>) => | ||
| new kibana.Plugin({ | ||
| id: 'security', | ||
| configPrefix: 'xpack.security', | ||
| publicDir: resolve(__dirname, 'public'), | ||
| require: ['kibana', 'elasticsearch', 'xpack_main'], | ||
|
|
||
| // This config is only used by `AuditLogger` and should be removed as soon as `AuditLogger` | ||
| // is migrated to Kibana Platform. | ||
| config(Joi: Root) { | ||
| return Joi.object({ | ||
| enabled: Joi.boolean().default(true), | ||
| audit: Joi.object({ enabled: Joi.boolean().default(false) }).default(), | ||
| }) | ||
| .unknown() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this obviate all of the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
| .default(); | ||
| }, | ||
|
|
||
| uiExports: { | ||
| hacks: ['plugins/security/hacks/legacy'], | ||
| injectDefaultVars: (server: Server) => { | ||
| return { | ||
| secureCookies: getSecurityPluginSetup(server).__legacyCompat.config.secureCookies, | ||
| enableSpaceAwarePrivileges: server.config().get('xpack.spaces.enabled'), | ||
| }; | ||
| }, | ||
| }, | ||
|
|
||
| async postInit(server: Server) { | ||
| watchStatusAndLicenseToInitialize(server.plugins.xpack_main, this, async () => { | ||
| const xpackInfo = server.plugins.xpack_main.info; | ||
| if (xpackInfo.isAvailable() && xpackInfo.feature('security').isEnabled()) { | ||
| await getSecurityPluginSetup(server).__legacyCompat.registerPrivilegesWithCluster(); | ||
| } | ||
| }); | ||
| }, | ||
|
|
||
| async init(server: Server) { | ||
| const securityPlugin = getSecurityPluginSetup(server); | ||
|
|
||
| const xpackInfo = server.plugins.xpack_main.info; | ||
| securityPlugin.__legacyCompat.registerLegacyAPI({ | ||
| auditLogger: new AuditLogger(server, 'security', server.config(), xpackInfo), | ||
| }); | ||
|
|
||
| // Legacy xPack Info endpoint returns whatever we return in a callback for `registerLicenseCheckResultsGenerator` | ||
| // and the result is consumed by the legacy plugins all over the place, so we should keep it here for now. We assume | ||
| // that when legacy callback is called license has been already propagated to the new platform security plugin and | ||
| // features are up to date. | ||
| xpackInfo | ||
| .feature(this.id) | ||
| .registerLicenseCheckResultsGenerator(() => | ||
| securityPlugin.__legacyCompat.license.getFeatures() | ||
| ); | ||
|
|
||
| server.expose({ | ||
| getUser: async (request: LegacyRequest) => | ||
| securityPlugin.authc.getCurrentUser(KibanaRequest.from(request)), | ||
| }); | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| * 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. | ||
| */ | ||
|
|
||
| // @ts-ignore | ||
| import { uiModules } from 'ui/modules'; | ||
| import { npSetup, npStart } from 'ui/new_platform'; | ||
| import routes from 'ui/routes'; | ||
| import { isSystemApiRequest } from '../../../../../../src/plugins/kibana_legacy/public'; | ||
| import { SecurityPluginSetup } from '../../../../../plugins/security/public'; | ||
|
|
||
| const securityPluginSetup = (npSetup.plugins as any).security as SecurityPluginSetup; | ||
| if (securityPluginSetup) { | ||
| routes.when('/account', { | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
| template: '<div />', | ||
| controller: () => npStart.core.application.navigateToApp('security/account'), | ||
| }); | ||
|
|
||
| const getNextParameter = () => { | ||
| const { location } = window; | ||
| const next = encodeURIComponent(`${location.pathname}${location.search}${location.hash}`); | ||
| return `&next=${next}`; | ||
| }; | ||
|
|
||
| const getProviderParameter = (tenant: string) => { | ||
| const key = `${tenant}/session_provider`; | ||
| const providerName = sessionStorage.getItem(key); | ||
| return providerName ? `&provider=${encodeURIComponent(providerName)}` : ''; | ||
| }; | ||
|
|
||
| const module = uiModules.get('security', []); | ||
| module.config(($httpProvider: ng.IHttpProvider) => { | ||
| $httpProvider.interceptors.push(($q, $window, Promise) => { | ||
| const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); | ||
|
|
||
| function interceptorFactory(responseHandler: (response: ng.IHttpResponse<unknown>) => any) { | ||
| return function interceptor(response: ng.IHttpResponse<unknown>) { | ||
| if (!isAnonymous && !isSystemApiRequest(response.config)) { | ||
| securityPluginSetup.sessionTimeout.extend(response.config.url); | ||
| } | ||
|
|
||
| if (response.status !== 401 || isAnonymous) { | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| return responseHandler(response); | ||
| } | ||
|
|
||
| const { logoutUrl, tenant } = securityPluginSetup.__legacyCompat; | ||
| const next = getNextParameter(); | ||
| const provider = getProviderParameter(tenant); | ||
|
|
||
| $window.location.href = `${logoutUrl}?msg=SESSION_EXPIRED${next}${provider}`; | ||
|
|
||
| return Promise.halt(); | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| response: interceptorFactory(response => response), | ||
| responseError: interceptorFactory($q.reject), | ||
| }; | ||
| }); | ||
| }); | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I haven't found any place that would use this, so just removed instead of updating.