From 5b26928751ea5ed6485d76065796ccfc1704237b Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Mon, 19 Aug 2024 20:25:07 +0800 Subject: [PATCH] misc: added audit logs --- .../ee/services/audit-log/audit-log-types.ts | 33 +++++++++++++++-- .../routes/v1/certificate-template-router.ts | 35 +++++++++++++++++++ .../certificate-template-service.ts | 7 ++-- .../src/hooks/api/auditLogs/constants.tsx | 7 +++- frontend/src/hooks/api/auditLogs/enums.tsx | 5 ++- frontend/src/hooks/api/auditLogs/types.tsx | 28 ++++++++++++++- .../AuditLogsPage/components/LogsTableRow.tsx | 14 ++++++++ 7 files changed, 121 insertions(+), 8 deletions(-) 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 0d07d005b..52972d942 100644 --- a/backend/src/ee/services/audit-log/audit-log-types.ts +++ b/backend/src/ee/services/audit-log/audit-log-types.ts @@ -166,7 +166,10 @@ export enum EventType { CREATE_CERTIFICATE_TEMPLATE = "create-certificate-template", UPDATE_CERTIFICATE_TEMPLATE = "update-certificate-template", DELETE_CERTIFICATE_TEMPLATE = "delete-certificate-template", - GET_CERTIFICATE_TEMPLATE = "get-certificate-template" + GET_CERTIFICATE_TEMPLATE = "get-certificate-template", + CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG = "create-certificate-template-est-config", + UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG = "update-certificate-template-est-config", + GET_CERTIFICATE_TEMPLATE_EST_CONFIG = "get-certificate-template-est-config" } interface UserActorMetadata { @@ -1420,6 +1423,29 @@ interface OrgAdminAccessProjectEvent { }; // no metadata yet } +interface CreateCertificateTemplateEstConfig { + type: EventType.CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + isEnabled: boolean; + }; +} + +interface UpdateCertificateTemplateEstConfig { + type: EventType.UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + isEnabled: boolean; + }; +} + +interface GetCertificateTemplateEstConfig { + type: EventType.GET_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + }; +} + export type Event = | GetSecretsEvent | GetSecretEvent @@ -1547,4 +1573,7 @@ export type Event = | CreateCertificateTemplate | UpdateCertificateTemplate | GetCertificateTemplate - | DeleteCertificateTemplate; + | DeleteCertificateTemplate + | CreateCertificateTemplateEstConfig + | UpdateCertificateTemplateEstConfig + | GetCertificateTemplateEstConfig; diff --git a/backend/src/server/routes/v1/certificate-template-router.ts b/backend/src/server/routes/v1/certificate-template-router.ts index 786f3bdae..c9d2410fd 100644 --- a/backend/src/server/routes/v1/certificate-template-router.ts +++ b/backend/src/server/routes/v1/certificate-template-router.ts @@ -241,6 +241,18 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid ...req.body }); + await server.services.auditLog.createAuditLog({ + ...req.auditLogInfo, + projectId: estConfig.projectId, + event: { + type: EventType.CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG, + metadata: { + certificateTemplateId: estConfig.certificateTemplateId, + isEnabled: estConfig.isEnabled as boolean + } + } + }); + return estConfig; } }); @@ -276,6 +288,18 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid ...req.body }); + await server.services.auditLog.createAuditLog({ + ...req.auditLogInfo, + projectId: estConfig.projectId, + event: { + type: EventType.UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG, + metadata: { + certificateTemplateId: estConfig.certificateTemplateId, + isEnabled: estConfig.isEnabled as boolean + } + } + }); + return estConfig; } }); @@ -308,6 +332,17 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid actorOrgId: req.permission.orgId }); + await server.services.auditLog.createAuditLog({ + ...req.auditLogInfo, + projectId: estConfig.projectId, + event: { + type: EventType.GET_CERTIFICATE_TEMPLATE_EST_CONFIG, + metadata: { + certificateTemplateId: estConfig.certificateTemplateId + } + } + }); + return estConfig; } }); diff --git a/backend/src/services/certificate-template/certificate-template-service.ts b/backend/src/services/certificate-template/certificate-template-service.ts index f18034058..cb1caa39f 100644 --- a/backend/src/services/certificate-template/certificate-template-service.ts +++ b/backend/src/services/certificate-template/certificate-template-service.ts @@ -257,7 +257,7 @@ export const certificateTemplateServiceFactory = ({ isEnabled }); - return estConfig; + return { ...estConfig, projectId: certTemplate.projectId }; }; const updateEstConfiguration = async ({ @@ -331,7 +331,7 @@ export const certificateTemplateServiceFactory = ({ const estConfig = await certificateTemplateEstConfigDAL.updateById(originalCaEstConfig.id, updatedData); - return estConfig; + return { ...estConfig, projectId: certTemplate.projectId }; }; const getEstConfiguration = async (dto: TGetEstConfigurationDTO) => { @@ -388,7 +388,8 @@ export const certificateTemplateServiceFactory = ({ id: estConfig.id, isEnabled: estConfig.isEnabled, caChain: decryptedCaChain.toString(), - hashedPassphrase: estConfig.hashedPassphrase + hashedPassphrase: estConfig.hashedPassphrase, + projectId: certTemplate.projectId }; }; diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsx index 210061f7c..b9ba07264 100644 --- a/frontend/src/hooks/api/auditLogs/constants.tsx +++ b/frontend/src/hooks/api/auditLogs/constants.tsx @@ -72,7 +72,12 @@ export const eventToNameMap: { [K in EventType]: string } = { [EventType.CREATE_CERTIFICATE_TEMPLATE]: "Create certificate template", [EventType.UPDATE_CERTIFICATE_TEMPLATE]: "Update certificate template", [EventType.DELETE_CERTIFICATE_TEMPLATE]: "Delete certificate template", - [EventType.GET_CERTIFICATE_TEMPLATE]: "Get certificate template" + [EventType.GET_CERTIFICATE_TEMPLATE]: "Get certificate template", + [EventType.GET_CERTIFICATE_TEMPLATE_EST_CONFIG]: "Get certificate template EST configuration", + [EventType.CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG]: + "Create certificate template EST configuration", + [EventType.UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG]: + "Update certificate template EST configuration" }; export const userAgentTTypeoNameMap: { [K in UserAgentType]: string } = { diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsx index 80c0ce431..6df32aa0b 100644 --- a/frontend/src/hooks/api/auditLogs/enums.tsx +++ b/frontend/src/hooks/api/auditLogs/enums.tsx @@ -86,5 +86,8 @@ export enum EventType { CREATE_CERTIFICATE_TEMPLATE = "create-certificate-template", UPDATE_CERTIFICATE_TEMPLATE = "update-certificate-template", DELETE_CERTIFICATE_TEMPLATE = "delete-certificate-template", - GET_CERTIFICATE_TEMPLATE = "get-certificate-template" + GET_CERTIFICATE_TEMPLATE = "get-certificate-template", + CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG = "create-certificate-template-est-config", + UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG = "update-certificate-template-est-config", + GET_CERTIFICATE_TEMPLATE_EST_CONFIG = "get-certificate-template-est-config" } diff --git a/frontend/src/hooks/api/auditLogs/types.tsx b/frontend/src/hooks/api/auditLogs/types.tsx index d7825637d..f9b53d037 100644 --- a/frontend/src/hooks/api/auditLogs/types.tsx +++ b/frontend/src/hooks/api/auditLogs/types.tsx @@ -719,6 +719,29 @@ interface DeleteCertificateTemplate { }; } +interface CreateCertificateTemplateEstConfig { + type: EventType.CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + isEnabled: boolean; + }; +} + +interface UpdateCertificateTemplateEstConfig { + type: EventType.UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + isEnabled: boolean; + }; +} + +interface GetCertificateTemplateEstConfig { + type: EventType.GET_CERTIFICATE_TEMPLATE_EST_CONFIG; + metadata: { + certificateTemplateId: string; + }; +} + export type Event = | GetSecretsEvent | GetSecretEvent @@ -791,7 +814,10 @@ export type Event = | CreateCertificateTemplate | UpdateCertificateTemplate | GetCertificateTemplate - | DeleteCertificateTemplate; + | DeleteCertificateTemplate + | UpdateCertificateTemplateEstConfig + | CreateCertificateTemplateEstConfig + | GetCertificateTemplateEstConfig; export type AuditLog = { id: string; diff --git a/frontend/src/views/Project/AuditLogsPage/components/LogsTableRow.tsx b/frontend/src/views/Project/AuditLogsPage/components/LogsTableRow.tsx index ea0e687bb..c1652aaba 100644 --- a/frontend/src/views/Project/AuditLogsPage/components/LogsTableRow.tsx +++ b/frontend/src/views/Project/AuditLogsPage/components/LogsTableRow.tsx @@ -428,6 +428,20 @@ export const LogsTableRow = ({ auditLog }: Props) => {

{`Certificate Template ID: ${event.metadata.certificateTemplateId}`}

); + case EventType.CREATE_CERTIFICATE_TEMPLATE_EST_CONFIG: + case EventType.UPDATE_CERTIFICATE_TEMPLATE_EST_CONFIG: + return ( + +

{`Certificate Template ID: ${event.metadata.certificateTemplateId}`}

+

{`Enabled: ${event.metadata.isEnabled}`}

+ + ); + case EventType.GET_CERTIFICATE_TEMPLATE_EST_CONFIG: + return ( + +

{`Certificate Template ID: ${event.metadata.certificateTemplateId}`}

+ + ); default: return ; }