Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Authz] Added support for security route configuration option (elasti…
…c#191973) ## Summary Extended `KibanaRouteOptions` to include security configuration at the route definition level. ## Security Config To facilitate iterative development security config is marked as optional for now. - `authz` supports both simple configuration (e.g., single privilege requirements) and more complex configurations that involve anyRequired and allRequired privilege sets. - `authc` property has been added and is expected to replace the existing `authRequired` option. This transition will be part of an upcoming deprecation process in scope of elastic#191711 - For versioned routes, the `authc` and `authz` configurations can be applied independently for each version, enabling version-specific security configuration. If none provided for the specific version it will fall back to the route root security option. - Validation logic has been added that ensures only supported configurations are specified. - Existing `registerOnPostAuth` hook has been modified to incorporate checks based on the new `authz` property in the security configuration. - Comprehensive documentation will be added in the separate PR before sunsetting new security configuration and deprecating old one. ## How to Test You can modify any existing route or use the example routes below ### Routes <details> <summary><b>Route 1: /api/security/authz_examples/authz_disabled</b></summary> ```javascript router.get( { path: '/api/security/authz_examples/authz_disabled', security: { authz: { enabled: false, reason: 'This route is opted out from authorization', }, }, validate: false, }, createLicensedRouteHandler(async (context, request, response) => { try { return response.ok({ body: { message: 'This route is opted out from authorization', }, }); } catch (error) { return response.customError(wrapIntoCustomErrorResponse(error)); } }) ); ``` </details> <details> <summary><b>Route 2: /api/security/authz_examples/simple_privileges_1</b></summary> ```javascript router.get( { path: '/api/security/authz_examples/simple_privileges_1', security: { authz: { requiredPrivileges: ['manageSpaces', 'taskManager'], }, }, validate: false, }, createLicensedRouteHandler(async (context, request, response) => { try { return response.ok({ body: { authzResult: request.authzResult, }, }); } catch (error) { return response.customError(wrapIntoCustomErrorResponse(error)); } }) ); ``` </details> <details> <summary><b>Route 3: /api/security/authz_examples/simple_privileges_2</b></summary> ```javascript router.get( { path: '/api/security/authz_examples/simple_privileges_2', security: { authz: { requiredPrivileges: [ 'manageSpaces', { anyRequired: ['taskManager', 'features'], }, ], }, }, validate: false, }, createLicensedRouteHandler(async (context, request, response) => { try { return response.ok({ body: { authzResult: request.authzResult, }, }); } catch (error) { return response.customError(wrapIntoCustomErrorResponse(error)); } }) ); ``` </details> <details> <summary><b>Versioned Route: /internal/security/authz_versioned_examples/simple_privileges_1</b></summary> ```javascript router.versioned .get({ path: '/internal/security/authz_versioned_examples/simple_privileges_1', access: 'internal', enableQueryVersion: true, }) .addVersion( { version: '1', validate: false, security: { authz: { requiredPrivileges: ['manageSpaces', 'taskManager'], }, authc: { enabled: 'optional', }, }, }, (context, request, response) => { return response.ok({ body: { authzResult: request.authzResult, version: '1', }, }); } ) .addVersion( { version: '2', validate: false, security: { authz: { requiredPrivileges: ['manageSpaces'], }, authc: { enabled: true, }, }, }, (context, request, response) => { return response.ok({ body: { authzResult: request.authzResult, version: '2', }, }); } ); ``` </details> ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios __Closes: https://github.com/elastic/kibana/issues/191710__ __Related: elastic#191712, https://github.com/elastic/kibana/issues/191713__ ### Release Note Extended `KibanaRouteOptions` to include security configuration at the route definition level. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information