Skip to content

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

feat(server): audit log streams db schema changes

Akhil Mohan69aa20e35c56
diff --git a/backend/src/@types/fastify.d.ts b/backend/src/@types/fastify.d.ts
index a4c3eea7bc..b3e9d99521 100644
--- a/backend/src/@types/fastify.d.ts
+++ b/backend/src/@types/fastify.d.ts
@@ -3,6 +3,7 @@ import "fastify";
import { TUsers } from "@app/db/schemas";
import { TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
+import { TAuditLogStreamServiceFactory } from "@app/ee/services/audit-log-stream/audit-log-stream-service";
import { TDynamicSecretServiceFactory } from "@app/ee/services/dynamic-secret/dynamic-secret-service";
import { TDynamicSecretLeaseServiceFactory } from "@app/ee/services/dynamic-secret-lease/dynamic-secret-lease-service";
import { TGroupServiceFactory } from "@app/ee/services/group/group-service";
@@ -120,6 +121,7 @@ declare module "fastify" {
scim: TScimServiceFactory;
ldap: TLdapConfigServiceFactory;
auditLog: TAuditLogServiceFactory;
+ auditLogStream: TAuditLogStreamServiceFactory;
secretScanning: TSecretScanningServiceFactory;
license: TLicenseServiceFactory;
trustedIp: TTrustedIpServiceFactory;
diff --git a/backend/src/@types/knex.d.ts b/backend/src/@types/knex.d.ts
index 8845c1d016..a7d76e9449 100644
--- a/backend/src/@types/knex.d.ts
+++ b/backend/src/@types/knex.d.ts
@@ -7,6 +7,9 @@ import {
TApiKeysUpdate,
TAuditLogs,
TAuditLogsInsert,
+ TAuditLogStreams,
+ TAuditLogStreamsInsert,
+ TAuditLogStreamsUpdate,
TAuditLogsUpdate,
TAuthTokens,
TAuthTokenSessions,
@@ -404,6 +407,11 @@ declare module "knex/types/tables" {
[TableName.LdapGroupMap]: Knex.CompositeTableType<TLdapGroupMaps, TLdapGroupMapsInsert, TLdapGroupMapsUpdate>;
[TableName.OrgBot]: Knex.CompositeTableType<TOrgBots, TOrgBotsInsert, TOrgBotsUpdate>;
[TableName.AuditLog]: Knex.CompositeTableType<TAuditLogs, TAuditLogsInsert, TAuditLogsUpdate>;
+ [TableName.AuditLogStream]: Knex.CompositeTableType<
+ TAuditLogStreams,
+ TAuditLogStreamsInsert,
+ TAuditLogStreamsUpdate
+ >;
[TableName.GitAppInstallSession]: Knex.CompositeTableType<
TGitAppInstallSessions,
TGitAppInstallSessionsInsert,
diff --git a/backend/src/db/migrations/20240423070528_audit-log-stream.ts b/backend/src/db/migrations/20240423070528_audit-log-stream.ts
new file mode 100644
index 0000000000..0fac59be89
--- /dev/null
+++ b/backend/src/db/migrations/20240423070528_audit-log-stream.ts
@@ -0,0 +1,28 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
+
+export async function up(knex: Knex): Promise<void> {
+ if (!(await knex.schema.hasTable(TableName.AuditLogStream))) {
+ await knex.schema.createTable(TableName.AuditLogStream, (t) => {
+ t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
+ t.string("url").notNullable();
+ t.text("encryptedTokenCiphertext");
+ t.text("encryptedTokenIV");
+ t.text("encryptedTokenTag");
+ t.string("encryptedTokenAlgorithm");
+ t.string("encryptedTokenKeyEncoding");
+ t.string("projectId").notNullable();
+ t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
+ t.timestamps(true, true, true);
+ });
+ }
+
+ await createOnUpdateTrigger(knex, TableName.AuditLogStream);
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await dropOnUpdateTrigger(knex, TableName.AuditLogStream);
+ await knex.schema.dropTableIfExists(TableName.AuditLogStream);
+}
diff --git a/backend/src/db/schemas/audit-log-streams.ts b/backend/src/db/schemas/audit-log-streams.ts
new file mode 100644
index 0000000000..154c865dec
--- /dev/null
+++ b/backend/src/db/schemas/audit-log-streams.ts
@@ -0,0 +1,25 @@
+// Code generated by automation script, DO NOT EDIT.
+// Automated by pulling database and generating zod schema
+// To update. Just run npm run generate:schema
+// Written by akhilmhdh.
+
+import { z } from "zod";
+
+import { TImmutableDBKeys } from "./models";
+
+export const AuditLogStreamsSchema = z.object({
+ id: z.string().uuid(),
+ url: z.string(),
+ encryptedTokenCiphertext: z.string().nullable().optional(),
+ encryptedTokenIV: z.string().nullable().optional(),
+ encryptedTokenTag: z.string().nullable().optional(),
+ encryptedTokenAlgorithm: z.string().nullable().optional(),
+ encryptedTokenKeyEncoding: z.string().nullable().optional(),
+ projectId: z.string(),
+ createdAt: z.date(),
+ updatedAt: z.date()
+});
+
+export type TAuditLogStreams = z.infer<typeof AuditLogStreamsSchema>;
+export type TAuditLogStreamsInsert = Omit<z.input<typeof AuditLogStreamsSchema>, TImmutableDBKeys>;
+export type TAuditLogStreamsUpdate = Partial<Omit<z.input<typeof AuditLogStreamsSchema>, TImmutableDBKeys>>;
diff --git a/backend/src/db/schemas/index.ts b/backend/src/db/schemas/index.ts
index 30d6208b8d..0eb9b19868 100644
--- a/backend/src/db/schemas/index.ts
+++ b/backend/src/db/schemas/index.ts
@@ -1,4 +1,5 @@
export * from "./api-keys";
+export * from "./audit-log-streams";
export * from "./audit-logs";
export * from "./auth-token-sessions";
export * from "./auth-tokens";
diff --git a/backend/src/db/schemas/models.ts b/backend/src/db/schemas/models.ts
index ea70dccdb1..3baa7f40d2 100644
--- a/backend/src/db/schemas/models.ts
+++ b/backend/src/db/schemas/models.ts
@@ -62,6 +62,7 @@ export enum TableName {
LdapConfig = "ldap_configs",
LdapGroupMap = "ldap_group_maps",
AuditLog = "audit_logs",
+ AuditLogStream = "audit_log_streams",
GitAppInstallSession = "git_app_install_sessions",
GitAppOrg = "git_app_org",
SecretScanningGitRisk = "secret_scanning_git_risks",