> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage custom roles

> This page describes how administrators can add, modify, and remove custom roles

export const BetaBadge = ({link, galaxyTrack, galaxyEvent}) => {
  if (link) {
    return <a href={link} target="_blank" rel="noopener noreferrer" className="betaBadge" onClick={galaxyTrack && galaxyEvent ? galaxyOnClick(galaxyEvent) : undefined}>
                <span>Beta</span>
            </a>;
  }
  return <a href="/reference/settings/beta-and-experimental-features#beta-features" className="betaBadge">
            <span>Beta feature</span>
        </a>;
};

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

This guide is intended for users with the Admin role in ClickHouse Cloud.

ClickHouse Cloud customers may select from pre-defined system roles or create custom roles to assign to users. For more information on system roles and their associated permissions, review [Console roles and permissions](/products/cloud/reference/security/console-roles). This guide provides details for managing custom roles.

<h2 id="create-custom-role">
  Create custom roles
</h2>

Custom roles can contain a combination of organization, service, and database permissions. Permissions may be applied to all or a subset of services and databases.

<Steps>
  <Step title="Access organization settings and select Users and roles" id="users-and-roles-1">
    From the services page, select the name of your organization. Select the `Users and roles` menu item from the popup menu.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/1_users_and_roles.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=232544779a6810ddfc21e34fbf95c769" size="lg" width="3418" height="1702" data-path="images/cloud/guides/control_plane/1_users_and_roles.webp" />
  </Step>

  <Step title={<>Select the <code>Roles</code> tab</>} id="roles-tab">
    Select the `Roles` tab from the top middle of the screen.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/manage_custom_roles/2_custom_role.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=2ff087521dac70e8a43792525826f7a9" size="lg" width="3414" height="984" data-path="images/cloud/guides/control_plane/manage_custom_roles/2_custom_role.webp" />
  </Step>

  <Step title={<>Select <code>Create new role</code> from the upper right</>} id="create-new-role">
    Select the `Create new role` button in the upper right of the screen.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/manage_custom_roles/3_custom_role.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=41863d1e1b5ccd00298fcb39c5bb8921" size="lg" width="3418" height="1706" data-path="images/cloud/guides/control_plane/manage_custom_roles/3_custom_role.webp" />
  </Step>

  <Step title="Name the role" id="name-the-role">
    Enter a descriptive role name. This will be the name you will see when assigning roles to users and API keys.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/manage_custom_roles/4_custom_role.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=51c44c5f1e5f5ca8025984257f7d7b0c" size="md" width="1200" height="1704" data-path="images/cloud/guides/control_plane/manage_custom_roles/4_custom_role.webp" />
  </Step>

  <Step title={<>Click <code>Allow</code> and select permission scope</>} id="scope-permissions">
    Click the `Allow` button and select from Organization, Service, and/or Database permissions. For a description of all permissions, see [Console roles and permissions](/products/cloud/reference/security/console-roles).

    <Tip>
      Ensure users who will log into the console have a minimum of Organization > Access organization permissions.
    </Tip>

    <Info>
      **Data Sources tab access**

      To access the **Data Sources** tab, the role currently requires the `Manage and Delete Selected Services` permission.
    </Info>

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/manage_custom_roles/5_custom_role.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=528631dc3a994da88bb7c904f8984867" size="md" width="1192" height="1700" data-path="images/cloud/guides/control_plane/manage_custom_roles/5_custom_role.webp" />
  </Step>

  <Step title="Review your new role" id="review-role">
    Review permissions assigned to your new role before finalizing. Click `Create role` when done.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/EvPjyFqV5fkDf49u/images/cloud/guides/control_plane/manage_custom_roles/6_custom_role.webp?fit=max&auto=format&n=EvPjyFqV5fkDf49u&q=85&s=8bfa82482fabf189d82b4e9eb46a90cc" size="md" width="1190" height="1696" data-path="images/cloud/guides/control_plane/manage_custom_roles/6_custom_role.webp" />
  </Step>
</Steps>

<h2 id="manage-database-roles">
  Manage database roles (beta)
</h2>

<BetaBadge />

In addition to console permissions, custom roles can include data permissions that control access to the databases of selected services. This lets you manage console and database access in one place instead of maintaining separate roles in each database.

<Note>
  This feature is in beta and is available for services running ClickHouse version 26.4 and above.
</Note>

When you add data permissions to a custom role, ClickHouse Cloud creates a matching role in each selected service, prefixed with `cloud:`. For example, a custom role named `readonly` appears in the database as `cloud:readonly`. Members of the custom role receive these database permissions when they connect to the service through SQL console passwordless authentication.

<Info>
  Roles assigned manually in the database using the [`sql-console-role:<email>` naming convention](/products/cloud/guides/security/cloud-access-management/manage-database-users#sql-console-users-and-roles) take precedence over roles assigned through the console.
</Info>

<Steps>
  <Step title="Add data permissions to a role" id="add-data-permissions">
    [Create a custom role](#create-custom-role) or edit an existing one. In the role dialog, click the `Allow permissions` button and select `Data`.
  </Step>

  <Step title="Select the service" id="select-data-permissions-service">
    Select the service the permissions apply to. Add more services to apply permissions across multiple services.
  </Step>

  <Step title="Choose the access level" id="choose-data-access-level">
    Select `Read-only`, `Admin`, or `Custom` access. With `Custom` access, define specific data access permissions using ClickHouse [`GRANT` statements](/reference/statements/grant).

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/jnjpUVU1ddCBeSFw/images/cloud/guides/control_plane/manage_custom_roles/create_role_data_permissions.webp?fit=max&auto=format&n=jnjpUVU1ddCBeSFw&q=85&s=8fab09d68435c701dea7d8e3c3421555" alt="Create new role dialog with data permissions defined by custom grant statements" size="md" width="1174" height="1230" data-path="images/cloud/guides/control_plane/manage_custom_roles/create_role_data_permissions.webp" />
  </Step>

  <Step title="Create the role" id="create-role-with-data-permissions">
    Click `Create role`. The database roles are created in the selected services.
  </Step>
</Steps>

<h3 id="verify-database-roles">
  Verify database roles
</h3>

Roles managed through the console are created in the database with the `cloud:` prefix and the `cloud` storage type. To list them, query the `system.roles` table in the service:

```sql theme={null}
SELECT * FROM system.roles;
```

```response theme={null}
┌─name───────────┬─id───────────────────────────────────┬─storage─┐
│ cloud:readonly │ 9a4910f4-abcf-4904-466a-717c8c75ac42 │ cloud   │
└────────────────┴──────────────────────────────────────┴─────────┘
```

<h2 id="update-custom-role">
  Update custom roles
</h2>

Custom roles may be updated after they're created. Users will lose any permissions removed from the role and will gain any permissions added.

<Tip>
  User permissions are additive. If a user has permission to perform an operation as part of multiple roles, they may not immediately lose access if permission is removed from only one role.
</Tip>

1. Access organization settings and select `Users and roles`
2. Select the `Roles` tab
3. Select the three dots next to the role you would like to update
4. Select `Edit`
5. Modify the permissions
6. Select `Edit role`

<h2 id="delete-custom-role">
  Delete custom roles
</h2>

Custom roles may be deleted at any time.

<Warning>
  You must have at least one user in the organization with administrative permissions. If deleting the role removes administrative permissions from the last user, you can't delete it. To resolve this, assign at least one user the Admin system role before deleting the custom role.
</Warning>

1. Access organization settings and select `Users and roles`
2. Select the `Roles` tab
3. Select the three dots next to the role you would like to delete
4. Review the users and API keys that will lose access when the role is removed. Adjust assignments as needed.
5. Select `Delete role` to complete the process
