permission-common: introduce ResourcePermission type

Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
Mike Lewis
2022-03-03 17:56:37 +00:00
committed by Joe Porpeglia
parent 05d345f20c
commit 95284162d6
6 changed files with 49 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-permission-backend': patch
---
Add more specific check for policies which return conditional decisions for non-resource permissions.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-permission-common': patch
---
Add more specific `Permission` types
@@ -109,6 +109,12 @@ const handleRequest = async (
};
}
if (!('resourceType' in request.permission)) {
throw new Error(
`Conditional decision returned from permission policy for non-resource permission ${request.permission.name}`,
);
}
if (decision.resourceType !== request.permission.resourceType) {
throw new Error(
`Invalid resource conditions returned from permission policy for permission ${request.permission.name}`,
+12 -5
View File
@@ -53,6 +53,12 @@ export enum AuthorizeResult {
DENY = 'DENY',
}
// @public
export type BasicPermission = {
name: string;
attributes: PermissionAttributes;
};
// @public
export type DiscoveryApi = {
getBaseUrl(pluginId: string): Promise<string>;
@@ -81,11 +87,7 @@ export type NotCriteria<TQuery> = {
};
// @public
export type Permission = {
name: string;
attributes: PermissionAttributes;
resourceType?: string;
};
export type Permission = BasicPermission | ResourcePermission;
// @public
export type PermissionAttributes = {
@@ -122,4 +124,9 @@ export type PermissionCriteria<TQuery> =
| AnyOfCriteria<TQuery>
| NotCriteria<TQuery>
| TQuery;
// @public
export type ResourcePermission<T extends string = string> = BasicPermission & {
resourceType: T;
};
```
@@ -29,8 +29,10 @@ export type {
} from './api';
export type { DiscoveryApi } from './discovery';
export type {
BasicPermission,
PermissionAttributes,
Permission,
PermissionAuthorizer,
ResourcePermission,
AuthorizeRequestOptions,
} from './permission';
@@ -28,6 +28,8 @@ export type PermissionAttributes = {
/**
* A permission that can be checked through authorization.
*
* @remarks
*
* Permissions are the "what" part of authorization, the action to be performed. This may be reading
* an entity from the catalog, executing a software template, or any other action a plugin author
* may wish to protect.
@@ -36,7 +38,13 @@ export type PermissionAttributes = {
* evaluated using an authorization policy.
* @public
*/
export type Permission = {
export type Permission = BasicPermission | ResourcePermission;
/**
* A standard {@link Permission} with no additional capabilities or restrictions.
* @public
*/
export type BasicPermission = {
/**
* The name of the permission.
*/
@@ -47,13 +55,19 @@ export type Permission = {
* all by name.
*/
attributes: PermissionAttributes;
};
/**
* ResourcePermissions are {@link Permission}s that can be authorized based on
* characteristics of a resource such a catalog entity.
* @public
*/
export type ResourcePermission<T extends string = string> = BasicPermission & {
/**
* Some permissions can be authorized based on characteristics of a resource
* such a catalog entity. For these permissions, the resourceType field
* denotes the type of the resource whose resourceRef should be passed when
* Denotes the type of the resource whose resourceRef should be passed when
* authorizing.
*/
resourceType?: string;
resourceType: T;
};
/**