Skip to content

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

trigger token using events from webhook

Matheus Nogueiraefff6a0071a3
diff --git a/backend/src/db/migrations/20260427174746_honey-tokens.ts b/backend/src/db/migrations/20260427174746_honey-tokens.ts
index f6c9a27dfe..536e961acc 100644
--- a/backend/src/db/migrations/20260427174746_honey-tokens.ts
+++ b/backend/src/db/migrations/20260427174746_honey-tokens.ts
@@ -26,6 +26,7 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable(TableName.HoneyToken, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
t.string("name", 64).notNullable();
+ t.string("description", 256).nullable();
t.string("type").notNullable();
t.string("status").notNullable().defaultTo("active");
t.string("projectId").notNullable();
@@ -36,6 +37,8 @@ export async function up(knex: Knex): Promise<void> {
t.foreign("connectionId").references("id").inTable(TableName.AppConnection);
t.binary("encryptedCredentials").notNullable();
t.jsonb("secretsMapping").notNullable();
+ t.string("tokenIdentifier", 256).nullable();
+ t.unique(["tokenIdentifier"]);
t.timestamps(true, true, true);
});
diff --git a/backend/src/db/migrations/20260428120000_honey-token-description.ts b/backend/src/db/migrations/20260428120000_honey-token-description.ts
deleted file mode 100644
index a1b9252e2a..0000000000
--- a/backend/src/db/migrations/20260428120000_honey-token-description.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { Knex } from "knex";
-
-import { TableName } from "@app/db/schemas";
-
-export async function up(knex: Knex): Promise<void> {
- if (await knex.schema.hasTable(TableName.HoneyToken)) {
- const hasDescription = await knex.schema.hasColumn(TableName.HoneyToken, "description");
- if (!hasDescription) {
- await knex.schema.alterTable(TableName.HoneyToken, (t) => {
- t.string("description", 256).nullable();
- });
- }
- }
-}
-
-export async function down(knex: Knex): Promise<void> {
- if (await knex.schema.hasTable(TableName.HoneyToken)) {
- const hasDescription = await knex.schema.hasColumn(TableName.HoneyToken, "description");
- if (hasDescription) {
- await knex.schema.alterTable(TableName.HoneyToken, (t) => {
- t.dropColumn("description");
- });
- }
- }
-}
diff --git a/backend/src/db/schemas/honey-tokens.ts b/backend/src/db/schemas/honey-tokens.ts
index f5c32b08b9..c90e32d9ce 100644
--- a/backend/src/db/schemas/honey-tokens.ts
+++ b/backend/src/db/schemas/honey-tokens.ts
@@ -20,6 +20,7 @@ export const HoneyTokensSchema = z.object({
connectionId: z.string().uuid(),
encryptedCredentials: zodBuffer,
secretsMapping: z.unknown(),
+ tokenIdentifier: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date()
});
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.ts
index aa227b0e07..12e43bd79a 100644
--- a/backend/src/ee/routes/v1/honey-token-router.ts
+++ b/backend/src/ee/routes/v1/honey-token-router.ts
@@ -1,6 +1,7 @@
import { z } from "zod";
import { HoneyTokenConfigsSchema } from "@app/db/schemas";
+import { logger } from "@app/lib/logger";
import { HoneyTokenType } from "@app/ee/services/honey-token/honey-token-enums";
import { AwsHoneyTokenConfigSchema } from "@app/ee/services/honey-token/honey-token-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
@@ -220,6 +221,11 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {
}
},
handler: async (req) => {
+ logger.info(
+ { orgId: req.params.orgId, payload: req.body, headers: req.headers },
+ `Honey token trigger received [orgId=${req.params.orgId}]`
+ );
+
const { acknowledged } = await server.services.honeyToken.handleTrigger({
orgId: req.params.orgId,
signature: req.headers["x-infisical-signature"] as string | undefined,
diff --git a/backend/src/ee/services/honey-token/honey-token-config-service.ts b/backend/src/ee/services/honey-token/honey-token-config-service.ts
index 9eec694e22..a297be08ac 100644
--- a/backend/src/ee/services/honey-token/honey-token-config-service.ts
+++ b/backend/src/ee/services/honey-token/honey-token-config-service.ts
@@ -13,11 +13,15 @@ import { TLicenseServiceFactory } from "../license/license-service";
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
import { TPermissionServiceFactory } from "../permission/permission-service-types";
import { THoneyTokenConfigDALFactory } from "./honey-token-config-dal";
-import { HoneyTokenType } from "./honey-token-enums";
-import { AwsHoneyTokenConfigSchema } from "./honey-token-types";
+import { THoneyTokenDALFactory } from "./honey-token-dal";
+import { HoneyTokenEventType, HoneyTokenStatus, HoneyTokenType } from "./honey-token-enums";
+import { THoneyTokenEventDALFactory } from "./honey-token-event-dal";
+import { AwsHoneyTokenConfigSchema, AwsHoneyTokenEventMetadataSchema } from "./honey-token-types";
type THoneyTokenConfigServiceFactoryDep = {
honeyTokenConfigDAL: THoneyTokenConfigDALFactory;
+ honeyTokenDAL: Pick<THoneyTokenDALFactory, "findOne" | "updateById">;
+ honeyTokenEventDAL: Pick<THoneyTokenEventDALFactory, "create">;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
@@ -27,6 +31,8 @@ export type THoneyTokenConfigServiceFactory = ReturnType<typeof honeyTokenConfig
export const honeyTokenConfigServiceFactory = ({
honeyTokenConfigDAL,
+ honeyTokenDAL,
+ honeyTokenEventDAL,
permissionService,
kmsService,
licenseService
@@ -207,6 +213,41 @@ export const honeyTokenConfigServiceFactory = ({
logger.info({ orgId, payload }, `Honey token trigger received [orgId=${orgId}]`);
+ const rawEvents = Array.isArray(payload) ? (payload as unknown[]) : [payload];
+
+ for (const rawEvent of rawEvents) {
+ const wrapped = rawEvent as { type?: string; event?: unknown };
+ const eventData = wrapped.event ?? rawEvent;
+
+ const parsed = AwsHoneyTokenEventMetadataSchema.safeParse(eventData);
+ if (!parsed.success) {
+ logger.warn({ orgId, event: rawEvent, error: parsed.error }, `Failed to parse honey token event [orgId=${orgId}]`);
+ continue;
+ }
+
+ const honeyToken = await honeyTokenDAL.findOne({ tokenIdentifier: parsed.data.accessKeyId });
+ if (!honeyToken) {
+ logger.warn(
+ { orgId, accessKeyId: parsed.data.accessKeyId },
+ `No honey token found for accessKeyId [orgId=${orgId}] [accessKeyId=${parsed.data.accessKeyId}]`
+ );
+ continue;
+ }
+
+ await honeyTokenEventDAL.create({
+ honeyTokenId: honeyToken.id,
+ eventType: HoneyTokenEventType.AWS,
+ metadata: parsed.data
+ });
+
+ await honeyTokenDAL.updateById(honeyToken.id, { status: HoneyTokenStatus.Triggered });
+
+ logger.info(
+ { orgId, honeyTokenId: honeyToken.id, eventName: parsed.data.eventName },
+ `Honey token triggered [orgId=${orgId}] [honeyTokenId=${honeyToken.id}]`
+ );
+ }
+
return { acknowledged: true };
};
diff --git a/backend/src/ee/services/honey-token/honey-token-event-dal.ts b/backend/src/ee/services/honey-token/honey-token-event-dal.ts
new file mode 100644
index 0000000000..b91ba3a26f
--- /dev/null
+++ b/backend/src/ee/services/honey-token/honey-token-event-dal.ts
@@ -0,0 +1,10 @@
+import { TDbClient } from "@app/db";
+import { TableName } from "@app/db/schemas";
+import { ormify } from "@app/lib/knex";
+
+export type THoneyTokenEventDALFactory = ReturnType<typeof honeyTokenEventDALFactory>;
+
+export const honeyTokenEventDALFactory = (db: TDbClient) => {
+ const orm = ormify(db, TableName.HoneyTokenEvent);
+ return orm;
+};
diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.ts
index cd81aacc7e..9c9b887853 100644
--- a/backend/src/ee/services/honey-token/honey-token-service.ts
+++ b/backend/src/ee/services/honey-token/honey-token-service.ts
@@ -208,7 +208,8 @@ export const honeyTokenServiceFactory = ({
folderId: folder.id,
connectionId: orgConfig.connectionId,
encryptedCredentials,
- secretsMapping
+ secretsMapping,
+ tokenIdentifier: AccessKey.AccessKeyId
});
const { encryptor: secretEncryptor } = await kmsService.createCipherPairWithDataKey({
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 2a42e619cf..716694b3fc 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -75,6 +75,7 @@ import { userGroupMembershipDALFactory } from "@app/ee/services/group/user-group
import { honeyTokenConfigDALFactory } from "@app/ee/services/honey-token/honey-token-config-dal";
import { honeyTokenConfigServiceFactory } from "@app/ee/services/honey-token/honey-token-config-service";
import { honeyTokenDALFactory } from "@app/ee/services/honey-token/honey-token-dal";
+import { honeyTokenEventDALFactory } from "@app/ee/services/honey-token/honey-token-event-dal";
import { honeyTokenServiceFactory } from "@app/ee/services/honey-token/honey-token-service";
import { isHsmActiveAndEnabled } from "@app/ee/services/hsm/hsm-fns";
import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
@@ -666,6 +667,7 @@ export const registerRoutes = async (
const githubOrgSyncDAL = githubOrgSyncDALFactory(db);
const honeyTokenConfigDAL = honeyTokenConfigDALFactory(db);
const honeyTokenDAL = honeyTokenDALFactory(db);
+ const honeyTokenEventDAL = honeyTokenEventDALFactory(db);
const secretRotationV2DAL = secretRotationV2DALFactory(db, folderDAL);
const microsoftTeamsIntegrationDAL = microsoftTeamsIntegrationDALFactory(db);
@@ -958,6 +960,8 @@ export const registerRoutes = async (
const honeyTokenConfigService = honeyTokenConfigServiceFactory({
honeyTokenConfigDAL,
+ honeyTokenDAL,
+ honeyTokenEventDAL,
permissionService,
kmsService,
licenseService