Skip to content

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

Fix github secret-sync not working with gateway v2

Carlos Monastyrskidf5ce6640fa0
diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.ts
index 41681502e2..fd142b7aea 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.ts
@@ -52,16 +52,21 @@ export const getGitHubGatewayConnectionDetails = async (
gatewayId: string,
targetHost: string,
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
-): Promise<Awaited<ReturnType<TGatewayV2ServiceFactory["getPlatformConnectionDetailsByGatewayId"]>>> => {
- const urlString = targetHost.includes("://") ? targetHost : `https://${targetHost}`;
- const url = new URL(urlString);
- const { hostname } = url;
-
- return gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
- gatewayId,
- targetHost: hostname,
- targetPort: 443
- });
+): Promise<Awaited<ReturnType<TGatewayV2ServiceFactory["getPlatformConnectionDetailsByGatewayId"]>> | undefined> => {
+ try {
+ const urlString = targetHost.includes("://") ? targetHost : `https://${targetHost}`;
+ const url = new URL(urlString);
+ const { hostname } = url;
+
+ return await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
+ gatewayId,
+ targetHost: hostname,
+ targetPort: 443
+ });
+ } catch {
+ // Return undefined to allow fallback to V1 gateway
+ return undefined;
+ }
};
export const requestWithGitHubGateway = async <T>(
diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.ts
index e7116d6045..4057f38b1a 100644
--- a/backend/src/services/secret-sync/github/github-sync-fns.ts
+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts
@@ -4,6 +4,7 @@ import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import {
getGitHubAppAuthToken,
+ getGitHubGatewayConnectionDetails,
getGitHubInstanceApiUrl,
GitHubConnectionMethod,
makePaginatedGitHubRequest,
@@ -77,15 +78,26 @@ const getPublicKey = async (
}
}
- const response = await requestWithGitHubGateway<TGitHubPublicKey>(connection, gatewayService, gatewayV2Service, {
- url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
- method: "GET",
- headers: {
- Accept: "application/vnd.github+json",
- Authorization: `Bearer ${token}`,
- "X-GitHub-Api-Version": "2022-11-28"
- }
- });
+ const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
+ const gatewayConnectionDetails = connection.gatewayId
+ ? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
+ : undefined;
+
+ const response = await requestWithGitHubGateway<TGitHubPublicKey>(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `https://${apiBaseUrl}${path}`,
+ method: "GET",
+ headers: {
+ Accept: "application/vnd.github+json",
+ Authorization: `Bearer ${token}`,
+ "X-GitHub-Api-Version": "2022-11-28"
+ }
+ },
+ gatewayConnectionDetails
+ );
return response.data;
};
@@ -116,15 +128,26 @@ const deleteSecret = async (
}
}
- await requestWithGitHubGateway(connection, gatewayService, gatewayV2Service, {
- url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
- method: "DELETE",
- headers: {
- Accept: "application/vnd.github+json",
- Authorization: `Bearer ${token}`,
- "X-GitHub-Api-Version": "2022-11-28"
- }
- });
+ const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
+ const gatewayConnectionDetails = connection.gatewayId
+ ? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
+ : undefined;
+
+ await requestWithGitHubGateway(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `https://${apiBaseUrl}${path}`,
+ method: "DELETE",
+ headers: {
+ Accept: "application/vnd.github+json",
+ Authorization: `Bearer ${token}`,
+ "X-GitHub-Api-Version": "2022-11-28"
+ }
+ },
+ gatewayConnectionDetails
+ );
};
const putSecret = async (
@@ -163,16 +186,27 @@ const putSecret = async (
}
}
- await requestWithGitHubGateway(connection, gatewayService, gatewayV2Service, {
- url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
- method: "PUT",
- headers: {
- Accept: "application/vnd.github+json",
- Authorization: `Bearer ${token}`,
- "X-GitHub-Api-Version": "2022-11-28"
+ const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
+ const gatewayConnectionDetails = connection.gatewayId
+ ? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
+ : undefined;
+
+ await requestWithGitHubGateway(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `https://${apiBaseUrl}${path}`,
+ method: "PUT",
+ headers: {
+ Accept: "application/vnd.github+json",
+ Authorization: `Bearer ${token}`,
+ "X-GitHub-Api-Version": "2022-11-28"
+ },
+ data: body
},
- data: body
- });
+ gatewayConnectionDetails
+ );
};
export const GithubSyncFns = {