From 1d3d10d6601e71ee56047a7e0384118e02d58f72 Mon Sep 17 00:00:00 2001 From: gabriel-farache Date: Fri, 14 Jun 2024 16:33:44 +0200 Subject: [PATCH] Orchestrator - workflow with permissions Signed-off-by: gabriel-farache --- packages/app/src/App.tsx | 2 +- packages/app/src/components/Root/Root.tsx | 2 -- .../src/service/router.ts | 6 ++++-- plugins/orchestrator/docs/Permissions.md | 14 +++++++++++++ .../src/components/WorkflowInstancePage.tsx | 9 ++++----- .../src/components/WorkflowsTable.tsx | 20 +++++++++---------- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 761f886b3b4..2297549e1a8 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -99,7 +99,7 @@ const routes = ( } /> } /> - } /> + } /> ); diff --git a/packages/app/src/components/Root/Root.tsx b/packages/app/src/components/Root/Root.tsx index 673174df377..cc7eb7c0a7a 100644 --- a/packages/app/src/components/Root/Root.tsx +++ b/packages/app/src/components/Root/Root.tsx @@ -105,7 +105,6 @@ export const Root = ({ to="orchestrator" text="Orchestrator" /> - @@ -116,7 +115,6 @@ export const Root = ({ > - {children} diff --git a/plugins/orchestrator-backend/src/service/router.ts b/plugins/orchestrator-backend/src/service/router.ts index 799f01448be..9d872452fb5 100644 --- a/plugins/orchestrator-backend/src/service/router.ts +++ b/plugins/orchestrator-backend/src/service/router.ts @@ -82,8 +82,10 @@ const authorize = async ( return decision; }; -declare class UnauthorizedError extends NotAllowedError { - message: 'Unauthorized'; +export class UnauthorizedError extends NotAllowedError { + constructor() { + super('Unauthorized'); + } } export async function createBackendRouter( diff --git a/plugins/orchestrator/docs/Permissions.md b/plugins/orchestrator/docs/Permissions.md index 0e45314c78b..801518736e7 100644 --- a/plugins/orchestrator/docs/Permissions.md +++ b/plugins/orchestrator/docs/Permissions.md @@ -31,3 +31,17 @@ g, user:default/guest, role:default/workflowViewer g, user:default/myOrgUser, role:default/workflowAdmin g, group:default/platformAdmins, role:default/worflowAdmin ``` + +See https://casbin.org/docs/rbac for more information about casbin rules + +## Enable permissions + +To enable permissions, you need to add the following in the [app-config file](../../../app-config.yaml): + +``` +permission: + enabled: true + rbac: + policies-csv-file: + policyFileReload: true +``` diff --git a/plugins/orchestrator/src/components/WorkflowInstancePage.tsx b/plugins/orchestrator/src/components/WorkflowInstancePage.tsx index 839a55aec2f..c8bd11a7a62 100644 --- a/plugins/orchestrator/src/components/WorkflowInstancePage.tsx +++ b/plugins/orchestrator/src/components/WorkflowInstancePage.tsx @@ -11,16 +11,17 @@ import { useRouteRef, useRouteRefParams, } from '@backstage/core-plugin-api'; +import { usePermission } from '@backstage/plugin-permission-react'; import Button from '@mui/material/Button'; import Grid from '@mui/material/Grid'; import { AssessedProcessInstance, + orchestratorWorkflowExecutePermission, QUERY_PARAM_ASSESSMENT_INSTANCE_ID, QUERY_PARAM_INSTANCE_ID, QUERY_PARAM_INSTANCE_STATE, - orchestratorWorkflowExecutePermission, } from '@janus-idp/backstage-plugin-orchestrator-common'; import { orchestratorApiRef } from '../api'; @@ -32,7 +33,6 @@ import { buildUrl } from '../utils/UrlUtils'; import { BaseOrchestratorPage } from './BaseOrchestratorPage'; import { InfoDialog } from './InfoDialog'; import { WorkflowInstancePageContent } from './WorkflowInstancePageContent'; -import { usePermission } from '@backstage/plugin-permission-react'; export type AbortConfirmationDialogActionsProps = { handleSubmit: () => void; @@ -90,11 +90,10 @@ export const WorkflowInstancePage = ({ const [isAbortAlertDialogOpen, setIsAbortAlertDialogOpen] = useState(false); const [abortWorkflowInstanceErrorMsg, setAbortWorkflowInstanceErrorMsg] = useState(''); - const permittedToExecute = usePermission({ + const permittedToExecute = usePermission({ permission: orchestratorWorkflowExecutePermission, }); - const fetchInstance = React.useCallback(async () => { if (!instanceId && !queryInstanceId) { return undefined; @@ -210,7 +209,7 @@ export const WorkflowInstancePage = ({