Skip to content

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

fix: structural changes

varonix083762e834567
diff --git a/backend/src/ee/routes/v1/audit-report-router.ts b/backend/src/ee/routes/v1/audit-report-router.ts
index cd9fcdf797..f133dab39c 100644
--- a/backend/src/ee/routes/v1/audit-report-router.ts
+++ b/backend/src/ee/routes/v1/audit-report-router.ts
@@ -34,9 +34,7 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
url: "/",
config: { rateLimit: writeLimit },
schema: {
- operationId: "requestAuditReport",
- description: "Request generation of one or more audit reports, delivered by email as CSV attachments",
- security: [{ bearerAuth: [] }],
+ hide: true,
body: z.object({
projectId: z.string().trim(),
reports: z
@@ -46,12 +44,8 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
inputs: z.record(z.unknown()).optional()
})
)
- .min(1)
- .describe("The report types to generate, each with optional type-specific inputs."),
- emailRecipients: z
- .array(z.string().email())
- .optional()
- .describe("Email addresses to deliver the reports to. Defaults to the requesting user's email.")
+ .min(1),
+ emailRecipients: z.array(z.string().email()).optional()
}),
response: {
200: AuditReportSchema
@@ -59,7 +53,7 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const report = await server.services.auditReport.requestReport(req.body, req.permission);
+ const report = await server.services.auditReport.generateReport(req.body, req.permission);
await server.services.auditLog.createAuditLog({
projectId: report.projectId,
event: {
@@ -82,9 +76,7 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
url: "/",
config: { rateLimit: readLimit },
schema: {
- operationId: "listAuditReports",
- description: "List audit reports for a project",
- security: [{ bearerAuth: [] }],
+ hide: true,
querystring: z.object({
projectId: z.string().trim(),
offset: z.coerce.number().min(0).default(0),
@@ -115,9 +107,7 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
url: "/:auditReportId",
config: { rateLimit: readLimit },
schema: {
- operationId: "getAuditReport",
- description: "Get a single audit report by ID",
- security: [{ bearerAuth: [] }],
+ hide: true,
params: z.object({ auditReportId: z.string().uuid() }),
querystring: z.object({ projectId: z.string().trim() }),
response: {
@@ -147,9 +137,7 @@ export const registerAuditReportRouter = async (server: FastifyZodProvider) => {
url: "/:auditReportId",
config: { rateLimit: writeLimit },
schema: {
- operationId: "deleteAuditReport",
- description: "Delete an audit report",
- security: [{ bearerAuth: [] }],
+ hide: true,
params: z.object({ auditReportId: z.string().uuid() }),
querystring: z.object({ projectId: z.string().trim() }),
response: {
diff --git a/backend/src/ee/services/audit-report/audit-report-dal.ts b/backend/src/ee/services/audit-report/audit-report-dal.ts
index 02caa50c54..352987de96 100644
--- a/backend/src/ee/services/audit-report/audit-report-dal.ts
+++ b/backend/src/ee/services/audit-report/audit-report-dal.ts
@@ -27,7 +27,7 @@ export const auditReportDALFactory = (db: TDbClient) => {
.limit(limit);
return docs;
} catch (error) {
- throw new DatabaseError({ error, name: "FindByProject - Audit Report" });
+ throw new DatabaseError({ error, name: "FindAuditReportsByProject" });
}
};
@@ -39,7 +39,7 @@ export const auditReportDALFactory = (db: TDbClient) => {
.first<{ count: string | number } | undefined>();
return Number(result?.count ?? 0);
} catch (error) {
- throw new DatabaseError({ error, name: "CountByProject - Audit Report" });
+ throw new DatabaseError({ error, name: "CountAuditReportsByProject" });
}
};
@@ -52,7 +52,7 @@ export const auditReportDALFactory = (db: TDbClient) => {
.first<{ count: string | number } | undefined>();
return Number(result?.count ?? 0);
} catch (error) {
- throw new DatabaseError({ error, name: "CountInFlightByProject - Audit Report" });
+ throw new DatabaseError({ error, name: "CountInFlightAuditReportsByProject" });
}
};
diff --git a/backend/src/ee/services/audit-report/audit-report-fns.ts b/backend/src/ee/services/audit-report/audit-report-fns.ts
index 7f9976b3c5..3e71f420c3 100644
--- a/backend/src/ee/services/audit-report/audit-report-fns.ts
+++ b/backend/src/ee/services/audit-report/audit-report-fns.ts
@@ -2,13 +2,20 @@ import { z } from "zod";
import { TAuditReports } from "@app/db/schemas";
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
+import {
+ CONSTRAINT_LABELS,
+ evaluateConstraint,
+ TStaticSecretConstraintViolation
+} from "@app/services/secret-validation-rule/secret-validation-rule-fns";
+import { TConstraint } from "@app/services/secret-validation-rule/secret-validation-rule-types";
import {
AuditReportResultEntrySchema,
AuditReportStatus,
AuditReportType,
MAX_AUDIT_REPORT_ROWS,
- TGeneratedReport
+ TGeneratedReport,
+ TSecretToValidate
} from "./audit-report-types";
export const DAY_IN_MS = 24 * 60 * 60 * 1000;
@@ -26,15 +33,11 @@ const escapeCsvCell = (value: string | number | null): string => {
const toCsvRow = (cells: (string | number | null)[]): string => cells.map(escapeCsvCell).join(",");
-// One report's block within the bundled CSV: a labelled section with its own column headers.
export type TAuditReportSection = {
title: string;
report: TGeneratedReport;
};
-// Serialize every requested report into a SINGLE CSV file. Each report becomes its own section
-// (title row → its column headers → its rows) so heterogeneous reports keep their natural columns,
-// preceded by a small metadata header. Sections are separated by a blank line for spreadsheet readability.
export const serializeReportBundle = ({
projectName,
generatedAt,
@@ -88,14 +91,12 @@ export const buildFolderPathMap = async (
return pathByFolderId;
};
-// jsonb columns surface as `unknown` from the generated schema; validate (never cast) on read.
const StoredReportConfigsSchema = z.array(
z.object({
type: z.nativeEnum(AuditReportType),
inputs: z.record(z.unknown())
})
);
-const StoredResultSummarySchema = z.array(AuditReportResultEntrySchema);
export const presentAuditReport = (report: TAuditReports) => ({
id: report.id,
@@ -104,10 +105,29 @@ export const presentAuditReport = (report: TAuditReports) => ({
status: z.nativeEnum(AuditReportStatus).parse(report.status),
reportConfigs: StoredReportConfigsSchema.parse(report.reportConfigs),
emailRecipients: report.emailRecipients,
- resultSummary: report.resultSummary == null ? null : StoredResultSummarySchema.parse(report.resultSummary),
+ resultSummary:
+ report.resultSummary == null ? null : z.array(AuditReportResultEntrySchema).parse(report.resultSummary),
errorMessage: report.errorMessage ?? null,
createdAt: report.createdAt,
updatedAt: report.updatedAt
});
export type TPresentedAuditReport = ReturnType<typeof presentAuditReport>;
+
+export const evaluateStaticSecretConstraints = (
+ constraints: TConstraint[],
+ secret: TSecretToValidate
+): TStaticSecretConstraintViolation[] => {
+ const violations: TStaticSecretConstraintViolation[] = [];
+ for (const constraint of constraints) {
+ const error = evaluateConstraint(constraint, secret);
+ if (error) {
+ violations.push({
+ constraintType: constraint.type,
+ constraintLabel: CONSTRAINT_LABELS[constraint.type],
+ message: error
+ });
+ }
+ }
+ return violations;
+};
diff --git a/backend/src/ee/services/audit-report/audit-report-generators.ts b/backend/src/ee/services/audit-report/audit-report-generators.ts
index 81cb833e46..4bb69580ae 100644
--- a/backend/src/ee/services/audit-report/audit-report-generators.ts
+++ b/backend/src/ee/services/audit-report/audit-report-generators.ts
@@ -18,8 +18,6 @@ import { SecretValidationRuleType } from "@app/services/secret-validation-rule/s
import { buildFolderPathMap, DAY_IN_MS, daysSince } from "./audit-report-fns";
import { AuditReportType, MAX_AUDIT_REPORT_ROWS, TGeneratedReport, TReportRow } from "./audit-report-types";
-// The DALs every generator may draw from. Narrowed with Pick so the dependency contract is explicit and
-// the same data-access layer the Insights feature uses is reused verbatim (no duplicate queries).
export type TAuditReportGeneratorDALs = {
secretV2BridgeDAL: Pick<
TSecretV2BridgeDALFactory,
@@ -57,8 +55,6 @@ const applyRowCap = <T>(items: T[]): { items: T[]; truncated: boolean } => {
return { items, truncated: false };
};
-// ─── Shared mappers ───────────────────────────────────────────────────────────
-
const ROTATION_COLUMNS = [
"rotationName",
"secretKeys",
@@ -213,8 +209,6 @@ const duplicateSecretsReport: TReportDefinition = {
projectId
});
- // Drop groups whose shared value is actually a secret reference (false-positive duplicates),
- // mirroring the Insights duplication logic.
const realGroups = groups.filter((group) => {
const [firstSecret] = group.secrets;
if (!firstSecret) return false;
diff --git a/backend/src/ee/services/audit-report/audit-report-service.ts b/backend/src/ee/services/audit-report/audit-report-service.ts
index 15c996e24d..216ed6d03c 100644
--- a/backend/src/ee/services/audit-report/audit-report-service.ts
+++ b/backend/src/ee/services/audit-report/audit-report-service.ts
@@ -52,9 +52,7 @@ export const auditReportServiceFactory = ({
userDAL,
queueService
}: TAuditReportServiceFactoryDep) => {
- // Audit reports share the Secret Insights entitlement (license) but have their own permission subject
- // with granular Create/Read/Delete actions.
- const checkPermission = async (
+ const $checkPermission = async (
projectId: string,
actor: TAuditReportServiceActor,
action: ProjectPermissionAuditReportActions
@@ -80,7 +78,7 @@ export const auditReportServiceFactory = ({
// Validate each requested report against its definition's input schema, applying defaults so the stored
// config is canonical. Rejects unknown/duplicate types and malformed inputs before anything is persisted.
- const buildReportConfigs = (reports: TRequestAuditReportDTO["reports"]): TAuditReportConfig[] => {
+ const $buildReportConfigs = (reports: TRequestAuditReportDTO["reports"]): TAuditReportConfig[] => {
if (!reports.length) {
throw new BadRequestError({ message: "At least one report must be requested" });
}
@@ -109,7 +107,7 @@ export const auditReportServiceFactory = ({
});
};
- const resolveRecipients = async (
+ const $resolveRecipients = async (
requestedRecipients: string[] | undefined,
actor: TAuditReportServiceActor
): Promise<string[]> => {
@@ -129,8 +127,8 @@ export const auditReportServiceFactory = ({
throw new BadRequestError({ message: "At least one email recipient is required" });
};
- const requestReport = async (dto: TRequestAuditReportDTO, actor: TAuditReportServiceActor) => {
- await checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Create);
+ const generateReport = async (dto: TRequestAuditReportDTO, actor: TAuditReportServiceActor) => {
+ await $checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Create);
const project = await projectDAL.findById(dto.projectId);
if (!project) {
@@ -144,8 +142,8 @@ export const auditReportServiceFactory = ({
throw new BadRequestError({ message: "Audit reports are not supported for this project version" });
}
- const reportConfigs = buildReportConfigs(dto.reports);
- const emailRecipients = await resolveRecipients(dto.emailRecipients, actor);
+ const reportConfigs = $buildReportConfigs(dto.reports);
+ const emailRecipients = await $resolveRecipients(dto.emailRecipients, actor);
const inFlightCount = await auditReportDAL.countInFlightByProject(dto.projectId);
if (inFlightCount >= MAX_CONCURRENT_AUDIT_REPORTS) {
@@ -183,7 +181,7 @@ export const auditReportServiceFactory = ({
};
const listReports = async (dto: TListAuditReportsDTO, actor: TAuditReportServiceActor) => {
- await checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Read);
+ await $checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Read);
const reports = await auditReportDAL.findByProject(dto.projectId, {
offset: dto.offset,
@@ -194,7 +192,7 @@ export const auditReportServiceFactory = ({
};
const getReportById = async (dto: TGetAuditReportDTO, actor: TAuditReportServiceActor) => {
- await checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Read);
+ await $checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Read);
const report = await auditReportDAL.findById(dto.auditReportId);
if (!report || report.projectId !== dto.projectId) {
@@ -205,7 +203,7 @@ export const auditReportServiceFactory = ({
};
const deleteReport = async (dto: TDeleteAuditReportDTO, actor: TAuditReportServiceActor) => {
- await checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Delete);
+ await $checkPermission(dto.projectId, actor, ProjectPermissionAuditReportActions.Delete);
const report = await auditReportDAL.findById(dto.auditReportId);
if (!report || report.projectId !== dto.projectId) {
@@ -217,7 +215,7 @@ export const auditReportServiceFactory = ({
};
return {
- requestReport,
+ generateReport,
listReports,
getReportById,
deleteReport
diff --git a/backend/src/ee/services/audit-report/audit-report-types.ts b/backend/src/ee/services/audit-report/audit-report-types.ts
index 0637c75e2c..9b172d20b7 100644
--- a/backend/src/ee/services/audit-report/audit-report-types.ts
+++ b/backend/src/ee/services/audit-report/audit-report-types.ts
@@ -24,35 +24,30 @@ export enum AuditReportStatus {
// Hard ceiling on rows per individual report. Beyond this the report is marked truncated.
export const MAX_AUDIT_REPORT_ROWS = 100_000;
-// Max number of in-flight (pending/processing) report batches per project, to bound DB-heavy work.
-export const MAX_CONCURRENT_AUDIT_REPORTS = 5;
-// One requested report within a batch. `inputs` is validated against the matching report definition's
-// schema by the service before persistence, so stored inputs are always canonical.
+export const MAX_CONCURRENT_AUDIT_REPORTS = 1;
+
export type TAuditReportConfig = {
type: AuditReportType;
inputs: Record<string, unknown>;
};
-// Per-report outcome recorded on the batch once generation completes.
export const AuditReportResultEntrySchema = z.object({
type: z.nativeEnum(AuditReportType),
rowCount: z.number(),
truncated: z.boolean()
});
+
export type TAuditReportResultEntry = z.infer<typeof AuditReportResultEntrySchema>;
-// A single generated report's tabular payload. Cells are pre-stringified at the generator boundary so
-// CSV serialization is a pure formatting step with no per-type knowledge.
export type TReportRow = Record<string, string | number | null>;
+
export type TGeneratedReport = {
columns: string[];
rows: TReportRow[];
truncated: boolean;
};
-// ─── Service DTOs ─────────────────────────────────────────────────────────────
-
export type TRequestAuditReportDTO = {
projectId: string;
reports: { type: AuditReportType; inputs?: Record<string, unknown> }[];
@@ -81,3 +76,9 @@ export type TAuditReportServiceActor = OrgServiceActor;
export type TGenerateAuditReportJobPayload = {
auditReportId: string;
};
+
+export type TSecretToValidate = {
+ key: string;
+ value?: string;
+ previousValues?: string[];
+};
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
index c73fa380ca..63d5c5c0bb 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
@@ -1348,9 +1348,6 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
}
};
- // All non-personal secrets in a project that carry a value, with just the fields needed to evaluate
- // them against secret validation rules (key for key-constraints, encryptedValue for value-constraints,
- // folderId to resolve the secret's path/environment for rule matching).
const findValueValidationCandidatesByProject = async (projectId: string, tx?: Knex) => {
try {
const result = await (tx || db.replicaNode())(TableName.SecretV2)
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
index 06231c2796..f438fa2aea 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
@@ -200,7 +200,7 @@ type TValidationViolation = {
message: string;
};
-const CONSTRAINT_LABELS: Record<ConstraintType, string> = {
+export const CONSTRAINT_LABELS: Record<ConstraintType, string> = {
[ConstraintType.MinLength]: "Minimum length",
[ConstraintType.MaxLength]: "Maximum length",
[ConstraintType.RegexPattern]: "Regex pattern",
@@ -215,7 +215,7 @@ const TARGET_LABELS: Record<ConstraintTarget, string> = {
[ConstraintTarget.GeneratedPassword]: "password"
};
-const evaluateConstraint = (constraint: TConstraint, secret: TSecretToValidate): string | null => {
+export const evaluateConstraint = (constraint: TConstraint, secret: TSecretToValidate): string | null => {
// Skip value constraints when no value mutation is occurring (e.g. key-only rename)
if (constraint.appliesTo === ConstraintTarget.SecretValue && secret.value === undefined) {
return null;