mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 22:27:22 +00:00
Merge pull request #3342 from Infisical/pki-telemetry
Add Telemetry for Infisical PKI
This commit is contained in:
@@ -6,6 +6,7 @@ import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
|||||||
import { CERTIFICATE_AUTHORITIES } from "@app/lib/api-docs";
|
import { CERTIFICATE_AUTHORITIES } from "@app/lib/api-docs";
|
||||||
import { ms } from "@app/lib/ms";
|
import { ms } from "@app/lib/ms";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
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 { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
import { CertExtendedKeyUsage, CertKeyAlgorithm, CertKeyUsage } from "@app/services/certificate/certificate-types";
|
import { CertExtendedKeyUsage, CertKeyAlgorithm, CertKeyUsage } from "@app/services/certificate/certificate-types";
|
||||||
@@ -14,6 +15,7 @@ import {
|
|||||||
validateAltNamesField,
|
validateAltNamesField,
|
||||||
validateCaDateField
|
validateCaDateField
|
||||||
} from "@app/services/certificate-authority/certificate-authority-validators";
|
} from "@app/services/certificate-authority/certificate-authority-validators";
|
||||||
|
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
|
||||||
|
|
||||||
export const registerCaRouter = async (server: FastifyZodProvider) => {
|
export const registerCaRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
@@ -649,6 +651,16 @@ export const registerCaRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await server.services.telemetry.sendPostHogEvents({
|
||||||
|
event: PostHogEventTypes.IssueCert,
|
||||||
|
distinctId: getTelemetryDistinctId(req),
|
||||||
|
properties: {
|
||||||
|
caId: ca.id,
|
||||||
|
commonName: req.body.commonName,
|
||||||
|
...req.auditLogInfo
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
certificate,
|
certificate,
|
||||||
certificateChain,
|
certificateChain,
|
||||||
@@ -707,7 +719,7 @@ export const registerCaRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { certificate, certificateChain, issuingCaCertificate, serialNumber, ca } =
|
const { certificate, certificateChain, issuingCaCertificate, serialNumber, ca, commonName } =
|
||||||
await server.services.certificateAuthority.signCertFromCa({
|
await server.services.certificateAuthority.signCertFromCa({
|
||||||
isInternal: false,
|
isInternal: false,
|
||||||
caId: req.params.caId,
|
caId: req.params.caId,
|
||||||
@@ -731,6 +743,16 @@ export const registerCaRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await server.services.telemetry.sendPostHogEvents({
|
||||||
|
event: PostHogEventTypes.SignCert,
|
||||||
|
distinctId: getTelemetryDistinctId(req),
|
||||||
|
properties: {
|
||||||
|
caId: ca.id,
|
||||||
|
commonName,
|
||||||
|
...req.auditLogInfo
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
certificate: certificate.toString("pem"),
|
certificate: certificate.toString("pem"),
|
||||||
certificateChain,
|
certificateChain,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
|||||||
import { CERTIFICATE_AUTHORITIES, CERTIFICATES } from "@app/lib/api-docs";
|
import { CERTIFICATE_AUTHORITIES, CERTIFICATES } from "@app/lib/api-docs";
|
||||||
import { ms } from "@app/lib/ms";
|
import { ms } from "@app/lib/ms";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
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 { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
import { CertExtendedKeyUsage, CertKeyUsage, CrlReason } from "@app/services/certificate/certificate-types";
|
import { CertExtendedKeyUsage, CertKeyUsage, CrlReason } from "@app/services/certificate/certificate-types";
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
validateAltNamesField,
|
validateAltNamesField,
|
||||||
validateCaDateField
|
validateCaDateField
|
||||||
} from "@app/services/certificate-authority/certificate-authority-validators";
|
} from "@app/services/certificate-authority/certificate-authority-validators";
|
||||||
|
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
|
||||||
|
|
||||||
export const registerCertRouter = async (server: FastifyZodProvider) => {
|
export const registerCertRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
@@ -150,6 +152,17 @@ export const registerCertRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await server.services.telemetry.sendPostHogEvents({
|
||||||
|
event: PostHogEventTypes.IssueCert,
|
||||||
|
distinctId: getTelemetryDistinctId(req),
|
||||||
|
properties: {
|
||||||
|
caId: req.body.caId,
|
||||||
|
certificateTemplateId: req.body.certificateTemplateId,
|
||||||
|
commonName: req.body.commonName,
|
||||||
|
...req.auditLogInfo
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
certificate,
|
certificate,
|
||||||
certificateChain,
|
certificateChain,
|
||||||
@@ -228,7 +241,7 @@ export const registerCertRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { certificate, certificateChain, issuingCaCertificate, serialNumber, ca } =
|
const { certificate, certificateChain, issuingCaCertificate, serialNumber, ca, commonName } =
|
||||||
await server.services.certificateAuthority.signCertFromCa({
|
await server.services.certificateAuthority.signCertFromCa({
|
||||||
isInternal: false,
|
isInternal: false,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
@@ -251,6 +264,17 @@ export const registerCertRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await server.services.telemetry.sendPostHogEvents({
|
||||||
|
event: PostHogEventTypes.SignCert,
|
||||||
|
distinctId: getTelemetryDistinctId(req),
|
||||||
|
properties: {
|
||||||
|
caId: req.body.caId,
|
||||||
|
certificateTemplateId: req.body.certificateTemplateId,
|
||||||
|
commonName,
|
||||||
|
...req.auditLogInfo
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
certificate: certificate.toString("pem"),
|
certificate: certificate.toString("pem"),
|
||||||
certificateChain,
|
certificateChain,
|
||||||
|
|||||||
@@ -1818,7 +1818,8 @@ export const certificateAuthorityServiceFactory = ({
|
|||||||
certificateChain: `${issuingCaCertificate}\n${caCertChain}`.trim(),
|
certificateChain: `${issuingCaCertificate}\n${caCertChain}`.trim(),
|
||||||
issuingCaCertificate,
|
issuingCaCertificate,
|
||||||
serialNumber,
|
serialNumber,
|
||||||
ca
|
ca,
|
||||||
|
commonName: cn
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ export enum PostHogEventTypes {
|
|||||||
SecretRequestCreated = "Secret Request Created",
|
SecretRequestCreated = "Secret Request Created",
|
||||||
SecretRequestDeleted = "Secret Request Deleted",
|
SecretRequestDeleted = "Secret Request Deleted",
|
||||||
SignSshKey = "Sign SSH Key",
|
SignSshKey = "Sign SSH Key",
|
||||||
IssueSshCreds = "Issue SSH Credentials"
|
IssueSshCreds = "Issue SSH Credentials",
|
||||||
|
SignCert = "Sign PKI Certificate",
|
||||||
|
IssueCert = "Issue PKI Certificate"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TSecretModifiedEvent = {
|
export type TSecretModifiedEvent = {
|
||||||
@@ -159,6 +161,26 @@ export type TIssueSshCredsEvent = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TSignCertificateEvent = {
|
||||||
|
event: PostHogEventTypes.SignCert;
|
||||||
|
properties: {
|
||||||
|
caId?: string;
|
||||||
|
certificateTemplateId?: string;
|
||||||
|
commonName: string;
|
||||||
|
userAgent?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TIssueCertificateEvent = {
|
||||||
|
event: PostHogEventTypes.IssueCert;
|
||||||
|
properties: {
|
||||||
|
caId?: string;
|
||||||
|
certificateTemplateId?: string;
|
||||||
|
commonName: string;
|
||||||
|
userAgent?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export type TPostHogEvent = { distinctId: string } & (
|
export type TPostHogEvent = { distinctId: string } & (
|
||||||
| TSecretModifiedEvent
|
| TSecretModifiedEvent
|
||||||
| TAdminInitEvent
|
| TAdminInitEvent
|
||||||
@@ -173,4 +195,6 @@ export type TPostHogEvent = { distinctId: string } & (
|
|||||||
| TSecretRequestDeletedEvent
|
| TSecretRequestDeletedEvent
|
||||||
| TSignSshKeyEvent
|
| TSignSshKeyEvent
|
||||||
| TIssueSshCredsEvent
|
| TIssueSshCredsEvent
|
||||||
|
| TSignCertificateEvent
|
||||||
|
| TIssueCertificateEvent
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user