Skip to content

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

feat: updated error message on update org for saml/oidc enforcement

=3c5c6aeca853
diff --git a/backend/src/ee/services/oidc/oidc-config-dal.ts b/backend/src/ee/services/oidc/oidc-config-dal.ts
index ffdba2cf76..b9b0a26598 100644
--- a/backend/src/ee/services/oidc/oidc-config-dal.ts
+++ b/backend/src/ee/services/oidc/oidc-config-dal.ts
@@ -1,6 +1,5 @@
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
-import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
export type TOidcConfigDALFactory = ReturnType<typeof oidcConfigDALFactory>;
@@ -8,22 +7,5 @@ export type TOidcConfigDALFactory = ReturnType<typeof oidcConfigDALFactory>;
export const oidcConfigDALFactory = (db: TDbClient) => {
const oidcCfgOrm = ormify(db, TableName.OidcConfig);
- const findEnforceableOidcCfg = async (orgId: string) => {
- try {
- const oidcCfg = await db
- .replicaNode()(TableName.OidcConfig)
- .where({
- orgId,
- isActive: true
- })
- .whereNotNull("lastUsed")
- .first();
-
- return oidcCfg;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find org by id" });
- }
- };
-
- return { ...oidcCfgOrm, findEnforceableOidcCfg };
+ return oidcCfgOrm;
};
diff --git a/backend/src/ee/services/saml-config/saml-config-dal.ts b/backend/src/ee/services/saml-config/saml-config-dal.ts
index aff42230ff..c82adcb894 100644
--- a/backend/src/ee/services/saml-config/saml-config-dal.ts
+++ b/backend/src/ee/services/saml-config/saml-config-dal.ts
@@ -1,6 +1,5 @@
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
-import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
@@ -8,25 +7,5 @@ export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
export const samlConfigDALFactory = (db: TDbClient) => {
const samlCfgOrm = ormify(db, TableName.SamlConfig);
- const findEnforceableSamlCfg = async (orgId: string) => {
- try {
- const samlCfg = await db
- .replicaNode()(TableName.SamlConfig)
- .where({
- orgId,
- isActive: true
- })
- .whereNotNull("lastUsed")
- .first();
-
- return samlCfg;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find org by id" });
- }
- };
-
- return {
- ...samlCfgOrm,
- findEnforceableSamlCfg
- };
+ return samlCfgOrm;
};
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 98b35f68fc..455d0ab22f 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -110,8 +110,8 @@ type TOrgServiceFactoryDep = {
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "delete" | "insertMany" | "findLatestProjectKey" | "create">;
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "findOrgMembershipById" | "findOne" | "findById">;
incidentContactDAL: TIncidentContactsDALFactory;
- samlConfigDAL: Pick<TSamlConfigDALFactory, "findOne" | "findEnforceableSamlCfg">;
- oidcConfigDAL: Pick<TOidcConfigDALFactory, "findOne" | "findEnforceableOidcCfg">;
+ samlConfigDAL: Pick<TSamlConfigDALFactory, "findOne">;
+ oidcConfigDAL: Pick<TOidcConfigDALFactory, "findOne">;
smtpService: TSmtpService;
tokenService: TAuthTokenServiceFactory;
permissionService: TPermissionServiceFactory;
@@ -402,13 +402,33 @@ export const orgServiceFactory = ({
}
if (authEnforced) {
- const samlCfg = await samlConfigDAL.findEnforceableSamlCfg(orgId);
- const oidcCfg = await oidcConfigDAL.findEnforceableOidcCfg(orgId);
+ const samlCfg = await samlConfigDAL.findOne({
+ orgId,
+ isActive: true
+ });
+ const oidcCfg = await oidcConfigDAL.findOne({
+ orgId,
+ isActive: true
+ });
if (!samlCfg && !oidcCfg)
throw new NotFoundError({
message: `SAML or OIDC configuration for organization with ID '${orgId}' not found`
});
+
+ if (samlCfg && !samlCfg.lastUsed) {
+ throw new BadRequestError({
+ message:
+ "To apply the new SAML auth enforcement, please log in via SAML again. This step is required to enforce SAML-based authentication."
+ });
+ }
+
+ if (oidcCfg && !oidcCfg.lastUsed) {
+ throw new BadRequestError({
+ message:
+ "To apply the new SAML auth enforcement, please log in via SAML again. This step is required to enforce SAML-based authentication."
+ });
+ }
}
let defaultMembershipRole: string | undefined;