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
2 changes: 1 addition & 1 deletion src/core/packages/security/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ export type {
export type { KibanaPrivilegesType, ElasticsearchPrivilegesType } from './src/roles';
export { isCreateRestAPIKeyParams } from './src/authentication/api_keys';
export type { CoreFipsService } from './src/fips';
export { AuthzDisabled, AuthzOptOutReason, unwindNestedSecurityPrivileges } from './src/authz';
export { ApiPrivileges, ApiOperation } from './src/api_privileges';
export { unwindNestedSecurityPrivileges } from './src/authz';
23 changes: 23 additions & 0 deletions src/core/packages/security/server/src/authz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export enum AuthzOptOutReason {
DelegateToESClient = 'Route delegates authorization to the scoped ES client',
DelegateToSOClient = 'Route delegates authorization to the scoped SO client',
ServeStaticFiles = 'Route serves static files that do not require authorization',
}

export class AuthzDisabled {
public static fromReason(reason: AuthzOptOutReason | string): { enabled: false; reason: string } {
return {
enabled: false,
reason,
};
}

static readonly delegateToESClient = AuthzDisabled.fromReason(
AuthzOptOutReason.DelegateToESClient
);
static readonly delegateToSOClient = AuthzDisabled.fromReason(
AuthzOptOutReason.DelegateToSOClient
);
static readonly serveStaticFiles = AuthzDisabled.fromReason(AuthzOptOutReason.ServeStaticFiles);
}

export const unwindNestedSecurityPrivileges = <
T extends Array<string | { allOf?: string[]; anyOf?: string[] }>
>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { AuthzDisabled } from '@kbn/core-security-server';

import type { RouteDefinitionParams } from '../..';
import { API_VERSIONS } from '../../../../common/constants';
Expand All @@ -22,10 +23,7 @@ export function defineDeleteRolesRoutes({ router }: RouteDefinitionParams) {
tags: ['oas-tag:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will we replace all other cases where routes delegate to the ES or SO client? Or will that be follow-up work for other teams?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It will be a follow up work

},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { AuthzDisabled } from '@kbn/core-security-server';

import type { RouteDefinitionParams } from '../..';
import { API_VERSIONS } from '../../../../common/constants';
Expand All @@ -29,10 +30,7 @@ export function defineGetRolesRoutes({
tags: ['oas-tag:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { AuthzDisabled } from '@kbn/core-security-server';

import type { RouteDefinitionParams } from '../..';
import { API_VERSIONS } from '../../../../common/constants';
Expand All @@ -30,10 +31,7 @@ export function defineGetAllRolesRoutes({
tags: ['oas-tag:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { AuthzDisabled } from '@kbn/core-security-server';

import { roleGrantsSubFeaturePrivileges } from './lib';
import {
getBulkCreateOrUpdatePayloadSchema,
Expand Down Expand Up @@ -49,10 +51,7 @@ export function defineBulkCreateOrUpdateRolesRoutes({
tags: ['oas-tag:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { AuthzDisabled } from '@kbn/core-security-server';

import { roleGrantsSubFeaturePrivileges } from './lib';
import { getPutPayloadSchema, transformPutPayloadToElasticsearchRole } from './model';
Expand All @@ -32,10 +33,7 @@ export function definePutRolesRoutes({
tags: ['oas-tag:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { AuthzDisabled } from '@kbn/core-security-server';
import type { QueryRolesResult } from '@kbn/security-plugin-types-common';

import type { RouteDefinitionParams } from '../..';
Expand Down Expand Up @@ -34,10 +35,7 @@ export function defineQueryRolesRoutes({
tags: ['oas-tags:roles'],
},
security: {
authz: {
enabled: false,
reason: `This route delegates authorization to Core's scoped ES cluster client`,
},
authz: AuthzDisabled.delegateToESClient,
},
})
.addVersion(
Expand Down