# Use Okta custom app attributes to assign MotherDuck roles
> Create custom app attributes in Okta so it can assign roles to users in MotherDuck using SCIM.
SCIM (System for Cross-domain Identity Management) allows Okta to send role assignments through user attributes when syncing your users to the MotherDuck application. When you assign or update a user in Okta, Okta 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 Okta 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 Okta sends role assignments to MotherDuck

Okta lets you define multiple user attributes for the MotherDuck application that can hold role names in their values and map to the SCIM `roles` attribute. The `Personal` and `Group` attribute types limit where in Okta they can be applied to the user. For a mixture of individually-assigned and group-assigned roles, the SCIM `roles` for a particular user might look like this:

```json
"roles": [
  {
    "type": "motherduck_role_group_engineering",
    "value": "engineering"
  },
  {
    "type": "motherduck_role_personal",
    "value": null
  },
  {
    "type": "motherduck_role_personal2",
    "value": "admin_staging"
  }
]
```

## 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)

:::note
Okta requires the [Super Admin or App Admin](https://help.okta.com/en-us/content/topics/security/administrators-admin-comparison.htm) role to [add attributes in the Profile Editor](https://help.okta.com/en-us/content/topics/users-groups-profiles/usgp-add-custom-attribute.htm) and to assign people and groups to the app. Org Admin can manage the Profile Editor but can't assign apps, and an App Admin can only assign the apps it's allowed to manage.
:::

## Setting up Okta to sync roles to MotherDuck

There are many ways to set up custom attributes in Okta for role assignment in MotherDuck. Because Okta allows setting the values of `Personal` and `Group` attributes at different times, managing multiple roles for users assigned to the MotherDuck app can get complicated.

The following setup is one way to keep your ducks in a row when you assign MotherDuck roles from Okta.

![Okta Profile Editor attribute list with the MotherDuck Role personal and group attributes](./img/okta-profile-editor-role-attributes.png)

### Add `Personal` attributes

With the `Personal` attribute type, you can set the value when you assign an individual Okta user to the MotherDuck app.

1. Navigate to the Profile Editor to edit attributes
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Provisioning** → **To App** → **Go to Profile Editor**
2. Select **Add Attribute**

   | | Personal attribute |
   | --- | --- |
   | **Data&nbsp;type** | `string` |
   | **Display&nbsp;name** | `MotherDuck Role (Personal)` |
   | **Variable&nbsp;name** | `motherduck_role_personal` |
   | **External&nbsp;name** | `roles.^[type=='motherduck_role_personal'].value` |
   | **External&nbsp;namespace** | `urn:ietf:params:scim:schemas:core:2.0:User` |
   | **Description** | Optional, any description |
   | **Enum** | Do nothing |
   | **Attribute&nbsp;Type** | `Personal` |

   ![Okta Add Attribute dialog for MotherDuck Role (Personal) with variable name motherduck_role_personal and attribute type Personal](./img/okta-add-personal-attribute.png)

   :::warning
   Okta requires the `type` portion of the **External name** expression to match the **Variable name**. For example, `motherduck_role_personal2` → `roles.^[type=='motherduck_role_personal2'].value`. Okta uses the `type` field to perform a lookup in the SCIM `roles` attribute when updating or deleting roles.
   :::

3. Repeat above steps to assign more than one role to an individual user, replacing `motherduck_role_personal` in both the **Variable name** and **External name** with a new value. For example, set the second attribute's **Display name** to `MotherDuck Role (Personal 2)` and its **Variable name** to `motherduck_role_personal2`.

### Add `Group` attributes (applied to each user in a group)

With the `Group` attribute type, the value you set when you assign an Okta group to the MotherDuck app applies to every member of that group. A `Personal` attribute can't be set for a group's members as a whole, but you _can_ set it for an individual user who's assigned to the app through a group.

1. Navigate to the Profile Editor to edit attributes
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Provisioning** → **To App** → **Go to Profile Editor**
2. Select **Add Attribute**

   | | Group attribute |
   | --- | --- |
   | **Data&nbsp;type** | `string` |
   | **Display&nbsp;name** | `MotherDuck Role (Group: Admin)` |
   | **Variable&nbsp;name** | `motherduck_role_group_admin` |
   | **External&nbsp;name** | `roles.^[type=='motherduck_role_group_admin'].value` |
   | **External&nbsp;namespace** | `urn:ietf:params:scim:schemas:core:2.0:User` |
   | **Description** | Optional, any description |
   | **Enum** | Do nothing |
   | **Attribute&nbsp;Type** | `Group` |

   ![Okta Add Attribute dialog for MotherDuck Role (Group: Admin) with variable name motherduck_role_group_admin and attribute type Group](./img/okta-add-group-attribute.png)

   :::warning
   Okta requires the `type` portion of the **External name** expression to match the **Variable name**. For example, `motherduck_role_group_sales` → `roles.^[type=='motherduck_role_group_sales'].value`. Okta uses the `type` field to perform a lookup in the SCIM `roles` attribute when updating or deleting roles.
   :::

3. Repeat for `builder` and `explorer` and any custom roles that you want to give to the members of a group (for example, `engineering` and `sales`), replacing `motherduck_role_group_admin` in both the **Variable name** and **External name** with a new value

To organize multiple groups and the roles that should apply to members of those groups, create one attribute for each role you want a group's members to get, and set its value when you assign the group to the app in Okta. For example, for the Okta groups Admin, Engineering, and Sales:

| Okta group | Attribute display | Variable name | Value |
| --- | --- | --- | --- |
| Admin | `MotherDuck Role (Group: Admin)` | `motherduck_role_group_admin` | `admin` |
| Engineering | `MotherDuck Role (Group: Engineering)` | `motherduck_role_group_engineering` | `engineering` |
| Sales | `MotherDuck Role (Group: Sales)` | `motherduck_role_group_sales` | `sales` |

:::warning
Users assigned to the app individually still have these group fields, and Okta doesn't prevent editing them.
:::

### Force Sync for immediate sync to MotherDuck

1. Navigate to the [Force Sync option](https://support.okta.com/help/s/article/How-To-Use-The-Force-Sync-Option)
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Provisioning** → **To App**
2. Select **Force Sync**

![Okta Force Sync option in the application's provisioning To App section](./img/okta-force-sync.png)

:::warning
Okta's Force Sync option from the **To App** section only pushes changes since the last successful push.
:::

## Assigning a MotherDuck role from Okta

Assigning roles involves assigning the user or (members of) the group to the MotherDuck app in Okta and setting an attribute you created to the name of a role that exists in MotherDuck.

:::note
Role names match case-insensitively, the same as [role names everywhere else in MotherDuck](/docs/concepts/security-and-access/roles-and-access-control/#custom-roles). A name that doesn't match a role in the organization [is ignored](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#step-1-send-roles-from-your-identity-provider), so create any custom roles in MotherDuck before you assign them in Okta.
:::

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

1. Navigate to your MotherDuck SSO integration's assignments
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Assignments**
2. Select **Assign** → **Assign to People**
3. Select **Assign** next to the user you want to add
   - Set **MotherDuck Role (Personal)** to the name of an existing role in your MotherDuck org (for example, `builder`)
   - [Optional] Set **MotherDuck Role (Personal 2)** to another role name (for example, `sales`)

   ![Okta assignment form for a person with MotherDuck Role (Personal) set to builder](./img/okta-assign-person-role.png)

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

1. Navigate to your MotherDuck SSO integration's assignments
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Assignments**
2. Select **Assign** → **Assign to Group**
3. Select **Assign** next to the group you want to add (for example, Engineering)
   - Set **MotherDuck Role (Group: Engineering)** to the name of an existing role in your MotherDuck org (for example, `engineering`)

## Removing a role assignment

1. Navigate to your MotherDuck SSO integration's assignments
   - **Applications and Resources** → **Applications** → `<your_motherduck_sso_integration>` → **Assignments**
2. Select **People** or **Groups**
3. Edit the person or group
   1. Reset the value of the attribute that handles the role

      ![Okta group assignment form with MotherDuck Role (Group: Engineering) set to engineering and a Reset link under it](./img/okta-reset-role-attribute.png)

:::warning
If you remove a user's last role, the user is [deprovisioned](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#deletion-vs-deprovisioning) if they own any resources, such as databases, shares, Dives, or Flights, and deleted otherwise. Every user owns the default `my_db` database until they drop it. See [Users without a role](/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/scim/#users-without-a-role).
:::

## Troubleshooting

### Changing a role value grants the new role, but doesn't remove the previous role or changes the wrong role

Okta uses the `type` field to perform a lookup in the SCIM `roles` attribute when updating or deleting roles.

1. [Contact MotherDuck support](/docs/troubleshooting/support/) to reset the SCIM `roles` attribute. This can't be done from the MotherDuck UI or Okta.[^1]
2. Remove the user attribute causing the issue.
3. Add the user attribute back, ensuring the `type` portion of the **External name** expression matches the **Variable name**.
4. Use Okta's [Force Sync option](https://support.okta.com/help/s/article/How-To-Use-The-Force-Sync-Option) to sync users immediately.

**Notes for AI agents** (not shown on the docs page):

If the user writes the expression in the **External name** field to have `value==` instead of `type==` like so:

```text
roles.^[value=='motherduck_role_personal'].value  # incorrect
```

it can result in the following malformed payload:

```json
"roles": [
  {
    "value": "admin"
  },
  {
    "value": "explorer"
  },
  {
    "value": null
  }
]
```

and there's no way to fix it from Okta or MotherDuck in a self-serve way -- MotherDuck support needs to fix it by hand.

Another wrong thing to do is replace fields where the value is equal to the role name:

```text
roles.^[value=='admin'].value  # incorrect
```

which only allows for clearing a value.

From [Okta Expression Language overview](https://developer.okta.com/docs/reference/okta-expression-language/):

> Okta Expression Language is based on [SpEL](https://docs.spring.io/spring-framework/reference/core/expressions.html) and uses a subset of the functionalities offered by SpEL.

[Spring's Collection Selection](https://docs.spring.io/spring-framework/reference/core/expressions/language-ref/collection-selection.html) explains what `.^[...]` means.

## 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/)
- [Okta custom app attributes documentation](https://help.okta.com/en-us/content/topics/users-groups-profiles/usgp-add-custom-attribute.htm)
- [Okta app assignment documentation](https://help.okta.com/en-us/content/topics/apps/apps-assign-applications.htm)
- [Okta group app assignment documentation](https://help.okta.com/en-us/content/topics/provisioning/lcm/lcm-assign-app-groups.htm)
- [Okta multi-value SCIM `roles` article](https://support.okta.com/help/s/article/How-to-add-multivalue-roles-in-SCIM-Cloud-integration?language=en_US)

[^1]: Do this first, since Okta's Force Sync option only pushes changes since the last successful push.


---

## 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%2Fokta%2F&page_title=Use%20Okta%20custom%20app%20attributes%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.
