Skip to content

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

improvement(pam): add posthog events for PAM endpoints (#5871)

Saif Ur Rahman2841168842b8
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts
index 1b3e761c98..92bc6576f8 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts
@@ -4,9 +4,11 @@ import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { PamResource } from "@app/ee/services/pam-resource/pam-resource-enums";
import { TPamAccount } from "@app/ee/services/pam-resource/pam-resource-types";
import { writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import { ResourceMetadataNonEncryptionSchema } from "@app/services/resource-metadata/resource-metadata-schema";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
export const registerPamAccountEndpoints = <C extends TPamAccount>({
server,
@@ -81,6 +83,18 @@ export const registerPamAccountEndpoints = <C extends TPamAccount>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamAccountCreated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType,
+ projectId: account.projectId
+ }
+ })
+ .catch(() => {});
+
return { account };
}
});
@@ -172,6 +186,18 @@ export const registerPamAccountEndpoints = <C extends TPamAccount>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamAccountDeleted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType,
+ projectId: account.projectId
+ }
+ })
+ .catch(() => {});
+
return { account };
}
});
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
index 5641d281c0..0913c8fe36 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
@@ -20,9 +20,11 @@ import { logger } from "@app/lib/logger";
import { ms } from "@app/lib/ms";
import { OrderByDirection } from "@app/lib/types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { ActorType, AuthMode } from "@app/services/auth/auth-type";
import { TokenType } from "@app/services/auth-token/auth-token-types";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
const SanitizedAccountSchema = z
.discriminatedUnion("resourceType", [
@@ -177,6 +179,18 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
const account = await server.services.pamAccount.triggerManualRotation(req.params.accountId, req.permission);
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamAccountRotated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType: account.resourceType,
+ projectId: account.projectId
+ }
+ })
+ .catch(() => {});
+
return { account: account as z.infer<typeof SanitizedAccountSchema> };
}
});
@@ -442,6 +456,19 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamAccountAccessed,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType: response.resourceType,
+ projectId: req.body.projectId,
+ duration: req.body.duration
+ }
+ })
+ .catch(() => {});
+
return response;
}
});
@@ -484,6 +511,17 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
mfaSessionId: req.body.mfaSessionId
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamWebAccessStarted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ projectId: req.body.projectId
+ }
+ })
+ .catch(() => {});
+
return { ticket };
}
});
diff --git a/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts b/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts
index 44d022b7ca..50531c2521 100644
--- a/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts
+++ b/backend/src/ee/routes/v1/pam-discovery-routers/pam-discovery-endpoints.ts
@@ -8,8 +8,10 @@ import {
} from "@app/ee/services/pam-discovery/pam-discovery-schemas";
import { TPamDiscoverySource } from "@app/ee/services/pam-discovery/pam-discovery-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
export const registerPamDiscoveryEndpoints = <T extends TPamDiscoverySource>({
server,
@@ -127,6 +129,18 @@ export const registerPamDiscoveryEndpoints = <T extends TPamDiscoverySource>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamDiscoverySourceCreated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ discoveryType,
+ projectId: req.body.projectId
+ }
+ })
+ .catch(() => {});
+
return { source };
}
});
@@ -216,6 +230,18 @@ export const registerPamDiscoveryEndpoints = <T extends TPamDiscoverySource>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamDiscoverySourceDeleted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ discoveryType,
+ projectId: source.projectId
+ }
+ })
+ .catch(() => {});
+
return { source };
}
});
@@ -259,6 +285,18 @@ export const registerPamDiscoveryEndpoints = <T extends TPamDiscoverySource>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamDiscoveryScanTriggered,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ discoveryType,
+ projectId: discoverySource.projectId
+ }
+ })
+ .catch(() => {});
+
return { message };
}
});
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
index 202b3bf89b..a9d89327b9 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-endpoints.ts
@@ -5,9 +5,11 @@ import { PamResource } from "@app/ee/services/pam-resource/pam-resource-enums";
import { TPamResource } from "@app/ee/services/pam-resource/pam-resource-types";
import { SanitizedWindowsResourceSchema } from "@app/ee/services/pam-resource/windows-server/windows-server-resource-schemas";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import { ResourceMetadataNonEncryptionSchema } from "@app/services/resource-metadata/resource-metadata-schema";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
export const registerPamResourceEndpoints = <T extends TPamResource>({
server,
@@ -121,6 +123,18 @@ export const registerPamResourceEndpoints = <T extends TPamResource>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamResourceCreated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType,
+ projectId: req.body.projectId
+ }
+ })
+ .catch(() => {});
+
return { resource };
}
});
@@ -208,6 +222,18 @@ export const registerPamResourceEndpoints = <T extends TPamResource>({
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamResourceDeleted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType,
+ projectId: resource.projectId
+ }
+ })
+ .catch(() => {});
+
return { resource };
}
});
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
index 2dc95df103..6e2f1bf9f5 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
@@ -2,8 +2,10 @@ import { z } from "zod";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
const RotationRuleResponseSchema = z.object({
id: z.string().uuid(),
@@ -117,6 +119,20 @@ export const registerPamResourceRotationRulesRouter = async (server: FastifyZodP
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamRotationRuleCreated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType: resource.resourceType,
+ projectId: resource.projectId,
+ enabled: rule.enabled,
+ hasSchedule: Boolean(rule.intervalSeconds)
+ }
+ })
+ .catch(() => {});
+
return { rule };
}
});
@@ -224,6 +240,18 @@ export const registerPamResourceRotationRulesRouter = async (server: FastifyZodP
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamRotationRuleDeleted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType: resource.resourceType,
+ projectId: resource.projectId
+ }
+ })
+ .catch(() => {});
+
return { rule };
}
});
diff --git a/backend/src/ee/routes/v1/pam-session-router.ts b/backend/src/ee/routes/v1/pam-session-router.ts
index 814033ad4c..e93117a50a 100644
--- a/backend/src/ee/routes/v1/pam-session-router.ts
+++ b/backend/src/ee/routes/v1/pam-session-router.ts
@@ -14,8 +14,10 @@ import {
TerminalEventSchema
} from "@app/ee/services/pam-session/pam-session-schemas";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
const SessionCredentialsSchema = z.union([
SSHSessionCredentialsSchema,
@@ -75,6 +77,17 @@ export const registerPamSessionRouter = async (server: FastifyZodProvider) => {
}
}
});
+
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamSessionStarted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ projectId
+ }
+ })
+ .catch(() => {});
}
return { credentials: credentials as z.infer<typeof SessionCredentialsSchema> };
@@ -171,6 +184,18 @@ export const registerPamSessionRouter = async (server: FastifyZodProvider) => {
}
});
+ await server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.PamSessionEnded,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ resourceType: session.resourceType,
+ projectId
+ }
+ })
+ .catch(() => {});
+
return { session };
}
});
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index 88fa1a4359..9a72395185 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -88,7 +88,21 @@ export enum PostHogEventTypes {
SecretRotationV2Created = "Secret Rotation V2 Created",
SecretRotationV2Deleted = "Secret Rotation V2 Deleted",
SecretRotationV2Executed = "Secret Rotation V2 Executed",
- GatewayCertExchanged = "Gateway Cert Exchanged"
+ GatewayCertExchanged = "Gateway Cert Exchanged",
+ PamResourceCreated = "PAM Resource Created",
+ PamResourceDeleted = "PAM Resource Deleted",
+ PamAccountCreated = "PAM Account Created",
+ PamAccountDeleted = "PAM Account Deleted",
+ PamAccountAccessed = "PAM Account Accessed",
+ PamAccountRotated = "PAM Account Rotated",
+ PamSessionStarted = "PAM Session Started",
+ PamSessionEnded = "PAM Session Ended",
+ PamWebAccessStarted = "PAM Web Access Started",
+ PamDiscoverySourceCreated = "PAM Discovery Source Created",
+ PamDiscoverySourceDeleted = "PAM Discovery Source Deleted",
+ PamDiscoveryScanTriggered = "PAM Discovery Scan Triggered",
+ PamRotationRuleCreated = "PAM Rotation Rule Created",
+ PamRotationRuleDeleted = "PAM Rotation Rule Deleted"
}
export type TSecretModifiedEvent = {
@@ -712,6 +726,90 @@ export type TGatewayCertExchangedEvent = {
};
};
+export type TPamResourceEvent = {
+ event: PostHogEventTypes.PamResourceCreated | PostHogEventTypes.PamResourceDeleted;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ };
+};
+
+export type TPamAccountEvent = {
+ event: PostHogEventTypes.PamAccountCreated | PostHogEventTypes.PamAccountDeleted;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ };
+};
+
+export type TPamAccountAccessedEvent = {
+ event: PostHogEventTypes.PamAccountAccessed;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ duration: number;
+ };
+};
+
+export type TPamAccountRotatedEvent = {
+ event: PostHogEventTypes.PamAccountRotated;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ };
+};
+
+export type TPamSessionStartedEvent = {
+ event: PostHogEventTypes.PamSessionStarted;
+ properties: {
+ projectId: string;
+ };
+};
+
+export type TPamSessionEndedEvent = {
+ event: PostHogEventTypes.PamSessionEnded;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ };
+};
+
+export type TPamWebAccessStartedEvent = {
+ event: PostHogEventTypes.PamWebAccessStarted;
+ properties: {
+ projectId: string;
+ };
+};
+
+export type TPamDiscoveryEvent = {
+ event:
+ | PostHogEventTypes.PamDiscoverySourceCreated
+ | PostHogEventTypes.PamDiscoverySourceDeleted
+ | PostHogEventTypes.PamDiscoveryScanTriggered;
+ properties: {
+ discoveryType: string;
+ projectId: string;
+ };
+};
+
+export type TPamRotationRuleCreatedEvent = {
+ event: PostHogEventTypes.PamRotationRuleCreated;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ enabled: boolean;
+ hasSchedule: boolean;
+ };
+};
+
+export type TPamRotationRuleDeletedEvent = {
+ event: PostHogEventTypes.PamRotationRuleDeleted;
+ properties: {
+ resourceType: string;
+ projectId: string;
+ };
+};
+
export type TPostHogEvent = { distinctId: string; organizationId?: string; organizationName?: string } & (
| TSecretModifiedEvent
| TAdminInitEvent
@@ -771,4 +869,14 @@ export type TPostHogEvent = { distinctId: string; organizationId?: string; organ
| TSecretRotationV2DeletedEvent
| TSecretRotationV2ExecutedEvent
| TGatewayCertExchangedEvent
+ | TPamResourceEvent
+ | TPamAccountEvent
+ | TPamAccountAccessedEvent
+ | TPamAccountRotatedEvent
+ | TPamSessionStartedEvent
+ | TPamSessionEndedEvent
+ | TPamWebAccessStartedEvent
+ | TPamDiscoveryEvent
+ | TPamRotationRuleCreatedEvent
+ | TPamRotationRuleDeletedEvent
);