mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 08:27:36 +00:00
Merge pull request #1510 from akhilmhdh/fix/audit-log-queue
fix(server): auditlog won't push if retention period is zero
This commit is contained in:
@@ -22,23 +22,13 @@ export const auditLogQueueServiceFactory = ({
|
|||||||
licenseService
|
licenseService
|
||||||
}: TAuditLogQueueServiceFactoryDep) => {
|
}: TAuditLogQueueServiceFactoryDep) => {
|
||||||
const pushToLog = async (data: TCreateAuditLogDTO) => {
|
const pushToLog = async (data: TCreateAuditLogDTO) => {
|
||||||
await queueService.queue(QueueName.AuditLog, QueueJobs.AuditLog, data, {
|
let { orgId } = data;
|
||||||
removeOnFail: {
|
|
||||||
count: 5
|
|
||||||
},
|
|
||||||
removeOnComplete: true
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
queueService.start(QueueName.AuditLog, async (job) => {
|
|
||||||
const { actor, event, ipAddress, projectId, userAgent, userAgentType } = job.data;
|
|
||||||
let { orgId } = job.data;
|
|
||||||
const MS_IN_DAY = 24 * 60 * 60 * 1000;
|
const MS_IN_DAY = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
if (!orgId) {
|
if (!orgId) {
|
||||||
// it will never be undefined for both org and project id
|
// it will never be undefined for both org and project id
|
||||||
// TODO(akhilmhdh): use caching here in dal to avoid db calls
|
// TODO(akhilmhdh): use caching here in dal to avoid db calls
|
||||||
const project = await projectDAL.findById(projectId as string);
|
const project = await projectDAL.findById(data.projectId as string);
|
||||||
orgId = project.orgId;
|
orgId = project.orgId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +36,26 @@ export const auditLogQueueServiceFactory = ({
|
|||||||
const ttl = plan.auditLogsRetentionDays * MS_IN_DAY;
|
const ttl = plan.auditLogsRetentionDays * MS_IN_DAY;
|
||||||
// skip inserting if audit log retention is 0 meaning its not supported
|
// skip inserting if audit log retention is 0 meaning its not supported
|
||||||
if (ttl === 0) return;
|
if (ttl === 0) return;
|
||||||
|
|
||||||
|
await queueService.queue(
|
||||||
|
QueueName.AuditLog,
|
||||||
|
QueueJobs.AuditLog,
|
||||||
|
{ ...data, orgId },
|
||||||
|
{
|
||||||
|
removeOnFail: {
|
||||||
|
count: 3
|
||||||
|
},
|
||||||
|
removeOnComplete: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
queueService.start(QueueName.AuditLog, async (job) => {
|
||||||
|
const { actor, event, ipAddress, projectId, userAgent, userAgentType, orgId } = job.data;
|
||||||
|
const MS_IN_DAY = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
const plan = await licenseService.getPlan(orgId as string);
|
||||||
|
const ttl = plan.auditLogsRetentionDays * MS_IN_DAY;
|
||||||
await auditLogDAL.create({
|
await auditLogDAL.create({
|
||||||
actor: actor.type,
|
actor: actor.type,
|
||||||
actorMetadata: actor.metadata,
|
actorMetadata: actor.metadata,
|
||||||
|
|||||||
@@ -39,11 +39,12 @@ export const registerIdentityUaRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { identityUa, accessToken, identityAccessToken, validClientSecretInfo } =
|
const { identityUa, accessToken, identityAccessToken, validClientSecretInfo, identityMembershipOrg } =
|
||||||
await server.services.identityUa.login(req.body.clientId, req.body.clientSecret, req.realIp);
|
await server.services.identityUa.login(req.body.clientId, req.body.clientSecret, req.realIp);
|
||||||
|
|
||||||
await server.services.auditLog.createAuditLog({
|
await server.services.auditLog.createAuditLog({
|
||||||
...req.auditLogInfo,
|
...req.auditLogInfo,
|
||||||
|
orgId: identityMembershipOrg?.orgId,
|
||||||
event: {
|
event: {
|
||||||
type: EventType.LOGIN_IDENTITY_UNIVERSAL_AUTH,
|
type: EventType.LOGIN_IDENTITY_UNIVERSAL_AUTH,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ export const identityUaServiceFactory = ({
|
|||||||
const identityUa = await identityUaDAL.findOne({ clientId });
|
const identityUa = await identityUaDAL.findOne({ clientId });
|
||||||
if (!identityUa) throw new UnauthorizedError();
|
if (!identityUa) throw new UnauthorizedError();
|
||||||
|
|
||||||
|
const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId: identityUa.identityId });
|
||||||
|
|
||||||
checkIPAgainstBlocklist({
|
checkIPAgainstBlocklist({
|
||||||
ipAddress: ip,
|
ipAddress: ip,
|
||||||
trustedIps: identityUa.clientSecretTrustedIps as TIp[]
|
trustedIps: identityUa.clientSecretTrustedIps as TIp[]
|
||||||
@@ -131,7 +133,7 @@ export const identityUaServiceFactory = ({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return { accessToken, identityUa, validClientSecretInfo, identityAccessToken };
|
return { accessToken, identityUa, validClientSecretInfo, identityAccessToken, identityMembershipOrg };
|
||||||
};
|
};
|
||||||
|
|
||||||
const attachUa = async ({
|
const attachUa = async ({
|
||||||
|
|||||||
Reference in New Issue
Block a user