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
Patch unsynchronized username/email for saml/scim
Tuan Dang3b88a2759b97
diff --git a/backend/src/db/migrations/20240429185709_trusted-saml-ldap-emails.ts b/backend/src/db/migrations/20240506163405_trusted-saml-ldap-emails.tssimilarity index 100%rename from backend/src/db/migrations/20240429185709_trusted-saml-ldap-emails.tsrename to backend/src/db/migrations/20240506163405_trusted-saml-ldap-emails.tsdiff --git a/backend/src/ee/routes/v1/ldap-router.ts b/backend/src/ee/routes/v1/ldap-router.tsindex 6730e9101b..e146668c24 100644--- a/backend/src/ee/routes/v1/ldap-router.ts+++ b/backend/src/ee/routes/v1/ldap-router.ts@@ -18,6 +18,7 @@ import { LdapConfigsSchema, LdapGroupMapsSchema } from "@app/db/schemas";import { TLDAPConfig } from "@app/ee/services/ldap-config/ldap-config-types";import { isValidLdapFilter, searchGroups } from "@app/ee/services/ldap-config/ldap-fns";import { getConfig } from "@app/lib/config/env";+import { BadRequestError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";@@ -52,6 +53,7 @@ export const registerLdapRouter = async (server: FastifyZodProvider) => {// eslint-disable-next-lineasync (req: IncomingMessage, user, cb) => {try {+ if (!user.email) throw new BadRequestError({ message: "Invalid request. Missing email." });const ldapConfig = (req as unknown as FastifyRequest).ldapConfig as TLDAPConfig;let groups: { dn: string; cn: string }[] | undefined;@@ -74,7 +76,7 @@ export const registerLdapRouter = async (server: FastifyZodProvider) => {username: user.uid,firstName: user.givenName ?? user.cn ?? "",lastName: user.sn ?? "",- emails: user.mail ? [user.mail] : [],+ email: user.mail,groups,relayState: ((req as unknown as FastifyRequest).body as { RelayState?: string }).RelayState,orgId: (req as unknown as FastifyRequest).ldapConfig.organizationdiff --git a/backend/src/ee/routes/v1/saml-router.ts b/backend/src/ee/routes/v1/saml-router.tsindex 81543c85e5..6001b8b6ec 100644--- a/backend/src/ee/routes/v1/saml-router.ts+++ b/backend/src/ee/routes/v1/saml-router.ts@@ -102,7 +102,7 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => {if (!profile) throw new BadRequestError({ message: "Missing profile" });const email = profile?.email ?? (profile?.emailAddress as string); // emailRippling is added because in Rippling the field `email` reserved- if (!profile.email || !profile.firstName) {+ if (!email || !profile.firstName) {throw new BadRequestError({ message: "Invalid request. Missing email or first name" });}diff --git a/backend/src/ee/routes/v1/scim-router.ts b/backend/src/ee/routes/v1/scim-router.tsindex 7283b8fe1a..8965c28f3b 100644--- a/backend/src/ee/routes/v1/scim-router.ts+++ b/backend/src/ee/routes/v1/scim-router.ts@@ -249,7 +249,7 @@ export const registerScimRouter = async (server: FastifyZodProvider) => {const primaryEmail = req.body.emails?.find((email) => email.primary)?.value;const user = await req.server.services.scim.createScimUser({- username: req.body.userName,+ externalId: req.body.userName,email: primaryEmail,firstName: req.body.name.givenName,lastName: req.body.name.familyName,diff --git a/backend/src/ee/services/group/group-fns.ts b/backend/src/ee/services/group/group-fns.tsindex e308891f92..4f96ddbf09 100644--- a/backend/src/ee/services/group/group-fns.ts+++ b/backend/src/ee/services/group/group-fns.ts@@ -1,6 +1,6 @@import { Knex } from "knex";-import { SecretKeyEncoding, TUsers } from "@app/db/schemas";+import { SecretKeyEncoding, TableName, TUsers } from "@app/db/schemas";import { decryptAsymmetric, encryptAsymmetric, infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";import { BadRequestError, ScimRequestError } from "@app/lib/errors";@@ -188,9 +188,9 @@ export const addUsersToGroupByUserIds = async ({// check if all user(s) are part of the organizationconst existingUserOrgMemberships = await orgDAL.findMembership({- orgId: group.orgId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: group.orgId,$in: {- userId: userIds+ [`${TableName.OrgMembership}.userId` as "userId"]: userIds}},{ tx }diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.ts b/backend/src/ee/services/ldap-config/ldap-config-service.tsindex d799b17544..6773c9486f 100644--- a/backend/src/ee/services/ldap-config/ldap-config-service.ts+++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts@@ -6,7 +6,8 @@ import {OrgMembershipStatus,SecretKeyEncoding,TableName,- TLdapConfigsUpdate+ TLdapConfigsUpdate,+ TUsers} from "@app/db/schemas";import { TGroupDALFactory } from "@app/ee/services/group/group-dal";import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee/services/group/group-fns";@@ -25,6 +26,7 @@ import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";import { TGroupProjectDALFactory } from "@app/services/group-project/group-project-dal";import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";import { TOrgDALFactory } from "@app/services/org/org-dal";+import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";import { TProjectDALFactory } from "@app/services/project/project-dal";import { TProjectBotDALFactory } from "@app/services/project-bot/project-bot-dal";import { TProjectKeyDALFactory } from "@app/services/project-key/project-key-dal";@@ -54,6 +56,7 @@ import { TLdapGroupMapDALFactory } from "./ldap-group-map-dal";type TLdapConfigServiceFactoryDep = {ldapConfigDAL: Pick<TLdapConfigDALFactory, "create" | "update" | "findOne">;ldapGroupMapDAL: Pick<TLdapGroupMapDALFactory, "find" | "create" | "delete" | "findLdapGroupMapsByLdapConfigId">;+ orgMembershipDAL: Pick<TOrgMembershipDALFactory, "create">;orgDAL: Pick<TOrgDALFactory,"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"@@ -83,6 +86,7 @@ export const ldapConfigServiceFactory = ({ldapConfigDAL,ldapGroupMapDAL,orgDAL,+ orgMembershipDAL,orgBotDAL,groupDAL,groupProjectDAL,@@ -387,7 +391,7 @@ export const ldapConfigServiceFactory = ({username,firstName,lastName,- emails,+ email,groups,orgId,relayState@@ -407,7 +411,7 @@ export const ldapConfigServiceFactory = ({await userDAL.transaction(async (tx) => {const [orgMembership] = await orgDAL.findMembership({- userId: userAlias.userId,+ [`${TableName.OrgMembership}.userId` as "userId"]: userAlias.userId,[`${TableName.OrgMembership}.orgId` as "id"]: orgId},{ tx }@@ -434,41 +438,75 @@ export const ldapConfigServiceFactory = ({});} else {userAlias = await userDAL.transaction(async (tx) => {- const uniqueUsername = await normalizeUsername(username, userDAL);- const newUser = await userDAL.create(- {- username: uniqueUsername,- email: emails[0],- isEmailVerified: serverCfg.trustLdapEmails,- firstName,- lastName,- authMethods: [],- isGhost: false- },- tx- );+ let newUser: TUsers | undefined;+ if (serverCfg.trustSamlEmails) {+ newUser = await userDAL.findOne(+ {+ email,+ isEmailVerified: true+ },+ tx+ );+ }++ if (!newUser) {+ const uniqueUsername = await normalizeUsername(username, userDAL);+ newUser = await userDAL.create(+ {+ username: serverCfg.trustLdapEmails ? email : uniqueUsername,+ email,+ isEmailVerified: serverCfg.trustLdapEmails,+ firstName,+ lastName,+ authMethods: [],+ isGhost: false+ },+ tx+ );+ }+const newUserAlias = await userAliasDAL.create({userId: newUser.id,username,aliasType: UserAliasType.LDAP,externalId,- emails,+ emails: [email],orgId},tx);- await orgDAL.createMembership(+ const [orgMembership] = await orgDAL.findMembership({- userId: newUser.id,- orgId,- role: OrgMembershipRole.Member,- status: OrgMembershipStatus.Invited+ [`${TableName.OrgMembership}.userId` as "userId"]: newUser.id,+ [`${TableName.OrgMembership}.orgId` as "id"]: orgId},- tx+ { tx });+ if (!orgMembership) {+ await orgMembershipDAL.create(+ {+ userId: userAlias.userId,+ inviteEmail: email,+ orgId,+ role: OrgMembershipRole.Member,+ status: newUser.isAccepted ? OrgMembershipStatus.Accepted : OrgMembershipStatus.Invited // if user is fully completed, then set status to accepted, otherwise set it to invited so we can update it later+ },+ tx+ );+ // Only update the membership to Accepted if the user account is already completed.+ } else if (orgMembership.status === OrgMembershipStatus.Invited && newUser.isAccepted) {+ await orgDAL.updateMembershipById(+ orgMembership.id,+ {+ status: OrgMembershipStatus.Accepted+ },+ tx+ );+ }+return newUserAlias;});}diff --git a/backend/src/ee/services/ldap-config/ldap-config-types.ts b/backend/src/ee/services/ldap-config/ldap-config-types.tsindex b7e9feb7b8..aa4aa8da70 100644--- a/backend/src/ee/services/ldap-config/ldap-config-types.ts+++ b/backend/src/ee/services/ldap-config/ldap-config-types.ts@@ -51,7 +51,7 @@ export type TLdapLoginDTO = {username: string;firstName: string;lastName: string;- emails: string[];+ email: string;orgId: string;groups?: {dn: string;diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.tsindex 42e77e4310..7dfd211e13 100644--- a/backend/src/ee/services/saml-config/saml-config-service.ts+++ b/backend/src/ee/services/saml-config/saml-config-service.ts@@ -347,7 +347,7 @@ export const samlConfigServiceFactory = ({const foundUser = await userDAL.findById(userAlias.userId, tx);const [orgMembership] = await orgDAL.findMembership({- userId: foundUser.id,+ [`${TableName.OrgMembership}.userId` as "userId"]: foundUser.id,[`${TableName.OrgMembership}.orgId` as "id"]: orgId},{ tx }@@ -378,19 +378,33 @@ export const samlConfigServiceFactory = ({});} else {user = await userDAL.transaction(async (tx) => {- const uniqueUsername = await normalizeUsername(`${firstName ?? ""}-${lastName ?? ""}`, userDAL);- const newUser = await userDAL.create(- {- username: uniqueUsername,- email,- isEmailVerified: serverCfg.trustSamlEmails,- firstName,- lastName,- authMethods: [],- isGhost: false- },- tx- );+ let newUser: TUsers | undefined;+ if (serverCfg.trustSamlEmails) {+ newUser = await userDAL.findOne(+ {+ email,+ isEmailVerified: true+ },+ tx+ );+ }++ if (!newUser) {+ const uniqueUsername = await normalizeUsername(`${firstName ?? ""}-${lastName ?? ""}`, userDAL);+ newUser = await userDAL.create(+ {+ username: serverCfg.trustSamlEmails ? email : uniqueUsername,+ email,+ isEmailVerified: serverCfg.trustSamlEmails,+ firstName,+ lastName,+ authMethods: [],+ isGhost: false+ },+ tx+ );+ }+await userAliasDAL.create({userId: newUser.id,@@ -402,17 +416,36 @@ export const samlConfigServiceFactory = ({tx);- await orgMembershipDAL.create(+ const [orgMembership] = await orgDAL.findMembership({- userId: newUser.id,- inviteEmail: email,- orgId,- role: OrgMembershipRole.Member,- status: OrgMembershipStatus.Invited+ [`${TableName.OrgMembership}.userId` as "userId"]: newUser.id,+ [`${TableName.OrgMembership}.orgId` as "id"]: orgId},- tx+ { tx });+ if (!orgMembership) {+ await orgMembershipDAL.create(+ {+ userId: newUser.id,+ inviteEmail: email,+ orgId,+ role: OrgMembershipRole.Member,+ status: newUser.isAccepted ? OrgMembershipStatus.Accepted : OrgMembershipStatus.Invited // if user is fully completed, then set status to accepted, otherwise set it to invited so we can update it later+ },+ tx+ );+ // Only update the membership to Accepted if the user account is already completed.+ } else if (orgMembership.status === OrgMembershipStatus.Invited && newUser.isAccepted) {+ await orgDAL.updateMembershipById(+ orgMembership.id,+ {+ status: OrgMembershipStatus.Accepted+ },+ tx+ );+ }+return newUser;});}diff --git a/backend/src/ee/services/saml-config/saml-config-types.ts b/backend/src/ee/services/saml-config/saml-config-types.tsindex 0e84ff6666..92ee32b5c6 100644--- a/backend/src/ee/services/saml-config/saml-config-types.ts+++ b/backend/src/ee/services/saml-config/saml-config-types.ts@@ -46,7 +46,7 @@ export type TGetSamlCfgDTO =export type TSamlLoginDTO = {externalId: string;- email?: string;+ email: string;firstName: string;lastName?: string;authProvider: string;diff --git a/backend/src/ee/services/scim/scim-service.ts b/backend/src/ee/services/scim/scim-service.tsindex c9cc6e1ed7..9a084c6d71 100644--- a/backend/src/ee/services/scim/scim-service.ts+++ b/backend/src/ee/services/scim/scim-service.ts@@ -209,10 +209,10 @@ export const scimServiceFactory = ({findOpts);- const scimUsers = users.map(({ id, username, firstName, lastName, email }) =>+ const scimUsers = users.map(({ id, externalId, username, firstName, lastName, email }) =>buildScimUser({orgMembershipId: id ?? "",- username,+ username: externalId ?? username,firstName: firstName ?? "",lastName: lastName ?? "",email,@@ -254,7 +254,7 @@ export const scimServiceFactory = ({return buildScimUser({orgMembershipId: membership.id,- username: membership.username,+ username: membership.externalId ?? membership.username,email: membership.email ?? "",firstName: membership.firstName as string,lastName: membership.lastName as string,@@ -262,7 +262,9 @@ export const scimServiceFactory = ({});};- const createScimUser = async ({ username, email, firstName, lastName, orgId }: TCreateScimUserDTO) => {+ const createScimUser = async ({ externalId, email, firstName, lastName, orgId }: TCreateScimUserDTO) => {+ if (!email) throw new ScimRequestError({ detail: "Invalid request. Missing email.", status: 400 });+const org = await orgDAL.findById(orgId);if (!org)@@ -281,13 +283,13 @@ export const scimServiceFactory = ({const serverCfg = await getServerCfg();const userAlias = await userAliasDAL.findOne({- externalId: username,+ externalId,orgId,aliasType: UserAliasType.SAML});const { user: createdUser, orgMembership: createdOrgMembership } = await userDAL.transaction(async (tx) => {- let user: TUsers;+ let user: TUsers | undefined;let orgMembership: TOrgMemberships;if (userAlias) {user = await userDAL.findById(userAlias.userId, tx);@@ -320,39 +322,74 @@ export const scimServiceFactory = ({);}} else {- const uniqueUsername = await normalizeUsername(`${firstName}-${lastName}`, userDAL);- user = await userDAL.create(- {- username: uniqueUsername,- email,- isEmailVerified: serverCfg.trustSamlEmails,- firstName,- lastName,- authMethods: [],- isGhost: false- },- tx- );+ if (serverCfg.trustSamlEmails) {+ user = await userDAL.findOne(+ {+ email,+ isEmailVerified: true+ },+ tx+ );+ }++ if (!user) {+ const uniqueUsername = await normalizeUsername(`${firstName}-${lastName}`, userDAL);+ user = await userDAL.create(+ {+ username: serverCfg.trustSamlEmails ? email : uniqueUsername,+ email,+ isEmailVerified: serverCfg.trustSamlEmails,+ firstName,+ lastName,+ authMethods: [],+ isGhost: false+ },+ tx+ );+ }+await userAliasDAL.create({userId: user.id,aliasType: UserAliasType.SAML,- externalId: username,+ externalId,emails: email ? [email] : [],orgId},tx);- orgMembership = await orgMembershipDAL.create(++ const [foundOrgMembership] = await orgDAL.findMembership({- userId: user.id,- inviteEmail: email,- orgId,- role: OrgMembershipRole.Member,- status: OrgMembershipStatus.Invited+ [`${TableName.OrgMembership}.userId` as "userId"]: user.id,+ [`${TableName.OrgMembership}.orgId` as "id"]: orgId},- tx+ { tx });++ orgMembership = foundOrgMembership;++ if (!orgMembership) {+ orgMembership = await orgMembershipDAL.create(+ {+ userId: user.id,+ inviteEmail: email,+ orgId,+ role: OrgMembershipRole.Member,+ status: user.isAccepted ? OrgMembershipStatus.Accepted : OrgMembershipStatus.Invited // if user is fully completed, then set status to accepted, otherwise set it to invited so we can update it later+ },+ tx+ );+ // Only update the membership to Accepted if the user account is already completed.+ } else if (orgMembership.status === OrgMembershipStatus.Invited && user.isAccepted) {+ orgMembership = await orgDAL.updateMembershipById(+ orgMembership.id,+ {+ status: OrgMembershipStatus.Accepted+ },+ tx+ );+ }}return { user, orgMembership };@@ -372,7 +409,7 @@ export const scimServiceFactory = ({return buildScimUser({orgMembershipId: createdOrgMembership.id,- username: createdUser.username,+ username: externalId,firstName: createdUser.firstName as string,lastName: createdUser.lastName as string,email: createdUser.email ?? "",@@ -380,11 +417,11 @@ export const scimServiceFactory = ({});};- const updateScimUser = async ({ userId, orgId, operations }: TUpdateScimUserDTO) => {+ const updateScimUser = async ({ orgMembershipId, orgId, operations }: TUpdateScimUserDTO) => {const [membership] = await orgDAL.findMembership({- userId,- [`${TableName.OrgMembership}.orgId` as "id"]: orgId+ [`${TableName.OrgMembership}.id` as "id"]: orgMembershipId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: orgId}).catch(() => {throw new ScimRequestError({@@ -433,7 +470,7 @@ export const scimServiceFactory = ({return buildScimUser({orgMembershipId: membership.id,- username: membership.username,+ username: membership.externalId ?? membership.username,email: membership.email,firstName: membership.firstName as string,lastName: membership.lastName as string,@@ -467,7 +504,6 @@ export const scimServiceFactory = ({});if (!active) {- // txawait deleteOrgMembershipFn({orgMembershipId: membership.id,orgId: membership.orgId,@@ -481,7 +517,7 @@ export const scimServiceFactory = ({return buildScimUser({orgMembershipId: membership.id,- username: membership.username,+ username: membership.externalId ?? membership.username,email: membership.email,firstName: membership.firstName as string,lastName: membership.lastName as string,@@ -627,9 +663,9 @@ export const scimServiceFactory = ({});const orgMemberships = await orgDAL.findMembership({- orgId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: orgId,$in: {- userId: newGroup.newMembers.map((member) => member.id)+ [`${TableName.OrgMembership}.userId` as "userId"]: newGroup.newMembers.map((member) => member.id)}});@@ -668,9 +704,11 @@ export const scimServiceFactory = ({});const orgMemberships = await orgDAL.findMembership({- orgId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: orgId,$in: {- userId: users.filter((user) => user.isPartOfGroup).map((user) => user.id)+ [`${TableName.OrgMembership}.userId` as "userId"]: users+ .filter((user) => user.isPartOfGroup)+ .map((user) => user.id)}});diff --git a/backend/src/ee/services/scim/scim-types.ts b/backend/src/ee/services/scim/scim-types.tsindex e804d51a54..46ab90b8f0 100644--- a/backend/src/ee/services/scim/scim-types.ts+++ b/backend/src/ee/services/scim/scim-types.ts@@ -32,7 +32,7 @@ export type TGetScimUserDTO = {};export type TCreateScimUserDTO = {- username: string;+ externalId: string;email?: string;firstName: string;lastName: string;@@ -40,7 +40,7 @@ export type TCreateScimUserDTO = {};export type TUpdateScimUserDTO = {- userId: string;+ orgMembershipId: string;orgId: string;operations: {op: string;diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex fd095389a4..aeb66d93f9 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -322,6 +322,7 @@ export const registerRoutes = async (ldapConfigDAL,ldapGroupMapDAL,orgDAL,+ orgMembershipDAL,orgBotDAL,groupDAL,groupProjectDAL,diff --git a/backend/src/services/auth/auth-signup-service.ts b/backend/src/services/auth/auth-signup-service.tsindex 5aea537869..be7f5777db 100644--- a/backend/src/services/auth/auth-signup-service.ts+++ b/backend/src/services/auth/auth-signup-service.ts@@ -1,6 +1,6 @@import jwt from "jsonwebtoken";-import { OrgMembershipStatus } from "@app/db/schemas";+import { OrgMembershipStatus, TableName } from "@app/db/schemas";import { convertPendingGroupAdditionsToGroupMemberships } from "@app/ee/services/group/group-fns";import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";@@ -102,6 +102,8 @@ export const authSignupServiceFactory = ({code});+ await userDAL.updateById(user.id, { isEmailVerified: true });+// generate jwt token this is a temporary tokenconst jwtToken = jwt.sign({@@ -171,9 +173,9 @@ export const authSignupServiceFactory = ({// If it's SAML Auth and the organization ID is present, we should check if the user has a pending invite for this org, and accept itif ((isAuthMethodSaml(authMethod) || authMethod === AuthMethod.LDAP) && organizationId) {const [pendingOrgMembership] = await orgDAL.findMembership({- userId: user.id,+ [`${TableName.OrgMembership}.userId` as "userId"]: user.id,status: OrgMembershipStatus.Invited,- orgId: organizationId+ [`${TableName.OrgMembership}.orgId` as "orgId"]: organizationId});if (pendingOrgMembership) {diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.tsindex 4dc76b6128..1e52053b2a 100644--- a/backend/src/services/org/org-dal.ts+++ b/backend/src/services/org/org-dal.ts@@ -262,13 +262,19 @@ export const orgDALFactory = (db: TDbClient) => {.where(buildFindFilter(filter)).join(TableName.Users, `${TableName.Users}.id`, `${TableName.OrgMembership}.userId`).join(TableName.Organization, `${TableName.Organization}.id`, `${TableName.OrgMembership}.orgId`)+ .leftJoin(TableName.UserAliases, function joinUserAlias() {+ this.on(`${TableName.UserAliases}.userId`, "=", `${TableName.OrgMembership}.userId`)+ .andOn(`${TableName.UserAliases}.orgId`, "=", `${TableName.OrgMembership}.orgId`)+ .andOn(`${TableName.UserAliases}.aliasType`, "=", (tx || db).raw("?", ["saml"]));+ }).select(selectAllTableCols(TableName.OrgMembership),db.ref("email").withSchema(TableName.Users),db.ref("username").withSchema(TableName.Users),db.ref("firstName").withSchema(TableName.Users),db.ref("lastName").withSchema(TableName.Users),- db.ref("scimEnabled").withSchema(TableName.Organization)+ db.ref("scimEnabled").withSchema(TableName.Organization),+ db.ref("externalId").withSchema(TableName.UserAliases)).where({ isGhost: false });diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.tsindex a666e6a03c..d7ee1ce933 100644--- a/backend/src/services/org/org-service.ts+++ b/backend/src/services/org/org-service.ts@@ -4,7 +4,7 @@ import crypto from "crypto";import jwt from "jsonwebtoken";import { Knex } from "knex";-import { OrgMembershipRole, OrgMembershipStatus } from "@app/db/schemas";+import { OrgMembershipRole, OrgMembershipStatus, TableName } from "@app/db/schemas";import { TProjects } from "@app/db/schemas/projects";import { TGroupDALFactory } from "@app/ee/services/group/group-dal";import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";@@ -431,7 +431,13 @@ export const orgServiceFactory = ({if (inviteeUser) {// if user already exist means its already part of infisical// Thus the signup flow is not needed anymore- const [inviteeMembership] = await orgDAL.findMembership({ orgId, userId: inviteeUser.id }, { tx });+ const [inviteeMembership] = await orgDAL.findMembership(+ {+ [`${TableName.OrgMembership}.orgId` as "orgId"]: orgId,+ [`${TableName.OrgMembership}.userId` as "userId"]: inviteeUser.id+ },+ { tx }+ );if (inviteeMembership && inviteeMembership.status === OrgMembershipStatus.Accepted) {throw new BadRequestError({message: "Failed to invite an existing member of org",@@ -523,9 +529,9 @@ export const orgServiceFactory = ({throw new BadRequestError({ message: "Invalid request", name: "Verify user to org" });}const [orgMembership] = await orgDAL.findMembership({- userId: user.id,+ [`${TableName.OrgMembership}.userId` as "userId"]: user.id,status: OrgMembershipStatus.Invited,- orgId+ [`${TableName.OrgMembership}.orgId` as "orgId"]: orgId});if (!orgMembership)throw new BadRequestError({diff --git a/backend/src/services/project-membership/project-membership-service.ts b/backend/src/services/project-membership/project-membership-service.tsindex 6d148d03b6..e12114feff 100644--- a/backend/src/services/project-membership/project-membership-service.ts+++ b/backend/src/services/project-membership/project-membership-service.ts@@ -110,7 +110,7 @@ export const projectMembershipServiceFactory = ({);ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.Member);const orgMembers = await orgDAL.findMembership({- orgId: project.orgId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: project.orgId,$in: {[`${TableName.OrgMembership}.id` as "id"]: members.map(({ orgMembershipId }) => orgMembershipId)}@@ -119,7 +119,7 @@ export const projectMembershipServiceFactory = ({const existingMembers = await projectMembershipDAL.find({projectId,- $in: { userId: orgMembers.map(({ userId }) => userId).filter(Boolean) as string[] }+ $in: { userId: orgMembers.map(({ userId }) => userId).filter(Boolean) }});if (existingMembers.length) throw new BadRequestError({ message: "Some users are already part of project" });@@ -134,7 +134,7 @@ export const projectMembershipServiceFactory = ({const projectMemberships = await projectMembershipDAL.insertMany(orgMembers.map(({ userId }) => ({projectId,- userId: userId as string+ userId})),tx);@@ -145,12 +145,12 @@ export const projectMembershipServiceFactory = ({const encKeyGroupByOrgMembId = groupBy(members, (i) => i.orgMembershipId);await projectKeyDAL.insertMany(orgMembers- .filter(({ userId }) => !userIdsToExcludeForProjectKeyAddition.has(userId as string))+ .filter(({ userId }) => !userIdsToExcludeForProjectKeyAddition.has(userId)).map(({ userId, id }) => ({encryptedKey: encKeyGroupByOrgMembId[id][0].workspaceEncryptedKey,nonce: encKeyGroupByOrgMembId[id][0].workspaceEncryptedNonce,senderId: actorId,- receiverId: userId as string,+ receiverId: userId,projectId})),txdiff --git a/backend/src/services/project/project-queue.ts b/backend/src/services/project/project-queue.tsindex 81ecd6da12..8f1e3fc3f0 100644--- a/backend/src/services/project/project-queue.ts+++ b/backend/src/services/project/project-queue.ts@@ -8,6 +8,7 @@ import {SecretKeyEncoding,SecretsSchema,SecretVersionsSchema,+ TableName,TIntegrationAuths,TSecretApprovalRequestsSecrets,TSecrets,@@ -273,7 +274,10 @@ export const projectQueueFactory = ({for (const key of existingProjectKeys) {const user = await userDAL.findUserEncKeyByUserId(key.receiverId);- const [orgMembership] = await orgDAL.findMembership({ userId: key.receiverId, orgId: project.orgId });+ const [orgMembership] = await orgDAL.findMembership({+ [`${TableName.OrgMembership}.userId` as "userId"]: key.receiverId,+ [`${TableName.OrgMembership}.orgId` as "orgId"]: project.orgId+ });if (!user) {throw new Error(`User with ID ${key.receiverId} was not found during upgrade.`);diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex 6d6bf274ac..089f3b8c68 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -63,6 +63,8 @@ export const userServiceFactory = ({const verifyEmailVerificationCode = async (username: string, code: string) => {const user = await userDAL.findOne({ username });if (!user) throw new BadRequestError({ name: "Failed to find user" });+ if (!user.email)+ throw new BadRequestError({ name: "Failed to verify email verification code due to no email on user" });if (user.isEmailVerified)throw new BadRequestError({ name: "Failed to verify email verification code due to email already verified" });@@ -72,6 +74,8 @@ export const userServiceFactory = ({code});+ const { email } = user;+await userDAL.transaction(async (tx) => {await userDAL.updateById(user.id,@@ -84,7 +88,7 @@ export const userServiceFactory = ({// check if there are users with the same email.const users = await userDAL.find({- email: user.email,+ email,isEmailVerified: true},{ tx }@@ -129,6 +133,15 @@ export const userServiceFactory = ({tx);}+ } else {+ // update current user's username to [email]+ await userDAL.updateById(+ user.id,+ {+ username: email+ },+ tx+ );}});};diff --git a/docs/documentation/platform/ldap/general.mdx b/docs/documentation/platform/ldap/general.mdxindex aa4841625b..5e4253a344 100644--- a/docs/documentation/platform/ldap/general.mdx+++ b/docs/documentation/platform/ldap/general.mdx@@ -12,6 +12,10 @@ description: "Learn how to log in to Infisical with LDAP."You can configure your organization in Infisical to have members authenticate with the platform via [LDAP](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol)+Prerequisites:++- You must have an email address to use LDAP, regardless of whether or not you use that email address to sign in.+<Steps><Step title="Prepare the LDAP configuration in Infisical">In Infisical, head to your Organization Settings > Security > LDAP and select **Manage**.diff --git a/docs/documentation/platform/ldap/jumpcloud.mdx b/docs/documentation/platform/ldap/jumpcloud.mdxindex 0b40d8b3af..b92b52bb90 100644--- a/docs/documentation/platform/ldap/jumpcloud.mdx+++ b/docs/documentation/platform/ldap/jumpcloud.mdx@@ -10,6 +10,10 @@ description: "Learn how to configure JumpCloud LDAP for authenticating into Infiit.</Info>+Prerequisites:++- You must have an email address to use LDAP, regardless of whether or not you use that email address to sign in.+<Steps><Step title="Prepare LDAP in JumpCloud">In JumpCloud, head to USER MANAGEMENT > Users and create a new user via the **Manual user entry** option. This userdiff --git a/docs/documentation/platform/ldap/overview.mdx b/docs/documentation/platform/ldap/overview.mdxindex 2423be8c06..4d6c75e153 100644--- a/docs/documentation/platform/ldap/overview.mdx+++ b/docs/documentation/platform/ldap/overview.mdx@@ -3,11 +3,13 @@ title: "LDAP Overview"sidebarTitle: "Overview"description: "Learn how to authenticate into Infisical with LDAP."---+<Info>LDAP is a paid feature.- If you're using Infisical Cloud, then it is available under the **Enterprise Tier**. If you're self-hosting Infisical,- then you should contact [email protected] to purchase an enterprise license to use it.+If you're using Infisical Cloud, then it is available under the **Enterprise Tier**. If you're self-hosting Infisical,+then you should contact [email protected] to purchase an enterprise license to use it.+</Info>You can configure your organization in Infisical to have members authenticate with the platform via [LDAP](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol).@@ -25,3 +27,18 @@ Read the general instructions for configuring LDAP [here](/documentation/platforIf the documentation for your required identity provider is not shown in the list above, please reach out to [[email protected]](mailto:[email protected]) for assistance.+## FAQ++<AccordionGroup>+ <Accordion title="Why does Infisical require additional email verification for users connected via LDAP?">+ By default, Infisical Cloud is configured to not trust emails from external+ identity providers to prevent any malicious account takeover attempts via+ email spoofing. Accordingly, Infisical creates a new user for anyone provisioned+ through an external identity provider and requires an additional email+ verification step upon their first login.++ If you're running a self-hosted instance of Infisical and would like it to trust emails from external identity providers,+ you can configure this behavior in the admin panel.++ </Accordion>+</AccordionGroup>diff --git a/docs/documentation/platform/sso/okta.mdx b/docs/documentation/platform/sso/okta.mdxindex c81141c92b..b0ac046d03 100644--- a/docs/documentation/platform/sso/okta.mdx+++ b/docs/documentation/platform/sso/okta.mdx@@ -4,10 +4,10 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."---<Info>- Okta SAML SSO is a paid feature.-- If you're using Infisical Cloud, then it is available under the **Pro Tier**. If you're self-hosting Infisical,- then you should contact [email protected] to purchase an enterprise license to use it.+ Okta SAML SSO is a paid feature. If you're using Infisical Cloud, then it is+ available under the **Pro Tier**. If you're self-hosting Infisical, then you+ should contact [email protected] to purchase an enterprise license to use+ it.</Info><Steps>@@ -22,24 +22,24 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."button.-+In the Create a New Application Integration dialog, select the **SAML 2.0** radio button:-+On the General Settings screen, give the application a unique name like Infisical and select **Next**.-+-+On the Configure SAML screen, set the **Single sign-on URL** and **Audience URI (SP Entity ID)** from step 1.-+<Note>If you're self-hosting Infisical, then you will want to replace`https://app.infisical.com` with your own domain.</Note>-+Also on the Configure SAML screen, configure the **Attribute Statements** to map:- `id -> user.id`,@@ -50,6 +50,7 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."Once configured, select **Next** to proceed to the Feedback screen and select **Finish**.+</Step><Step title="Retrieve Identity Provider (IdP) Information from Okta">Once your application is created, select the **Sign On** tab for the app and select the **View Setup Instructions** button located on the right side of the screen:@@ -59,12 +60,14 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."Copy the **Identity Provider Single Sign-On URL**, the **Identity Provider Issuer**, and the **X.509 Certificate** to use when finishing configuring Okta SAML in Infisical.+</Step><Step title="Finish configuring SAML in Infisical">Back in Infisical, set **Identity Provider Single Sign-On URL**, **Identity Provider Issuer**,and **Certificate** to **X.509 Certificate** from step 3. Once you've done that, press **Update** to complete the required configuration.+</Step><Step title="Assign users in Okta to the application">Back in Okta, navigate to the **Assignments** tab and select **Assign**. You can assign access to the application on a user-by-user basis using the Assign to People option, or in-bulk using the Assign to Groups option.@@ -72,11 +75,13 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."At this point, you have configured everything you need within the context of the Okta Admin Portal.+</Step><Step title="Enable SAML SSO in Infisical">Enabling SAML SSO allows members in your organization to log into Infisical via Okta.+</Step><Step title="Enforce SAML SSO in Infisical">Enforcing SAML SSO ensures that members in your organization can only access Infisical@@ -89,13 +94,15 @@ description: "Learn how to configure Okta SAML 2.0 for Infisical SSO."We recommend ensuring that your account is provisioned the application in Oktaprior to enforcing SAML SSO to prevent any unintended issues.</Warning>+</Step></Steps><Note>- If you're configuring SAML SSO on a self-hosted instance of Infisical, make sure to- set the `AUTH_SECRET` and `SITE_URL` environment variable for it to work:-- - `AUTH_SECRET`: A secret key used for signing and verifying JWT. This can be a random 32-byte base64 string generated with `openssl rand -base64 32`.- - `SITE_URL`: The URL of your self-hosted instance of Infisical - should be an absolute URL including the protocol (e.g. https://app.infisical.com)-</Note>\ No newline at end of file+ If you're configuring SAML SSO on a self-hosted instance of Infisical, make+ sure to set the `AUTH_SECRET` and `SITE_URL` environment variable for it to+ work: - `AUTH_SECRET`: A secret key used for signing and verifying JWT. This+ can be a random 32-byte base64 string generated with `openssl rand -base64+ 32`. - `SITE_URL`: The URL of your self-hosted instance of Infisical - should+ be an absolute URL including the protocol (e.g. https://app.infisical.com)+</Note>diff --git a/docs/documentation/platform/sso/overview.mdx b/docs/documentation/platform/sso/overview.mdxindex 6064f26e8a..9ab0acc3ae 100644--- a/docs/documentation/platform/sso/overview.mdx+++ b/docs/documentation/platform/sso/overview.mdx@@ -5,11 +5,12 @@ description: "Learn how to log in to Infisical via SSO protocols."---<Info>- Infisical offers Google SSO and GitHub SSO for free across both Infisical Cloud and Infisical Self-hosted.-- Infisical also offers SAML SSO authentication but as paid features that can be unlocked on Infisical Cloud's **Pro** tier- or via enterprise license on self-hosted instances of Infisical. On this front, we support industry-leading providers including- Okta, Azure AD, and JumpCloud; with any questions, please reach out to [email protected].+ Infisical offers Google SSO and GitHub SSO for free across both Infisical+ Cloud and Infisical Self-hosted. Infisical also offers SAML SSO authentication+ but as paid features that can be unlocked on Infisical Cloud's **Pro** tier or+ via enterprise license on self-hosted instances of Infisical. On this front,+ we support industry-leading providers including Okta, Azure AD, and JumpCloud;+ with any questions, please reach out to [email protected].</Info>You can configure your organization in Infisical to have members authenticate with the platform via protocols like [SAML 2.0](https://en.wikipedia.org/wiki/SAML_2.0).@@ -31,3 +32,19 @@ Infisical supports these and many other identity providers:- [Google SAML](/documentation/platform/sso/google-saml)If your required identity provider is not shown in the list above, please reach out to [[email protected]](mailto:[email protected]) for assistance.++## FAQ++<AccordionGroup>+ <Accordion title="Why does Infisical require additional email verification for users connected via SAML?">+ By default, Infisical Cloud is configured to not trust emails from external+ identity providers to prevent any malicious account takeover attempts via+ email spoofing. Accordingly, Infisical creates a new user for anyone provisioned+ through an external identity provider and requires an additional email+ verification step upon their first login.++ If you're running a self-hosted instance of Infisical and would like it to trust emails from external identity providers,+ you can configure this behavior in the admin panel.++ </Accordion>+</AccordionGroup>diff --git a/frontend/src/views/Signup/SignupSSO.tsx b/frontend/src/views/Signup/SignupSSO.tsxindex 88021ab449..2510c9fa43 100644--- a/frontend/src/views/Signup/SignupSSO.tsx+++ b/frontend/src/views/Signup/SignupSSO.tsx@@ -54,14 +54,6 @@ export const SignupSSO = ({ providerAuthToken }: Props) => {providerAuthToken={providerAuthToken}/>);- // case 2:- // return (- // <MergeUsersStep- // username={username}- // authType={authType}- // organizationSlug={organizationSlug}- // />- // );case 2:return (<BackupPDFStep email={username} password={password} name={`${firstName} ${lastName}`} />