Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: added workspaceSlug support get secret by key
=20f29c752dd0
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 10006b9efb..b8ad185a0b 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -276,7 +276,7 @@ export const RAW_SECRETS = {recursive:"Whether or not to fetch all secrets from the specified base path, and all of its subdirectories. Note, the max depth is 20 deep.",workspaceId: "The ID of the project to list secrets from.",- workspaceSlug: "The slug of the project to list secrets from. This parameter is only usable by machine identities.",+ workspaceslug: "the slug of the project to list secrets from. this parameter is only usable by machine identities.",environment: "The slug of the environment to list secrets from.",secretPath: "The secret path to list secrets from.",includeImports: "Weather to include imported secrets or not."@@ -295,6 +295,7 @@ export const RAW_SECRETS = {GET: {secretName: "The name of the secret to get.",workspaceId: "The ID of the project to get the secret from.",+ workspaceSlug: "The slug of the project to get the secret from.",environment: "The slug of the environment to get the secret from.",secretPath: "The path of the secret to get.",version: "The version of the secret to get.",diff --git a/backend/src/server/routes/v3/secret-router.ts b/backend/src/server/routes/v3/secret-router.tsindex cae51f8583..b16b4706de 100644--- a/backend/src/server/routes/v3/secret-router.ts+++ b/backend/src/server/routes/v3/secret-router.ts@@ -163,7 +163,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {],querystring: z.object({workspaceId: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceId),- workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceSlug),+ workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceslug),environment: z.string().trim().optional().describe(RAW_SECRETS.LIST.environment),secretPath: z.string().trim().default("/").transform(removeTrailingSlash).describe(RAW_SECRETS.LIST.secretPath),expandSecretReferences: z@@ -293,6 +293,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {}),querystring: z.object({workspaceId: z.string().trim().optional().describe(RAW_SECRETS.GET.workspaceId),+ workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.GET.workspaceSlug),environment: z.string().trim().optional().describe(RAW_SECRETS.GET.environment),secretPath: z.string().trim().default("/").transform(removeTrailingSlash).describe(RAW_SECRETS.GET.secretPath),version: z.coerce.number().optional().describe(RAW_SECRETS.GET.version),@@ -311,6 +312,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {},onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {+ const { workspaceSlug } = req.query;let { secretPath, environment, workspaceId } = req.query;if (req.auth.actor === ActorType.SERVICE) {const scope = ServiceTokenScopes.parse(req.auth.serviceToken.scopes);@@ -322,7 +324,9 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {}}- if (!workspaceId || !environment) throw new BadRequestError({ message: "Missing workspace id or environment" });+ if (!environment) throw new BadRequestError({ message: "Missing environment" });+ if (!workspaceId && !workspaceSlug)+ throw new BadRequestError({ message: "You must provide workspaceSlug or workspaceId" });const secret = await server.services.secret.getSecretByNameRaw({actorId: req.permission.id,@@ -331,6 +335,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {actorOrgId: req.permission.orgId,environment,projectId: workspaceId,+ projectSlug: workspaceSlug,path: secretPath,secretName: req.params.secretName,type: req.query.type,@@ -339,7 +344,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {});await server.services.auditLog.createAuditLog({- projectId: req.query.workspaceId,+ projectId: secret.workspace,...req.auditLogInfo,event: {type: EventType.GET_SECRET,@@ -358,7 +363,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {distinctId: getTelemetryDistinctId(req),properties: {numberOfSecrets: 1,- workspaceId,+ workspaceId: secret.workspace,environment,secretPath: req.query.secretPath,channel: getUserAgentType(req.headers["user-agent"]),diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.tsindex 3f647d8a9b..feb8c01d5f 100644--- a/backend/src/services/secret/secret-service.ts+++ b/backend/src/services/secret/secret-service.ts@@ -972,7 +972,8 @@ export const secretServiceFactory = ({path,actor,environment,- projectId,+ projectId: workspaceId,+ projectSlug,actorId,actorOrgId,actorAuthMethod,@@ -980,6 +981,8 @@ export const secretServiceFactory = ({includeImports,version}: TGetASecretRawDTO) => {+ const projectId = workspaceId || (await projectDAL.findProjectBySlug(projectSlug as string, actorOrgId)).id;+const botKey = await projectBotService.getBotKey(projectId);if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });diff --git a/backend/src/services/secret/secret-types.ts b/backend/src/services/secret/secret-types.tsindex df0af5b5d8..9f2addc89b 100644--- a/backend/src/services/secret/secret-types.ts+++ b/backend/src/services/secret/secret-types.ts@@ -152,7 +152,9 @@ export type TGetASecretRawDTO = {type: "shared" | "personal";includeImports?: boolean;version?: number;-} & TProjectPermission;+ projectSlug?: string;+ projectId?: string;+} & Omit<TProjectPermission, "projectId">;export type TCreateSecretRawDTO = TProjectPermission & {secretPath: string;