Skip to content

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

feat: added audit log and more improvements

=215c7bece4f2
diff --git a/backend/src/ee/routes/v1/email-domain-router.ts b/backend/src/ee/routes/v1/email-domain-router.ts
index 59b354a50d..e49d933451 100644
--- a/backend/src/ee/routes/v1/email-domain-router.ts
+++ b/backend/src/ee/routes/v1/email-domain-router.ts
@@ -1,6 +1,7 @@
import { z } from "zod";
import { EmailDomainsSchema } from "@app/db/schemas";
+import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
@@ -33,6 +34,18 @@ export const registerEmailDomainRouter = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId
});
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.CREATE_EMAIL_DOMAIN,
+ metadata: {
+ emailDomainId: emailDomain.id,
+ domain: emailDomain.domain
+ }
+ }
+ });
+
return { emailDomain };
}
});
@@ -64,6 +77,18 @@ export const registerEmailDomainRouter = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId
});
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.VERIFY_EMAIL_DOMAIN,
+ metadata: {
+ emailDomainId: result.emailDomain.id,
+ domain: result.emailDomain.domain
+ }
+ }
+ });
+
return result;
}
});
@@ -122,6 +147,18 @@ export const registerEmailDomainRouter = async (server: FastifyZodProvider) => {
orgId: req.permission.orgId
});
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ event: {
+ type: EventType.DELETE_EMAIL_DOMAIN,
+ metadata: {
+ emailDomainId: emailDomain.id,
+ domain: emailDomain.domain
+ }
+ }
+ });
+
return { emailDomain };
}
});
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 3fd4913399..af31cfef6c 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -731,7 +731,12 @@ export enum EventType {
// Secret Validation Rules
SECRET_VALIDATION_RULE_CREATE = "secret-validation-rule-create",
SECRET_VALIDATION_RULE_UPDATE = "secret-validation-rule-update",
- SECRET_VALIDATION_RULE_DELETE = "secret-validation-rule-delete"
+ SECRET_VALIDATION_RULE_DELETE = "secret-validation-rule-delete",
+
+ // Email Domains
+ CREATE_EMAIL_DOMAIN = "create-email-domain",
+ VERIFY_EMAIL_DOMAIN = "verify-email-domain",
+ DELETE_EMAIL_DOMAIN = "delete-email-domain"
}
// Maps each actor type to the JSONB key that holds the actor's primary ID in actorMetadata.
@@ -5764,6 +5769,30 @@ interface SecretValidationRuleDeleteEvent {
};
}
+interface CreateEmailDomainEvent {
+ type: EventType.CREATE_EMAIL_DOMAIN;
+ metadata: {
+ emailDomainId: string;
+ domain: string;
+ };
+}
+
+interface VerifyEmailDomainEvent {
+ type: EventType.VERIFY_EMAIL_DOMAIN;
+ metadata: {
+ emailDomainId: string;
+ domain: string;
+ };
+}
+
+interface DeleteEmailDomainEvent {
+ type: EventType.DELETE_EMAIL_DOMAIN;
+ metadata: {
+ emailDomainId: string;
+ domain: string;
+ };
+}
+
export type Event =
| CreateSubOrganizationEvent
| UpdateSubOrganizationEvent
@@ -6285,4 +6314,7 @@ export type Event =
| ScepRenewalEvent
| SecretValidationRuleCreateEvent
| SecretValidationRuleUpdateEvent
- | SecretValidationRuleDeleteEvent;
+ | SecretValidationRuleDeleteEvent
+ | CreateEmailDomainEvent
+ | VerifyEmailDomainEvent
+ | DeleteEmailDomainEvent;
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.ts
index 782d6e73d5..45f8bf0c41 100644
--- a/backend/src/services/auth/auth-login-service.ts
+++ b/backend/src/services/auth/auth-login-service.ts
@@ -989,6 +989,7 @@ export const authLoginServiceFactory = ({
{
username: sanitizedEmail,
email: sanitizedEmail,
+ // reverify email verification status on login
isGitHubVerified: authMethod !== AuthMethod.GITHUB && user?.isGitHubVerified,
isGoogleVerified: authMethod !== AuthMethod.GOOGLE && user?.isGoogleVerified,
isGitLabVerified: authMethod !== AuthMethod.GITLAB && user?.isGitLabVerified
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index 3951d41482..2d5a5edc34 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -14,7 +14,7 @@ import { TokenType } from "@app/services/auth-token/auth-token-types";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";
-import { ActorType, AuthMethod, AuthTokenType } from "../auth/auth-type";
+import { ActorType, AuthMethod, AuthModeSignUpTokenPayload, AuthTokenType } from "../auth/auth-type";
import { TGroupProjectDALFactory } from "../group-project/group-project-dal";
import { TMembershipUserDALFactory } from "../membership-user/membership-user-dal";
import { TUserAliasDALFactory } from "../user-alias/user-alias-dal";
@@ -61,20 +61,17 @@ export const userServiceFactory = ({
const sendEmailVerificationCode = async (token: string) => {
const config = getConfig();
- const { authType, aliasId, username, authTokenType } = crypto.jwt().verify(token, config.AUTH_SECRET) as {
- authType: string;
- aliasId?: string;
- username: string;
- authTokenType: AuthTokenType;
- };
+ const { aliasId, userId, authTokenType } = crypto
+ .jwt()
+ .verify(token, config.AUTH_SECRET) as AuthModeSignUpTokenPayload;
if (authTokenType !== AuthTokenType.SIGNUP_TOKEN) throw new BadRequestError({ name: "Invalid auth token type" });
- const user = await userDAL.findOne({ username });
+ const user = await userDAL.findById(userId);
if (!user) throw new BadRequestError({ message: "Invalid token" });
let { isEmailVerified } = user;
if (aliasId) {
- const userAlias = await userAliasDAL.findOne({ userId: user.id, aliasType: authType, id: aliasId });
+ const userAlias = await userAliasDAL.findOne({ userId: user.id, id: aliasId });
if (!userAlias) throw new NotFoundError({ name: `User alias with ID '${aliasId}' not found` });
isEmailVerified = userAlias.isEmailVerified;
}
diff --git a/frontend/src/pages/middlewares/authenticate.tsx b/frontend/src/pages/middlewares/authenticate.tsx
index 114789c33d..92c8c98f38 100644
--- a/frontend/src/pages/middlewares/authenticate.tsx
+++ b/frontend/src/pages/middlewares/authenticate.tsx
@@ -15,7 +15,6 @@ export const Route = createFileRoute("/_authenticate")({
throw redirect({ to: "/admin/signup" });
}
- console.log("trigger authenticate");
const data = await context.queryClient
.fetchQuery({
queryKey: authKeys.getAuthToken,
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/HerokuAppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/HerokuAppConnectionForm.tsx
index 92549bdb71..86253fb7d8 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/HerokuAppConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/HerokuAppConnectionForm.tsx
@@ -185,7 +185,6 @@ export const HerokuConnectionForm = ({ appConnection, onSubmit: formSubmit, proj
isDisabled={isUpdate}
value={value}
onValueChange={(val) => {
- console.log("val", val === HerokuConnectionMethod.OAuth);
onChange(val);
if (val === HerokuConnectionMethod.OAuth) {
setValue("credentials.code", "custom");