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
allow using gateway for manifest creation
Thiago Araujo da Silvaae72b472442b
diff --git a/backend/src/server/routes/v1/github-app-router.ts b/backend/src/server/routes/v1/github-app-router.tsindex 83c1bd32c6..9403ec5bfb 100644--- a/backend/src/server/routes/v1/github-app-router.ts+++ b/backend/src/server/routes/v1/github-app-router.ts@@ -21,7 +21,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {githubOrg: z.string().trim().optional(),githubHost: z.string().trim().optional(),installState: z.string().trim().min(1),- projectId: z.string().trim().optional()+ projectId: z.string().trim().optional(),+ gatewayId: z.string().uuid().optional()}),response: {200: z.object({@@ -39,7 +40,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {githubOrg: req.body.githubOrg,githubHost: req.body.githubHost,installState: req.body.installState,- projectId: req.body.projectId+ projectId: req.body.projectId,+ gatewayId: req.body.gatewayId});return result;diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.tsindex 74386c6da1..dba4c29475 100644--- a/backend/src/services/github-app/github-app-service.ts+++ b/backend/src/services/github-app/github-app-service.ts@@ -24,6 +24,7 @@ import { crypto } from "@app/lib/crypto";import { DatabaseErrorCode } from "@app/lib/error-codes";import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";+import { OrgServiceActor } from "@app/lib/types";import { safeRequest } from "@app/lib/validator/safe-request";import {assertPlatformGitHubHostAllowed,@@ -126,6 +127,42 @@ export const gitHubAppServiceFactory = ({}};+ // Validates that the actor may attach the given gateway and that it exists for the org.+ // Mirrors the gateway checks in resolveUserInstallations so the manifest exchange can route+ // through a gateway when the GitHub host (e.g. a private GitHub Enterprise Server) isn't+ // directly reachable from the Infisical backend.+ const assertGatewayUsable = async (gatewayId: string, orgPermission: OrgServiceActor) => {+ const plan = await licenseService.getPlan(orgPermission.orgId);+ if (!plan.gateway) {+ throw new BadRequestError({+ message:+ "Your current plan does not support gateway usage with app connections. Please upgrade your plan or contact Infisical Sales for assistance."+ });+ }++ const { permission } = await permissionService.getOrgPermission({+ actor: orgPermission.type,+ actorId: orgPermission.id,+ orgId: orgPermission.orgId,+ actorAuthMethod: orgPermission.authMethod,+ actorOrgId: orgPermission.orgId,+ scope: OrganizationActionScope.Any+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionGatewayActions.AttachGateways,+ OrgPermissionSubjects.Gateway+ );++ const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: orgPermission.orgId });+ const [gatewayV2] = await gatewayV2DAL.find({ id: gatewayId, orgId: orgPermission.orgId });+ if (!gateway && !gatewayV2) {+ throw new NotFoundError({+ message: `Gateway with ID ${gatewayId} not found for org`+ });+ }+ };+const listGitHubApps = async ({ orgPermission, projectId }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {await checkAppConnectionPermission({actor: orgPermission,@@ -343,6 +380,7 @@ export const gitHubAppServiceFactory = ({githubHost,installState,projectId,+ gatewayId,orgPermission}: TInitiateGitHubManifestDTO) => {await checkAppConnectionPermission({@@ -355,6 +393,10 @@ export const gitHubAppServiceFactory = ({assertPlatformGitHubHostAllowed(githubHost);+ if (gatewayId) {+ await assertGatewayUsable(gatewayId, orgPermission);+ }+const existing = await gitHubAppDAL.findOne({orgId: orgPermission.orgId,projectId: projectId ?? null,@@ -386,6 +428,7 @@ export const gitHubAppServiceFactory = ({instanceType,githubOrg: githubOrg ?? "",githubHost: githubHost ?? "",+ gatewayId: gatewayId ?? null,installState} satisfies TGitHubManifestStatePayload,AUTH_SECRET,@@ -447,6 +490,7 @@ export const gitHubAppServiceFactory = ({instanceType,githubOrg,githubHost,+ gatewayId = null,installState} = statePayload;@@ -503,23 +547,40 @@ export const gitHubAppServiceFactory = ({const apiBaseUrl = await getGitHubInstanceApiUrl({credentials: { host: githubHost || undefined, instanceType }});- const { data } = await safeRequest.post<TGitHubAppManifestResponse>(- `https://${apiBaseUrl}/app-manifests/${encodeURIComponent(code)}/conversions`,- {},- {- headers: {- Accept: "application/vnd.github+json",- "X-GitHub-Api-Version": "2022-11-28"- }++ const requestConfig: AxiosRequestConfig & { url: string } = {+ url: `https://${apiBaseUrl}/app-manifests/${encodeURIComponent(code)}/conversions`,+ method: "POST",+ data: {},+ headers: {+ Accept: "application/vnd.github+json",+ "X-GitHub-Api-Version": "2022-11-28"}- );+ };++ const { data } = gatewayId+ ? await requestWithGitHubGateway<TGitHubAppManifestResponse>(+ { gatewayId },+ gatewayService,+ gatewayV2Service,+ requestConfig,+ await getGitHubGatewayConnectionDetails(gatewayId, apiBaseUrl, gatewayV2Service)+ )+ : await safeRequest.request<TGitHubAppManifestResponse>(requestConfig);manifestResponse = data;} catch (err) {logger.error(- { ...sanitizeGitHubAxiosError(err), orgId, projectId, instanceType, host: githubHost || "github.com" },+ {+ ...sanitizeGitHubAxiosError(err),+ orgId,+ projectId,+ instanceType,+ host: githubHost || "github.com",+ gatewayId+ },`Failed to exchange GitHub App manifest code [orgId=${orgId}] [projectId=${projectId ?? "null"- }] [instanceType=${instanceType}] [host=${githubHost || "github.com"}]`+ }] [instanceType=${instanceType}] [host=${githubHost || "github.com"}] [gatewayId=${gatewayId ?? "null"}]`);throw new BadRequestError({message:diff --git a/backend/src/services/github-app/github-app-types.ts b/backend/src/services/github-app/github-app-types.tsindex 4b4f1170ff..622c4a3e02 100644--- a/backend/src/services/github-app/github-app-types.ts+++ b/backend/src/services/github-app/github-app-types.ts@@ -10,6 +10,7 @@ export type TInitiateGitHubManifestDTO = {githubHost?: string;installState: string;projectId?: string;+ gatewayId?: string;orgPermission: OrgServiceActor;};@@ -24,6 +25,7 @@ export type TGitHubManifestStatePayload = {instanceType: "cloud" | "server";githubOrg: string;githubHost: string;+ gatewayId: string | null;installState: string;};diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsxindex f5671965a7..c195a5e387 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx@@ -284,7 +284,8 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: ProgithubOrg: githubOrg || undefined,githubHost: formData.credentials?.host || undefined,installState,- projectId: projectId || undefined+ projectId: projectId || undefined,+ gatewayId: formData.gatewayId || undefined});const formEl = document.createElement("form");