From 30a6ca16178c328e66a777f00ed37820bc4a0af7 Mon Sep 17 00:00:00 2001 From: Peter Macdonald Date: Thu, 25 Apr 2024 15:03:10 +0200 Subject: [PATCH] cuts out writing policies and save it for next section Signed-off-by: Peter Macdonald --- docs/permissions/getting-started.md | 63 +---------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/docs/permissions/getting-started.md b/docs/permissions/getting-started.md index 9e71a6f924..7e828bac56 100644 --- a/docs/permissions/getting-started.md +++ b/docs/permissions/getting-started.md @@ -66,65 +66,4 @@ permission: enabled: true ``` -2. Its now all wired up and working, great! But perhaps we don't want to simply allow everything, lets try and create our own policy, to do this you can create a new folder in `packages/backend/src` called `permissions` and create a new file called `policy.ts`, in that file we can add the following to create a policy that denies deleting entities from the catalog: - -```ts title="packages/backend/src/permissions/policy.ts" -import { - AuthorizeResult, - PolicyDecision, -} from '@backstage/plugin-permission-common'; -import { - PermissionPolicy, - PolicyQuery, -} from '@backstage/plugin-permission-node'; - -export class DenyCatalogDeletePolicy implements PermissionPolicy { - async handle(request: PolicyQuery): Promise { - if (request.permission.name === 'catalog.entity.delete') { - return { - result: AuthorizeResult.DENY, - }; - } - - return { result: AuthorizeResult.ALLOW }; - } -} -``` - -3. We then need to use the permissions backend policy extension point to register our policy, to do this we can add the following to `packages/backend/src/index.ts`: - -```ts title="packages/backend/src/index.ts" -import { createBackend } from '@backstage/backend-defaults'; -import { DenyCatalogDeletePolicy } from './permissions/policy'; -const backend = createBackend(); -// ... -backend.add(import('@backstage/plugin-permission-backend/alpha')); -/* highlight-remove-next-line */ -backend.add( - import('@backstage/plugin-permission-backend-module-allow-all-policy'), -); -/* highlight-add-start */ -backend.add( - createBackendModule({ - pluginId: 'permission', - moduleId: 'deny-catalog-delete-policy', - register(reg) { - reg.registerInit({ - deps: { policy: policyExtensionPoint }, - async init({ policy }) { - policy.setPolicy(new DenyCatalogDeletePolicy()); - }, - }); - }, - }), -); -/* highlight-add-end */ -// ... -backend.start(); -``` - -4. Now that you’ve made this change, you should find that the unregister entity menu option on the catalog entity page is disabled. - -![Entity detail page showing disabled unregister entity context menu entry](../assets/permissions/disabled-unregister-entity.png) - -Now that the framework is fully configured, you can craft a permission policy that works best for your organization by utilizing a provided authorization method or by [writing your own policy](./writing-a-policy.md)! +Congratulations! Now that the framework is configured, you can craft a permission policy that works best for your organization by utilizing a provided authorization method or by [writing your own policy](./writing-a-policy.md)!