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
feat(infisical-pg): fixed bugs in integrations and self hosted license failure
Akhil Mohand90fdac5ce68
diff --git a/backend-pg/src/ee/services/license/license-service.ts b/backend-pg/src/ee/services/license/license-service.tsindex 26ce0fe462..c8115832a2 100644--- a/backend-pg/src/ee/services/license/license-service.ts+++ b/backend-pg/src/ee/services/license/license-service.ts@@ -85,7 +85,11 @@ export const licenseServiceFactory = ({logger.info(`Instance type: ${InstanceType.EnterpriseOnPrem}`);isValidLicense = true;}+ return;}+ // this means this is self hosted oss version+ // else it would reach catch statement+ isValidLicense = true;} catch (error) {logger.error(error);}diff --git a/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts b/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.tsindex 4691c5e1c0..f8ba4e1875 100644--- a/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts+++ b/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts@@ -19,6 +19,7 @@ import {import { TSnapshotDalFactory } from "./snapshot-dal";import { TSnapshotFolderDalFactory } from "./snapshot-folder-dal";import { TSnapshotSecretDalFactory } from "./snapshot-secret-dal";+import { logger } from "@app/lib/logger";type TSecretSnapshotServiceFactoryDep = {snapshotDal: TSnapshotDalFactory;@@ -112,44 +113,50 @@ export const secretSnapshotServiceFactory = ({};const performSnapshot = async (folderId: string) => {- if (!licenseService.isValidLicense)- throw new InternalServerError({ message: "Invalid license" });+ try {+ if (!licenseService.isValidLicense)+ throw new InternalServerError({ message: "Invalid license" });- const snapshot = await snapshotDal.transaction(async (tx) => {- const folder = await folderDal.findById(folderId, tx);- if (!folder) throw new BadRequestError({ message: "Folder not found" });+ const snapshot = await snapshotDal.transaction(async (tx) => {+ const folder = await folderDal.findById(folderId, tx);+ if (!folder) throw new BadRequestError({ message: "Folder not found" });- const secretVersions = await secretVersionDal.findLatestVersionByFolderId(folderId, tx);- const folderVersions = await folderVersionDal.findLatestVersionByFolderId(folderId, tx);- const newSnapshot = await snapshotDal.create(- {- folderId,- envId: folder.environment.envId,- parentFolderId: folder.parentId- },- tx- );- const snapshotSecrets = await snapshotSecretDal.insertMany(- secretVersions.map(({ id }) => ({- secretVersionId: id,- envId: folder.environment.envId,- snapshotId: newSnapshot.id- })),- tx- );- const snapshotFolders = await snapshotFolderDal.insertMany(- folderVersions.map(({ id }) => ({- folderVersionId: id,- envId: folder.environment.envId,- snapshotId: newSnapshot.id- })),- tx- );+ const secretVersions = await secretVersionDal.findLatestVersionByFolderId(folderId, tx);+ const folderVersions = await folderVersionDal.findLatestVersionByFolderId(folderId, tx);+ const newSnapshot = await snapshotDal.create(+ {+ folderId,+ envId: folder.environment.envId,+ parentFolderId: folder.parentId+ },+ tx+ );+ const snapshotSecrets = await snapshotSecretDal.insertMany(+ secretVersions.map(({ id }) => ({+ secretVersionId: id,+ envId: folder.environment.envId,+ snapshotId: newSnapshot.id+ })),+ tx+ );+ const snapshotFolders = await snapshotFolderDal.insertMany(+ folderVersions.map(({ id }) => ({+ folderVersionId: id,+ envId: folder.environment.envId,+ snapshotId: newSnapshot.id+ })),+ tx+ );- return { ...newSnapshot, secrets: snapshotSecrets, folder: snapshotFolders };- });+ return { ...newSnapshot, secrets: snapshotSecrets, folder: snapshotFolders };+ });- return snapshot;+ return snapshot;+ } catch (error) {+ // this to avoid snapshot errors+ logger.error("Failed to perform snasphot");+ logger.error(error);+ }};const rollbackSnapshot = async ({ id: snapshotId, actor, actorId }: TRollbackSnapshotDTO) => {diff --git a/backend-pg/src/server/routes/v1/project-router.ts b/backend-pg/src/server/routes/v1/project-router.tsindex 6c226ba3bb..5e8ee8b46d 100644--- a/backend-pg/src/server/routes/v1/project-router.ts+++ b/backend-pg/src/server/routes/v1/project-router.ts@@ -330,7 +330,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {},onRequest: verifyAuth([AuthMode.JWT]),handler: async (req) => {- const authorizations = await server.services.integration.listIntegrationByProject({+ const authorizations = await server.services.integrationAuth.listIntegrationAuthByProjectId({actorId: req.permission.id,actor: req.permission.type,projectId: req.params.workspaceIddiff --git a/backend-pg/src/server/routes/v1/sso-router.ts b/backend-pg/src/server/routes/v1/sso-router.tsindex 68d3c056f1..dd12ccd17a 100644--- a/backend-pg/src/server/routes/v1/sso-router.ts+++ b/backend-pg/src/server/routes/v1/sso-router.ts@@ -16,7 +16,6 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {await server.register(fastifySession, { secret: appCfg.COOKIE_SECRET_SIGN_KEY });await server.register(passport.initialize());await server.register(passport.secureSession());-// passport oauth strategy for Googleconst isGoogleOauthActive = Boolean(appCfg.CLIENT_ID_GOOGLE_LOGIN && appCfg.CLIENT_SECRET_GOOGLE_LOGIN@@ -123,7 +122,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {}server.route({- url: "/sso/redirect/google",+ url: "/redirect/google",method: "GET",schema: {querystring: z.object({@@ -144,7 +143,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {});server.route({- url: "/sso/google",+ url: "/google",method: "GET",preValidation: passport.authenticate("google", {session: false,@@ -169,7 +168,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {});server.route({- url: "/sso/redirect/github",+ url: "/redirect/github",method: "GET",schema: {querystring: z.object({@@ -189,7 +188,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {});server.route({- url: "/sso/github",+ url: "/github",method: "GET",preValidation: passport.authenticate("github", {session: false,@@ -214,7 +213,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {});server.route({- url: "/sso/redirect/gitlab",+ url: "/redirect/gitlab",method: "GET",schema: {querystring: z.object({@@ -234,7 +233,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {});server.route({- url: "/sso/gitlab",+ url: "/gitlab",method: "GET",preValidation: passport.authenticate("gitlab", {session: false,diff --git a/backend-pg/src/services/integration-auth/integration-list.ts b/backend-pg/src/services/integration-auth/integration-list.tsindex 43cf02e1f6..334a60e1d3 100644--- a/backend-pg/src/services/integration-auth/integration-list.ts+++ b/backend-pg/src/services/integration-auth/integration-list.ts@@ -102,7 +102,7 @@ export const getIntegrationOptions = async () => {isAvailable: true,type: "oauth",clientId: "",- clientSlug: appCfg.CLIENT_ID_VERCEL,+ clientSlug: appCfg.CLIENT_SLUG_VERCEL,docsLink: ""},{@@ -120,7 +120,7 @@ export const getIntegrationOptions = async () => {image: "GitHub.png",isAvailable: true,type: "oauth",- clientId: appCfg.CLIENT_ID_BITBUCKET,+ clientId: appCfg.CLIENT_ID_GITHUB,docsLink: ""},{diff --git a/backend-pg/src/services/integration/integration-dal.ts b/backend-pg/src/services/integration/integration-dal.tsindex 80a9957e6e..1977bad3e8 100644--- a/backend-pg/src/services/integration/integration-dal.ts+++ b/backend-pg/src/services/integration/integration-dal.ts@@ -50,7 +50,9 @@ export const integrationDalFactory = (db: TDbClient) => {const findById = async (id: string, tx?: Knex) => {try {- const doc = await integrationFindQuery(tx || db, { id }).first();+ const doc = await integrationFindQuery(tx || db, {+ [`${TableName.Integration}.id` as "id"]: id+ }).first();if (!doc) return;const { envName: name, envSlug: slug, envId, ...el } = doc;diff --git a/backend-pg/src/services/secret/secret-queue.ts b/backend-pg/src/services/secret/secret-queue.tsindex ed60964271..fdebd3708f 100644--- a/backend-pg/src/services/secret/secret-queue.ts+++ b/backend-pg/src/services/secret/secret-queue.ts@@ -159,7 +159,6 @@ export const secretQueueFactory = ({};queueService.start(QueueName.IntegrationSync, async (job) => {- logger.info("Secret integration sync started", job.data, job.id);const { environment, projectId, secretPath } = job.data;const folder = await folderDal.findBySecretPath(projectId, environment, secretPath);if (!folder) {@@ -173,6 +172,8 @@ export const secretQueueFactory = ({isActive && isSamePath(secretPath, integrationSecPath));+ if (!integrations.length) return;+ logger.info("Secret integration sync started", job.data, job.id);for (const integration of toBeSyncedIntegrations) {const integrationAuth = {...integration.integrationAuth,@@ -222,9 +223,7 @@ export const secretQueueFactory = ({});queueService.start(QueueName.SecretWebhook, async (job) => {- logger.info("Secret webhook job started", job.data, job.id);await fnTriggerWebhook({ ...job.data, projectEnvDal, webhookDal });- logger.info("Secret webhook job ended", job.id);});return { syncSecrets };diff --git a/backend-pg/src/services/secret/secret-service.ts b/backend-pg/src/services/secret/secret-service.tsindex 9287fe8c86..40fcce50cc 100644--- a/backend-pg/src/services/secret/secret-service.ts+++ b/backend-pg/src/services/secret/secret-service.ts@@ -569,7 +569,7 @@ export const secretServiceFactory = ({secretDal,folderDal});- for (let i = importedSecrets.length; i >= 0; i -= 1) {+ for (let i = importedSecrets.length - 1; i >= 0; i -= 1) {for (let j = 0; j < importedSecrets[i].secrets.length; j += 1) {if (secretBlindIndex === importedSecrets[i].secrets[j].secretBlindIndex) {return importedSecrets[i].secrets[j];diff --git a/backend-pg/src/services/webhook/webhook-fns.ts b/backend-pg/src/services/webhook/webhook-fns.tsindex 0169b6a425..d661bf0162 100644--- a/backend-pg/src/services/webhook/webhook-fns.ts+++ b/backend-pg/src/services/webhook/webhook-fns.ts@@ -10,6 +10,7 @@ import { BadRequestError } from "@app/lib/errors";import { TProjectEnvDalFactory } from "../project-env/project-env-dal";import { TWebhookDalFactory } from "./webhook-dal";+import { logger } from "@app/lib/logger";const WEBHOOK_TRIGGER_TIMEOUT = 15 * 1000;export const triggerWebhookRequest = async (@@ -93,6 +94,7 @@ export const fnTriggerWebhook = async ({!isDisabled && picomatch.isMatch(secretPath, hookSecretPath, { strictSlashes: false }));if (!toBeTriggeredHooks.length) return;+ logger.info("Secret webhook job started", { environment, secretPath, projectId });const webhooksTriggered = await Promise.allSettled(toBeTriggeredHooks.map((hook) =>triggerWebhookRequest(@@ -133,4 +135,5 @@ export const fnTriggerWebhook = async ({);}});+ logger.info("Secret webhook job ended", { environment, secretPath, projectId });};