Skip to content

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

feat(audit-logs): query by secret path

Daniel Hougaard27efc908e218
diff --git a/backend/src/ee/services/audit-log/audit-log-dal.ts b/backend/src/ee/services/audit-log/audit-log-dal.ts
index bcef06e100..21f7858353 100644
--- a/backend/src/ee/services/audit-log/audit-log-dal.ts
+++ b/backend/src/ee/services/audit-log/audit-log-dal.ts
@@ -39,11 +39,13 @@ export const auditLogDALFactory = (db: TDbClient) => {
offset = 0,
actorId,
actorType,
+ secretPath,
eventType,
eventMetadata
}: Omit<TFindQuery, "actor" | "eventType"> & {
actorId?: string;
actorType?: ActorType;
+ secretPath?: string;
eventType?: EventType[];
eventMetadata?: Record<string, string>;
},
@@ -88,6 +90,10 @@ export const auditLogDALFactory = (db: TDbClient) => {
});
}
+ if (projectId && secretPath) {
+ void sqlQuery.whereRaw(`"eventMetadata" @> jsonb_build_object('secretPath', ?::text)`, [secretPath]);
+ }
+
// Filter by actor type
if (actorType) {
void sqlQuery.where("actor", actorType);
diff --git a/backend/src/ee/services/audit-log/audit-log-service.ts b/backend/src/ee/services/audit-log/audit-log-service.ts
index ff7dede5fc..3b860864f6 100644
--- a/backend/src/ee/services/audit-log/audit-log-service.ts
+++ b/backend/src/ee/services/audit-log/audit-log-service.ts
@@ -46,10 +46,6 @@ export const auditLogServiceFactory = ({
actorOrgId
);
- /**
- * NOTE (dangtony98): Update this to organization-level audit log permission check once audit logs are moved
- * to the organization level ✅
- */
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.AuditLogs);
}
@@ -64,6 +60,7 @@ export const auditLogServiceFactory = ({
actorId: filter.auditLogActorId,
actorType: filter.actorType,
eventMetadata: filter.eventMetadata,
+ secretPath: filter.secretPath,
...(filter.projectId ? { projectId: filter.projectId } : { orgId: actorOrgId })
});
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 9c19cd3ccb..6e83147315 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -32,6 +32,7 @@ export type TListProjectAuditLogDTO = {
projectId?: string;
auditLogActorId?: string;
actorType?: ActorType;
+ secretPath?: string;
eventMetadata?: Record<string, string>;
};
} & Omit<TProjectPermission, "projectId">;
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 800788179d..eca11e9833 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -828,6 +828,8 @@ export const AUDIT_LOGS = {
projectId:
"Optionally filter logs by project ID. If not provided, logs from the entire organization will be returned.",
eventType: "The type of the event to export.",
+ secretPath:
+ "The path of the secret to query audit logs for. Note that the projectId parameter must also be provided.",
userAgentType: "Choose which consuming application to export audit logs for.",
eventMetadata:
"Filter by event metadata key-value pairs. Formatted as `key1=value1,key2=value2`, with comma-separation.",
diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.ts
index 1048980992..db0008ebe2 100644
--- a/backend/src/server/routes/v1/organization-router.ts
+++ b/backend/src/server/routes/v1/organization-router.ts
@@ -11,7 +11,7 @@ import {
} from "@app/db/schemas";
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { AUDIT_LOGS, ORGANIZATIONS } from "@app/lib/api-docs";
-import { getLastMidnightDateISO } from "@app/lib/fn";
+import { getLastMidnightDateISO, removeTrailingSlash } from "@app/lib/fn";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { slugSchema } from "@app/server/lib/schemas";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
@@ -113,6 +113,12 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
querystring: z.object({
projectId: z.string().optional().describe(AUDIT_LOGS.EXPORT.projectId),
actorType: z.nativeEnum(ActorType).optional(),
+ secretPath: z
+ .string()
+ .optional()
+ .transform((val) => (!val ? val : removeTrailingSlash(val)))
+ .describe(AUDIT_LOGS.EXPORT.secretPath),
+
// eventType is split with , for multiple values, we need to transform it to array
eventType: z
.string()
diff --git a/frontend/src/hooks/api/auditLogs/types.tsx b/frontend/src/hooks/api/auditLogs/types.tsx
index 3a5070ef54..338671cab5 100644
--- a/frontend/src/hooks/api/auditLogs/types.tsx
+++ b/frontend/src/hooks/api/auditLogs/types.tsx
@@ -10,6 +10,7 @@ export type TGetAuditLogsFilter = {
actorType?: ActorType;
projectId?: string;
actor?: string; // user ID format
+ secretPath?: string;
startDate?: Date;
endDate?: Date;
limit: number;
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsFilter.tsx
index 3a21958aea..a1246c6951 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/LogsFilter.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsFilter.tsx
@@ -14,6 +14,7 @@ import {
DropdownMenuTrigger,
FilterableSelect,
FormControl,
+ Input,
Select,
SelectItem
} from "@app/components/v2";
@@ -50,6 +51,7 @@ export const LogsFilter = ({
className,
control,
reset,
+ setValue,
watch
}: Props) => {
const [isStartDatePickerOpen, setIsStartDatePickerOpen] = useState(false);
@@ -101,6 +103,7 @@ export const LogsFilter = ({
};
const selectedEventTypes = watch("eventType") as EventType[] | undefined;
+ const selectedProjectId = watch("project")?.id;
return (
<div
@@ -109,30 +112,49 @@ export const LogsFilter = ({
className
)}
>
- {isOrgAuditLogs && workspacesInOrg.length > 0 && (
- <Controller
- control={control}
- name="project"
- render={({ field: { onChange, value }, fieldState: { error } }) => (
- <FormControl
- label="Project"
- errorText={error?.message}
- isError={Boolean(error)}
- className="mr-12 w-64"
- >
- <FilterableSelect
- value={value}
- isClearable
- onChange={onChange}
- placeholder="Select a project..."
- options={workspacesInOrg.map(({ name, id }) => ({ name, id }))}
- getOptionValue={(option) => option.id}
- getOptionLabel={(option) => option.name}
- />
- </FormControl>
- )}
- />
- )}
+ <div className="flex items-center gap-4">
+ {isOrgAuditLogs && workspacesInOrg.length > 0 && (
+ <Controller
+ control={control}
+ name="project"
+ render={({ field: { onChange, value }, fieldState: { error } }) => (
+ <FormControl
+ label="Project"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ className="w-64"
+ >
+ <FilterableSelect
+ value={value}
+ isClearable
+ onChange={(e) => {
+ console.log(e);
+ if (e === null) {
+ setValue("secretPath", "");
+ }
+ onChange(e);
+ }}
+ placeholder="Select a project..."
+ options={workspacesInOrg.map(({ name, id }) => ({ name, id }))}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ />
+ </FormControl>
+ )}
+ />
+ )}
+ {selectedProjectId && (
+ <Controller
+ control={control}
+ name="secretPath"
+ render={({ field: { onChange, value, ...field } }) => (
+ <FormControl label="Secret path" className="w-40">
+ <Input {...field} value={value} onChange={(e) => onChange(e.target.value)} />
+ </FormControl>
+ )}
+ />
+ )}
+ </div>
<div className="mt-1 flex items-center space-x-2">
<Controller
control={control}
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
index 5a64a83f81..2e1561449d 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
@@ -5,6 +5,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
import { OrgPermissionActions, OrgPermissionSubjects, useSubscription } from "@app/context";
import { withPermission } from "@app/hoc";
+import { useDebounce } from "@app/hooks";
import { ActorType, EventType, UserAgentType } from "@app/hooks/api/auditLogs/enums";
import { usePopUp } from "@app/hooks/usePopUp";
@@ -67,10 +68,13 @@ export const LogsSection = withPermission(
const userAgentType = watch("userAgentType") as UserAgentType | undefined;
const actor = watch("actor");
const projectId = watch("project")?.id;
+ const secretPath = watch("secretPath");
const startDate = watch("startDate");
const endDate = watch("endDate");
+ const [debouncedSecretPath] = useDebounce<string>(secretPath!, 500);
+
return (
<div>
{showFilters && (
@@ -90,6 +94,7 @@ export const LogsSection = withPermission(
isOrgAuditLogs={isOrgAuditLogs}
showActorColumn={!!showActorColumn}
filter={{
+ secretPath: debouncedSecretPath || undefined,
eventMetadata: presets?.eventMetadata,
projectId,
actorType: presets?.actorType,
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/types.tsx b/frontend/src/pages/organization/AuditLogsPage/components/types.tsx
index 05c44fa4dc..0854bd8cfd 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/types.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/types.tsx
@@ -12,7 +12,8 @@ export const auditLogFilterFormSchema = z
startDate: z.date().optional(),
endDate: z.date().optional(),
page: z.coerce.number().optional(),
- perPage: z.coerce.number().optional()
+ perPage: z.coerce.number().optional(),
+ secretPath: z.string().optional()
})
.superRefine((el, ctx) => {
if (el.endDate && el.startDate && el.endDate < el.startDate) {