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: added endpoint to update integration auth
=40d69d46203f
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 99822da295..518654da15 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -1032,6 +1032,9 @@ export const INTEGRATION_AUTH = {DELETE_BY_ID: {integrationAuthId: "The ID of integration authentication object to delete."},+ UPDATE_BY_ID: {+ integrationAuthId: "The ID of integration authentication object to update."+ },CREATE_ACCESS_TOKEN: {workspaceId: "The ID of the project to create the integration auth for.",integration: "The slug of integration for the auth object.",@@ -1088,11 +1091,13 @@ export const INTEGRATION = {},UPDATE: {integrationId: "The ID of the integration object.",+ region: "AWS region to sync secrets to.",app: "The name of the external integration providers app entity that you want to sync secrets with. Used in Netlify, GitHub, Vercel integrations.",appId:"The ID of the external integration providers app entity that you want to sync secrets with. Used in Netlify, GitHub, Vercel integrations.",isActive: "Whether the integration should be active or disabled.",secretPath: "The path of the secrets to sync secrets from.",+ path: "Path to save the synced secrets. Used by Gitlab, AWS Parameter Store, Vault.",owner: "External integration providers service entity owner. Used in Github.",targetEnvironment:"The target environment of the integration provider. Used in cloudflare pages, TeamCity, Gitlab integrations.",diff --git a/backend/src/server/routes/v1/integration-auth-router.ts b/backend/src/server/routes/v1/integration-auth-router.tsindex 575544cc77..ea7b6f917d 100644--- a/backend/src/server/routes/v1/integration-auth-router.ts+++ b/backend/src/server/routes/v1/integration-auth-router.ts@@ -82,6 +82,67 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider)}});+ server.route({+ method: "PATCH",+ url: "/:integrationAuthId",+ config: {+ rateLimit: writeLimit+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ schema: {+ description: "Update the integration authentication object required for syncing secrets.",+ security: [+ {+ bearerAuth: []+ }+ ],+ querystring: z.object({+ integrationAuthId: z.string().trim().describe(INTEGRATION_AUTH.UPDATE_BY_ID.integrationAuthId)+ }),+ body: z.object({+ integration: z.string().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.integration),+ accessId: z.string().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.accessId),+ accessToken: z.string().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.accessToken),+ awsAssumeIamRoleArn: z+ .string()+ .url()+ .trim()+ .optional()+ .describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.awsAssumeIamRoleArn),+ url: z.string().url().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.url),+ namespace: z.string().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.namespace),+ refreshToken: z.string().trim().optional().describe(INTEGRATION_AUTH.CREATE_ACCESS_TOKEN.refreshToken)+ }),+ response: {+ 200: z.object({+ integrationAuth: integrationAuthPubSchema+ })+ }+ },+ handler: async (req) => {+ const integrationAuth = await server.services.integrationAuth.updateIntegrationAuth({+ actorId: req.permission.id,+ actor: req.permission.type,+ actorAuthMethod: req.permission.authMethod,+ actorOrgId: req.permission.orgId,+ integrationAuthId: req.query.integrationAuthId,+ ...req.body+ });++ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ projectId: integrationAuth.projectId,+ event: {+ type: EventType.AUTHORIZE_INTEGRATION,+ metadata: {+ integration: integrationAuth.integration+ }+ }+ });+ return { integrationAuth };+ }+ });+server.route({method: "DELETE",url: "/",diff --git a/backend/src/server/routes/v1/integration-router.ts b/backend/src/server/routes/v1/integration-router.tsindex 40141e2c09..059d244638 100644--- a/backend/src/server/routes/v1/integration-router.ts+++ b/backend/src/server/routes/v1/integration-router.ts@@ -141,7 +141,9 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {targetEnvironment: z.string().trim().optional().describe(INTEGRATION.UPDATE.targetEnvironment),owner: z.string().trim().optional().describe(INTEGRATION.UPDATE.owner),environment: z.string().trim().optional().describe(INTEGRATION.UPDATE.environment),- metadata: IntegrationMetadataSchema.optional()+ path: z.string().trim().optional().describe(INTEGRATION.UPDATE.path),+ metadata: IntegrationMetadataSchema.optional(),+ region: z.string().trim().optional().describe(INTEGRATION.UPDATE.region)}),response: {200: z.object({diff --git a/backend/src/services/integration-auth/integration-auth-service.ts b/backend/src/services/integration-auth/integration-auth-service.tsindex be1a8d53c8..6768e12bfc 100644--- a/backend/src/services/integration-auth/integration-auth-service.ts+++ b/backend/src/services/integration-auth/integration-auth-service.ts@@ -55,6 +55,7 @@ import {TOctopusDeployVariableSet,TSaveIntegrationAccessTokenDTO,TTeamCityBuildConfig,+ TUpdateIntegrationAuthDTO,TVercelBranches} from "./integration-auth-types";import { getIntegrationOptions, Integrations, IntegrationUrls } from "./integration-list";@@ -368,6 +369,149 @@ export const integrationAuthServiceFactory = ({return integrationAuthDAL.create(updateDoc);};+ const updateIntegrationAuth = async ({+ integrationAuthId,+ refreshToken,+ actorId,+ integration: newIntegration,+ url,+ actor,+ actorOrgId,+ actorAuthMethod,+ accessId,+ namespace,+ accessToken,+ awsAssumeIamRoleArn+ }: TUpdateIntegrationAuthDTO) => {+ const integrationAuth = await integrationAuthDAL.findById(integrationAuthId);+ if (!integrationAuth) {+ throw new NotFoundError({ message: `Integration auth with id ${integrationAuthId} not found.` });+ }++ const { permission } = await permissionService.getProjectPermission(+ actor,+ actorId,+ integrationAuth.projectId,+ actorAuthMethod,+ actorOrgId+ );+ ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Integrations);++ const { projectId } = integrationAuth;+ const integration = newIntegration || integrationAuth.integration;+ if (!Object.values(Integrations).includes(integration as Integrations))+ throw new BadRequestError({ message: "Invalid integration" });+ const updateDoc: TIntegrationAuthsInsert = {+ projectId,+ integration,+ namespace,+ url,+ algorithm: SecretEncryptionAlgo.AES_256_GCM,+ keyEncoding: SecretKeyEncoding.UTF8,+ ...(integration === Integrations.GCP_SECRET_MANAGER+ ? {+ metadata: {+ authMethod: "serviceAccount"+ }+ }+ : {})+ };++ const { shouldUseSecretV2Bridge, botKey } = await projectBotService.getBotKey(projectId);+ if (shouldUseSecretV2Bridge) {+ const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });+ if (refreshToken) {+ const tokenDetails = await exchangeRefresh(+ integration,+ refreshToken,+ url,+ updateDoc.metadata as Record<string, string>+ );+ const refreshEncToken = secretManagerEncryptor({+ plainText: Buffer.from(tokenDetails.refreshToken)+ }).cipherTextBlob;+ updateDoc.encryptedRefresh = refreshEncToken;++ const accessEncToken = secretManagerEncryptor({+ plainText: Buffer.from(tokenDetails.accessToken)+ }).cipherTextBlob;+ updateDoc.encryptedAccess = accessEncToken;+ updateDoc.accessExpiresAt = tokenDetails.accessExpiresAt;+ }++ if (!refreshToken && (accessId || accessToken || awsAssumeIamRoleArn)) {+ if (accessToken) {+ const accessEncToken = secretManagerEncryptor({+ plainText: Buffer.from(accessToken)+ }).cipherTextBlob;+ updateDoc.encryptedAccess = accessEncToken;+ updateDoc.encryptedAwsAssumeIamRoleArn = null;+ }+ if (accessId) {+ const accessEncToken = secretManagerEncryptor({+ plainText: Buffer.from(accessId)+ }).cipherTextBlob;+ updateDoc.encryptedAccessId = accessEncToken;+ updateDoc.encryptedAwsAssumeIamRoleArn = null;+ }+ if (awsAssumeIamRoleArn) {+ const awsAssumeIamRoleArnEncrypted = secretManagerEncryptor({+ plainText: Buffer.from(awsAssumeIamRoleArn)+ }).cipherTextBlob;+ updateDoc.encryptedAwsAssumeIamRoleArn = awsAssumeIamRoleArnEncrypted;+ updateDoc.encryptedAccess = null;+ updateDoc.encryptedAccessId = null;+ }+ }+ } else {+ if (!botKey) throw new NotFoundError({ message: `Project bot key for project with ID '${projectId}' not found` });+ if (refreshToken) {+ const tokenDetails = await exchangeRefresh(+ integration,+ refreshToken,+ url,+ updateDoc.metadata as Record<string, string>+ );+ const refreshEncToken = encryptSymmetric128BitHexKeyUTF8(tokenDetails.refreshToken, botKey);+ updateDoc.refreshIV = refreshEncToken.iv;+ updateDoc.refreshTag = refreshEncToken.tag;+ updateDoc.refreshCiphertext = refreshEncToken.ciphertext;+ const accessEncToken = encryptSymmetric128BitHexKeyUTF8(tokenDetails.accessToken, botKey);+ updateDoc.accessIV = accessEncToken.iv;+ updateDoc.accessTag = accessEncToken.tag;+ updateDoc.accessCiphertext = accessEncToken.ciphertext;++ updateDoc.accessExpiresAt = tokenDetails.accessExpiresAt;+ }++ if (!refreshToken && (accessId || accessToken || awsAssumeIamRoleArn)) {+ if (accessToken) {+ const accessEncToken = encryptSymmetric128BitHexKeyUTF8(accessToken, botKey);+ updateDoc.accessIV = accessEncToken.iv;+ updateDoc.accessTag = accessEncToken.tag;+ updateDoc.accessCiphertext = accessEncToken.ciphertext;+ }+ if (accessId) {+ const accessEncToken = encryptSymmetric128BitHexKeyUTF8(accessId, botKey);+ updateDoc.accessIdIV = accessEncToken.iv;+ updateDoc.accessIdTag = accessEncToken.tag;+ updateDoc.accessIdCiphertext = accessEncToken.ciphertext;+ }+ if (awsAssumeIamRoleArn) {+ const awsAssumeIamRoleArnEnc = encryptSymmetric128BitHexKeyUTF8(awsAssumeIamRoleArn, botKey);+ updateDoc.awsAssumeIamRoleArnCipherText = awsAssumeIamRoleArnEnc.ciphertext;+ updateDoc.awsAssumeIamRoleArnIV = awsAssumeIamRoleArnEnc.iv;+ updateDoc.awsAssumeIamRoleArnTag = awsAssumeIamRoleArnEnc.tag;+ }+ }+ }++ return integrationAuthDAL.updateById(integrationAuthId, updateDoc);+ };+// helper functionconst getIntegrationAccessToken = async (integrationAuth: TIntegrationAuths,@@ -1615,6 +1759,7 @@ export const integrationAuthServiceFactory = ({getIntegrationAuth,oauthExchange,saveIntegrationToken,+ updateIntegrationAuth,deleteIntegrationAuthById,deleteIntegrationAuths,getIntegrationAuthTeams,diff --git a/backend/src/services/integration-auth/integration-auth-types.ts b/backend/src/services/integration-auth/integration-auth-types.tsindex 80e8d6c36f..3ffa6959a1 100644--- a/backend/src/services/integration-auth/integration-auth-types.ts+++ b/backend/src/services/integration-auth/integration-auth-types.ts@@ -22,6 +22,11 @@ export type TSaveIntegrationAccessTokenDTO = {awsAssumeIamRoleArn?: string;} & TProjectPermission;+export type TUpdateIntegrationAuthDTO = Omit<TSaveIntegrationAccessTokenDTO, "projectId" | "integration"> & {+ integrationAuthId: string;+ integration?: string;+};+export type TDeleteIntegrationAuthsDTO = TProjectPermission & {integration: string;projectId: string;diff --git a/backend/src/services/integration/integration-service.ts b/backend/src/services/integration/integration-service.tsindex 1db10405d7..a990b1ca6e 100644--- a/backend/src/services/integration/integration-service.ts+++ b/backend/src/services/integration/integration-service.ts@@ -151,7 +151,9 @@ export const integrationServiceFactory = ({isActive,environment,secretPath,- metadata+ region,+ metadata,+ path}: TUpdateIntegrationDTO) => {const integration = await integrationDAL.findById(id);if (!integration) throw new NotFoundError({ message: `Integration with ID '${id}' not found` });@@ -192,7 +194,9 @@ export const integrationServiceFactory = ({appId,targetEnvironment,owner,+ region,secretPath,+ path,metadata: {...(integration.metadata as object),...metadatadiff --git a/backend/src/services/integration/integration-types.ts b/backend/src/services/integration/integration-types.tsindex a27c4f6acb..f662affd81 100644--- a/backend/src/services/integration/integration-types.ts+++ b/backend/src/services/integration/integration-types.ts@@ -49,6 +49,8 @@ export type TUpdateIntegrationDTO = {appId?: string;isActive?: boolean;secretPath?: string;+ region?: string;+ path?: string;targetEnvironment?: string;owner?: string;environment?: string;