Skip to content

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

manage project level git hub apps

Thiago Araujo da Silvab6b87c087a42
diff --git a/backend/src/db/migrations/20260529204743_create-github-apps.ts b/backend/src/db/migrations/20260529204743_create-github-apps.ts
index db0ea8fca9..81969ea298 100644
--- a/backend/src/db/migrations/20260529204743_create-github-apps.ts
+++ b/backend/src/db/migrations/20260529204743_create-github-apps.ts
@@ -3,6 +3,8 @@ import { Knex } from "knex";
import { TableName } from "@app/db/schemas";
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "@app/db/utils";
+const UNIQUE_NAME_ORG_GITHUB_APP_INDEX = "unique_name_org_github_app";
+
export async function up(knex: Knex): Promise<void> {
if (!(await knex.schema.hasTable(TableName.GitHubApp))) {
await knex.schema.createTable(TableName.GitHubApp, (t) => {
@@ -18,10 +20,19 @@ export async function up(knex: Knex): Promise<void> {
t.string("owner").nullable();
t.string("host").nullable();
t.string("instanceType").notNullable().defaultTo("cloud");
+ t.string("projectId").nullable();
+ t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
t.timestamps(true, true, true);
- t.unique(["orgId", "name"]);
+ t.unique(["orgId", "projectId", "name"]);
});
+ // unique name for org-level apps
+ await knex.raw(`
+ CREATE UNIQUE INDEX ${UNIQUE_NAME_ORG_GITHUB_APP_INDEX}
+ ON ${TableName.GitHubApp} ("orgId", "name")
+ WHERE "projectId" IS NULL
+ `);
+
await createOnUpdateTrigger(knex, TableName.GitHubApp);
}
}
diff --git a/backend/src/db/schemas/github-apps.ts b/backend/src/db/schemas/github-apps.ts
index 82616f6463..84fe0be85f 100644
--- a/backend/src/db/schemas/github-apps.ts
+++ b/backend/src/db/schemas/github-apps.ts
@@ -21,6 +21,7 @@ export const GithubAppsSchema = z.object({
owner: z.string().nullable().optional(),
host: z.string().nullable().optional(),
instanceType: z.string().default("cloud"),
+ projectId: z.string().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date()
});
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 2efbfcfcaf..faea68bbaa 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -4484,6 +4484,7 @@ interface CreateGitHubAppEvent {
owner?: string | null;
host?: string | null;
instanceType: string;
+ projectId?: string | null;
};
}
@@ -4494,6 +4495,7 @@ interface DeleteGitHubAppEvent {
name: string;
appId: string;
slug: string;
+ projectId?: string | null;
};
}
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 9eaf0399dc..9016f89a70 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -89,7 +89,8 @@ export const KeyStorePrefixes = {
UsedTotpCode: (userId: string, code: string) => `used-totp-code:${userId}:${code}` as const,
UsedAccountRecoveryToken: (userId: string, jti: string) => `used-account-recovery-token:${userId}:${jti}` as const,
UsedGitHubManifestState: (jti: string) => `used-github-manifest-state:${jti}` as const,
- GitHubManifestNameLock: (orgId: string, name: string) => `github-manifest-name-lock:${orgId}:${name}` as const,
+ GitHubManifestNameLock: (orgId: string, projectId: string | null, name: string) =>
+ `github-manifest-name-lock:${orgId}:${projectId ?? "org"}:${name}` as const,
UsedGitHubInstallationsToken: (jti: string) => `used-github-installations-token:${jti}` as const,
AiMcpServerOAuth: (sessionId: string) => `ai-mcp-server-oauth:${sessionId}` as const,
diff --git a/backend/src/server/routes/v1/github-app-router.ts b/backend/src/server/routes/v1/github-app-router.ts
index 8fd925a3f0..83c1bd32c6 100644
--- a/backend/src/server/routes/v1/github-app-router.ts
+++ b/backend/src/server/routes/v1/github-app-router.ts
@@ -20,7 +20,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
instanceType: z.enum(["cloud", "server"]).default("cloud"),
githubOrg: z.string().trim().optional(),
githubHost: z.string().trim().optional(),
- installState: z.string().trim().min(1)
+ installState: z.string().trim().min(1),
+ projectId: z.string().trim().optional()
}),
response: {
200: z.object({
@@ -37,7 +38,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
instanceType: req.body.instanceType,
githubOrg: req.body.githubOrg,
githubHost: req.body.githubHost,
- installState: req.body.installState
+ installState: req.body.installState,
+ projectId: req.body.projectId
});
return result;
@@ -79,6 +81,9 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
schema: {
+ querystring: z.object({
+ projectId: z.string().trim().optional()
+ }),
response: {
200: z.object({
gitHubApps: SanitizedGitHubAppSchema.array()
@@ -87,7 +92,8 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
},
handler: async (req) => {
const gitHubApps = await server.services.gitHubApp.listGitHubApps({
- orgPermission: req.permission
+ orgPermission: req.permission,
+ projectId: req.query.projectId
});
return { gitHubApps };
@@ -164,13 +170,15 @@ export const registerGitHubAppRouter = async (server: FastifyZodProvider) => {
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
+ ...(gitHubApp.projectId ? { projectId: gitHubApp.projectId } : {}),
event: {
type: EventType.DELETE_GITHUB_APP,
metadata: {
gitHubAppId: req.params.id,
name: gitHubApp.name,
appId: gitHubApp.appId,
- slug: gitHubApp.slug
+ slug: gitHubApp.slug,
+ projectId: gitHubApp.projectId
}
}
});
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 cbe7c3609b..e5b6b94ac5 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.ts
@@ -42,25 +42,30 @@ type TResolvedGitHubAppCredentials = {
export const resolveGitHubAppCredentials = async (
{
gitHubAppId,
- orgId
+ orgId,
+ projectId
}: {
gitHubAppId?: string | null;
orgId: string;
+ projectId?: string | null;
},
{ gitHubAppDAL, kmsService }: TGitHubAppCredentialResolverDeps
): Promise<TResolvedGitHubAppCredentials> => {
if (gitHubAppId) {
const app = await gitHubAppDAL.findOne({ id: gitHubAppId, orgId });
- if (!app) {
+ if (!app || (projectId !== undefined && app.projectId && app.projectId !== projectId)) {
throw new BadRequestError({
- message: `GitHub App with id ${gitHubAppId} not found in this organization.`
+ message: `GitHub App with id ${gitHubAppId} not found in this ${projectId ? "project" : "organization"}.`
});
}
- const { decryptor } = await kmsService.createCipherPairWithDataKey({
- type: KmsDataKey.Organization,
- orgId
- });
+ // Project-scoped apps are encrypted with the project's data key, org-scoped apps with the
+ // org's, mirroring how app connection credentials are encrypted per scope.
+ const { decryptor } = await kmsService.createCipherPairWithDataKey(
+ app.projectId
+ ? { type: KmsDataKey.SecretManager, projectId: app.projectId }
+ : { type: KmsDataKey.Organization, orgId }
+ );
return {
appId: app.appId,
@@ -345,7 +350,11 @@ export const getGitHubAppAuthToken = async (
host: appHost,
instanceType: appInstanceType
} = await resolveGitHubAppCredentials(
- { gitHubAppId: appConnection.credentials.gitHubAppId, orgId: appConnection.orgId },
+ {
+ gitHubAppId: appConnection.credentials.gitHubAppId,
+ orgId: appConnection.orgId,
+ projectId: appConnection.projectId ?? null
+ },
deps
);
@@ -734,7 +743,7 @@ export const validateGitHubConnectionCredentials = async (
let resolvedAppCredentials: TResolvedGitHubAppCredentials | undefined;
if (method === GitHubConnectionMethod.App) {
resolvedAppCredentials = await resolveGitHubAppCredentials(
- { gitHubAppId: credentials.gitHubAppId, orgId: config.orgId },
+ { gitHubAppId: credentials.gitHubAppId, orgId: config.orgId, projectId: config.projectId ?? null },
deps
);
diff --git a/backend/src/services/app-connection/github/github-connection-types.ts b/backend/src/services/app-connection/github/github-connection-types.ts
index 31c9b1b9c0..bdb7dff309 100644
--- a/backend/src/services/app-connection/github/github-connection-types.ts
+++ b/backend/src/services/app-connection/github/github-connection-types.ts
@@ -20,4 +20,4 @@ export type TValidateGitHubConnectionCredentialsSchema = typeof ValidateGitHubCo
export type TGitHubConnectionConfig = DiscriminativePick<
TGitHubConnectionInput,
"method" | "app" | "credentials" | "gatewayId" | "gatewayPoolId"
-> & { orgId: string };
+> & { orgId: string; projectId?: string | null };
diff --git a/backend/src/services/github-app/github-app-dal.ts b/backend/src/services/github-app/github-app-dal.ts
index 280473f44b..463c6a7939 100644
--- a/backend/src/services/github-app/github-app-dal.ts
+++ b/backend/src/services/github-app/github-app-dal.ts
@@ -33,6 +33,8 @@ export const gitHubAppDALFactory = (db: TDbClient) => {
// Returns connection counts per GitHub App for the org, keyed by app id. The null key counts
// GitHub App method connections with no link row, i.e. those using the instance-default app.
+ // Counts are org-wide: org apps are usable from any project, so an app's usage (and its delete
+ // protection) spans every scope in the org.
const countConnectionsPerApp = async (orgId: string, tx?: Knex) => {
const linkedRows = (await (tx || db.replicaNode())(TableName.GitHubAppConnection)
.join(
diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.ts
index ea1816fde8..a1a668889f 100644
--- a/backend/src/services/github-app/github-app-service.ts
+++ b/backend/src/services/github-app/github-app-service.ts
@@ -86,28 +86,64 @@ export const gitHubAppServiceFactory = ({
auditLogService,
userDAL
}: TGitHubAppServiceFactoryDep) => {
- const listGitHubApps = async ({ orgPermission }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {
- const { permission } = await permissionService.getOrgPermission({
- actor: orgPermission.type,
- actorId: orgPermission.id,
- orgId: orgPermission.orgId,
- actorAuthMethod: orgPermission.authMethod,
- actorOrgId: orgPermission.orgId,
- scope: OrganizationActionScope.Any
- });
+ const checkAppConnectionPermission = async ({
+ actor,
+ projectId,
+ orgAction,
+ projectAction,
+ orgScope
+ }: {
+ actor: { type: ActorType; id: string; orgId: string; authMethod: ActorAuthMethod };
+ projectId: string | null | undefined;
+ orgAction: OrgPermissionAppConnectionActions;
+ projectAction: ProjectPermissionAppConnectionActions;
+ orgScope: OrganizationActionScope;
+ }) => {
+ if (projectId) {
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ projectId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId,
+ actionProjectType: ActionProjectType.Any
+ });
- ForbiddenError.from(permission).throwUnlessCan(
- OrgPermissionAppConnectionActions.Read,
- OrgPermissionSubjects.AppConnections
- );
+ ForbiddenError.from(permission).throwUnlessCan(projectAction, ProjectPermissionSub.AppConnections);
+ } else {
+ const { permission } = await permissionService.getOrgPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId,
+ scope: orgScope
+ });
- const apps = await gitHubAppDAL.find({ orgId: orgPermission.orgId });
+ ForbiddenError.from(permission).throwUnlessCan(orgAction, OrgPermissionSubjects.AppConnections);
+ }
+ };
+
+ const listGitHubApps = async ({ orgPermission, projectId }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {
+ await checkAppConnectionPermission({
+ actor: orgPermission,
+ projectId,
+ orgAction: OrgPermissionAppConnectionActions.Read,
+ projectAction: ProjectPermissionAppConnectionActions.Read,
+ orgScope: OrganizationActionScope.Any
+ });
+
+ // Org apps are visible from project scope too, but not the other way around.
+ const orgApps = await gitHubAppDAL.find({ orgId: orgPermission.orgId, projectId: null });
+ const projectApps = projectId ? await gitHubAppDAL.find({ orgId: orgPermission.orgId, projectId }) : [];
+ const apps = [...orgApps, ...projectApps];
const countByAppId = await gitHubAppDAL.countConnectionsPerApp(orgPermission.orgId);
const dbApps: TSanitizedGitHubApp[] = apps.map((app) => ({
id: app.id,
orgId: app.orgId,
+ projectId: app.projectId ?? null,
name: app.name,
appId: app.appId,
slug: app.slug,
@@ -129,6 +165,7 @@ export const gitHubAppServiceFactory = ({
? {
id: null,
orgId: orgPermission.orgId,
+ projectId: null,
name: INF_APP_CONNECTION_GITHUB_APP_SLUG,
appId: INF_APP_CONNECTION_GITHUB_APP_ID,
slug: INF_APP_CONNECTION_GITHUB_APP_SLUG,
@@ -200,19 +237,18 @@ export const gitHubAppServiceFactory = ({
};
const deleteGitHubApp = async ({ id, orgPermission }: TDeleteGitHubAppDTO): Promise<TSanitizedGitHubApp> => {
- const { permission } = await permissionService.getOrgPermission({
- actor: orgPermission.type,
- actorId: orgPermission.id,
- orgId: orgPermission.orgId,
- actorAuthMethod: orgPermission.authMethod,
- actorOrgId: orgPermission.orgId,
- scope: OrganizationActionScope.ParentOrganization
- });
+ const app = await gitHubAppDAL.findOne({ id, orgId: orgPermission.orgId });
+ if (!app) {
+ throw new NotFoundError({ message: `GitHub App with id ${id} not found in this organization.` });
+ }
- ForbiddenError.from(permission).throwUnlessCan(
- OrgPermissionAppConnectionActions.Delete,
- OrgPermissionSubjects.AppConnections
- );
+ await checkAppConnectionPermission({
+ actor: orgPermission,
+ projectId: app.projectId,
+ orgAction: OrgPermissionAppConnectionActions.Delete,
+ projectAction: ProjectPermissionAppConnectionActions.Delete,
+ orgScope: OrganizationActionScope.ParentOrganization
+ });
// Resolve credentials up front — once the row is deleted the private key is gone and we can no
// longer sign the app JWT needed to uninstall the app's installations on GitHub.
@@ -247,6 +283,7 @@ export const gitHubAppServiceFactory = ({
const result: TSanitizedGitHubApp = {
id: existing.id,
orgId: existing.orgId,
+ projectId: existing.projectId ?? null,
name: existing.name,
appId: existing.appId,
slug: existing.slug,
@@ -291,28 +328,27 @@ export const gitHubAppServiceFactory = ({
githubOrg,
githubHost,
installState,
+ projectId,
orgPermission
}: TInitiateGitHubManifestDTO) => {
- const { permission } = await permissionService.getOrgPermission({
- actor: orgPermission.type,
- actorId: orgPermission.id,
- orgId: orgPermission.orgId,
- actorAuthMethod: orgPermission.authMethod,
- actorOrgId: orgPermission.orgId,
- scope: OrganizationActionScope.ParentOrganization
+ await checkAppConnectionPermission({
+ actor: orgPermission,
+ projectId,
+ orgAction: OrgPermissionAppConnectionActions.Create,
+ projectAction: ProjectPermissionAppConnectionActions.Create,
+ orgScope: OrganizationActionScope.ParentOrganization
});
- ForbiddenError.from(permission).throwUnlessCan(
- OrgPermissionAppConnectionActions.Create,
- OrgPermissionSubjects.AppConnections
- );
-
assertPlatformGitHubHostAllowed(githubHost);
- const existing = await gitHubAppDAL.findOne({ orgId: orgPermission.orgId, name });
+ const existing = await gitHubAppDAL.findOne({
+ orgId: orgPermission.orgId,
+ projectId: projectId ?? null,
+ name
+ });
if (existing) {
throw new BadRequestError({
- message: `A GitHub App with name "${name}" already exists in this organization.`
+ message: `A GitHub App with name "${name}" already exists in this ${projectId ? "project" : "organization"}.`
});
}
@@ -328,6 +364,7 @@ export const gitHubAppServiceFactory = ({
{
jti: crypto.nativeCrypto.randomUUID(),
orgId: orgPermission.orgId,
+ projectId: projectId ?? null,
actorId: orgPermission.id,
actorType: orgPermission.type,
authMethod: orgPermission.authMethod,
@@ -384,8 +421,20 @@ export const gitHubAppServiceFactory = ({
throw new BadRequestError({ message: "Invalid or expired GitHub manifest state. Please try again." });
}
- const { jti, exp, orgId, actorId, actorType, authMethod, name, instanceType, githubOrg, githubHost, installState } =
- statePayload;
+ const {
+ jti,
+ exp,
+ orgId,
+ projectId = null,
+ actorId,
+ actorType,
+ authMethod,
+ name,
+ instanceType,
+ githubOrg,
+ githubHost,
+ installState
+ } = statePayload;
if (!jti) {
throw new BadRequestError({ message: "Invalid or expired GitHub manifest state. Please try again." });
@@ -402,34 +451,35 @@ export const gitHubAppServiceFactory = ({
let created: Awaited<ReturnType<typeof gitHubAppDAL.create>>;
let codeExchanged = false;
try {
- const { permission } = await permissionService.getOrgPermission({
- actor: actorType as ActorType,
- actorId,
- orgId,
- actorAuthMethod: authMethod as ActorAuthMethod,
- actorOrgId: orgId,
- scope: OrganizationActionScope.ParentOrganization
+ await checkAppConnectionPermission({
+ actor: {
+ type: actorType as ActorType,
+ id: actorId,
+ orgId,
+ authMethod: authMethod as ActorAuthMethod
+ },
+ projectId,
+ orgAction: OrgPermissionAppConnectionActions.Create,
+ projectAction: ProjectPermissionAppConnectionActions.Create,
+ orgScope: OrganizationActionScope.ParentOrganization
});
- ForbiddenError.from(permission).throwUnlessCan(
- OrgPermissionAppConnectionActions.Create,
- OrgPermissionSubjects.AppConnections
- );
-
- const existingByName = await gitHubAppDAL.findOne({ orgId, name });
+ const existingByName = await gitHubAppDAL.findOne({ orgId, projectId, name });
if (existingByName) {
throw new BadRequestError({
- message: `A GitHub App with name "${name}" already exists in this organization.`
+ message: `A GitHub App with name "${name}" already exists in this ${projectId ? "project" : "organization"}.`
});
}
assertPlatformGitHubHostAllowed(githubHost);
- const nameLockKey = KeyStorePrefixes.GitHubManifestNameLock(orgId, name);
+ const nameLockKey = KeyStorePrefixes.GitHubManifestNameLock(orgId, projectId, name);
const nameLockClaimed = await keyStore.setItemWithExpiryNX(nameLockKey, 60, "1");
if (!nameLockClaimed) {
throw new BadRequestError({
- message: `A GitHub App with name "${name}" is already being registered in this organization.`
+ message: `A GitHub App with name "${name}" is already being registered in this ${
+ projectId ? "project" : "organization"
+ }.`
});
}
@@ -458,16 +508,16 @@ export const gitHubAppServiceFactory = ({
}
codeExchanged = true;
- const { encryptor } = await kmsService.createCipherPairWithDataKey({
- type: KmsDataKey.Organization,
- orgId
- });
+ const { encryptor } = await kmsService.createCipherPairWithDataKey(
+ projectId ? { type: KmsDataKey.SecretManager, projectId } : { type: KmsDataKey.Organization, orgId }
+ );
const owner = manifestResponse.owner?.login ?? (githubOrg || null);
try {
created = await gitHubAppDAL.create({
orgId,
+ projectId,
name,
appId: String(manifestResponse.id),
clientId: manifestResponse.client_id,
@@ -488,7 +538,9 @@ export const gitHubAppServiceFactory = ({
(err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation
) {
throw new BadRequestError({
- message: `A GitHub App with name "${name}" already exists in this organization. Note: a duplicate app was still created on GitHub (${manifestResponse.html_url}) — please delete it from your GitHub app settings.`
+ message: `A GitHub App with name "${name}" already exists in this ${
+ projectId ? "project" : "organization"
+ }. Note: a duplicate app was still created on GitHub (${manifestResponse.html_url}) — please delete it from your GitHub app settings.`
});
}
throw err;
@@ -509,6 +561,7 @@ export const gitHubAppServiceFactory = ({
await auditLogService.createAuditLog({
...auditLogInfo,
orgId,
+ ...(projectId ? { projectId } : {}),
actor: actorUser
? {
type: ActorType.USER,
@@ -532,7 +585,8 @@ export const gitHubAppServiceFactory = ({
slug: created.slug,
owner: created.owner,
host: created.host,
- instanceType
+ instanceType,
+ projectId
}
}
});
@@ -625,7 +679,7 @@ export const gitHubAppServiceFactory = ({
host: appHost,
instanceType: appInstanceType
} = await resolveGitHubAppCredentials(
- { gitHubAppId: gitHubAppId ?? null, orgId: orgPermission.orgId },
+ { gitHubAppId: gitHubAppId ?? null, orgId: orgPermission.orgId, projectId: projectId ?? null },
{
gitHubAppDAL,
kmsService
diff --git a/backend/src/services/github-app/github-app-types.ts b/backend/src/services/github-app/github-app-types.ts
index 72f966e707..4b4f1170ff 100644
--- a/backend/src/services/github-app/github-app-types.ts
+++ b/backend/src/services/github-app/github-app-types.ts
@@ -9,12 +9,14 @@ export type TInitiateGitHubManifestDTO = {
githubOrg?: string;
githubHost?: string;
installState: string;
+ projectId?: string;
orgPermission: OrgServiceActor;
};
export type TGitHubManifestStatePayload = {
jti: string;
orgId: string;
+ projectId: string | null;
actorId: string;
actorType: string;
authMethod: string | null;
@@ -32,6 +34,7 @@ export type THandleManifestCallbackDTO = {
};
export type TListGitHubAppsDTO = {
+ projectId?: string;
orgPermission: OrgServiceActor;
};
@@ -71,6 +74,7 @@ export type TGitHubAppManifestResponse = {
export const SanitizedGitHubAppSchema = z.object({
id: z.string().uuid().nullable(),
orgId: z.string().uuid(),
+ projectId: z.string().nullable(),
name: z.string(),
appId: z.string(),
slug: z.string(),
diff --git a/docs/integrations/app-connections/github.mdx b/docs/integrations/app-connections/github.mdx
index b1a635414a..adc8f105b3 100644
--- a/docs/integrations/app-connections/github.mdx
+++ b/docs/integrations/app-connections/github.mdx
@@ -104,6 +104,10 @@ Infisical supports three methods for connecting to GitHub.
- **Shared app** — the instance-default GitHub App configured by your Infisical admin.
- **Org-managed app** — a GitHub App registered under your GitHub organization. Select an existing one from the list, or click **Create new GitHub App** to register a new app directly from Infisical via GitHub's app manifest flow. The new app will be automatically configured with the correct permissions and callback URLs.
+ <Note>
+ GitHub Apps are scoped to where they were created: apps created from the organization's App Connections page are available to organization-level connections and to every project, while apps created from a project's App Connections page are only available within that project. The shared instance-default app is available in both scopes.
+ </Note>
+
You may optionally enable **GitHub Enterprise** to configure enterprise-specific options:
- **Instance Type:** Enterprise Cloud or Enterprise Server
- **Instance Hostname:** The hostname of your GitHub Enterprise instance (e.g. `github.mycompany.com`)
diff --git a/frontend/src/hooks/api/gitHubApps/queries.tsx b/frontend/src/hooks/api/gitHubApps/queries.tsx
index 2a7ff28f52..44d1f03f9d 100644
--- a/frontend/src/hooks/api/gitHubApps/queries.tsx
+++ b/frontend/src/hooks/api/gitHubApps/queries.tsx
@@ -6,11 +6,14 @@ import { TGitHubApp, TGitHubAppInstallation } from "./types";
export const gitHubAppKeys = {
all: ["github-apps"] as const,
- list: (orgId?: string) => [...gitHubAppKeys.all, "list", orgId] as const
+ list: (orgId?: string, projectId?: string | null) =>
+ [...gitHubAppKeys.all, "list", orgId, projectId ?? null] as const
};
-const fetchGitHubApps = async () => {
- const { data } = await apiRequest.get<{ gitHubApps: TGitHubApp[] }>("/api/v1/github-apps");
+const fetchGitHubApps = async (projectId?: string) => {
+ const { data } = await apiRequest.get<{ gitHubApps: TGitHubApp[] }>("/api/v1/github-apps", {
+ params: projectId ? { projectId } : undefined
+ });
return data.gitHubApps;
};
@@ -29,10 +32,10 @@ export const resolveGitHubAppInstallations = async (params: {
return data;
};
-export const useListGitHubApps = (orgId?: string) =>
+export const useListGitHubApps = (orgId?: string, projectId?: string | null) =>
useQuery({
- queryKey: gitHubAppKeys.list(orgId),
- queryFn: fetchGitHubApps,
+ queryKey: gitHubAppKeys.list(orgId, projectId),
+ queryFn: () => fetchGitHubApps(projectId ?? undefined),
enabled: Boolean(orgId),
retry: false
});
diff --git a/frontend/src/hooks/api/gitHubApps/types.ts b/frontend/src/hooks/api/gitHubApps/types.ts
index 6f70e2d171..f684dc6eca 100644
--- a/frontend/src/hooks/api/gitHubApps/types.ts
+++ b/frontend/src/hooks/api/gitHubApps/types.ts
@@ -1,6 +1,7 @@
export type TGitHubApp = {
id: string | null;
orgId: string;
+ projectId: string | null;
name: string;
appId: string;
slug: string;
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx
index dee7e87b0c..6afbbe6e0e 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx
@@ -37,10 +37,9 @@ type Props = {
onChange: (app: TGitHubApp | null) => void;
host?: string;
instanceType?: "cloud" | "server";
- // Kicks off the GitHub App manifest creation flow on the parent form (redirects to GitHub).
- // Returns false when the parent form is invalid so we can return to the list view.
onCreateApp: (params: { name: string; githubOrg: string }) => Promise<boolean> | void;
isCreating?: boolean;
+ projectId?: string | null;
};
export const GitHubAppSelector = ({
@@ -51,7 +50,8 @@ export const GitHubAppSelector = ({
host,
instanceType,
onCreateApp,
- isCreating
+ isCreating,
+ projectId
}: Props) => {
const [mode, setMode] = useState<"list" | "create">("list");
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
@@ -77,6 +77,8 @@ export const GitHubAppSelector = ({
const sharedApp = apps.find((app) => app.id === null) ?? null;
const customApps = apps.filter((app) => app.id !== null);
+ const projectApps = customApps.filter((app) => app.projectId !== null);
+ const orgApps = customApps.filter((app) => app.projectId === null);
const resetCreate = () => {
switchMode("list");
@@ -116,7 +118,7 @@ export const GitHubAppSelector = ({
}
};
- const renderCustomAppRow = (app: TGitHubApp) => {
+ const renderCustomAppRow = (app: TGitHubApp, canDelete: boolean) => {
const isInUse = app.connectionCount > 0;
if (deleteTargetId === app.id) {
@@ -191,7 +193,7 @@ export const GitHubAppSelector = ({
>
<FontAwesomeIcon icon={faArrowUpRightFromSquare} className="text-xs" />
</button>
- {isInUse ? (
+ {isInUse || !canDelete ? (
<Tooltip>
<TooltipTrigger asChild>
{/* Native disabled buttons don't fire pointer events, so the tooltip
@@ -208,8 +210,14 @@ export const GitHubAppSelector = ({
</span>
</TooltipTrigger>
<TooltipContent>
- Remove the connection{app.connectionCount === 1 ? "" : "s"} before deleting this
- app.
+ {canDelete ? (
+ <>
+ Remove the connection{app.connectionCount === 1 ? "" : "s"} before deleting this
+ app.
+ </>
+ ) : (
+ "Organization apps can only be deleted from the organization's App Connections page."
+ )}
</TooltipContent>
</Tooltip>
) : (
@@ -351,29 +359,45 @@ export const GitHubAppSelector = ({
<CommandGroup
heading={
<span className="flex items-center gap-2">
- CUSTOM APPS
- {customApps.length > 0 && (
+ {projectId ? "PROJECT APPS" : "CUSTOM APPS"}
+ {(projectId ? projectApps : customApps).length > 0 && (
<span className="rounded-full bg-mineshaft-600 px-1.5 text-[10px] text-mineshaft-200">
- {customApps.length}
+ {(projectId ? projectApps : customApps).length}
</span>
)}
</span>
}
>
- {customApps.length === 0 && !isLoading ? (
+ {(projectId ? projectApps : customApps).length === 0 && !isLoading ? (
<div className="flex flex-col items-center gap-2 px-4 py-6 text-center">
<div className="flex h-12 w-12 items-center justify-center rounded-md bg-mineshaft-600 text-xl text-mineshaft-300">
<FontAwesomeIcon icon={faGithub} />
</div>
- <p className="text-sm font-medium text-mineshaft-100">No custom apps yet</p>
+ <p className="text-sm font-medium text-mineshaft-100">
+ No {projectId ? "project" : "custom"} apps yet
+ </p>
<p className="max-w-[260px] text-xs leading-relaxed text-mineshaft-400">
Create a dedicated GitHub App for tighter, per-team permission scoping.
</p>
</div>
) : (
- customApps.map((app) => renderCustomAppRow(app))
+ (projectId ? projectApps : customApps).map((app) => renderCustomAppRow(app, true))
)}
</CommandGroup>
+ {Boolean(projectId) && orgApps.length > 0 && (
+ <CommandGroup
+ heading={
+ <span className="flex items-center gap-2">
+ ORGANIZATION APPS
+ <span className="rounded-full bg-mineshaft-600 px-1.5 text-[10px] text-mineshaft-200">
+ {orgApps.length}
+ </span>
+ </span>
+ }
+ >
+ {orgApps.map((app) => renderCustomAppRow(app, false))}
+ </CommandGroup>
+ )}
</CommandList>
</Command>
<button
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 d6f5dfd8ce..3780ddaecb 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
@@ -125,7 +125,8 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
} = useGetAppConnectionOption(AppConnection.GitHub);
const { data: gitHubApps = [], isPending: isGitHubAppsLoading } = useListGitHubApps(
- currentOrg?.id
+ currentOrg?.id,
+ projectId
);
const form = useForm<FormData>({
@@ -273,7 +274,8 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
instanceType: formData.credentials?.instanceType ?? "cloud",
githubOrg: githubOrg || undefined,
githubHost: formData.credentials?.host || undefined,
- installState
+ installState,
+ projectId: projectId || undefined
});
const formEl = document.createElement("form");
@@ -521,7 +523,9 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
{selectedMethod === GitHubConnectionMethod.App && !isUpdate && (
<FormControl
label="GitHub App"
- tooltipText="Reuse an existing GitHub App in your organization or create a new one. Apps can be shared across multiple connections."
+ tooltipText={`Reuse an existing GitHub App from ${
+ projectId ? "this project or your organization" : "your organization"
+ }, or create a new one. Apps can be shared across multiple connections.`}
>
<GitHubAppSelector
apps={gitHubApps}
@@ -532,6 +536,7 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
instanceType={instanceType}
onCreateApp={handleCreateApp}
isCreating={isRedirecting}
+ projectId={projectId}
/>
</FormControl>
)}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
index b4991cff1e..4059352168 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
@@ -112,7 +112,8 @@ export const AppConnectionRow = ({
: null;
const { data: gitHubApps } = useListGitHubApps(
- isGitHubAppConnection ? currentOrg?.id : undefined
+ isGitHubAppConnection ? currentOrg?.id : undefined,
+ appConnection.projectId
);
const linkedGitHubApp = isGitHubAppConnection
diff --git a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
index 88008cb20d..4d81ff23d7 100644
--- a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
+++ b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx
@@ -81,6 +81,12 @@ export const OAuthCallbackPage = () => {
localStorage.removeItem(dataFieldName!);
};
+ const getIntegrationsTab = () => {
+ if (localStorage.getItem("pkiSyncFormData")) return IntegrationsListPageTabs.PkiSyncs;
+ if (localStorage.getItem("secretSyncFormData")) return IntegrationsListPageTabs.SecretSyncs;
+ return IntegrationsListPageTabs.AppConnections;
+ };
+
// Shared post-success step: notify and navigate back to where the connection flow started.
const finalizeConnection = async (data: {
returnUrl: string;
@@ -105,11 +111,7 @@ export const OAuthCallbackPage = () => {
connectionId: data.connection.id,
connectionName: data.connection.name,
...(data.returnUrl.includes("integrations")
- ? {
- selectedTab: localStorage.getItem("pkiSyncFormData")
- ? IntegrationsListPageTabs.PkiSyncs
- : IntegrationsListPageTabs.SecretSyncs
- }
+ ? { selectedTab: getIntegrationsTab() }
: {})
}
});
@@ -445,7 +447,10 @@ export const OAuthCallbackPage = () => {
to: returnUrl,
params: {
projectId
- }
+ },
+ search: returnUrl.includes("integrations")
+ ? { selectedTab: getIntegrationsTab() }
+ : undefined
});
}
return null;
@@ -508,7 +513,10 @@ export const OAuthCallbackPage = () => {
to: returnUrl,
params: {
projectId
- }
+ },
+ search: returnUrl.includes("integrations")
+ ? { selectedTab: getIntegrationsTab() }
+ : undefined
});
return null;
}
@@ -580,7 +588,10 @@ export const OAuthCallbackPage = () => {
to: returnUrl,
params: {
projectId
- }
+ },
+ search: returnUrl.includes("integrations")
+ ? { selectedTab: getIntegrationsTab() }
+ : undefined
});
}
};
@@ -599,7 +610,10 @@ export const OAuthCallbackPage = () => {
to: formData.returnUrl,
params: {
projectId: formData.projectId
- }
+ },
+ search: formData.returnUrl.includes("integrations")
+ ? { selectedTab: getIntegrationsTab() }
+ : undefined
});
return;
}