Skip to content

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

feat: introduce SSO permission actions and integrate into existing permission checks

Victor Hugo dos Santos4bc160149863
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts
index 3e8b0117e5..81b134ba29 100644
--- a/backend/src/ee/services/oidc/oidc-config-service.ts
+++ b/backend/src/ee/services/oidc/oidc-config-service.ts
@@ -11,7 +11,7 @@ import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee
import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";
import { throwOnPlanSeatLimitReached } from "@app/ee/services/license/license-fns";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
-import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
+import { OrgPermissionActions, OrgPermissionSsoActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto";
@@ -129,7 +129,7 @@ export const oidcConfigServiceFactory = ({
actorAuthMethod: dto.actorAuthMethod,
scope: OrganizationActionScope.ParentOrganization
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Read, OrgPermissionSubjects.Sso);
}
const { decryptor } = await kmsService.createCipherPairWithDataKey({
@@ -529,7 +529,7 @@ export const oidcConfigServiceFactory = ({
actorAuthMethod,
scope: OrganizationActionScope.ParentOrganization
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
if (org.googleSsoAuthEnforced && isActive) {
throw new BadRequestError({
@@ -624,7 +624,7 @@ export const oidcConfigServiceFactory = ({
actorAuthMethod,
scope: OrganizationActionScope.ParentOrganization
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Create, OrgPermissionSubjects.Sso);
if (org.googleSsoAuthEnforced && isActive) {
throw new BadRequestError({
diff --git a/backend/src/ee/services/permission/org-permission.ts b/backend/src/ee/services/permission/org-permission.ts
index e068a80d64..c79904d2cb 100644
--- a/backend/src/ee/services/permission/org-permission.ts
+++ b/backend/src/ee/services/permission/org-permission.ts
@@ -15,6 +15,14 @@ export enum OrgPermissionActions {
Delete = "delete"
}
+export enum OrgPermissionSsoActions {
+ Read = "read",
+ Create = "create",
+ Edit = "edit",
+ Delete = "delete",
+ BypassSsoEnforcement = "bypass-sso-enforcement"
+}
+
export enum OrgPermissionSubOrgActions {
Create = "create",
DirectAccess = "direct-access",
@@ -140,7 +148,7 @@ export type OrgPermissionSet =
| [OrgPermissionActions, OrgPermissionSubjects.Member]
| [OrgPermissionActions, OrgPermissionSubjects.Settings]
| [OrgPermissionActions, OrgPermissionSubjects.IncidentAccount]
- | [OrgPermissionActions, OrgPermissionSubjects.Sso]
+ | [OrgPermissionSsoActions, OrgPermissionSubjects.Sso]
| [OrgPermissionActions, OrgPermissionSubjects.Scim]
| [OrgPermissionActions, OrgPermissionSubjects.GithubOrgSync]
| [OrgPermissionActions, OrgPermissionSubjects.GithubOrgSyncManual]
@@ -217,7 +225,7 @@ export const OrgPermissionSchema = z.discriminatedUnion("subject", [
}),
z.object({
subject: z.literal(OrgPermissionSubjects.Sso).describe("The entity this permission pertains to."),
- action: CASL_ACTION_SCHEMA_NATIVE_ENUM(OrgPermissionActions).describe("Describe what action an entity can take.")
+ action: CASL_ACTION_SCHEMA_NATIVE_ENUM(OrgPermissionSsoActions).describe("Describe what action an entity can take.")
}),
z.object({
subject: z.literal(OrgPermissionSubjects.Scim).describe("The entity this permission pertains to."),
@@ -357,10 +365,11 @@ const buildAdminPermission = () => {
can(OrgPermissionActions.Edit, OrgPermissionSubjects.IncidentAccount);
can(OrgPermissionActions.Delete, OrgPermissionSubjects.IncidentAccount);
- can(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
- can(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
- can(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
- can(OrgPermissionActions.Delete, OrgPermissionSubjects.Sso);
+ can(OrgPermissionSsoActions.Read, OrgPermissionSubjects.Sso);
+ can(OrgPermissionSsoActions.Create, OrgPermissionSubjects.Sso);
+ can(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
+ can(OrgPermissionSsoActions.Delete, OrgPermissionSubjects.Sso);
+ can(OrgPermissionSsoActions.BypassSsoEnforcement, OrgPermissionSubjects.Sso);
can(OrgPermissionActions.Read, OrgPermissionSubjects.Scim);
can(OrgPermissionActions.Create, OrgPermissionSubjects.Scim);
diff --git a/backend/src/ee/services/permission/permission-service.ts b/backend/src/ee/services/permission/permission-service.ts
index 7894c1505d..adafbe62f2 100644
--- a/backend/src/ee/services/permission/permission-service.ts
+++ b/backend/src/ee/services/permission/permission-service.ts
@@ -32,7 +32,14 @@ import { TRoleDALFactory } from "@app/services/role/role-dal";
import { TServiceTokenDALFactory } from "@app/services/service-token/service-token-dal";
import { TUserDALFactory } from "@app/services/user/user-dal";
-import { orgAdminPermissions, orgMemberPermissions, orgNoAccessPermissions, OrgPermissionSet } from "./org-permission";
+import {
+ orgAdminPermissions,
+ orgMemberPermissions,
+ orgNoAccessPermissions,
+ OrgPermissionSet,
+ OrgPermissionSsoActions,
+ OrgPermissionSubjects
+} from "./org-permission";
import { TPermissionDALFactory } from "./permission-dal";
import { escapeHandlebarsMissingDict, validateOrgSSO } from "./permission-fns";
import {
@@ -244,18 +251,25 @@ export const permissionServiceFactory = ({
const hasRole = (role: string) =>
permissionData.some((memberships) => memberships.roles.some((el) => role === (el.customRoleSlug || el.role)));
- validateOrgSSO(
- actorAuthMethod,
- permissionData?.[0].orgAuthEnforced,
- Boolean(permissionData?.[0].orgGoogleSsoAuthEnforced),
- Boolean(permissionData?.[0].bypassOrgAuthEnabled),
- hasRole(OrgMembershipRole.Admin)
- );
-
const permission = createMongoAbility<OrgPermissionSet>(buildOrgPermissionRules(permissionFromRoles), {
conditionsMatcher
});
+ const canBypassSso =
+ hasRole(OrgMembershipRole.Admin) ||
+ permission.can(OrgPermissionSsoActions.BypassSsoEnforcement, OrgPermissionSubjects.Sso);
+
+ // SSO enforcement applies only to users
+ if (actor === ActorType.USER) {
+ validateOrgSSO(
+ actorAuthMethod,
+ permissionData?.[0].orgAuthEnforced,
+ Boolean(permissionData?.[0].orgGoogleSsoAuthEnforced),
+ Boolean(permissionData?.[0].bypassOrgAuthEnabled),
+ canBypassSso
+ );
+ }
+
return {
permission,
memberships: permissionData,
diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.ts
index a521d3a039..5872efafac 100644
--- a/backend/src/ee/services/saml-config/saml-config-service.ts
+++ b/backend/src/ee/services/saml-config/saml-config-service.ts
@@ -43,7 +43,7 @@ import { TGroupDALFactory } from "../group/group-dal";
import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "../group/group-fns";
import { TUserGroupMembershipDALFactory } from "../group/user-group-membership-dal";
import { TLicenseServiceFactory } from "../license/license-service";
-import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
+import { OrgPermissionActions, OrgPermissionSsoActions, OrgPermissionSubjects } from "../permission/org-permission";
import { TPermissionServiceFactory } from "../permission/permission-service-types";
import { TSamlConfigDALFactory } from "./saml-config-dal";
import { SamlProviders, TSamlConfigServiceFactory } from "./saml-config-types";
@@ -274,7 +274,7 @@ export const samlConfigServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Create, OrgPermissionSubjects.Sso);
const plan = await licenseService.getPlan(orgId);
if (!plan.samlSSO)
@@ -347,7 +347,7 @@ export const samlConfigServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
const plan = await licenseService.getPlan(orgId);
if (!plan.samlSSO)
throw new BadRequestError({
@@ -461,7 +461,7 @@ export const samlConfigServiceFactory = ({
actorAuthMethod: dto.actorAuthMethod,
actorOrgId: dto.actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Read, OrgPermissionSubjects.Sso);
}
const { decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index ede9548aba..3ff30ed4dd 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -987,7 +987,8 @@ export const registerRoutes = async (
notificationService,
membershipRoleDAL,
membershipUserDAL,
- keyStore
+ keyStore,
+ permissionService
});
const passwordService = authPaswordServiceFactory({
tokenService,
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.ts
index 9b15d7c076..ce3d102bbc 100644
--- a/backend/src/services/auth/auth-login-service.ts
+++ b/backend/src/services/auth/auth-login-service.ts
@@ -1,8 +1,10 @@
import { Knex } from "knex";
-import { AccessScope, OrgMembershipRole, OrgMembershipStatus, TUsers, UserDeviceSchema } from "@app/db/schemas";
+import { AccessScope, OrganizationActionScope, OrgMembershipRole, OrgMembershipStatus, TUsers, UserDeviceSchema } from "@app/db/schemas";
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
+import { OrgPermissionSsoActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { isAuthMethodSaml } from "@app/ee/services/permission/permission-fns";
+import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { crypto, generateSrpServerKey, srpCheckClientProof } from "@app/lib/crypto";
@@ -61,6 +63,7 @@ type TAuthLoginServiceFactoryDep = {
membershipRoleDAL: TMembershipRoleDALFactory;
notificationService: Pick<TNotificationServiceFactory, "createUserNotifications">;
keyStore: Pick<TKeyStoreFactory, "acquireLock" | "setItemWithExpiry" | "getItem">;
+ permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
};
export type TAuthLoginFactory = ReturnType<typeof authLoginServiceFactory>;
@@ -74,7 +77,8 @@ export const authLoginServiceFactory = ({
notificationService,
membershipUserDAL,
membershipRoleDAL,
- keyStore
+ keyStore,
+ permissionService
}: TAuthLoginServiceFactoryDep) => {
/*
* Private
@@ -553,8 +557,6 @@ export const authLoginServiceFactory = ({
const isSubOrganization = Boolean(selectedOrg.rootOrgId && selectedOrg.id !== selectedOrg.rootOrgId);
- const membershipRole = (await membershipRoleDAL.findOne({ membershipId: orgMembership.id })).role;
-
let rootOrg = selectedOrg;
if (isSubOrganization) {
@@ -586,11 +588,22 @@ export const authLoginServiceFactory = ({
}
}
+ const { permission } = await permissionService.getOrgPermission({
+ actor: ActorType.USER,
+ actorId: user.id,
+ orgId: rootOrg.id,
+ actorAuthMethod: decodedToken.authMethod,
+ actorOrgId: rootOrg.id,
+ scope: OrganizationActionScope.Any
+ });
+ const canBypassSso = rootOrg.bypassOrgAuthEnabled &&
+ permission.can(OrgPermissionSsoActions.BypassSsoEnforcement, OrgPermissionSubjects.Sso);
+
if (
rootOrg.authEnforced &&
!isAuthMethodSaml(decodedToken.authMethod) &&
decodedToken.authMethod !== AuthMethod.OIDC &&
- !(rootOrg.bypassOrgAuthEnabled && membershipRole === OrgMembershipRole.Admin)
+ !canBypassSso
) {
throw new BadRequestError({
message: "Login with the auth method required by your organization."
@@ -598,9 +611,7 @@ export const authLoginServiceFactory = ({
}
if (rootOrg.googleSsoAuthEnforced && decodedToken.authMethod !== AuthMethod.GOOGLE) {
- const canBypass = rootOrg.bypassOrgAuthEnabled && membershipRole === OrgMembershipRole.Admin;
-
- if (!canBypass) {
+ if (!canBypassSso) {
throw new ForbiddenRequestError({
message: "Google SSO is enforced for this organization. Please use Google SSO to login.",
error: "GoogleSsoEnforced"
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index afeaaa59fd..7dd0519bcc 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -20,6 +20,7 @@ import {
OrgPermissionActions,
OrgPermissionGroupActions,
OrgPermissionSecretShareAction,
+ OrgPermissionSsoActions,
OrgPermissionSubjects
} from "@app/ee/services/permission/org-permission";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
@@ -479,7 +480,7 @@ export const orgServiceFactory = ({
throw new BadRequestError({
message: "Failed to enforce/un-enforce SSO due to plan restriction. Upgrade plan to enforce/un-enforce SSO."
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
}
if (scimEnabled !== undefined) {
@@ -502,7 +503,7 @@ export const orgServiceFactory = ({
message: "Failed to enforce Google SSO due to plan restriction. Upgrade plan to enforce Google SSO."
});
}
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
}
if (authEnforced && googleSsoAuthEnforced) {
diff --git a/frontend/src/context/OrgPermissionContext/types.ts b/frontend/src/context/OrgPermissionContext/types.ts
index fc3f94f7fb..0aadd2bb87 100644
--- a/frontend/src/context/OrgPermissionContext/types.ts
+++ b/frontend/src/context/OrgPermissionContext/types.ts
@@ -7,6 +7,14 @@ export enum OrgPermissionActions {
Delete = "delete"
}
+export enum OrgPermissionSsoActions {
+ Read = "read",
+ Create = "create",
+ Edit = "edit",
+ Delete = "delete",
+ BypassSsoEnforcement = "bypass-sso-enforcement"
+}
+
export enum OrgPermissionBillingActions {
Read = "read",
ManageBilling = "manage-billing"
@@ -133,7 +141,7 @@ export type OrgPermissionSet =
| [OrgPermissionActions, OrgPermissionSubjects.Scim]
| [OrgPermissionActions, OrgPermissionSubjects.GithubOrgSync]
| [OrgPermissionActions, OrgPermissionSubjects.GithubOrgSyncManual]
- | [OrgPermissionActions, OrgPermissionSubjects.Sso]
+ | [OrgPermissionSsoActions, OrgPermissionSubjects.Sso]
| [OrgPermissionActions, OrgPermissionSubjects.Ldap]
| [OrgPermissionGroupActions, OrgPermissionSubjects.Groups]
| [OrgPermissionActions, OrgPermissionSubjects.SecretScanning]
diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
index 8bfb8dd885..14de15a2ba 100644
--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
@@ -13,7 +13,6 @@ import { IsCliLoginSuccessful } from "@app/components/utilities/attemptCliLogin"
import SecurityClient from "@app/components/utilities/SecurityClient";
import { Button, ContentLoader, Input, Spinner } from "@app/components/v2";
import { SessionStorageKeys } from "@app/const";
-import { OrgMembershipRole } from "@app/helpers/roles";
import { useToggle } from "@app/hooks";
import {
TOrgWithSubOrgs,
@@ -97,24 +96,14 @@ export const SelectOrganizationSection = () => {
const handleSelectOrganization = useCallback(
async (organization: Organization) => {
- const isUserOrgAdmin = organization.userRole === OrgMembershipRole.Admin;
- const canBypassOrgAuth = organization.bypassOrgAuthEnabled && isUserOrgAdmin && isAdminLogin;
-
- if (isAdminLogin) {
- if (!organization.bypassOrgAuthEnabled) {
- createNotification({
- text: "This organization does not have bypass org auth enabled",
- type: "error"
- });
- return;
- }
- if (!isUserOrgAdmin) {
- createNotification({
- text: "Only organization admins can bypass org auth",
- type: "error"
- });
- return;
- }
+ const canBypassOrgAuth = organization.bypassOrgAuthEnabled && isAdminLogin;
+
+ if (isAdminLogin && !organization.bypassOrgAuthEnabled) {
+ createNotification({
+ text: "This organization does not have bypass org auth enabled",
+ type: "error"
+ });
+ return;
}
if ((organization.authEnforced || organization.googleSsoAuthEnforced) && !canBypassOrgAuth) {
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts b/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
index 40d9cc080c..83cc10a8d9 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
+++ b/frontend/src/pages/organization/RoleByIDPage/components/OrgRoleModifySection.utils.ts
@@ -12,6 +12,7 @@ import {
OrgPermissionKmipActions,
OrgPermissionMachineIdentityAuthTemplateActions,
OrgPermissionSecretShareAction,
+ OrgPermissionSsoActions,
OrgPermissionSubOrgActions,
OrgRelayPermissionActions
} from "@app/context/OrgPermissionContext/types";
@@ -131,6 +132,16 @@ const subOrganizationPermissionSchema = z
})
.optional();
+const ssoPermissionSchema = z
+ .object({
+ [OrgPermissionSsoActions.Read]: z.boolean().optional(),
+ [OrgPermissionSsoActions.Create]: z.boolean().optional(),
+ [OrgPermissionSsoActions.Edit]: z.boolean().optional(),
+ [OrgPermissionSsoActions.Delete]: z.boolean().optional(),
+ [OrgPermissionSsoActions.BypassSsoEnforcement]: z.boolean().optional()
+ })
+ .optional();
+
export const formSchema = z.object({
name: z.string().trim(),
description: z.string().trim().optional(),
@@ -153,7 +164,7 @@ export const formSchema = z.object({
"service-account": generalPermissionSchema,
"incident-contact": generalPermissionSchema,
"secret-scanning": generalPermissionSchema,
- sso: generalPermissionSchema,
+ sso: ssoPermissionSchema,
scim: generalPermissionSchema,
[OrgPermissionSubjects.GithubOrgSync]: generalPermissionSchema,
ldap: generalPermissionSchema,
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionSsoRow.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionSsoRow.tsx
new file mode 100644
index 0000000000..5db78ae6bb
--- /dev/null
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/OrgPermissionSsoRow.tsx
@@ -0,0 +1,195 @@
+import { useEffect, useMemo } from "react";
+import { Control, Controller, UseFormSetValue, useWatch } from "react-hook-form";
+import { faChevronDown, faChevronRight } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+import { createNotification } from "@app/components/notifications";
+import { Checkbox, Select, SelectItem, Td, Tr } from "@app/components/v2";
+import { OrgPermissionSsoActions } from "@app/context/OrgPermissionContext/types";
+import { useToggle } from "@app/hooks";
+
+import { TFormSchema } from "../OrgRoleModifySection.utils";
+
+const PERMISSION_ACTIONS = [
+ { action: OrgPermissionSsoActions.Read, label: "View" },
+ { action: OrgPermissionSsoActions.Create, label: "Create" },
+ { action: OrgPermissionSsoActions.Edit, label: "Modify" },
+ { action: OrgPermissionSsoActions.Delete, label: "Remove" },
+ { action: OrgPermissionSsoActions.BypassSsoEnforcement, label: "Bypass SSO Enforcement" }
+] as const;
+
+type Props = {
+ isEditable: boolean;
+ setValue: UseFormSetValue<TFormSchema>;
+ control: Control<TFormSchema>;
+};
+
+enum Permission {
+ NoAccess = "no-access",
+ ReadOnly = "read-only",
+ FullAccess = "full-access",
+ Custom = "custom"
+}
+
+export const OrgPermissionSsoRow = ({ isEditable, control, setValue }: Props) => {
+ const [isRowExpanded, setIsRowExpanded] = useToggle();
+ const [isCustom, setIsCustom] = useToggle();
+
+ const rule = useWatch({
+ control,
+ name: "permissions.sso"
+ });
+
+ const selectedPermissionCategory = useMemo(() => {
+ const actions = Object.keys(rule || {}) as Array<keyof typeof rule>;
+ const totalActions = PERMISSION_ACTIONS.length;
+ const score = actions.map((key) => (rule?.[key] ? 1 : 0)).reduce((a, b) => a + b, 0 as number);
+
+ if (isCustom) return Permission.Custom;
+ if (score === 0) return Permission.NoAccess;
+ if (score === totalActions) return Permission.FullAccess;
+ if (score === 1 && rule?.read) return Permission.ReadOnly;
+
+ return Permission.Custom;
+ }, [rule, isCustom]);
+
+ useEffect(() => {
+ if (selectedPermissionCategory === Permission.Custom) setIsCustom.on();
+ else setIsCustom.off();
+ }, [selectedPermissionCategory]);
+
+ useEffect(() => {
+ const isRowCustom = selectedPermissionCategory === Permission.Custom;
+ if (isRowCustom) {
+ setIsRowExpanded.on();
+ }
+ }, []);
+
+ const handlePermissionChange = (val: Permission) => {
+ if (val === Permission.Custom) {
+ setIsRowExpanded.on();
+ setIsCustom.on();
+ return;
+ }
+ setIsCustom.off();
+
+ switch (val) {
+ case Permission.NoAccess:
+ setValue(
+ "permissions.sso",
+ {
+ [OrgPermissionSsoActions.Read]: false,
+ [OrgPermissionSsoActions.Create]: false,
+ [OrgPermissionSsoActions.Edit]: false,
+ [OrgPermissionSsoActions.Delete]: false,
+ [OrgPermissionSsoActions.BypassSsoEnforcement]: false
+ },
+ { shouldDirty: true }
+ );
+ break;
+ case Permission.FullAccess:
+ setValue(
+ "permissions.sso",
+ {
+ [OrgPermissionSsoActions.Read]: true,
+ [OrgPermissionSsoActions.Create]: true,
+ [OrgPermissionSsoActions.Edit]: true,
+ [OrgPermissionSsoActions.Delete]: true,
+ [OrgPermissionSsoActions.BypassSsoEnforcement]: true
+ },
+ { shouldDirty: true }
+ );
+ break;
+ case Permission.ReadOnly:
+ setValue(
+ "permissions.sso",
+ {
+ [OrgPermissionSsoActions.Read]: true,
+ [OrgPermissionSsoActions.Create]: false,
+ [OrgPermissionSsoActions.Edit]: false,
+ [OrgPermissionSsoActions.Delete]: false,
+ [OrgPermissionSsoActions.BypassSsoEnforcement]: false
+ },
+ { shouldDirty: true }
+ );
+ break;
+ default:
+ setValue(
+ "permissions.sso",
+ {
+ [OrgPermissionSsoActions.Read]: false,
+ [OrgPermissionSsoActions.Create]: false,
+ [OrgPermissionSsoActions.Edit]: false,
+ [OrgPermissionSsoActions.Delete]: false,
+ [OrgPermissionSsoActions.BypassSsoEnforcement]: false
+ },
+ { shouldDirty: true }
+ );
+ break;
+ }
+ };
+
+ return (
+ <>
+ <Tr
+ className="h-10 cursor-pointer transition-colors duration-100 hover:bg-mineshaft-700"
+ onClick={() => setIsRowExpanded.toggle()}
+ >
+ <Td className="w-4">
+ <FontAwesomeIcon className="w-4" icon={isRowExpanded ? faChevronDown : faChevronRight} />
+ </Td>
+ <Td className="w-full select-none">SSO</Td>
+ <Td>
+ <Select
+ value={selectedPermissionCategory}
+ className="h-8 w-40 bg-mineshaft-700"
+ dropdownContainerClassName="border text-left border-mineshaft-600 bg-mineshaft-800"
+ onValueChange={handlePermissionChange}
+ isDisabled={!isEditable}
+ position="popper"
+ >
+ <SelectItem value={Permission.NoAccess}>No Access</SelectItem>
+ <SelectItem value={Permission.ReadOnly}>Read Only</SelectItem>
+ <SelectItem value={Permission.FullAccess}>Full Access</SelectItem>
+ <SelectItem value={Permission.Custom}>Custom</SelectItem>
+ </Select>
+ </Td>
+ </Tr>
+ {isRowExpanded && (
+ <Tr>
+ <Td colSpan={3} className="border-mineshaft-500 bg-mineshaft-900 p-8">
+ <div className="flex grow flex-wrap justify-start gap-x-8 gap-y-4">
+ {PERMISSION_ACTIONS.map(({ action, label }) => {
+ return (
+ <Controller
+ name={`permissions.sso.${action}`}
+ key={`permissions.sso.${action}`}
+ control={control}
+ render={({ field }) => (
+ <Checkbox
+ isChecked={field.value}
+ onCheckedChange={(e) => {
+ if (!isEditable) {
+ createNotification({
+ type: "error",
+ text: "Failed to update default role"
+ });
+ return;
+ }
+ field.onChange(e);
+ }}
+ id={`permissions.sso.${action}`}
+ >
+ {label}
+ </Checkbox>
+ )}
+ />
+ );
+ })}
+ </div>
+ </Td>
+ </Tr>
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
index 7fb1a38421..7adc15959f 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionRow.tsx
@@ -75,6 +75,7 @@ type Props = {
| "audit-logs"
| "machine-identity-auth-template"
| "sub-organization"
+ | "sso"
>;
setValue: UseFormSetValue<TFormSchema>;
control: Control<TFormSchema>;
diff --git a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
index c25d11cb74..27c19ffae8 100644
--- a/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
+++ b/frontend/src/pages/organization/RoleByIDPage/components/RolePermissionsSection/RolePermissionsSection.tsx
@@ -25,6 +25,7 @@ import { OrgPermissionKmipRow } from "./OrgPermissionKmipRow";
import { OrgPermissionMachineIdentityAuthTemplateRow } from "./OrgPermissionMachineIdentityAuthTemplateRow";
import { OrgRelayPermissionRow } from "./OrgPermissionRelayRow";
import { OrgPermissionSecretShareRow } from "./OrgPermissionSecretShareRow";
+import { OrgPermissionSsoRow } from "./OrgPermissionSsoRow";
import { OrgPermissionSubOrgRow } from "./OrgPermissionSubOrgRow";
import { OrgRoleWorkspaceRow } from "./OrgRoleWorkspaceRow";
import { RolePermissionRow } from "./RolePermissionRow";
@@ -50,10 +51,6 @@ const SIMPLE_PERMISSION_OPTIONS = [
title: "Secret Scanning",
formName: "secret-scanning"
},
- {
- title: "SSO",
- formName: "sso"
- },
{
title: "LDAP",
formName: "ldap"
@@ -174,6 +171,11 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
/>
);
})}
+ <OrgPermissionSsoRow
+ control={control}
+ setValue={setValue}
+ isEditable={isCustomRole}
+ />
<OrgPermissionAuditLogsRow
control={control}
setValue={setValue}