diff --git a/backend/src/orchestration/orchestration.module.ts b/backend/src/orchestration/orchestration.module.ts
index 6bd7ab74..9d4ecf9d 100644
--- a/backend/src/orchestration/orchestration.module.ts
+++ b/backend/src/orchestration/orchestration.module.ts
@@ -2,6 +2,7 @@ import {
PrepareWorkflowService,
PREPARE_WORKFLOW_CONFIG,
} from './prepare-workflow.service';
+import { workflowConfig } from './workflow-config';
import { Module } from '@nestjs/common';
import { PrismaModule } from '../prisma/prisma.module';
import { KillSwitchService } from './kill-switch.service';
@@ -18,7 +19,7 @@ import { OrchestrationService } from './orchestration.service';
PrepareWorkflowService,
{
provide: PREPARE_WORKFLOW_CONFIG,
- useValue: { workerIds: [], stageCiIds: [] },
+ useFactory: () => workflowConfig(process.env),
},
],
exports: [
diff --git a/backend/src/orchestration/owner-decisions.spec.ts b/backend/src/orchestration/owner-decisions.spec.ts
index 7e65c914..b5025984 100644
--- a/backend/src/orchestration/owner-decisions.spec.ts
+++ b/backend/src/orchestration/owner-decisions.spec.ts
@@ -6,7 +6,26 @@ describe('owner Gate1 hold operation', () => {
beforeEach(()=>{
task={id:'t',state:'GATE1_PENDING',version:2,operationMode:'PREPARE',metadata:{workflowScope:'STAGE_PREPARE',createdBy:'proposer'}};
tx={$queryRaw:jest.fn().mockResolvedValue([]),orchestrationTask:{findUnique:jest.fn(async()=>task),update:jest.fn(async({data}:any)=>(task={...task,state:data.state,version:task.version+1}))},orchestrationEvent:{findUnique:jest.fn(),create:jest.fn()},orchestrationApprovalDecision:{create:jest.fn()}};
- service=new PrepareWorkflowService({$transaction:async(cb:any)=>cb(tx)}, {workerIds:[],stageCiIds:[]});
+ service=new PrepareWorkflowService({$transaction:async(cb:any)=>cb(tx)}, {workerIds:[],stageCiIds:[],ownerReviewerIds:['12345678-1234-1234-1234-123456789012']} as any);
+ });
+ it('advertises and permits the pinned canonical Admin independent reviewer only',async()=>{
+ const owner={id:'12345678-1234-1234-1234-123456789012',role:'Admin'};
+ expect(service.project(task,owner).availableActions).toEqual(['APPROVE_GATE1','REJECT_GATE1','HOLD_GATE1']);
+ await expect(service.transition('t',hold,owner)).resolves.toMatchObject({state:'GATE1_HELD'});
+ await expect(service.decide('t',1,{decision:'APPROVED',expectedVersion:3,idempotencyKey:'owner-approve',expiresAt:new Date(Date.now()+60000).toISOString()},owner)).resolves.toMatchObject({state:'GATE1_APPROVED'});
+ expect(tx.orchestrationApprovalDecision.create).toHaveBeenCalledWith({data:expect.objectContaining({actorId:owner.id})});
+ });
+ it.each(['Admin','SUPER_ADMIN'])('never permits proposer self-review even if allowlisted: %s',async role=>{
+ const actor={id:'12345678-1234-1234-1234-123456789012',role}; task.metadata.createdBy=actor.id;
+ expect(service.project(task,actor).availableActions).toEqual([]);
+ await expect(service.transition('t',hold,actor)).rejects.toMatchObject({status:403});
+ await expect(service.decide('t',1,{decision:'REJECTED',expectedVersion:2,idempotencyKey:'self',expiresAt:new Date(Date.now()+60000).toISOString()},actor)).rejects.toMatchObject({status:403});
+ expect(tx.orchestrationTask.update).not.toHaveBeenCalled();
+ });
+ it.each([{id:'other',role:'Admin'},{id:'12345678-1234-1234-1234-123456789012',role:'User'},{id:'12345678-1234-1234-1234-123456789012',role:'ADMIN'}])('denies noncanonical or ungranted reviewer %j',async actor=>{
+ expect(service.project(task,actor).availableActions).toEqual([]);
+ await expect(service.decide('t',1,{decision:'REJECTED',expectedVersion:2,idempotencyKey:'deny',expiresAt:new Date(Date.now()+60000).toISOString()},actor)).rejects.toMatchObject({status:403});
+ expect(tx.orchestrationTask.update).not.toHaveBeenCalled();
});
const hold={toState:'GATE1_HELD',expectedVersion:2,idempotencyKey:'hold-t',reason:'Need revised budget'};
it('advertises hold only to independent owner reviewer',()=>{
diff --git a/backend/src/orchestration/owner-review.http.spec.ts b/backend/src/orchestration/owner-review.http.spec.ts
new file mode 100644
index 00000000..eed53be5
--- /dev/null
+++ b/backend/src/orchestration/owner-review.http.spec.ts
@@ -0,0 +1,48 @@
+import {Test} from '@nestjs/testing';
+import {INestApplication} from '@nestjs/common';
+import request from 'supertest';
+import {OrchestrationController} from './orchestration.controller';
+import {OrchestrationService} from './orchestration.service';
+import {PrepareWorkflowService} from './prepare-workflow.service';
+import {JwtAuthGuard} from '../auth/jwt-auth.guard';
+import {RolesGuard} from '../common/guards/roles.guard';
+describe('configured owner real workflow HTTP authorization',()=>{
+ const owner='12345678-1234-1234-1234-123456789012';
+ let app:INestApplication,task:any,tx:any;
+ beforeAll(async()=>{
+ tx={$queryRaw:jest.fn(async()=>[]),orchestrationTask:{findUnique:async()=>task,update:jest.fn(async({data}:any)=>(task={...task,state:data.state,version:task.version+1}))},orchestrationEvent:{findUnique:jest.fn(),create:jest.fn()},orchestrationApprovalDecision:{create:jest.fn()}};
+ const workflow=new PrepareWorkflowService({$transaction:async(cb:any)=>cb(tx)},{workerIds:[],stageCiIds:[],ownerReviewerIds:[owner]});
+ const m=await Test.createTestingModule({controllers:[OrchestrationController],providers:[{provide:OrchestrationService,useValue:{findAll:async()=>[task],findOne:async()=>task}},{provide:PrepareWorkflowService,useValue:workflow},RolesGuard]})
+ .overrideGuard(JwtAuthGuard).useValue({canActivate(c:any){const r=c.switchToHttp().getRequest();if(!r.headers.authorization)return false;r.user={sub:r.headers.authorization,role:'ADMIN'};return true;}}).compile();
+ app=m.createNestApplication();await app.init();
+ });
+ beforeEach(()=>{jest.clearAllMocks();task={id:'t',state:'GATE1_PENDING',version:2,operationMode:'PREPARE',metadata:{workflowScope:'STAGE_PREPARE',createdBy:'pmo'}};});
+ afterAll(async()=>{await app.close();});
+ it.each(['APPROVED','REJECTED'])('advertises and executes %s only for verified granted JWT subject',async decision=>{
+ const r=await request(app.getHttpServer()).get('/admin/orchestration/tasks').set('Authorization',owner).expect(200);
+ expect(r.body[0].availableActions).toEqual(['APPROVE_GATE1','REJECT_GATE1','HOLD_GATE1']);
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/gates/1/decide').set('Authorization',owner).send({decision,expectedVersion:2,idempotencyKey:'decision',expiresAt:new Date(Date.now()+60000).toISOString(),notes:'Delegated system testing by independent owner'}).expect(201);
+ expect(tx.orchestrationApprovalDecision.create).toHaveBeenCalledWith({data:expect.objectContaining({actorId:owner,decision})});
+ expect(tx.orchestrationEvent.create).toHaveBeenCalledWith({data:expect.objectContaining({actorId:owner,payload:expect.objectContaining({fingerprint:expect.stringContaining('Delegated system testing')})})});
+ });
+ it('holds via canonicalized ADMIN without granting proposer powers',async()=>{
+ await request(app.getHttpServer()).put('/admin/orchestration/tasks/t/transition').set('Authorization',owner).send({toState:'GATE1_HELD',expectedVersion:2,idempotencyKey:'hold',reason:'Independent owner needs evidence'}).expect(200);
+ expect(tx.orchestrationApprovalDecision.create).not.toHaveBeenCalled();
+ });
+ it.each(['ordinary-admin','pmo'])('denies ungranted subject %s and body impersonation',async subject=>{
+ const r=await request(app.getHttpServer()).get('/admin/orchestration/tasks').set('Authorization',subject).expect(200);
+ expect(r.body[0].availableActions).toEqual([]);
+ const body={decision:'APPROVED',expectedVersion:2,idempotencyKey:'deny',expiresAt:new Date(Date.now()+60000).toISOString()};
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/gates/1/decide').set('Authorization',subject).send(body).expect(403);
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/gates/1/decide').set('Authorization',subject).send({...body,actorId:owner}).expect(400);
+ await request(app.getHttpServer()).put('/admin/orchestration/tasks/t/transition').set('Authorization',subject).send({toState:'GATE1_HELD',expectedVersion:2,idempotencyKey:'hold',reason:'hold'}).expect(403);
+ expect(tx.orchestrationTask.update).not.toHaveBeenCalled();
+ });
+ it('denies grant holder self review, Gate2 and release',async()=>{
+ task.metadata.createdBy=owner;
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/gates/1/decide').set('Authorization',owner).send({decision:'APPROVED',expectedVersion:2,idempotencyKey:'self',expiresAt:new Date(Date.now()+60000).toISOString()}).expect(403);
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/gates/2/decide').set('Authorization',owner).send({}).expect(403);
+ await request(app.getHttpServer()).post('/admin/orchestration/tasks/t/commands/RELEASE_AUTHORIZE').set('Authorization',owner).send({}).expect(403);
+ expect(tx.orchestrationTask.update).not.toHaveBeenCalled();
+ });
+});
diff --git a/backend/src/orchestration/prepare-workflow.service.ts b/backend/src/orchestration/prepare-workflow.service.ts
index 7c25d7e8..6699059e 100644
--- a/backend/src/orchestration/prepare-workflow.service.ts
+++ b/backend/src/orchestration/prepare-workflow.service.ts
@@ -14,6 +14,7 @@ export interface WorkflowIdentity {
role: string;
}
export interface WorkflowConfig {
+ ownerReviewerIds?: string[];
workerIds: string[];
stageCiIds: string[];
}
@@ -34,6 +35,11 @@ export class PrepareWorkflowService {
)
throw new ForbiddenException('Authenticated workflow identity required');
}
+ private reviewer(a: WorkflowIdentity) {
+ return typeof a?.id === 'string' && !!a.id && a.id.length <= 100 &&
+ (a.role === 'SUPER_ADMIN' ||
+ (a.role === 'Admin' && (this.config.ownerReviewerIds ?? []).includes(a.id)));
+ }
private worker(a: WorkflowIdentity) {
this.identity(a, ['WORKFLOW_WORKER']);
if (!this.config.workerIds.includes(a.id))
@@ -199,7 +205,7 @@ export class PrepareWorkflowService {
if (await this.replay(tx, dto.idempotencyKey, fingerprint)) return t;
this.version(t, dto);
if (dto.toState === 'GATE1_HELD') {
- if (a.role !== 'SUPER_ADMIN' || t.metadata.createdBy === a.id || t.state !== 'GATE1_PENDING')
+ if (!this.reviewer(a) || t.metadata.createdBy === a.id || t.state !== 'GATE1_PENDING')
throw new ForbiddenException('Independent Gate1 reviewer and pending proposal required');
if (typeof dto.reason !== 'string' || !dto.reason.trim() || dto.reason.length > 2000)
throw new BadRequestException('Hold requires reason of 1..2000 characters');
@@ -237,7 +243,8 @@ export class PrepareWorkflowService {
});
}
async decide(id: string, gate: number, dto: any, a: WorkflowIdentity) {
- this.identity(a, ['SUPER_ADMIN']);
+ if (!this.reviewer(a))
+ throw new ForbiddenException('Provisioned independent Gate1 reviewer required');
if (gate !== 1)
throw new ForbiddenException(
'Gate2 decisions and release remain disabled',
@@ -543,7 +550,7 @@ export class PrepareWorkflowService {
actions.push('QUEUE_PREPARE');
if (
safe &&
- a?.role === 'SUPER_ADMIN' &&
+ this.reviewer(a) &&
t.metadata?.createdBy !== a.id &&
['GATE1_PENDING', 'GATE1_HELD'].includes(t.state)
) {
diff --git a/backend/src/orchestration/workflow-config.spec.ts b/backend/src/orchestration/workflow-config.spec.ts
new file mode 100644
index 00000000..e1baebc6
--- /dev/null
+++ b/backend/src/orchestration/workflow-config.spec.ts
@@ -0,0 +1,11 @@
+import { workflowConfig } from './workflow-config';
+describe('startup owner reviewer configuration',()=>{
+ it('defaults denied, accepts explicit UUID only in staging',()=>{
+ expect(workflowConfig({}).ownerReviewerIds).toEqual([]);
+ expect(workflowConfig({NODE_ENV:'production',CANINA_WORKFLOW_OWNER_REVIEWER_IDS:'12345678-1234-1234-1234-123456789012'})).toMatchObject({ownerReviewerIds:[]});
+ expect(workflowConfig({CANINA_ENV:'staging',CANINA_WORKFLOW_OWNER_REVIEWER_IDS:'12345678-1234-1234-1234-123456789012'}).ownerReviewerIds).toEqual(['12345678-1234-1234-1234-123456789012']);
+ });
+ it.each(['*','admin','12345678-1234-1234-1234-123456789012,'])('fails startup on malformed explicit grant %s',ids=>{
+ expect(()=>workflowConfig({CANINA_ENV:'staging',CANINA_WORKFLOW_OWNER_REVIEWER_IDS:ids})).toThrow('Invalid owner reviewer UUID allowlist');
+ });
+});
diff --git a/backend/src/orchestration/workflow-config.ts b/backend/src/orchestration/workflow-config.ts
new file mode 100644
index 00000000..cf1104be
--- /dev/null
+++ b/backend/src/orchestration/workflow-config.ts
@@ -0,0 +1,9 @@
+import type { WorkflowConfig } from './prepare-workflow.service';
+/** Startup-only configuration; HTTP payloads can never supply reviewer grants. */
+export function workflowConfig(env: NodeJS.ProcessEnv): WorkflowConfig {
+ const raw = env.CANINA_ENV === 'staging' ? env.CANINA_WORKFLOW_OWNER_REVIEWER_IDS ?? '' : '';
+ const ids = raw ? raw.split(',') : [];
+ if (ids.length > 20 || ids.some(id => !/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(id)))
+ throw new Error('Invalid owner reviewer UUID allowlist');
+ return {workerIds:[],stageCiIds:[],ownerReviewerIds:[...new Set(ids)]};
+}
diff --git a/frontend/admin-panel/src/pages/OrchestrationCommandCenter.test.tsx b/frontend/admin-panel/src/pages/OrchestrationCommandCenter.test.tsx
index 1c96e25d..e94c5ddd 100644
--- a/frontend/admin-panel/src/pages/OrchestrationCommandCenter.test.tsx
+++ b/frontend/admin-panel/src/pages/OrchestrationCommandCenter.test.tsx
@@ -116,3 +116,17 @@ it('separates human evidence from server workflow scope without inventing a mark
expect(await screen.findByText('محدوده و معیارهای پذیرش گزارششده از سرور')).toBeInTheDocument();
expect(screen.getByText('محدوده گردش کار سرور: در نمای امن در دسترس نیست.')).toBeInTheDocument();
});
+
+it('shows advertised decisions directly on pending card and labels reservation not measured cost',async()=>{
+ const ownerTask={...task,budgetLimitCents:20,availableActions:['APPROVE_GATE1','REJECT_GATE1','HOLD_GATE1']};
+ vi.mocked(api.get).mockImplementation(async url=>({data:url.endsWith('/overview')?{items:[],measuredAt:'now',capabilities:{mutations:true}}:url.endsWith('/tasks')?[ownerTask]:ownerTask}));
+ render();
+ const card=await screen.findByRole('region',{name:'منتظر تصمیم شما'});
+ expect(await within(card).findByRole('button',{name:'تأیید کار محدود در Gate1'})).toBeEnabled();
+ expect(within(card).getByRole('button',{name:'رد کار در Gate1'})).toBeEnabled();
+ expect(within(card).getByRole('button',{name:'تعویق تصمیم Gate1'})).toBeEnabled();
+ expect(within(card).getByText('رزرو آزمایشی؛ هزینه واقعی نامشخص')).toBeInTheDocument();
+ fireEvent.click(within(card).getByRole('button',{name:'تعویق تصمیم Gate1'}));
+ expect(await screen.findByRole('region',{name:'جزئیات وظیفه'})).toBeInTheDocument();
+ expect(api.post).not.toHaveBeenCalled(); expect(api.put).not.toHaveBeenCalled();
+});
diff --git a/frontend/admin-panel/src/pages/OrchestrationCommandCenter.tsx b/frontend/admin-panel/src/pages/OrchestrationCommandCenter.tsx
index 0a8fef67..0d3ec538 100644
--- a/frontend/admin-panel/src/pages/OrchestrationCommandCenter.tsx
+++ b/frontend/admin-panel/src/pages/OrchestrationCommandCenter.tsx
@@ -64,10 +64,10 @@ export default function OrchestrationCommandCenter() {
{success&&
{success}
}
{section==='وظیفهها و تأییدها'&&capabilities.mutations&&void loadTasks()}/>}
{section==='نمای کلی'&&
-
منتظر تصمیم شما
تصمیم Gate1 برای کار محدود؛ تأیید بهمعنای انتشار یا اجرای Production نیست. اقدامها پس از دریافت جزئیات از سرور نمایش داده میشوند.
+
منتظر تصمیم شما
تصمیم Gate1 برای کار محدود؛ تأیید بهمعنای انتشار یا اجرای Production نیست. دکمهها فقط اقدامهای مجاز اعلامشده توسط سرور هستند؛ برای بررسی و تصمیم، جزئیات را باز کنید.
}
{(['نمای کلی','وظیفهها و تأییدها','اجراها و خروجیها'] as Section[]).includes(section)&&
@@ -78,7 +78,7 @@ export default function OrchestrationCommandCenter() {
اقدامهای مجاز اعلامشده توسط سرور
{!selected.availableActions.length&&
اقدامی اعلام نشده است. این نما فقط خواندنی است؛ مرورگر مجوز یا تغییر وضعیت ایجاد نمیکند.