mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #2046 from Infisical/misc/add-check-for-ldap-group
misc: added backend check for ldap group config
This commit is contained in:
@@ -53,7 +53,7 @@ import {
|
|||||||
TTestLdapConnectionDTO,
|
TTestLdapConnectionDTO,
|
||||||
TUpdateLdapCfgDTO
|
TUpdateLdapCfgDTO
|
||||||
} from "./ldap-config-types";
|
} from "./ldap-config-types";
|
||||||
import { testLDAPConfig } from "./ldap-fns";
|
import { searchGroups, testLDAPConfig } from "./ldap-fns";
|
||||||
import { TLdapGroupMapDALFactory } from "./ldap-group-map-dal";
|
import { TLdapGroupMapDALFactory } from "./ldap-group-map-dal";
|
||||||
|
|
||||||
type TLdapConfigServiceFactoryDep = {
|
type TLdapConfigServiceFactoryDep = {
|
||||||
@@ -286,7 +286,7 @@ export const ldapConfigServiceFactory = ({
|
|||||||
return ldapConfig;
|
return ldapConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLdapCfg = async (filter: { orgId: string; isActive?: boolean }) => {
|
const getLdapCfg = async (filter: { orgId: string; isActive?: boolean; id?: string }) => {
|
||||||
const ldapConfig = await ldapConfigDAL.findOne(filter);
|
const ldapConfig = await ldapConfigDAL.findOne(filter);
|
||||||
if (!ldapConfig) throw new BadRequestError({ message: "Failed to find organization LDAP data" });
|
if (!ldapConfig) throw new BadRequestError({ message: "Failed to find organization LDAP data" });
|
||||||
|
|
||||||
@@ -716,11 +716,25 @@ export const ldapConfigServiceFactory = ({
|
|||||||
message: "Failed to create LDAP group map due to plan restriction. Upgrade plan to create LDAP group map."
|
message: "Failed to create LDAP group map due to plan restriction. Upgrade plan to create LDAP group map."
|
||||||
});
|
});
|
||||||
|
|
||||||
const ldapConfig = await ldapConfigDAL.findOne({
|
const ldapConfig = await getLdapCfg({
|
||||||
id: ldapConfigId,
|
orgId,
|
||||||
orgId
|
id: ldapConfigId
|
||||||
});
|
});
|
||||||
if (!ldapConfig) throw new BadRequestError({ message: "Failed to find organization LDAP data" });
|
|
||||||
|
if (!ldapConfig.groupSearchBase) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Configure a group search base in your LDAP configuration in order to proceed."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupSearchFilter = `(cn=${ldapGroupCN})`;
|
||||||
|
const groups = await searchGroups(ldapConfig, groupSearchFilter, ldapConfig.groupSearchBase);
|
||||||
|
|
||||||
|
if (!groups.some((g) => g.cn === ldapGroupCN)) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Failed to find LDAP Group CN"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const group = await groupDAL.findOne({ slug: groupSlug, orgId });
|
const group = await groupDAL.findOne({ slug: groupSlug, orgId });
|
||||||
if (!group) throw new BadRequestError({ message: "Failed to find group" });
|
if (!group) throw new BadRequestError({ message: "Failed to find group" });
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
import { faUsers, faXmark } from "@fortawesome/free-solid-svg-icons";
|
import { faUsers, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@@ -66,8 +68,9 @@ export const LDAPGroupMapModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }:
|
|||||||
const { mutateAsync: createLDAPGroupMapping, isLoading: createIsLoading } =
|
const { mutateAsync: createLDAPGroupMapping, isLoading: createIsLoading } =
|
||||||
useCreateLDAPGroupMapping();
|
useCreateLDAPGroupMapping();
|
||||||
const { mutateAsync: deleteLDAPGroupMapping } = useDeleteLDAPGroupMapping();
|
const { mutateAsync: deleteLDAPGroupMapping } = useDeleteLDAPGroupMapping();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const { control, handleSubmit, reset } = useForm<TFormData>({
|
const { control, handleSubmit, reset, setValue } = useForm<TFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
ldapGroupCN: "",
|
ldapGroupCN: "",
|
||||||
@@ -130,6 +133,12 @@ export const LDAPGroupMapModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (groups && groups.length > 0) {
|
||||||
|
setValue("groupSlug", groups[0].slug);
|
||||||
|
}
|
||||||
|
}, [groups, popUp.ldapGroupMap.isOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={popUp?.ldapGroupMap?.isOpen}
|
isOpen={popUp?.ldapGroupMap?.isOpen}
|
||||||
@@ -139,6 +148,8 @@ export const LDAPGroupMapModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }:
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ModalContent title="Manage LDAP Group Mappings">
|
<ModalContent title="Manage LDAP Group Mappings">
|
||||||
|
{groups && groups.length > 0 && (
|
||||||
|
<>
|
||||||
<h2 className="mb-4">New Group Mapping</h2>
|
<h2 className="mb-4">New Group Mapping</h2>
|
||||||
<form onSubmit={handleSubmit(onFormSubmit)} className="mb-8">
|
<form onSubmit={handleSubmit(onFormSubmit)} className="mb-8">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
@@ -179,7 +190,12 @@ export const LDAPGroupMapModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }:
|
|||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
<Button className="ml-4" size="sm" type="submit" isLoading={createIsLoading}>
|
<Button
|
||||||
|
className="ml-4"
|
||||||
|
size="sm"
|
||||||
|
type="submit"
|
||||||
|
isLoading={createIsLoading}
|
||||||
|
>
|
||||||
Add mapping
|
Add mapping
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -250,6 +266,23 @@ export const LDAPGroupMapModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }:
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{groups && groups.length === 0 && (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
You do not have any Infisical groups in your organization. Create one in order to
|
||||||
|
proceed.
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
className="mt-4"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => router.push(`/org/${currentOrg?.id}/members`)}
|
||||||
|
>
|
||||||
|
Create
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user