-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
454 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "loginSelector", | ||
"version": "8.0.0", | ||
"kibanaVersion": "kibana", | ||
"configPath": ["xpack", "loginSelector"], | ||
"requiredPlugins": ["security", "licensing"], | ||
"server": true, | ||
"ui": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 { PluginInitializerContext } from '../../../../src/core/server'; | ||
import { Plugin } from './plugin'; | ||
|
||
export const plugin = (initializerContext: PluginInitializerContext) => | ||
new Plugin(initializerContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 { ByteSizeValue } from '@kbn/config-schema'; | ||
import { CoreSetup, Logger, PluginInitializerContext } from '../../../../src/core/server'; | ||
import { LicensingPluginSetup } from '../../licensing/server'; | ||
import { PluginSetupContract as SecurityPluginSetup } from '../../security/server'; | ||
import { defineRoutes } from './routes'; | ||
|
||
export interface PluginSetupDependencies { | ||
licensing: LicensingPluginSetup; | ||
security: SecurityPluginSetup; | ||
} | ||
|
||
/** | ||
* Represents Login Selector Plugin instance that will be managed by the Kibana plugin system. | ||
*/ | ||
export class Plugin { | ||
private readonly logger: Logger; | ||
|
||
constructor(private readonly initializerContext: PluginInitializerContext) { | ||
this.logger = this.initializerContext.logger.get(); | ||
} | ||
|
||
public async setup(core: CoreSetup, { security }: PluginSetupDependencies) { | ||
if (!security.authc.isProviderEnabled('saml')) { | ||
security.authc.enableProvider('saml', { | ||
realm: '__fake-realm__', | ||
maxRedirectURLSize: new ByteSizeValue(2048), | ||
}); | ||
} | ||
|
||
if (!security.authc.isProviderEnabled('oidc')) { | ||
security.authc.enableProvider('oidc', { | ||
realm: '__fake-realm__', | ||
}); | ||
} | ||
|
||
defineRoutes({ | ||
router: core.http.createRouter(), | ||
basePath: core.http.basePath, | ||
logger: this.initializerContext.logger.get('routes'), | ||
security, | ||
}); | ||
} | ||
|
||
public start() { | ||
this.logger.debug('Starting plugin'); | ||
} | ||
|
||
public stop() { | ||
this.logger.debug('Stopping plugin'); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/login_selector/server/routes/authentication/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
import { OIDCLogin, SAMLLogin } from '../../../../security/server'; | ||
import { RouteDefinitionParams } from '..'; | ||
|
||
export function defineAuthenticationRoutes({ | ||
basePath, | ||
logger, | ||
router, | ||
security, | ||
}: RouteDefinitionParams) { | ||
router.get( | ||
{ | ||
path: '/login-selector/quick-sso-login/{provider}/{realm}', | ||
validate: { | ||
params: schema.object({ | ||
provider: schema.oneOf([schema.literal('saml'), schema.literal('oidc')]), | ||
realm: schema.string({ minLength: 1 }), | ||
}), | ||
}, | ||
options: { authRequired: false }, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
logger.info(`Logging with ${request.params.provider}/${request.params.realm}`); | ||
const authenticationResult = await security.authc.login(request, { | ||
provider: request.params.provider, | ||
value: { | ||
type: | ||
request.params.provider === 'saml' | ||
? SAMLLogin.LoginWithRealm | ||
: OIDCLogin.LoginWithRealm, | ||
realm: request.params.realm, | ||
redirectURL: `${basePath.get(request)}/`, | ||
}, | ||
}); | ||
|
||
// When authenticating using SAML we _expect_ to redirect to the SAML Identity provider. | ||
if (authenticationResult.redirected()) { | ||
return response.redirected({ headers: { location: authenticationResult.redirectURL! } }); | ||
} | ||
|
||
return response.unauthorized(); | ||
} catch (err) { | ||
logger.error(err); | ||
return response.internalError(); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 { CoreSetup, IRouter, Logger } from '../../../../../src/core/server'; | ||
import { PluginSetupContract as SecurityPluginSetup } from '../../../security/server'; | ||
|
||
import { defineAuthenticationRoutes } from './authentication'; | ||
|
||
/** | ||
* Describes parameters used to define HTTP routes. | ||
*/ | ||
export interface RouteDefinitionParams { | ||
router: IRouter; | ||
basePath: CoreSetup['http']['basePath']; | ||
logger: Logger; | ||
security: SecurityPluginSetup; | ||
} | ||
|
||
export function defineRoutes(params: RouteDefinitionParams) { | ||
defineAuthenticationRoutes(params); | ||
} |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/login_selector/server/routes/licensed_route_handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 { RequestHandler } from 'src/core/server'; | ||
import { ObjectType } from '@kbn/config-schema'; | ||
import { LICENSE_CHECK_STATE } from '../../../licensing/server'; | ||
|
||
export const createLicensedRouteHandler = < | ||
P extends ObjectType<any>, | ||
Q extends ObjectType<any>, | ||
B extends ObjectType<any> | ||
>( | ||
handler: RequestHandler<P, Q, B> | ||
) => { | ||
const licensedRouteHandler: RequestHandler<P, Q, B> = (context, request, responseToolkit) => { | ||
const { license } = context.licensing; | ||
const licenseCheck = license.check('security', 'basic'); | ||
if ( | ||
licenseCheck.state === LICENSE_CHECK_STATE.Unavailable || | ||
licenseCheck.state === LICENSE_CHECK_STATE.Invalid | ||
) { | ||
return responseToolkit.forbidden({ body: { message: licenseCheck.message! } }); | ||
} | ||
|
||
return handler(context, request, responseToolkit); | ||
}; | ||
|
||
return licensedRouteHandler; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.