Skip to content

Commit aff200f

Browse files
committed
feat(deployment): add server access validation for deployment actions
- Implemented server access validation in deployment procedures to ensure users can only access deployments associated with their active organization. - Added checks to throw an UNAUTHORIZED error if a user attempts to access a deployment linked to a server outside their organization. This enhancement improves security and access control within the deployment management system.
1 parent 558d809 commit aff200f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

apps/dokploy/server/api/routers/deployment.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ export const deploymentRouter = createTRPCRouter({
151151
await checkServicePermissionAndAccess(ctx, serviceId, {
152152
deployment: ["cancel"],
153153
});
154+
} else if (deployment.schedule?.serverId) {
155+
const targetServer = await findServerById(deployment.schedule.serverId);
156+
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
157+
throw new TRPCError({
158+
code: "UNAUTHORIZED",
159+
message: "You don't have access to this deployment.",
160+
});
161+
}
154162
}
155163

156164
if (!deployment.pid) {
@@ -188,6 +196,14 @@ export const deploymentRouter = createTRPCRouter({
188196
await checkServicePermissionAndAccess(ctx, serviceId, {
189197
deployment: ["cancel"],
190198
});
199+
} else if (deployment.schedule?.serverId) {
200+
const targetServer = await findServerById(deployment.schedule.serverId);
201+
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
202+
throw new TRPCError({
203+
code: "UNAUTHORIZED",
204+
message: "You don't have access to this deployment.",
205+
});
206+
}
191207
}
192208
const result = await removeDeployment(input.deploymentId);
193209
await audit(ctx, {
@@ -212,6 +228,14 @@ export const deploymentRouter = createTRPCRouter({
212228
await checkServicePermissionAndAccess(ctx, serviceId, {
213229
deployment: ["read"],
214230
});
231+
} else if (deployment.schedule?.serverId) {
232+
const targetServer = await findServerById(deployment.schedule.serverId);
233+
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
234+
throw new TRPCError({
235+
code: "UNAUTHORIZED",
236+
message: "You don't have access to this deployment.",
237+
});
238+
}
215239
}
216240

217241
if (!deployment.logPath) {

0 commit comments

Comments
 (0)