feat(orchestration): integrate read-only v4 surfaces with mutation lockdown
This commit is contained in:
1 parent
70d8128bfb
commit
ac065fa911
8 files changed
+357
-17
No files matched your search
@@ -1,13 +1,147 @@
|
||||
import { Body, Controller, Get, Param, Post, Put, Req, UseGuards } from "@nestjs/common";
|
||||
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
|
||||
import { JwtAuthGuard } from "../auth/jwt-auth.guard"; import { RolesGuard } from "../common/guards/roles.guard"; import { Roles } from "../common/decorators/roles.decorator";
|
||||
import { CreateOrchestrationTaskDto, GateDecisionDto, RecordBudgetDto, SetKillSwitchDto, TransitionTaskDto } from "./dto/orchestration.dto"; import { OrchestrationService } from "./orchestration.service";
|
||||
@ApiTags("Admin - Orchestration v4") @ApiBearerAuth() @UseGuards(JwtAuthGuard,RolesGuard) @Roles("Admin","SUPER_ADMIN") @Controller("admin/orchestration")
|
||||
export class OrchestrationController { constructor(private readonly service:OrchestrationService){} private actor(req:any){return String(req.user?.id??req.user?.sub??"SYSTEM")}
|
||||
@Get("tasks") all(){return this.service.findAll()} @Get("tasks/:id") one(@Param("id")id:string){return this.service.findOne(id)}
|
||||
@Post("tasks") create(@Body()dto:CreateOrchestrationTaskDto,@Req()req:any){return this.service.createTask(dto,this.actor(req))}
|
||||
@Put("tasks/:id/transition") transition(@Param("id")id:string,@Body()dto:TransitionTaskDto,@Req()req:any){return this.service.transition(id,dto,this.actor(req))}
|
||||
@Post("tasks/:id/gates/:gate/decide") decide(@Param("id")id:string,@Param("gate")gate:string,@Body()dto:GateDecisionDto,@Req()req:any){if(gate!=="1"&&gate!=="2")throw new Error("gate must be 1 or 2");return this.service.decideGate(id,Number(gate) as 1|2,dto,this.actor(req))}
|
||||
@Post("tasks/:id/budget") budget(@Param("id")id:string,@Body()dto:RecordBudgetDto,@Req()req:any){return this.service.recordBudget(id,dto,this.actor(req))}
|
||||
@Put("kill-switch") kill(@Body()dto:SetKillSwitchDto,@Req()req:any){return this.service.setKillSwitch(dto.level,dto.reason,this.actor(req))}
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
ForbiddenException,
|
||||
ServiceUnavailableException,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../common/guards/roles.guard';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import { OrchestrationService } from './orchestration.service';
|
||||
|
||||
// Explicit response allowlists: never serialize arbitrary JSON, signatures, URIs or BigInt.
|
||||
function pick(row: any, keys: string[]) {
|
||||
return Object.fromEntries(
|
||||
keys.filter((k) => row[k] !== undefined).map((k) => [k, row[k]]),
|
||||
);
|
||||
}
|
||||
function project(row: any) {
|
||||
return {
|
||||
...pick(row, [
|
||||
'id',
|
||||
'key',
|
||||
'title',
|
||||
'department',
|
||||
'state',
|
||||
'version',
|
||||
'operationMode',
|
||||
'budgetLimitCents',
|
||||
]),
|
||||
availableActions: [],
|
||||
runs: (row.runs ?? []).map((run: any) => ({
|
||||
...pick(run, ['id', 'commitSha', 'environment', 'status']),
|
||||
artifacts: (run.artifacts ?? []).map((a: any) =>
|
||||
pick(a, ['id', 'kind', 'sha256']),
|
||||
),
|
||||
})),
|
||||
decisions: (row.decisions ?? []).map((d: any) =>
|
||||
pick(d, [
|
||||
'id',
|
||||
'gate',
|
||||
'decision',
|
||||
'expiresAt',
|
||||
'runId',
|
||||
'artifactHash',
|
||||
'commitSha',
|
||||
'environment',
|
||||
'createdAt',
|
||||
]),
|
||||
),
|
||||
events: (row.events ?? []).map((e: any) =>
|
||||
pick(e, [
|
||||
'id',
|
||||
'eventType',
|
||||
'fromState',
|
||||
'toState',
|
||||
'sequence',
|
||||
'createdAt',
|
||||
]),
|
||||
),
|
||||
budgetLedger: (row.budgetLedger ?? []).map((b: any) =>
|
||||
pick(b, ['id', 'amountCents', 'kind', 'createdAt']),
|
||||
),
|
||||
};
|
||||
}
|
||||
@ApiTags('Admin - Orchestration v4')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin', 'SUPER_ADMIN')
|
||||
@Controller('admin/orchestration')
|
||||
export class OrchestrationController {
|
||||
constructor(private readonly service: OrchestrationService) {}
|
||||
@Get('tasks') async all() {
|
||||
return (await this.service.findAll()).map(project);
|
||||
}
|
||||
@Get('tasks/:id') async one(@Param('id') id: string) {
|
||||
return project(await this.service.findOne(id));
|
||||
}
|
||||
@Get('overview') async overview() {
|
||||
const tasks = await this.service.findAll();
|
||||
return {
|
||||
items: [
|
||||
{ id: 'tasks', title: 'Persisted task inventory', count: tasks.length },
|
||||
],
|
||||
measuredAt: new Date().toISOString(),
|
||||
capabilities: { mutations: false, chat: false, runtime: false },
|
||||
reason: 'security_hardening_pending',
|
||||
};
|
||||
}
|
||||
@Get('releases') async releases() {
|
||||
const tasks = await this.service.findAll();
|
||||
const details = await Promise.all(
|
||||
tasks.map((t: any) => this.service.findOne(t.id)),
|
||||
);
|
||||
return {
|
||||
items: details.flatMap((t: any) =>
|
||||
(t.runs ?? []).map((run: any) =>
|
||||
pick(run, ['id', 'status', 'commitSha', 'environment']),
|
||||
),
|
||||
),
|
||||
measuredAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@Get('agents') agents() {
|
||||
throw new ServiceUnavailableException(
|
||||
'Hermes runtime unavailable: trusted identity and runtime authentication not configured',
|
||||
);
|
||||
}
|
||||
@Get('schedules') schedules() {
|
||||
throw new ServiceUnavailableException(
|
||||
'Hermes schedules unavailable; runtime remains disabled',
|
||||
);
|
||||
}
|
||||
@Get('model-policy') models() {
|
||||
throw new ServiceUnavailableException(
|
||||
'No persisted model policy read contract available',
|
||||
);
|
||||
}
|
||||
// The committed legacy core is not safe to expose. No env switch or role may bypass this boundary.
|
||||
@Post('tasks') create() {
|
||||
return this.deny();
|
||||
}
|
||||
@Put('tasks/:id/transition') transition() {
|
||||
return this.deny();
|
||||
}
|
||||
@Post('tasks/:id/gates/:gate/decide') decide() {
|
||||
return this.deny();
|
||||
}
|
||||
@Post('tasks/:id/budget') budget() {
|
||||
return this.deny();
|
||||
}
|
||||
@Put('kill-switch') kill() {
|
||||
return this.deny();
|
||||
}
|
||||
@Post('chat/messages') chat() {
|
||||
return this.deny();
|
||||
}
|
||||
private deny(): never {
|
||||
throw new ForbiddenException(
|
||||
'Orchestration mutations and chat disabled pending hardened core and trusted runtime integration',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user