# Use Entra app roles to assign MotherDuck roles
> Define an Entra App Role for each MotherDuck role to allow Entra to assign roles to users in MotherDuck using SCIM.
SCIM (System for Cross-domain Identity Management) allows Entra to send role assignments defined by app roles when syncing your users to the MotherDuck application. When you assign or update a user in your IdP, Entra sends role names that MotherDuck can then apply to the user in MotherDuck. [Enabling SCIM role assignment](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#assign-roles-from-your-identity-provider) makes Entra the source of truth for each user's roles, disabling role changes to users in MotherDuck.

:::note
SCIM role assignment is available on the **Enterprise** plan, requiring an active [SSO connection](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/sso-setup/) and [SCIM](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/) enabled.
:::

## How Entra sends role assignments to MotherDuck

Entra lets you define [app roles](https://learn.microsoft.com/en-us/entra/identity-platform/howto-add-app-roles-in-apps#declare-roles-for-an-application) for the MotherDuck application and then map the app role's **Value** to the `roles` attribute during SCIM provisioning.
[Enabling SCIM](./index.md#enabling-scim) with MotherDuck sets [a compatibility flag in the SCIM endpoint URL Entra uses](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/application-provisioning-config-problem-scim-compatibility#flags-to-alter-the-scim-behavior:~:text=URL%20(SCIM%20Compliant)%3A%20aadOptscim062020), and creating an attribute map with the right [transform expression](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/customize-application-attributes#provisioning-a-role-to-a-scim-app:~:text=AssertiveAppRoleAssignmentsComplex%20%28Recommended%20for%20complex%20roles%29) tells Entra to include a `roles` attribute in SCIM user updates like so:

```json
"roles": [
  {
    "display": "MotherDuck Explorer (built-in)",
    "primary": false,
    "type": "WindowsAzureActiveDirectoryRole",
    "value": "explorer"
  },
  {
    "display": "MotherDuck Engineer (custom)",
    "primary": false,
    "type": "WindowsAzureActiveDirectoryRole",
    "value": "engineer"
  },
  {
    "display": "MotherDuck Admin (built-in)",
    "primary": false,
    "type": "WindowsAzureActiveDirectoryRole",
    "value": "admin"
  }
]
```

## Prerequisites

- [Enable SSO](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/sso-setup/#setting-up-sso-1)
- [Enable SCIM](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#enabling-scim)
- [Perform Entra-Specific Setup](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#microsoft-entra): For the `externalId` target attribute, set the source attribute to `objectId`.

:::note
Microsoft requires at least [Application Administrator](https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/permissions-reference#application-administrator) to [edit attribute mappings](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/customize-application-attributes) and at least [Cloud Application Administrator](https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/permissions-reference#cloud-application-administrator) to [create app roles](https://learn.microsoft.com/en-us/entra/identity-platform/howto-add-app-roles-in-apps#declare-roles-for-an-application).
:::

## Set up Entra to sync roles to MotherDuck

### Create app roles

1. Navigate to your MotherDuck SSO integration's settings for app roles:
   - **App registrations** → **All apps** → `<your_motherduck_sso_integration>` → **App roles**
2. Select **Create app role**

   | | Admin |
   | --- | --- |
   | **Display Name** | `MotherDuck Admin (built-in)` |
   | **Allowed&nbsp;member&nbsp;types** | `Users/Groups` |
   | **Value** | `admin` |
   | **Description** | `MotherDuck's preset admin role for RBAC: https://motherduck.com/docs/concepts/security-and-access/roles-and-access-control/#preset-roles` |

   ![Entra Create app role panel with display name MotherDuck Admin (built-in), Users/Groups selected, value admin and a description](./img/entra-create-app-role.png)

3. Repeat for built-in `builder` and `explorer` and any custom roles you have defined in MotherDuck

   | | Builder |
   | --- | --- |
   | **Display Name** | `MotherDuck Builder (built-in)` |
   | **Allowed&nbsp;member&nbsp;types** | `Users/Groups` |
   | **Value** | `builder` |
   | **Description** | `MotherDuck's preset builder role for RBAC: https://motherduck.com/docs/concepts/security-and-access/roles-and-access-control/#preset-roles` |

   | | Explorer |
   | --- | --- |
   | **Display Name** | `MotherDuck Explorer (built-in)` |
   | **Allowed&nbsp;member&nbsp;types** | `Users/Groups` |
   | **Value** | `explorer` |
   | **Description** | `MotherDuck's preset explorer role for RBAC: https://motherduck.com/docs/concepts/security-and-access/roles-and-access-control/#preset-roles` |

   ![Entra App roles list for the MotherDuck app with engineer, explorer, builder, and admin roles](./img/entra-app-roles.png)

### Add roles attribute

1. Navigate to your MotherDuck SSO integration's settings for attribute mappings
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Provisioning** → **Attribute mapping**
2. Append the following to your URL:

   ```text
   ?Microsoft_AAD_Connect_Provisioning_forceSchemaEditorEnabled=true
   ```

3. Edit the user attributes that SCIM sends with each user
   - **Advanced options** → **Edit `customappsso` user attributes**

   ![Entra Attribute mapping page with the Advanced options menu open on Edit customappsso user attributes](./img/entra-attribute-mapping-advanced-options.png)

4. Select **Add new attribute**
   1. Check the **Multi-value** box (it's the third one)
   2. Set **Type** to `String`
   3. Set **Name** to `roles`

   ![Entra Edit attribute list page with a new multi-value String attribute named roles](./img/entra-edit-attribute-list-roles.png)

### Create attribute map

1. Navigate to your MotherDuck SSO integration's settings for attribute mappings
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Provisioning** → **Attribute mapping**
2. Select **Add attribute mapping**

   | | Attribute mapping |
   | --- | --- |
   | **Mapping&nbsp;Type** | `Expression` |
   | **Expression** | `AssertiveAppRoleAssignmentsComplex([appRoleAssignments])` |
   | **Target&nbsp;attribute**&nbsp;(`customappsso`) | `roles` |
   | **Apply&nbsp;this&nbsp;mapping** | `Always` |

   ![Entra Add Attribute Mapping panel with an Expression mapping type, the AssertiveAppRoleAssignmentsComplex expression and target attribute roles](./img/entra-add-attribute-mapping.png)

## Assigning a MotherDuck role from Entra

### Assign a user to the MotherDuck app with a MotherDuck role

1. Navigate to your MotherDuck SSO integration's settings for user and group assignment
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Users and groups**
2. Select **Add user/group**
   1. Select the user

      ![Entra Add Assignment page with the Users picker open and one user selected](./img/entra-add-assignment-select-user.png)

   2. Select the app role

      ![Entra Add Assignment page with one user selected and the MotherDuck Builder (built-in) role selected](./img/entra-add-assignment-role-selected.png)

      ![Entra Select a role panel listing the MotherDuck app roles](./img/entra-add-assignment-select-role.png)

   3. Select **Assign**
3. Repeat to assign multiple roles to a single user – each user-role assignment appears as a separate assignment row:

   ![Entra Users and groups application assignments page with one user assigned three times, one per assigned MotherDuck role](./img/entra-users-and-groups-app-assignments.png)

4. [Provision the user right away](#provision-on-demand-for-immediate-sync-to-motherduck), before they sign in to MotherDuck. Otherwise, Entra only syncs about every 40 minutes, and a user who signs in with SSO first blocks provisioning with `Resource already exists`.

   :::warning[Provision users before they sign in to MotherDuck]
   A user who signs in to MotherDuck with SSO before Entra provisions them [blocks provisioning with](#resource-already-exists-when-provisioning-a-user) `Resource already exists`, and only MotherDuck support can fix it.
   :::

### Assign (members of) a group to the MotherDuck app with a MotherDuck role

:::note
[Assigning a group to an app](https://learn.microsoft.com/en-us/entra/identity/users/groups-saasapps) requires Microsoft Entra ID P1 or P2 and works only with security groups. Only direct members of the group get the role: Entra [doesn't provision members of nested groups](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/how-provisioning-works#assignment-based-scoping).
:::

1. Navigate to your MotherDuck SSO integration's settings for user and group assignment
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Users and groups**
2. Select **Add user/group**
   1. Select the group
   2. Select the app role
   3. Select **Assign**
3. Repeat to assign multiple roles to a group
4. [Provision the group right away](#provision-on-demand-for-immediate-sync-to-motherduck), before they sign in to MotherDuck. Otherwise, Entra only syncs about every 40 minutes, and a user who signs in with SSO first blocks provisioning with `Resource already exists`.

   :::warning[Provision users before they sign in to MotherDuck]
   A user who signs in to MotherDuck with SSO before Entra provisions them [blocks provisioning with](#resource-already-exists-when-provisioning-a-user) `Resource already exists`, and only MotherDuck support can fix it.
   :::

:::tip

Use Microsoft Entra groups to organize how you assign users to the MotherDuck application:

![Entra Groups page with a group for each of the roles in MotherDuck named 'MotherDuck_SSO_\<role_name\>'](./img/entra-groups-tip.png)

_One Microsoft Entra group per MotherDuck role, each named in the format `MotherDuck_SSO_<role_name>`_

:::

### Provision on-demand for immediate sync to MotherDuck

Entra only [sends provisioning requests roughly every 40 minutes](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/use-scim-to-provision-users-and-groups#getting-started:~:text=The%20process%20runs%20every%2040%20minutes), so a user who signs in to MotherDuck with SSO before Entra provisions them [can block provisioning](#resource-already-exists-when-provisioning-a-user).

Restarting provisioning doesn't sync right away either. It [starts a new initial cycle](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/how-provisioning-works#incremental-cycles), which Microsoft says ["can take some time"](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/application-provisioning-quarantine-status#how-do-i-get-my-application-out-of-quarantine) and takes longer than the regular cycles. To provision a user or group right away, use **Provision on demand**:

- **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Provisioning** → **Provision on demand** → select the user or group → **Provision**

![Entra Provision on demand page for the MotherDuck app, with one user selected from the search results and the Provision button below](./img/entra-provision-on-demand.png)

![Entra Provision on demand results: the user was updated in customappsso and the Added attributes table includes roles with the MotherDuck Admin (built-in) app role](./img/entra-provision-on-demand-result.png)

## Removing a role assignment

1. Navigate to your MotherDuck SSO integration's settings for user and group assignment
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Users and groups**
2. Select the user/group with the role you want to remove
3. Select **Remove assignment**

## Troubleshooting

### Failed to initialize user

Your identity provider's sign-in logs show a successful sign-in to the MotherDuck app, but MotherDuck shows this error:

![MotherDuck Initialization Error dialog: Failed to initialize user - Error: Unexpected status received from user service: 403, with Username unknown and User E-mail unknown](./img/entra-failed-to-initialize-user.png)

Set the email attribute on the user's identity in Entra. See [Add or update a user's profile information](https://learn.microsoft.com/en-us/entra/fundamentals/how-to-manage-user-profile-info#add-or-change-profile-information) in the Microsoft Entra documentation.

![Entra user overview page with the Email row under Contact Information highlighted, showing that MotherDuck requires that value in order to sign a user in](./img/entra-user-email-attribute.png)

### "Resource already exists" when provisioning a user

If a user assigned to the MotherDuck app in Entra signs in to MotherDuck using SSO before Entra sends provisioning requests, Entra sends MotherDuck an incomplete identity that causes SCIM provisioning to fail.

1. Ask the user to sign out of MotherDuck completely.
2. [Contact MotherDuck support](/docs/troubleshooting/support/) to remove the identity. This can't be done from the MotherDuck UI.
3. Provision the user right away using Entra's **Provision on demand** feature, as in [Provision on-demand for immediate sync to MotherDuck](#provision-on-demand-for-immediate-sync-to-motherduck).

### Entra still doesn't send roles

If Entra provisions users but their roles in MotherDuck don't match their app role assignments, check the provisioning scope. The `AssertiveAppRoleAssignmentsComplex` expression [doesn't work when the scope is **Sync all users and groups**](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/customize-application-attributes#provisioning-a-role-to-a-scim-app).

1. Navigate to your MotherDuck SSO integration's provisioning settings
   - **Enterprise Apps** → `<your_motherduck_sso_integration>` → **Provisioning** → **Overview** → **Properties**
2. Check that **Provisioning scope** is `Sync only assigned users and groups`

   ![Entra provisioning Properties tab for the MotherDuck app, with the Provisioning scope row highlighted, set to Sync only assigned users and groups](./img/entra-provision-assigned-only.png)

3. If it isn't, select the edit icon next to **Settings** and set **Provisioning scope** to `Sync only assigned users and groups`

## Related

- [Setting up SSO](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/sso-setup/)
- [Setting up SCIM](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/)
- [Roles and access control](/docs/concepts/security-and-access/roles-and-access-control/)
- [Microsoft Entra app roles documentation](https://learn.microsoft.com/en-us/entra/identity-platform/howto-add-app-roles-in-apps#declare-roles-for-an-application)
- [Microsoft Entra `roles` attribute mapping documentation](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/customize-application-attributes#provisioning-a-role-to-a-scim-app)
- [Microsoft Entra on-demand provisioning documentation](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/provision-on-demand?pivots=app-provisioning)


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fkey-tasks%2Fauthenticating-and-connecting-to-motherduck%2Fauthenticating-to-motherduck%2Fscim%2Fentra%2F&page_title=Use%20Entra%20app%20roles%20to%20assign%20MotherDuck%20roles&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
