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(github): add support for custom GitHub hosts in self-hosted environments
Victor Hugo dos Santosf358829c2566
diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.tsindex e104177575..481b4eac88 100644--- a/backend/src/services/app-connection/github/github-connection-fns.ts+++ b/backend/src/services/app-connection/github/github-connection-fns.ts@@ -49,6 +49,20 @@ export const getGitHubInstanceApiUrl = async (config: {return apiBase;};+export const PLATFORM_GITHUB_CREDENTIAL_HOST = "github.com";++export const assertPlatformGitHubHostAllowed = (host?: string | null) => {+ const { isCloud } = getConfig();+ const normalizedHost = (host || PLATFORM_GITHUB_CREDENTIAL_HOST).trim().toLowerCase();++ if (isCloud && normalizedHost !== PLATFORM_GITHUB_CREDENTIAL_HOST) {+ throw new BadRequestError({+ message:+ "GitHub App and OAuth connections to a custom host (e.g. GitHub Enterprise Server) are only supported on self-hosted Infisical, where you can register your own GitHub App. To use a custom host, self-host Infisical — or use the Personal Access Token method on Infisical Cloud."+ });+ }+};+export const getGitHubGatewayConnectionDetails = async (gatewayId: string,targetHost: string,@@ -198,6 +212,8 @@ export const getGitHubAppAuthToken = async (throw new InternalServerError({ message: "Cannot generate GitHub App token for non-app connection" });}+ assertPlatformGitHubHostAllowed(appConnection.credentials.host);+const now = Math.floor(Date.now() / 1000);const payload = {iat: now,@@ -601,6 +617,8 @@ export const validateGitHubConnectionCredentials = async (let tokenResp: AxiosResponse<GithubTokenRespData>;const host = credentials.host || "github.com";+ assertPlatformGitHubHostAllowed(host);+const oauthGatewayConnectionDetails = config.gatewayId? await getGitHubGatewayConnectionDetails(config.gatewayId, host, gatewayV2Service): undefined;diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsxindex 9e2b3f43db..c3c145a7f0 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx@@ -195,8 +195,28 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Prothrow new Error(`Unhandled GitHub Connection method: ${selectedMethod}`);}+ const customHost = watch("credentials.host")?.trim().toLowerCase();+ const isCloudCustomHostUnsupported =+ isInfisicalCloud() &&+ selectedMethod !== GitHubConnectionMethod.Pat &&+ !!customHost &&+ customHost !== "github.com";+const methodDetails = getAppConnectionMethodDetails(selectedMethod);+ const getMethodErrorText = (fieldError?: { message?: string }) => {+ if (!isLoading && isMissingConfig) {+ const configHint = isInfisicalCloud()+ ? "Please contact Infisical."+ : `See Docs to configure ${methodDetails.name.startsWith("GitHub") ? methodDetails.name : `GitHub ${methodDetails.name}`} Connections.`;+ return `Credentials have not been configured. ${configHint}`;+ }+ if (isCloudCustomHostUnsupported) {+ return "GitHub App/OAuth with a custom host is only supported on self-hosted Infisical.";+ }+ return fieldError?.message;+ };+const getButtonText = () => {if (selectedMethod === GitHubConnectionMethod.Pat) {return isUpdate ? "Update Connection" : "Create Connection";@@ -217,16 +237,8 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: ProtooltipText={`The method you would like to use to connect with ${APP_CONNECTION_MAP[AppConnection.GitHub].name}. This field cannot be changed after creation.`}- errorText={- !isLoading && isMissingConfig- ? `Credentials have not been configured. ${- isInfisicalCloud()- ? "Please contact Infisical."- : `See Docs to configure ${methodDetails.name.startsWith("GitHub") ? methodDetails.name : `GitHub ${methodDetails.name}`} Connections.`- }`- : error?.message- }- isError={Boolean(error?.message) || isMissingConfig}+ errorText={getMethodErrorText(error)}+ isError={Boolean(error?.message) || isMissingConfig || isCloudCustomHostUnsupported}label="Method"><Select@@ -356,7 +368,13 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Protype="submit"colorSchema="secondary"isLoading={isSubmitting || isRedirecting}- isDisabled={isSubmitting || (!isUpdate && !isDirty) || isMissingConfig || isRedirecting}+ isDisabled={+ isSubmitting ||+ (!isUpdate && !isDirty) ||+ isMissingConfig ||+ isRedirecting ||+ isCloudCustomHostUnsupported+ }>{getButtonText()}</Button>