Skip to content

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

a

Carlos Monastyrski66a8176617bf
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index d042d13f89..113f9d53d0 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1507,6 +1507,8 @@ export const registerRoutes = async (
userDAL,
identityDAL,
groupDAL,
+ userGroupMembershipDAL,
+ identityGroupMembershipDAL,
approvalPolicyDAL
});
diff --git a/backend/src/services/pki-application/pki-application-membership-service.ts b/backend/src/services/pki-application/pki-application-membership-service.ts
index 72d37c9430..6a5ac6ba50 100644
--- a/backend/src/services/pki-application/pki-application-membership-service.ts
+++ b/backend/src/services/pki-application/pki-application-membership-service.ts
@@ -3,6 +3,8 @@ import { Knex } from "knex";
import { AccessScope, RESOURCE_SCOPE, ResourceMembershipRole, ResourceType } from "@app/db/schemas";
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
+import { TIdentityGroupMembershipDALFactory } from "@app/ee/services/group/identity-group-membership-dal";
+import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionMemberActions } from "@app/ee/services/permission/project-permission";
import {
@@ -48,6 +50,8 @@ type TPkiApplicationMembershipServiceFactoryDep = {
userDAL: Pick<TUserDALFactory, "find" | "findByEmailsOrUsernames">;
identityDAL: Pick<TIdentityDALFactory, "find">;
groupDAL: Pick<TGroupDALFactory, "find">;
+ userGroupMembershipDAL: Pick<TUserGroupMembershipDALFactory, "find">;
+ identityGroupMembershipDAL: Pick<TIdentityGroupMembershipDALFactory, "find">;
approvalPolicyDAL: Pick<
TApprovalPolicyDALFactory,
"findPoliciesWhereSubjectIsApprover" | "deleteStepApproversBySubject"
@@ -74,8 +78,52 @@ export const pkiApplicationMembershipServiceFactory = ({
userDAL,
identityDAL,
groupDAL,
+ userGroupMembershipDAL,
+ identityGroupMembershipDAL,
approvalPolicyDAL
}: TPkiApplicationMembershipServiceFactoryDep) => {
+ const $projectGroupIds = async (projectId: string, tx?: Knex): Promise<string[]> => {
+ const projectMemberships = await membershipDAL.find(
+ { scope: AccessScope.Project, scopeProjectId: projectId },
+ tx ? { tx } : undefined
+ );
+ return projectMemberships.map((m) => m.actorGroupId).filter((id): id is string => Boolean(id));
+ };
+
+ const $usersWithGroupProjectAccess = async (
+ projectId: string,
+ userIds: string[],
+ tx?: Knex
+ ): Promise<Set<string>> => {
+ if (userIds.length === 0) return new Set();
+ const projectGroupIds = await $projectGroupIds(projectId, tx);
+ if (projectGroupIds.length === 0) return new Set();
+
+ const candidateIds = new Set(userIds);
+ const groupUsers = await userGroupMembershipDAL.find(
+ { $in: { groupId: projectGroupIds } },
+ tx ? { tx } : undefined
+ );
+ return new Set(groupUsers.map((gu) => gu.userId).filter((id) => candidateIds.has(id)));
+ };
+
+ const $identitiesWithGroupProjectAccess = async (
+ projectId: string,
+ identityIds: string[],
+ tx?: Knex
+ ): Promise<Set<string>> => {
+ if (identityIds.length === 0) return new Set();
+ const projectGroupIds = await $projectGroupIds(projectId, tx);
+ if (projectGroupIds.length === 0) return new Set();
+
+ const candidateIds = new Set(identityIds);
+ const groupIdentities = await identityGroupMembershipDAL.find(
+ { $in: { groupId: projectGroupIds } },
+ tx ? { tx } : undefined
+ );
+ return new Set(groupIdentities.map((gi) => gi.identityId).filter((id) => candidateIds.has(id)));
+ };
+
const $loadApplicationOrThrow = async (applicationId: string, projectId: string) => {
const application = await pkiApplicationDAL.findById(applicationId);
if (!application || application.projectId !== projectId) {
@@ -215,7 +263,17 @@ export const pkiApplicationMembershipServiceFactory = ({
else if (groupId) projectMembershipFilter.actorGroupId = groupId;
const existingProjectMembership = await membershipDAL.find(projectMembershipFilter, { tx });
- if (existingProjectMembership.length === 0) {
+ let hasProjectAccess = existingProjectMembership.length > 0;
+ if (!hasProjectAccess && userId) {
+ const usersViaGroup = await $usersWithGroupProjectAccess(projectId, [userId], tx);
+ hasProjectAccess = usersViaGroup.has(userId);
+ }
+ if (!hasProjectAccess && identityId) {
+ const identitiesViaGroup = await $identitiesWithGroupProjectAccess(projectId, [identityId], tx);
+ hasProjectAccess = identitiesViaGroup.has(identityId);
+ }
+
+ if (!hasProjectAccess) {
// eslint-disable-next-line no-nested-ternary
const subjectLabel = userId ? "user" : identityId ? "machine identity" : "group";
throw new BadRequestError({
@@ -577,6 +635,9 @@ export const pkiApplicationMembershipServiceFactory = ({
const projectMemberIds = new Set(
projectMemberRows.map((m) => m.actorUserId).filter((v): v is string => Boolean(v))
);
+ const usersViaGroup = await $usersWithGroupProjectAccess(projectId, candidateIds);
+ usersViaGroup.forEach((id) => projectMemberIds.add(id));
+
const targets = candidates.filter((t) => {
if (projectMemberIds.has(t.userId)) return true;
unresolved.push(t.label);
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
index 53c781269d..db4afb2ad1 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
@@ -1,4 +1,5 @@
import { useMemo, useState } from "react";
+import { useQueries } from "@tanstack/react-query";
import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
@@ -14,6 +15,7 @@ import {
DialogHeader,
DialogTitle
} from "@app/components/v3";
+import { apiRequest } from "@app/config/request";
import { useProject } from "@app/context";
import {
TPkiApplicationMember,
@@ -99,7 +101,8 @@ export const AddApplicationMemberModal = ({
const [role, setRole] = useState("operator");
const [submitting, setSubmitting] = useState(false);
- const usersQuery = useGetWorkspaceUsers(projectId);
+ // includeGroupMembers so users who only have project access via a group still appear.
+ const usersQuery = useGetWorkspaceUsers(projectId, true);
const identitiesQuery = useListProjectIdentityMemberships({
projectId,
projectType: ProjectType.CertificateManager,
@@ -107,6 +110,23 @@ export const AddApplicationMemberModal = ({
});
const groupsQuery = useListWorkspaceGroups(projectId, ProjectType.CertificateManager);
+ const projectGroups = groupsQuery.data ?? [];
+ const groupIdentityQueries = useQueries({
+ queries: projectGroups.map((gm) => ({
+ queryKey: ["pki-application-add-member", "group-identities", gm.group.id],
+ enabled: isOpen,
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{
+ machineIdentities: { id: string; name: string }[];
+ }>(`/api/v1/groups/${gm.group.id}/machine-identities`, {
+ params: { offset: 0, limit: 1000 }
+ });
+ return data.machineIdentities;
+ }
+ }))
+ });
+ const groupIdentities = groupIdentityQueries.flatMap((q) => q.data ?? []);
+
const addMember = useAddPkiApplicationMember();
const addUserMembers = useAddPkiApplicationUserMembers();
@@ -135,11 +155,19 @@ export const AddApplicationMemberModal = ({
}, [usersQuery.data, taken]);
const identityOptions: Option[] = useMemo(() => {
- const memberships = identitiesQuery.data?.identityMemberships ?? [];
- return memberships
- .filter((im) => !taken.has(`identity:${im.identity.id}`))
- .map((im) => ({ value: im.identity.id, label: im.identity.name }));
- }, [identitiesQuery.data, taken]);
+ const byId = new Map<string, Option>();
+ (identitiesQuery.data?.identityMemberships ?? []).forEach((im) => {
+ if (!taken.has(`identity:${im.identity.id}`)) {
+ byId.set(im.identity.id, { value: im.identity.id, label: im.identity.name });
+ }
+ });
+ groupIdentities.forEach((i) => {
+ if (!taken.has(`identity:${i.id}`) && !byId.has(i.id)) {
+ byId.set(i.id, { value: i.id, label: i.name });
+ }
+ });
+ return Array.from(byId.values());
+ }, [identitiesQuery.data, groupIdentities, taken]);
const groupOptions: Option[] = useMemo(() => {
const memberships = groupsQuery.data ?? [];