Skip to content

Commit 9747e83

Browse files
committed
feat: enhance vault provider access control and environment variable handling
- Updated the environment autocomplete component to include projectId and environmentId in vault secret fetching logic. - Added authorization checks in the vault provider router to ensure users have access to the specified project and environment. - Modified the vault provider schema to include projectId and optional environmentId for better validation. - Improved error handling for unauthorized access and invalid vault provider assignments.
1 parent ce717a3 commit 9747e83

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

‎apps/dokploy/components/shared/env-autocomplete.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ export const useEnvCompletionSource = ({
8585
const vaultSecret = /^vault\.([a-zA-Z0-9_-]+)\.([^}\n]*)$/.exec(inner);
8686
if (vaultSecret) {
8787
const provider = providers?.find((p) => p.name === vaultSecret[1]);
88-
if (!provider) return null;
88+
if (!provider || !projectId) return null;
8989
const names = await utils.vaultProvider.listSecretNames
90-
.fetch({ vaultProviderId: provider.vaultProviderId })
90+
.fetch({
91+
vaultProviderId: provider.vaultProviderId,
92+
projectId,
93+
environmentId,
94+
})
9195
.catch(() => [] as string[]);
9296
return {
9397
from: innerFrom + `vault.${vaultSecret[1]}.`.length,
@@ -176,6 +180,14 @@ export const useEnvCompletionSource = ({
176180

177181
return null;
178182
},
179-
[providers, projectEnv, environmentEnv, includeShared, utils],
183+
[
184+
providers,
185+
projectEnv,
186+
environmentEnv,
187+
includeShared,
188+
projectId,
189+
environmentId,
190+
utils,
191+
],
180192
);
181193
};

‎apps/dokploy/server/api/routers/vault-provider.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import {
22
createVaultProvider,
33
findVaultProviderInOrganization,
44
findVaultProvidersByOrganizationId,
5+
isVaultProviderAssigned,
56
listVaultProviderSecretNames,
67
maskVaultProviderConfig,
78
mergeVaultProviderConfig,
89
removeVaultProvider,
910
testVaultProviderConnection,
1011
updateVaultProvider,
1112
} from "@dokploy/server";
13+
import { findMemberByUserId } from "@dokploy/server/services/permission";
1214
import { TRPCError } from "@trpc/server";
1315
import { audit } from "@/server/api/utils/audit";
1416
import {
@@ -129,6 +131,34 @@ export const vaultProviderRouter = createTRPCRouter({
129131
input.vaultProviderId,
130132
ctx.session.activeOrganizationId,
131133
);
134+
135+
if (ctx.user.role !== "owner" && ctx.user.role !== "admin") {
136+
const { accessedProjects } = await findMemberByUserId(
137+
ctx.user.id,
138+
ctx.session.activeOrganizationId,
139+
);
140+
if (!accessedProjects.includes(input.projectId)) {
141+
throw new TRPCError({
142+
code: "UNAUTHORIZED",
143+
message: "You don't have access to this project",
144+
});
145+
}
146+
}
147+
148+
if (
149+
!isVaultProviderAssigned(
150+
provider.assignments,
151+
input.projectId,
152+
input.environmentId,
153+
)
154+
) {
155+
throw new TRPCError({
156+
code: "FORBIDDEN",
157+
message:
158+
"This vault provider is not enabled for the given project/environment",
159+
});
160+
}
161+
132162
return await listVaultProviderSecretNames(provider.config);
133163
}),
134164
});

‎packages/server/src/db/schema/vault-provider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,6 @@ export const apiTestVaultProvider = z.object({
140140

141141
export const apiListVaultSecretNames = z.object({
142142
vaultProviderId: z.string().min(1),
143+
projectId: z.string().min(1),
144+
environmentId: z.string().optional(),
143145
});
88 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)