mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat: updated error message on update org for saml/oidc enforcement
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
|
||||||
import { ormify } from "@app/lib/knex";
|
import { ormify } from "@app/lib/knex";
|
||||||
|
|
||||||
export type TOidcConfigDALFactory = ReturnType<typeof oidcConfigDALFactory>;
|
export type TOidcConfigDALFactory = ReturnType<typeof oidcConfigDALFactory>;
|
||||||
@@ -8,22 +7,5 @@ export type TOidcConfigDALFactory = ReturnType<typeof oidcConfigDALFactory>;
|
|||||||
export const oidcConfigDALFactory = (db: TDbClient) => {
|
export const oidcConfigDALFactory = (db: TDbClient) => {
|
||||||
const oidcCfgOrm = ormify(db, TableName.OidcConfig);
|
const oidcCfgOrm = ormify(db, TableName.OidcConfig);
|
||||||
|
|
||||||
const findEnforceableOidcCfg = async (orgId: string) => {
|
return oidcCfgOrm;
|
||||||
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 };
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
|
||||||
import { ormify } from "@app/lib/knex";
|
import { ormify } from "@app/lib/knex";
|
||||||
|
|
||||||
export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
|
export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
|
||||||
@@ -8,25 +7,5 @@ export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
|
|||||||
export const samlConfigDALFactory = (db: TDbClient) => {
|
export const samlConfigDALFactory = (db: TDbClient) => {
|
||||||
const samlCfgOrm = ormify(db, TableName.SamlConfig);
|
const samlCfgOrm = ormify(db, TableName.SamlConfig);
|
||||||
|
|
||||||
const findEnforceableSamlCfg = async (orgId: string) => {
|
return samlCfgOrm;
|
||||||
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
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ type TOrgServiceFactoryDep = {
|
|||||||
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "delete" | "insertMany" | "findLatestProjectKey" | "create">;
|
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "delete" | "insertMany" | "findLatestProjectKey" | "create">;
|
||||||
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "findOrgMembershipById" | "findOne" | "findById">;
|
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "findOrgMembershipById" | "findOne" | "findById">;
|
||||||
incidentContactDAL: TIncidentContactsDALFactory;
|
incidentContactDAL: TIncidentContactsDALFactory;
|
||||||
samlConfigDAL: Pick<TSamlConfigDALFactory, "findOne" | "findEnforceableSamlCfg">;
|
samlConfigDAL: Pick<TSamlConfigDALFactory, "findOne">;
|
||||||
oidcConfigDAL: Pick<TOidcConfigDALFactory, "findOne" | "findEnforceableOidcCfg">;
|
oidcConfigDAL: Pick<TOidcConfigDALFactory, "findOne">;
|
||||||
smtpService: TSmtpService;
|
smtpService: TSmtpService;
|
||||||
tokenService: TAuthTokenServiceFactory;
|
tokenService: TAuthTokenServiceFactory;
|
||||||
permissionService: TPermissionServiceFactory;
|
permissionService: TPermissionServiceFactory;
|
||||||
@@ -402,13 +402,33 @@ export const orgServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (authEnforced) {
|
if (authEnforced) {
|
||||||
const samlCfg = await samlConfigDAL.findEnforceableSamlCfg(orgId);
|
const samlCfg = await samlConfigDAL.findOne({
|
||||||
const oidcCfg = await oidcConfigDAL.findEnforceableOidcCfg(orgId);
|
orgId,
|
||||||
|
isActive: true
|
||||||
|
});
|
||||||
|
const oidcCfg = await oidcConfigDAL.findOne({
|
||||||
|
orgId,
|
||||||
|
isActive: true
|
||||||
|
});
|
||||||
|
|
||||||
if (!samlCfg && !oidcCfg)
|
if (!samlCfg && !oidcCfg)
|
||||||
throw new NotFoundError({
|
throw new NotFoundError({
|
||||||
message: `SAML or OIDC configuration for organization with ID '${orgId}' not found`
|
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;
|
let defaultMembershipRole: string | undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user