Skip to content

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

org permissions when using org git hub app

Thiago Araujo da Silvaced3b050a1e4
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.ts
index a5b55ec194..39392df37f 100644
--- a/backend/src/services/app-connection/app-connection-service.ts
+++ b/backend/src/services/app-connection/app-connection-service.ts
@@ -440,6 +440,23 @@ export const appConnectionServiceFactory = ({
return decryptAppConnection(appConnection, kmsService);
};
+ // In project scope, an org-managed GitHub App can only be referenced by actors who can also
+ // connect org-level app connections — everyone else is limited to the project's own apps and
+ // the shared instance app.
+ const checkGitHubAppScopeAccess = async (
+ gitHubAppId: string,
+ orgId: string,
+ orgPermission: Awaited<ReturnType<TPermissionServiceFactory["getOrgPermission"]>>["permission"]
+ ) => {
+ const gitHubApp = await gitHubAppDAL.findOne({ id: gitHubAppId, orgId });
+ if (gitHubApp && !gitHubApp.projectId) {
+ ForbiddenError.from(orgPermission).throwUnlessCan(
+ OrgPermissionAppConnectionActions.Connect,
+ OrgPermissionSubjects.AppConnections
+ );
+ }
+ };
+
const createAppConnection = async (
{
method,
@@ -537,6 +554,13 @@ export const appConnectionServiceFactory = ({
"Failed to create app connection due to plan restriction. Upgrade plan to access enterprise app connections."
);
+ if (app === AppConnection.GitHub && method === GitHubConnectionMethod.App && projectId) {
+ const { gitHubAppId } = credentials as { gitHubAppId?: string | null };
+ if (gitHubAppId) {
+ await checkGitHubAppScopeAccess(gitHubAppId, actor.orgId, orgPermission);
+ }
+ }
+
const validatedCredentials = await validateAppConnectionCredentials(
{
app,
@@ -784,6 +808,15 @@ export const appConnectionServiceFactory = ({
validationGatewayId = picked.id;
}
+ // Only checked when the caller explicitly selects an app — merged-in existing credentials
+ // (gitHubAppId undefined) keep already-configured connections editable.
+ if (app === AppConnection.GitHub && method === GitHubConnectionMethod.App && appConnection.projectId) {
+ const requestedGitHubAppId = (credentials as { gitHubAppId?: string | null }).gitHubAppId;
+ if (requestedGitHubAppId) {
+ await checkGitHubAppScopeAccess(requestedGitHubAppId, actor.orgId, orgPermission);
+ }
+ }
+
let credentialsToValidate = credentials;
if (
diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.ts
index 49dae3ca22..82a5c6373d 100644
--- a/backend/src/services/github-app/github-app-service.ts
+++ b/backend/src/services/github-app/github-app-service.ts
@@ -135,8 +135,20 @@ export const gitHubAppServiceFactory = ({
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 });
+ let includeOrgApps = true;
+ if (projectId) {
+ const { permission } = await permissionService.getOrgPermission({
+ actor: orgPermission.type,
+ actorId: orgPermission.id,
+ orgId: orgPermission.orgId,
+ actorAuthMethod: orgPermission.authMethod,
+ actorOrgId: orgPermission.orgId,
+ scope: OrganizationActionScope.Any
+ });
+ includeOrgApps = permission.can(OrgPermissionAppConnectionActions.Read, OrgPermissionSubjects.AppConnections);
+ }
+
+ const orgApps = includeOrgApps ? await gitHubAppDAL.find({ orgId: orgPermission.orgId, projectId: null }) : [];
const projectApps = projectId ? await gitHubAppDAL.find({ orgId: orgPermission.orgId, projectId }) : [];
const apps = [...orgApps, ...projectApps];
@@ -644,6 +656,16 @@ export const gitHubAppServiceFactory = ({
ProjectPermissionAppConnectionActions.Create,
ProjectPermissionSub.AppConnections
);
+
+ if (gitHubAppId) {
+ const app = await gitHubAppDAL.findOne({ id: gitHubAppId, orgId: orgPermission.orgId });
+ if (app && !app.projectId) {
+ ForbiddenError.from(orgScopedPermission).throwUnlessCan(
+ OrgPermissionAppConnectionActions.Connect,
+ OrgPermissionSubjects.AppConnections
+ );
+ }
+ }
} else {
ForbiddenError.from(orgScopedPermission).throwUnlessCan(
OrgPermissionAppConnectionActions.Create,
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 ba09c7f57a..f29f6d7cbd 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubAppSelector.tsx
@@ -52,8 +52,9 @@ type Props = {
// 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;
- // When set, the selector is in project scope: org apps are listed (and selectable) but managed
- // from the organization's App Connections page, and newly created apps are project-scoped.
+ // When set, the selector is in project scope: org apps are listed (and selectable) only for
+ // users who can read org-level app connections, and are managed from the organization's App
+ // Connections page; newly created apps are project-scoped.
projectId?: string | null;
};
@@ -94,9 +95,9 @@ export const GitHubAppSelector = ({
const deleteGitHubApp = useDeleteGitHubApp();
const sharedApp = apps.find((app) => app.id === null) ?? null;
- // In project scope the private list mixes both scopes: the project's own apps plus the org's
- // (projects have visibility over their org, not the other way around). Each row's scope icon
- // tells them apart.
+ // In project scope the private list can mix both scopes: the project's own apps plus the org's,
+ // when the user can read org-level app connections (the API filters org apps out otherwise).
+ // Each row's scope icon tells them apart.
const customApps = apps.filter((app) => app.id !== null);
const resetCreate = () => {
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 269195b3c1..f5671965a7 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx
@@ -21,9 +21,10 @@ import {
} from "@app/components/v2";
import { GatewayPicker } from "@app/components/v3/platform/GatewayPicker";
import { apiRequest } from "@app/config/request";
-import { useOrganization, useSubscription } from "@app/context";
+import { useOrganization, useOrgPermission, useSubscription } from "@app/context";
import {
OrgGatewayPermissionActions,
+ OrgPermissionAppConnectionActions,
OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
import {
@@ -118,6 +119,14 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
);
const { currentOrg } = useOrganization();
+ const { permission: orgPermission } = useOrgPermission();
+ // In project scope, org apps are only listed when the user can read org-level app connections
+ // (mirrors the backend filtering on the list endpoint); using one additionally requires the
+ // org-level connect action, enforced server-side.
+ const canSeeOrgApps = orgPermission.can(
+ OrgPermissionAppConnectionActions.Read,
+ OrgPermissionSubjects.AppConnections
+ );
const {
option: { oauthClientId, appClientSlug },
@@ -526,7 +535,12 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro
<FormControl
label="GitHub App"
tooltipText={`Reuse an existing GitHub App from ${
- projectId ? "this project or your organization" : "your organization"
+ // eslint-disable-next-line no-nested-ternary
+ projectId
+ ? canSeeOrgApps
+ ? "this project or your organization"
+ : "this project"
+ : "your organization"
}, or create a new one. Apps can be shared across multiple connections.`}
>
<GitHubAppSelector