Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: move current endpoint to have a projectID prefix

adilson9e4061e3570e
diff --git a/backend/src/ee/routes/v1/insights-router.ts b/backend/src/ee/routes/v1/insights-router.ts
index 2e975789fc..10ff53fd9a 100644
--- a/backend/src/ee/routes/v1/insights-router.ts
+++ b/backend/src/ee/routes/v1/insights-router.ts
@@ -49,14 +49,16 @@ const AuditReportSchema = z.object({
export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/calendar",
+ url: "/:projectId/secrets/calendar",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsCalendar",
description: "Get secret rotation and reminder events for a calendar month view",
security: [{ bearerAuth: [] }],
+ params: z.object({
+ projectId: z.string().trim()
+ }),
querystring: z.object({
- projectId: z.string().trim(),
month: z.coerce.number().min(1).max(12),
year: z.coerce.number().min(2000).max(2100)
}),
@@ -93,7 +95,8 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId, month, year } = req.query;
+ const { projectId } = req.params;
+ const { month, year } = req.query;
const result = await server.services.insights.getCalendar({ projectId, month, year }, req.permission);
await server.services.auditLog.createAuditLog({
projectId,
@@ -106,13 +109,13 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/access-volume",
+ url: "/:projectId/secrets/access-volume",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsAccessVolume",
description: "Get secret access volume aggregated by day and actor for the past week",
security: [{ bearerAuth: [] }],
- querystring: z.object({
+ params: z.object({
projectId: z.string().trim()
}),
response: {
@@ -129,7 +132,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId } = req.query;
+ const { projectId } = req.params;
const result = await server.services.insights.getAccessVolume({ projectId }, req.permission);
await server.services.auditLog.createAuditLog({
projectId,
@@ -142,14 +145,16 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
// server.route({
// method: "GET",
- // url: "/secrets/access-locations",
+ // url: "/:projectId/secrets/access-locations",
// config: { rateLimit: readLimit },
// schema: {
// operationId: "getInsightsAccessLocations",
// description: "Get geographic locations of secret access based on audit log IP addresses",
// security: [{ bearerAuth: [] }],
+ // params: z.object({
+ // projectId: z.string().trim()
+ // }),
// querystring: z.object({
- // projectId: z.string().trim(),
// days: z.coerce.number().min(1).max(90).default(30)
// }),
// response: {
@@ -162,7 +167,8 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
// },
// onRequest: verifyAuth([AuthMode.JWT]),
// handler: async (req) => {
- // const { projectId, days } = req.query;
+ // const { projectId } = req.params;
+ // const { days } = req.query;
// const result = await server.services.insights.getAccessLocations({ projectId, days }, req.permission);
// await server.services.auditLog.createAuditLog({
// projectId,
@@ -175,14 +181,16 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/auth/method-distribution",
+ url: "/:projectId/auth/method-distribution",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsAuthMethodDistribution",
description: "Get distribution of authentication methods from secret access audit logs",
security: [{ bearerAuth: [] }],
+ params: z.object({
+ projectId: z.string().trim()
+ }),
querystring: z.object({
- projectId: z.string().trim(),
days: z.coerce.number().min(1).max(90).default(30)
}),
response: {
@@ -193,7 +201,8 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId, days } = req.query;
+ const { projectId } = req.params;
+ const { days } = req.query;
const result = await server.services.insights.getAuthMethodDistribution({ projectId, days }, req.permission);
await server.services.auditLog.createAuditLog({
projectId,
@@ -206,13 +215,13 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/secrets-duplication",
+ url: "/:projectId/secrets/secrets-duplication",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsSecretsDuplication",
description: "Get groups of duplicated secrets across environments and paths",
security: [{ bearerAuth: [] }],
- querystring: z.object({
+ params: z.object({
projectId: z.string().trim()
}),
response: {
@@ -237,7 +246,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req, reply) => {
- const { projectId } = req.query;
+ const { projectId } = req.params;
const { result, remainingTTL } = await server.services.insights.getSecretsDuplication(
{ projectId },
req.permission
@@ -258,15 +267,17 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/summary",
+ url: "/:projectId/secrets/summary",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsSummary",
description:
"Get summary stats for the insights dashboard: upcoming rotations, upcoming reminders, and stale secrets",
security: [{ bearerAuth: [] }],
+ params: z.object({
+ projectId: z.string().trim()
+ }),
querystring: z.object({
- projectId: z.string().trim(),
staleSecretsOffset: z.coerce.number().min(0).max(10000).default(0),
staleSecretsLimit: z.coerce.number().min(1).max(100).default(50)
}),
@@ -315,7 +326,8 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId, staleSecretsOffset, staleSecretsLimit } = req.query;
+ const { projectId } = req.params;
+ const { staleSecretsOffset, staleSecretsLimit } = req.query;
const result = await server.services.insights.getSummary(
{ projectId, staleSecretsOffset, staleSecretsLimit },
req.permission
@@ -331,13 +343,13 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/counts",
+ url: "/:projectId/secrets/counts",
config: { rateLimit: readLimit },
schema: {
operationId: "getInsightsCounts",
description: "Get project-wide entity counts for the insights dashboard header",
security: [{ bearerAuth: [] }],
- querystring: z.object({
+ params: z.object({
projectId: z.string().trim()
}),
response: {
@@ -352,7 +364,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId } = req.query;
+ const { projectId } = req.params;
const result = await server.services.insights.getCounts({ projectId }, req.permission);
await server.services.auditLog.createAuditLog({
projectId,
@@ -365,12 +377,14 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "POST",
- url: "/secrets/reports",
+ url: "/:projectId/secrets/reports",
config: { rateLimit: writeLimit },
schema: {
hide: true,
+ params: z.object({
+ projectId: z.string().trim()
+ }),
body: z.object({
- projectId: z.string().trim(),
reports: AuditReportRequestConfigSchema.array().min(1),
emailRecipients: z.array(z.string().email()).optional()
}),
@@ -380,7 +394,10 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const report = await server.services.auditReport.generateReport(req.body, req.permission);
+ const report = await server.services.auditReport.generateReport(
+ { projectId: req.params.projectId, ...req.body },
+ req.permission
+ );
await server.services.auditLog.createAuditLog({
projectId: report.projectId,
event: {
@@ -400,12 +417,14 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/reports",
+ url: "/:projectId/secrets/reports",
config: { rateLimit: readLimit },
schema: {
hide: true,
+ params: z.object({
+ projectId: z.string().trim()
+ }),
querystring: z.object({
- projectId: z.string().trim(),
offset: z.coerce.number().min(0).default(0),
limit: z.coerce.number().min(1).max(100).default(10)
}),
@@ -415,7 +434,8 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const { projectId, offset, limit } = req.query;
+ const { projectId } = req.params;
+ const { offset, limit } = req.query;
const { reports, totalCount } = await server.services.auditReport.listReports(
{ projectId, offset, limit },
req.permission
@@ -431,11 +451,11 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
- url: "/secrets/reports/:reportId",
+ url: "/:projectId/secrets/reports/:reportId",
config: { rateLimit: readLimit },
schema: {
hide: true,
- params: z.object({ reportId: z.string().uuid() }),
+ params: z.object({ projectId: z.string().trim(), reportId: z.string().uuid() }),
response: {
200: AuditReportSchema
}
@@ -457,11 +477,11 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
server.route({
method: "DELETE",
- url: "/secrets/reports/:reportId",
+ url: "/:projectId/secrets/reports/:reportId",
config: { rateLimit: writeLimit },
schema: {
hide: true,
- params: z.object({ reportId: z.string().uuid() }),
+ params: z.object({ projectId: z.string().trim(), reportId: z.string().uuid() }),
response: {
200: AuditReportSchema
}
diff --git a/frontend/src/hooks/api/auditReports/mutations.tsx b/frontend/src/hooks/api/auditReports/mutations.tsx
index 50cb2a1a5b..4e0d1d0088 100644
--- a/frontend/src/hooks/api/auditReports/mutations.tsx
+++ b/frontend/src/hooks/api/auditReports/mutations.tsx
@@ -3,13 +3,16 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { auditReportKeys } from "./queries";
-import { TAuditReport, TRequestAuditReportDTO } from "./types";
+import { TAuditReport, TDeleteAuditReportDTO, TRequestAuditReportDTO } from "./types";
export const useRequestAuditReport = () => {
const queryClient = useQueryClient();
return useMutation({
- mutationFn: async (dto: TRequestAuditReportDTO) => {
- const { data } = await apiRequest.post<TAuditReport>("/api/v1/insights/secrets/reports", dto);
+ mutationFn: async ({ projectId, ...body }: TRequestAuditReportDTO) => {
+ const { data } = await apiRequest.post<TAuditReport>(
+ `/api/v1/insights/${projectId}/secrets/reports`,
+ body
+ );
return data;
},
onSuccess: () => queryClient.invalidateQueries({ queryKey: auditReportKeys.all() })
@@ -21,7 +24,7 @@ export const useDeleteAuditReport = () => {
return useMutation({
mutationFn: async (auditReportId: string) => {
const { data } = await apiRequest.delete<TAuditReport>(
- `/api/v1/insights/secrets/reports/${auditReportId}`
+ `/api/v1/insights/${projectId}/secrets/reports/${auditReportId}`
);
return data;
},
diff --git a/frontend/src/hooks/api/auditReports/queries.tsx b/frontend/src/hooks/api/auditReports/queries.tsx
index 8a61abc7aa..3ef639e6fc 100644
--- a/frontend/src/hooks/api/auditReports/queries.tsx
+++ b/frontend/src/hooks/api/auditReports/queries.tsx
@@ -30,10 +30,11 @@ export const useGetAuditReports = (
return useQuery({
queryKey: auditReportKeys.list(params),
queryFn: async () => {
+ const { projectId, ...query } = params;
const { data } = await apiRequest.get<TGetAuditReportsResponse>(
- "/api/v1/insights/secrets/reports",
+ `/api/v1/insights/${projectId}/secrets/reports`,
{
- params
+ params: query
}
);
return data;
diff --git a/frontend/src/hooks/api/auditReports/types.ts b/frontend/src/hooks/api/auditReports/types.ts
index f2b13a3fe5..64c3474214 100644
--- a/frontend/src/hooks/api/auditReports/types.ts
+++ b/frontend/src/hooks/api/auditReports/types.ts
@@ -51,3 +51,8 @@ export type TRequestAuditReportDTO = {
reports: { type: AuditReportType; inputs?: Record<string, unknown> }[];
emailRecipients?: string[];
};
+
+export type TDeleteAuditReportDTO = {
+ projectId: string;
+ auditReportId: string;
+};
diff --git a/frontend/src/hooks/api/secretInsights/queries.tsx b/frontend/src/hooks/api/secretInsights/queries.tsx
index f85e053dce..37aafa9457 100644
--- a/frontend/src/hooks/api/secretInsights/queries.tsx
+++ b/frontend/src/hooks/api/secretInsights/queries.tsx
@@ -58,9 +58,10 @@ export const useGetCalendarInsights = (
return useQuery({
queryKey: secretInsightsKeys.calendarEvents(params),
queryFn: async () => {
+ const { projectId, ...query } = params;
const { data } = await apiRequest.get<TGetCalendarInsightsResponse>(
- "/api/v1/insights/secrets/calendar",
- { params }
+ `/api/v1/insights/${projectId}/secrets/calendar`,
+ { params: query }
);
return data;
},
@@ -85,8 +86,7 @@ export const useGetSecretAccessVolume = (
queryKey: secretInsightsKeys.accessVolume(params),
queryFn: async () => {
const { data } = await apiRequest.get<TGetSecretAccessVolumeResponse>(
- "/api/v1/insights/secrets/access-volume",
- { params }
+ `/api/v1/insights/${params.projectId}/secrets/access-volume`
);
return data;
},
@@ -110,9 +110,10 @@ export const useGetSecretAccessVolume = (
// return useQuery({
// queryKey: secretInsightsKeys.accessLocations(params),
// queryFn: async () => {
+// const { projectId, ...query } = params;
// const { data } = await apiRequest.get<TGetSecretAccessLocationsResponse>(
-// "/api/v1/insights/secrets/access-locations",
-// { params }
+// `/api/v1/insights/${projectId}/secrets/access-locations`,
+// { params: query }
// );
// return data;
// },
@@ -136,9 +137,10 @@ export const useGetAuthMethodDistribution = (
return useQuery({
queryKey: secretInsightsKeys.authMethodDistribution(params),
queryFn: async () => {
+ const { projectId, ...query } = params;
const { data } = await apiRequest.get<TGetAuthMethodDistributionResponse>(
- "/api/v1/insights/auth/method-distribution",
- { params }
+ `/api/v1/insights/${projectId}/auth/method-distribution`,
+ { params: query }
);
return data;
},
@@ -162,9 +164,10 @@ export const useGetInsightsSummary = (
return useQuery({
queryKey: secretInsightsKeys.summary(params),
queryFn: async () => {
+ const { projectId, ...query } = params;
const { data } = await apiRequest.get<TGetInsightsSummaryResponse>(
- "/api/v1/insights/secrets/summary",
- { params }
+ `/api/v1/insights/${projectId}/secrets/summary`,
+ { params: query }
);
return data;
},
@@ -189,8 +192,7 @@ export const useGetInsightsCounts = (
queryKey: secretInsightsKeys.counts(params),
queryFn: async () => {
const { data } = await apiRequest.get<TGetInsightsCountsResponse>(
- "/api/v1/insights/secrets/counts",
- { params }
+ `/api/v1/insights/${params.projectId}/secrets/counts`
);
return data;
},
@@ -215,8 +217,7 @@ export const useGetSecretsDuplication = (
queryKey: secretInsightsKeys.secretsDuplication(params),
queryFn: async () => {
const res = await apiRequest.get<TGetSecretsDuplicationResponse>(
- "/api/v1/insights/secrets/secrets-duplication",
- { params }
+ `/api/v1/insights/${params.projectId}/secrets/secrets-duplication`
);
const remainingTtl = Number(res.headers["x-cache-ttl"] ?? -1);
return { ...res.data, remainingTtl };
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/AuditReportsCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/AuditReportsCard.tsx
index d22e900021..0ff02de6e7 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/AuditReportsCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/AuditReportsCard.tsx
@@ -114,7 +114,7 @@ export const AuditReportsCard = () => {
const handleDeleteReport = async () => {
const report = popUp.deleteReport.data as TAuditReport;
try {
- await deleteAuditReport.mutateAsync(report.id);
+ await deleteAuditReport.mutateAsync({ projectId, auditReportId: report.id });
createNotification({ type: "success", text: "Successfully deleted report" });
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to delete report";