Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add migration to create honey tokens in DB
Matheus Nogueiraeb08843bf4a6
diff --git a/backend/src/db/migrations/20260427174746_honey-tokens.ts b/backend/src/db/migrations/20260427174746_honey-tokens.tsnew file mode 100644index 0000000000..d97ed7ffde--- /dev/null+++ b/backend/src/db/migrations/20260427174746_honey-tokens.ts@@ -0,0 +1,47 @@+import { Knex } from "knex";++import { TableName } from "@app/db/schemas";+import { createOnUpdateTrigger, dropOnUpdateTrigger } from "@app/db/utils";++export async function up(knex: Knex): Promise<void> {+ if (!(await knex.schema.hasTable(TableName.HoneyToken))) {+ await knex.schema.createTable(TableName.HoneyToken, (t) => {+ t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());+ t.string("name", 64).notNullable();+ t.string("type").notNullable();+ t.string("status").notNullable().defaultTo("active");+ t.string("projectId").notNullable();+ t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");+ t.uuid("connectionId").notNullable();+ t.foreign("connectionId").references("id").inTable(TableName.AppConnection);+ t.binary("encryptedCredentials").notNullable();+ t.jsonb("secretsMapping").notNullable();+ t.timestamps(true, true, true);+ });++ await createOnUpdateTrigger(knex, TableName.HoneyToken);+ }++ if (!(await knex.schema.hasTable(TableName.HoneyTokenEvent))) {+ await knex.schema.createTable(TableName.HoneyTokenEvent, (t) => {+ t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());+ t.uuid("honeyTokenId").notNullable();+ t.foreign("honeyTokenId").references("id").inTable(TableName.HoneyToken).onDelete("CASCADE");+ t.string("eventType").notNullable();+ t.jsonb("metadata");+ t.timestamps(true, true, true);+ });++ await createOnUpdateTrigger(knex, TableName.HoneyTokenEvent);+ await knex.schema.alterTable(TableName.HoneyTokenEvent, (t) => {+ t.index(["honeyTokenId", "createdAt"]);+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ await knex.schema.dropTableIfExists(TableName.HoneyTokenEvent);+ await dropOnUpdateTrigger(knex, TableName.HoneyTokenEvent);+ await knex.schema.dropTableIfExists(TableName.HoneyToken);+ await dropOnUpdateTrigger(knex, TableName.HoneyToken);+}diff --git a/backend/src/db/schemas/honey-token-events.ts b/backend/src/db/schemas/honey-token-events.tsnew file mode 100644index 0000000000..b3c9a2f6bd--- /dev/null+++ b/backend/src/db/schemas/honey-token-events.ts@@ -0,0 +1,21 @@+// 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 HoneyTokenEventsSchema = z.object({+ id: z.string().uuid(),+ honeyTokenId: z.string().uuid(),+ eventType: z.string(),+ metadata: z.unknown().nullable().optional(),+ createdAt: z.date(),+ updatedAt: z.date()+});++export type THoneyTokenEvents = z.infer<typeof HoneyTokenEventsSchema>;+export type THoneyTokenEventsInsert = Omit<z.input<typeof HoneyTokenEventsSchema>, TImmutableDBKeys>;+export type THoneyTokenEventsUpdate = Partial<Omit<z.input<typeof HoneyTokenEventsSchema>, TImmutableDBKeys>>;diff --git a/backend/src/db/schemas/honey-tokens.ts b/backend/src/db/schemas/honey-tokens.tsnew file mode 100644index 0000000000..c8448a12c1--- /dev/null+++ b/backend/src/db/schemas/honey-tokens.ts@@ -0,0 +1,27 @@+// 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 { zodBuffer } from "@app/lib/zod";++import { TImmutableDBKeys } from "./models";++export const HoneyTokensSchema = z.object({+ id: z.string().uuid(),+ name: z.string(),+ type: z.string(),+ status: z.string().default("active"),+ projectId: z.string(),+ connectionId: z.string().uuid(),+ encryptedCredentials: zodBuffer,+ secretsMapping: z.unknown(),+ createdAt: z.date(),+ updatedAt: z.date()+});++export type THoneyTokens = z.infer<typeof HoneyTokensSchema>;+export type THoneyTokensInsert = Omit<z.input<typeof HoneyTokensSchema>, TImmutableDBKeys>;+export type THoneyTokensUpdate = Partial<Omit<z.input<typeof HoneyTokensSchema>, TImmutableDBKeys>>;diff --git a/backend/src/db/schemas/index.ts b/backend/src/db/schemas/index.tsindex 8ac69fffb7..885a20fde9 100644--- a/backend/src/db/schemas/index.ts+++ b/backend/src/db/schemas/index.ts@@ -64,6 +64,8 @@ export * from "./github-org-sync-configs";export * from "./group-project-membership-roles";export * from "./group-project-memberships";export * from "./groups";+export * from "./honey-token-events";+export * from "./honey-tokens";export * from "./identities";export * from "./identity-access-tokens";export * from "./identity-alicloud-auths";diff --git a/backend/src/db/schemas/models.ts b/backend/src/db/schemas/models.tsindex 5eec2ab6be..935d144086 100644--- a/backend/src/db/schemas/models.ts+++ b/backend/src/db/schemas/models.ts@@ -289,6 +289,10 @@ export enum TableName {CaSigningConfig = "ca_signing_configs",SecretValidationRule = "secret_validation_rules",+ // Honey Tokens+ HoneyToken = "honey_tokens",+ HoneyTokenEvent = "honey_token_events",+// Deprecated - Not used anymore now that Redis is persistentDeprecatedDurableQueueJobs = "queue_jobs",DeprecatedSecretRotationV1 = "secret_rotations",diff --git a/backend/src/ee/services/honey-token/honey-token-enums.ts b/backend/src/ee/services/honey-token/honey-token-enums.tsnew file mode 100644index 0000000000..67c89cd058--- /dev/null+++ b/backend/src/ee/services/honey-token/honey-token-enums.ts@@ -0,0 +1,12 @@+export enum HoneyTokenType {+ AWS = "aws"+}++export enum HoneyTokenStatus {+ Active = "active",+ Triggered = "triggered"+}++export enum HoneyTokenEventType {+ AWS = "aws"+}diff --git a/backend/src/ee/services/honey-token/honey-token-types.ts b/backend/src/ee/services/honey-token/honey-token-types.tsnew file mode 100644index 0000000000..655132ccf0--- /dev/null+++ b/backend/src/ee/services/honey-token/honey-token-types.ts@@ -0,0 +1,30 @@+import { z } from "zod";++import { HoneyTokenEventType } from "./honey-token-enums";++export const AwsHoneyTokenEventMetadataSchema = z.object({+ username: z.string(),+ eventName: z.string(),+ eventSource: z.string(),+ sourceIp: z.string().optional(),+ userAgent: z.string().optional(),+ awsRegion: z.string(),+ eventTime: z.string(),+ accountId: z.string(),+ accessKeyId: z.string(),+ errorCode: z.string().optional(),+ errorMessage: z.string().optional(),+ eventId: z.string(),+ requestParameters: z.unknown().nullable()+});++export type TAwsHoneyTokenEventMetadata = z.infer<typeof AwsHoneyTokenEventMetadataSchema>;++export const HoneyTokenEventMetadataSchema = z.discriminatedUnion("eventType", [+ z.object({+ eventType: z.literal(HoneyTokenEventType.AWS),+ metadata: AwsHoneyTokenEventMetadataSchema+ })+]);++export type THoneyTokenEventMetadata = z.infer<typeof HoneyTokenEventMetadataSchema>;