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
fix(telemetry): added back email for telemetry when using service token
Akhil Mohanbe49de5f345c
diff --git a/backend/src/ee/routes/v1/scim-router.ts b/backend/src/ee/routes/v1/scim-router.tsindex 095815212a..80eed5231e 100644--- a/backend/src/ee/routes/v1/scim-router.ts+++ b/backend/src/ee/routes/v1/scim-router.ts@@ -5,7 +5,7 @@ import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";export const registerScimRouter = async (server: FastifyZodProvider) => {- server.addContentTypeParser("application/scim+json", { parseAs: "string" }, function (req, body, done) {+ server.addContentTypeParser("application/scim+json", { parseAs: "string" }, (_, body, done) => {try {const strBody = body instanceof Buffer ? body.toString() : body;diff --git a/backend/src/ee/services/permission/permission-service.ts b/backend/src/ee/services/permission/permission-service.tsindex 4735312e40..67db2473cf 100644--- a/backend/src/ee/services/permission/permission-service.ts+++ b/backend/src/ee/services/permission/permission-service.ts@@ -177,6 +177,8 @@ export const permissionServiceFactory = ({const getServiceTokenProjectPermission = async (serviceTokenId: string, projectId: string) => {const serviceToken = await serviceTokenDAL.findById(serviceTokenId);+ if (!serviceToken) throw new BadRequestError({ message: "Service token not found" });+if (serviceToken.projectId !== projectId)throw new UnauthorizedError({message: "Failed to find service authorization for given project"diff --git a/backend/src/server/plugins/auth/inject-identity.ts b/backend/src/server/plugins/auth/inject-identity.tsindex cf8d9dea33..3a0a0ab39f 100644--- a/backend/src/server/plugins/auth/inject-identity.ts+++ b/backend/src/server/plugins/auth/inject-identity.ts@@ -27,7 +27,7 @@ export type TAuthMode =}| {authMode: AuthMode.SERVICE_TOKEN;- serviceToken: TServiceTokens;+ serviceToken: TServiceTokens & { createdByEmail: string };actor: ActorType.SERVICE;serviceTokenId: string;}diff --git a/backend/src/server/routes/v3/secret-router.ts b/backend/src/server/routes/v3/secret-router.tsindex 1aac862050..1ba5b4e082 100644--- a/backend/src/server/routes/v3/secret-router.ts+++ b/backend/src/server/routes/v3/secret-router.ts@@ -28,7 +28,7 @@ const getDistinctId = (req: FastifyRequest) => {return `identity-${req.auth.identityId}`;}if (req.auth.actor === ActorType.SERVICE) {- return `service-token-${req.auth.serviceToken.id}`;+ return req.auth.serviceToken.createdByEmail || `service-token-${req.auth.serviceTokenId}`; // when user gets removed from system}return "unknown-auth-data";};diff --git a/backend/src/services/service-token/service-token-dal.ts b/backend/src/services/service-token/service-token-dal.tsindex b94c7ee352..5d3fcc5c80 100644--- a/backend/src/services/service-token/service-token-dal.ts+++ b/backend/src/services/service-token/service-token-dal.ts@@ -1,10 +1,32 @@+import { Knex } from "knex";+import { TDbClient } from "@app/db";-import { TableName } from "@app/db/schemas";-import { ormify } from "@app/lib/knex";+import { TableName, TUsers } from "@app/db/schemas";+import { DatabaseError } from "@app/lib/errors";+import { ormify, selectAllTableCols } from "@app/lib/knex";export type TServiceTokenDALFactory = ReturnType<typeof serviceTokenDALFactory>;export const serviceTokenDALFactory = (db: TDbClient) => {const stOrm = ormify(db, TableName.ServiceToken);- return stOrm;++ const findById = async (id: string, tx?: Knex) => {+ try {+ const doc = await (tx || db)(TableName.ServiceToken)+ .leftJoin<TUsers>(+ TableName.Users,+ `${TableName.Users}.id`,+ db.raw(`${TableName.ServiceToken}."createdBy"::uuid`)+ )+ .where(`${TableName.ServiceToken}.id`, id)+ .select(selectAllTableCols(TableName.ServiceToken))+ .select(db.ref("email").withSchema(TableName.Users).as("createdByEmail"))+ .first();+ return doc;+ } catch (err) {+ throw new DatabaseError({ error: err, name: "FindById" });+ }+ };++ return { ...stOrm, findById };};diff --git a/backend/src/services/service-token/service-token-service.ts b/backend/src/services/service-token/service-token-service.tsindex 76d33bd6b4..cce0d3780f 100644--- a/backend/src/services/service-token/service-token-service.ts+++ b/backend/src/services/service-token/service-token-service.ts@@ -142,7 +142,7 @@ export const serviceTokenServiceFactory = ({const updatedToken = await serviceTokenDAL.updateById(serviceToken.id, {lastUsed: new Date()});- return updatedToken;+ return { ...serviceToken, lastUsed: updatedToken.lastUsed };};return {