Skip to content

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

support gateway pool

Thiago Araujo da Silvaf0ec95b38a9d
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 2165c49fbe..413c1f11bd 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1688,6 +1688,7 @@ export const registerRoutes = async (
licenseService,
gatewayService,
gatewayV2Service,
+ gatewayPoolService,
gatewayDAL,
gatewayV2DAL,
auditLogService,
diff --git a/backend/src/server/routes/v1/github-app-router.ts b/backend/src/server/routes/v1/github-app-router.ts
index 9403ec5bfb..1f82ba1097 100644
--- a/backend/src/server/routes/v1/github-app-router.ts
+++ b/backend/src/server/routes/v1/github-app-router.ts
@@ -15,15 +15,21 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
schema: {
- body: z.object({
- name: z.string().trim().min(1).max(64),
- instanceType: z.enum(["cloud", "server"]).default("cloud"),
- githubOrg: z.string().trim().optional(),
- githubHost: z.string().trim().optional(),
- installState: z.string().trim().min(1),
- projectId: z.string().trim().optional(),
- gatewayId: z.string().uuid().optional()
- }),
+ body: z
+ .object({
+ name: z.string().trim().min(1).max(64),
+ instanceType: z.enum(["cloud", "server"]).default("cloud"),
+ githubOrg: z.string().trim().optional(),
+ githubHost: z.string().trim().optional(),
+ installState: z.string().trim().min(1),
+ projectId: z.string().trim().optional(),
+ gatewayId: z.string().uuid().optional(),
+ gatewayPoolId: z.string().uuid().optional()
+ })
+ .refine((data) => !(data.gatewayId && data.gatewayPoolId), {
+ message: "Cannot specify both a gateway and a gateway pool",
+ path: ["gatewayPoolId"]
+ }),
response: {
200: z.object({
state: z.string(),
@@ -41,7 +47,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
githubHost: req.body.githubHost,
installState: req.body.installState,
projectId: req.body.projectId,
- gatewayId: req.body.gatewayId
+ gatewayId: req.body.gatewayId,
+ gatewayPoolId: req.body.gatewayPoolId
});
return result;
@@ -110,14 +117,20 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
schema: {
- body: z.object({
- code: z.string().trim().min(1),
- gitHubAppId: z.string().uuid().optional(),
- host: z.string().trim().optional(),
- instanceType: z.enum(["cloud", "server"]).optional(),
- gatewayId: z.string().uuid().optional(),
- projectId: z.string().optional()
- }),
+ body: z
+ .object({
+ code: z.string().trim().min(1),
+ gitHubAppId: z.string().uuid().optional(),
+ host: z.string().trim().optional(),
+ instanceType: z.enum(["cloud", "server"]).optional(),
+ gatewayId: z.string().uuid().optional(),
+ gatewayPoolId: z.string().uuid().optional(),
+ projectId: z.string().optional()
+ })
+ .refine((data) => !(data.gatewayId && data.gatewayPoolId), {
+ message: "Cannot specify both a gateway and a gateway pool",
+ path: ["gatewayPoolId"]
+ }),
response: {
200: z.object({
installations: z
@@ -139,6 +152,7 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
host: req.body.host,
instanceType: req.body.instanceType,
gatewayId: req.body.gatewayId,
+ gatewayPoolId: req.body.gatewayPoolId,
projectId: req.body.projectId
});
diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.ts
index b5487da2c1..6a7710c516 100644
--- a/backend/src/services/github-app/github-app-service.ts
+++ b/backend/src/services/github-app/github-app-service.ts
@@ -5,6 +5,7 @@ import { ActionProjectType, OrganizationActionScope } from "@app/db/schemas";
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
import { TGatewayDALFactory } from "@app/ee/services/gateway/gateway-dal";
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
+import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
import { TGatewayV2DALFactory } from "@app/ee/services/gateway-v2/gateway-v2-dal";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
@@ -68,6 +69,10 @@ type TGitHubAppServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
+ gatewayPoolService: Pick<
+ TGatewayPoolServiceFactory,
+ "resolveAttachableGatewayFromPool" | "resolveEffectiveGatewayId"
+ >;
gatewayDAL: Pick<TGatewayDALFactory, "find">;
gatewayV2DAL: Pick<TGatewayV2DALFactory, "find">;
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
@@ -84,6 +89,7 @@ export const gitHubAppServiceFactory = ({
licenseService,
gatewayService,
gatewayV2Service,
+ gatewayPoolService,
gatewayDAL,
gatewayV2DAL,
auditLogService,
@@ -163,6 +169,23 @@ export const gitHubAppServiceFactory = ({
}
};
+ const assertGatewayConfigUsable = async (
+ { gatewayId, gatewayPoolId }: { gatewayId?: string | null; gatewayPoolId?: string | null },
+ orgPermission: OrgServiceActor
+ ) => {
+ if (gatewayId) {
+ await assertGatewayUsable(gatewayId, orgPermission);
+ return;
+ }
+ if (gatewayPoolId) {
+ await gatewayPoolService.resolveAttachableGatewayFromPool({
+ poolId: gatewayPoolId,
+ orgId: orgPermission.orgId,
+ actor: orgPermission
+ });
+ }
+ };
+
const listGitHubApps = async ({ orgPermission, projectId }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {
await checkAppConnectionPermission({
actor: orgPermission,
@@ -381,6 +404,7 @@ export const gitHubAppServiceFactory = ({
installState,
projectId,
gatewayId,
+ gatewayPoolId,
orgPermission
}: TInitiateGitHubManifestDTO) => {
await checkAppConnectionPermission({
@@ -393,9 +417,7 @@ export const gitHubAppServiceFactory = ({
assertPlatformGitHubHostAllowed(githubHost);
- if (gatewayId) {
- await assertGatewayUsable(gatewayId, orgPermission);
- }
+ await assertGatewayConfigUsable({ gatewayId, gatewayPoolId }, orgPermission);
const existing = await gitHubAppDAL.findOne({
orgId: orgPermission.orgId,
@@ -429,6 +451,7 @@ export const gitHubAppServiceFactory = ({
githubOrg: githubOrg ?? "",
githubHost: githubHost ?? "",
gatewayId: gatewayId ?? null,
+ gatewayPoolId: gatewayPoolId ?? null,
installState
} satisfies TGitHubManifestStatePayload,
AUTH_SECRET,
@@ -491,6 +514,7 @@ export const gitHubAppServiceFactory = ({
githubOrg,
githubHost,
gatewayId = null,
+ gatewayPoolId = null,
installState
} = statePayload;
@@ -558,13 +582,15 @@ export const gitHubAppServiceFactory = ({
}
};
- const { data } = gatewayId
+ const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({ gatewayId, gatewayPoolId });
+
+ const { data } = effectiveGatewayId
? await requestWithGitHubGateway<TGitHubAppManifestResponse>(
- { gatewayId },
+ { gatewayId: effectiveGatewayId },
gatewayService,
gatewayV2Service,
requestConfig,
- await getGitHubGatewayConnectionDetails(gatewayId, apiBaseUrl, gatewayV2Service)
+ await getGitHubGatewayConnectionDetails(effectiveGatewayId, apiBaseUrl, gatewayV2Service)
)
: await safeRequest.request<TGitHubAppManifestResponse>(requestConfig);
manifestResponse = data;
@@ -576,11 +602,14 @@ export const gitHubAppServiceFactory = ({
projectId,
instanceType,
host: githubHost || "github.com",
- gatewayId
+ gatewayId,
+ gatewayPoolId
},
`Failed to exchange GitHub App manifest code [orgId=${orgId}] [projectId=${
projectId ?? "null"
- }] [instanceType=${instanceType}] [host=${githubHost || "github.com"}] [gatewayId=${gatewayId ?? "null"}]`
+ }] [instanceType=${instanceType}] [host=${githubHost || "github.com"}] [gatewayId=${
+ gatewayId ?? "null"
+ }] [gatewayPoolId=${gatewayPoolId ?? "null"}]`
);
throw new BadRequestError({
message:
@@ -694,6 +723,7 @@ export const gitHubAppServiceFactory = ({
gitHubAppId,
instanceType,
gatewayId,
+ gatewayPoolId,
projectId,
orgPermission
}: TResolveGitHubAppInstallationsDTO): Promise<{
@@ -740,9 +770,9 @@ export const gitHubAppServiceFactory = ({
);
}
- if (gatewayId) {
- await assertGatewayUsable(gatewayId, orgPermission);
- }
+ await assertGatewayConfigUsable({ gatewayId, gatewayPoolId }, orgPermission);
+
+ const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({ gatewayId, gatewayPoolId });
const { SITE_URL } = getConfig();
if (!SITE_URL) {
@@ -780,9 +810,9 @@ export const gitHubAppServiceFactory = ({
requestConfig: AxiosRequestConfig & { url: string },
gatewayConnectionDetails?: Awaited<ReturnType<typeof getGitHubGatewayConnectionDetails>>
): Promise<AxiosResponse<T>> =>
- gatewayId
+ effectiveGatewayId
? requestWithGitHubGateway<T>(
- { gatewayId },
+ { gatewayId: effectiveGatewayId },
gatewayService,
gatewayV2Service,
requestConfig,
@@ -790,8 +820,8 @@ export const gitHubAppServiceFactory = ({
)
: safeRequest.request<T>(requestConfig);
- const oauthGatewayConnectionDetails = gatewayId
- ? await getGitHubGatewayConnectionDetails(gatewayId, oauthHost, gatewayV2Service)
+ const oauthGatewayConnectionDetails = effectiveGatewayId
+ ? await getGitHubGatewayConnectionDetails(effectiveGatewayId, oauthHost, gatewayV2Service)
: undefined;
let tokenData: GithubTokenRespData;
@@ -825,8 +855,8 @@ export const gitHubAppServiceFactory = ({
credentials: { host: effectiveHost, instanceType: effectiveInstanceType }
});
- const apiGatewayConnectionDetails = gatewayId
- ? await getGitHubGatewayConnectionDetails(gatewayId, apiBaseUrl, gatewayV2Service)
+ const apiGatewayConnectionDetails = effectiveGatewayId
+ ? await getGitHubGatewayConnectionDetails(effectiveGatewayId, apiBaseUrl, gatewayV2Service)
: undefined;
const installations = await listGitHubUserInstallations(apiBaseUrl, tokenData.access_token, (requestConfig) =>
diff --git a/backend/src/services/github-app/github-app-types.ts b/backend/src/services/github-app/github-app-types.ts
index 622c4a3e02..5e86f40dab 100644
--- a/backend/src/services/github-app/github-app-types.ts
+++ b/backend/src/services/github-app/github-app-types.ts
@@ -11,6 +11,7 @@ export type TInitiateGitHubManifestDTO = {
installState: string;
projectId?: string;
gatewayId?: string;
+ gatewayPoolId?: string;
orgPermission: OrgServiceActor;
};
@@ -26,6 +27,7 @@ export type TGitHubManifestStatePayload = {
githubOrg: string;
githubHost: string;
gatewayId: string | null;
+ gatewayPoolId: string | null;
installState: string;
};
@@ -51,6 +53,7 @@ export type TResolveGitHubAppInstallationsDTO = {
host?: string;
instanceType?: "cloud" | "server";
gatewayId?: string | null;
+ gatewayPoolId?: string | null;
projectId?: string;
orgPermission: OrgServiceActor;
};
diff --git a/frontend/src/hooks/api/gitHubApps/queries.tsx b/frontend/src/hooks/api/gitHubApps/queries.tsx
index 44d1f03f9d..b436a120dd 100644
--- a/frontend/src/hooks/api/gitHubApps/queries.tsx
+++ b/frontend/src/hooks/api/gitHubApps/queries.tsx
@@ -23,6 +23,7 @@ export const resolveGitHubAppInstallations = async (params: {
host?: string;
instanceType?: "cloud" | "server";
gatewayId?: string;
+ gatewayPoolId?: string;
projectId?: string;
}) => {
const { data } = await apiRequest.post<{
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
index c195a5e387..1f0e315d5c 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
@@ -285,7 +285,8 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
githubHost: formData.credentials?.host || undefined,
installState,
projectId: projectId || undefined,
- gatewayId: formData.gatewayId || undefined
+ gatewayId: formData.gatewayId || undefined,
+ gatewayPoolId: formData.gatewayPoolId || undefined
});
const formEl = document.createElement("form");
diff --git a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
index 3e6c11f6dc..c6242ce8a9 100644
--- a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
+++ b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
@@ -424,8 +424,16 @@ export const OAuthCallbackPage = () => {
clearState(AppConnection.GitHub);
- const { connectionId, name, description, returnUrl, gatewayId, credentials, projectId } =
- formData;
+ const {
+ connectionId,
+ name,
+ description,
+ returnUrl,
+ gatewayId,
+ gatewayPoolId,
+ credentials,
+ projectId
+ } = formData;
const storedGitHubAppId = (credentials as { gitHubAppId?: string | null } | undefined)
?.gitHubAppId;
@@ -438,6 +446,7 @@ export const OAuthCallbackPage = () => {
...(credentials?.instanceType && { instanceType: credentials.instanceType }),
...(credentials?.host && { host: credentials.host }),
...(gatewayId && { gatewayId }),
+ ...(gatewayPoolId && { gatewayPoolId }),
...(projectId && { projectId })
});
setGitHubPicker({ ...result, formData });
@@ -478,7 +487,8 @@ export const OAuthCallbackPage = () => {
app: AppConnection.GitHub,
connectionId,
credentials: isAppMethod ? appCredentials : oauthCredentials,
- gatewayId
+ gatewayId,
+ gatewayPoolId
});
} else {
connection = await createAppConnection.mutateAsync({
@@ -490,12 +500,14 @@ export const OAuthCallbackPage = () => {
? {
method: GitHubConnectionMethod.App,
credentials: appCredentials,
- gatewayId
+ gatewayId,
+ gatewayPoolId
}
: {
method: GitHubConnectionMethod.OAuth,
credentials: oauthCredentials,
- gatewayId
+ gatewayId,
+ gatewayPoolId
})
});
}
@@ -523,8 +535,16 @@ export const OAuthCallbackPage = () => {
if (!gitHubPicker) return;
const { installationsToken, formData } = gitHubPicker;
- const { connectionId, name, description, returnUrl, gatewayId, credentials, projectId } =
- formData;
+ const {
+ connectionId,
+ name,
+ description,
+ returnUrl,
+ gatewayId,
+ gatewayPoolId,
+ credentials,
+ projectId
+ } = formData;
const gitHubAppId = (credentials as { gitHubAppId?: string | null } | undefined)?.gitHubAppId;
setPickedInstallationId(selectedInstallationId);
@@ -545,7 +565,8 @@ export const OAuthCallbackPage = () => {
app: AppConnection.GitHub,
connectionId,
credentials: appCredentials,
- gatewayId
+ gatewayId,
+ gatewayPoolId
});
} else {
connection = await createAppConnection.mutateAsync({
@@ -555,7 +576,8 @@ export const OAuthCallbackPage = () => {
projectId,
method: GitHubConnectionMethod.App,
credentials: appCredentials,
- gatewayId
+ gatewayId,
+ gatewayPoolId
});
}
diff --git a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.types.ts b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.types.ts
index d5b1a66ac6..515f8c82db 100644
--- a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.types.ts
+++ b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.types.ts
@@ -19,7 +19,10 @@ type BaseFormData = {
};
export type GitHubFormData = BaseFormData &
- Pick<TGitHubConnection, "name" | "method" | "description" | "gatewayId" | "credentials"> & {
+ Pick<
+ TGitHubConnection,
+ "name" | "method" | "description" | "gatewayId" | "gatewayPoolId" | "credentials"
+ > & {
appSlug?: string;
};