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

# Manage Users, Roles, and Service Accounts

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

This page details procedures for managing CockroachDB Cloud access to CockroachDB Cloud. Before proceeding, it is recommended to review the concepts related to the two levels of CockroachDB Cloud access management model (the organization level and the SQL level in a cluster), which are detailed in <InternalLink path="authorization">CockroachDB Cloud Access Management Overview and FAQ</InternalLink>.

Access management tasks for the organization level are performed in the CockroachDB Cloud console **Access Management** page, found at `https://cockroachlabs.cloud/access`. This page allows organization administrators to invite users to the CockroachDB Cloud organization, create service accounts, and manage the access roles assigned to both. Users with Cluster Admin role on a cluster can also manage the access role assignments on that cluster. Roles can be assigned at different scopes (levels) of the resource hierarchy.

Access management tasks for SQL level in a cluster are a bit distributed. SQL users on particular clusters can be created in the console's 'SQL user' page for a specific cluster, found at `https://cockroachlabs.cloud/cluster/<CLUSTER ID>/users`, or with the `ccloud` command line utility's <InternalLink path="ccloud-reference#create-a-sql-user">`cluster user create`</InternalLink> command, or with a SQL client. However, the SQL roles that govern permissions in the cluster for SQL users must be managed with a SQL client. Furthermore, SQL users created with the console or with `ccloud` utility are granted the `admin` SQL role on the cluster by default; this makes it important from a security perspective to immediately modify this user if needed, revoking the `admin` role and replacing it with a SQL role with privileges required for its task, according to the [principle of least privilege](https://wikipedia.org/wiki/Principle_of_least_privilege).

See [Manage SQL users on a cluster](#manage-sql-users-on-a-cluster)

## Manage your organizations

An **organization** allows you to manage your clusters under a shared <InternalLink path="billing-management">billing</InternalLink> account and collaborate with team members. You can belong to multiple organizations, like a personal organization, an enterprise organization for evaluating CockroachDB Cloud, and another enterprise organization with <InternalLink path="billing-management">CockroachDB Cloud credits</InternalLink> to map to all application clusters.

To switch to a different organization:

1. Log in to the console at `https://cockroachlabs.cloud/` or your organization's custom domain.
2. From the drop-down box in the top-right corner, select the organization you want to access.

The settings and information about the organization are found on the **Information** page. The organization ID and organization label used by the `ccloud` CLI are listed on that page.

## Manage an organization's users

### Invite team members to an organization

An <InternalLink path="authorization#organization-admin">Organization Admin</InternalLink> can invite team members to CockroachDB Cloud. To invite team members:

1. If you are a member of multiple organizations, navigate to the organization to which you want to invite a team member. You can navigate to the correct organization by using the drop-down box in the top-right corner.
2. On the **Access Management** page, under the *Members* tab, click **Invite**.
3. In the **Email Address** field, enter the email address of the team member you want to invite. By default, a user is assigned the <InternalLink path="authorization#organization-member">Organization member</InternalLink> role; this default role adds no permissions. After the user is invited, you will be able to [assign additional roles](#change-a-team-member’s-roles).
4. If required, you could invite multiple users at the same time by adding a row per email address using **+ Add Member**.

It is also possible to enable <InternalLink path="cloud-org-sso#autoprovisioning">autoprovisioning</InternalLink> for your organization, which removes the need to invite team members.

<a id="change-a-team-members-role" />

### Change a team member's roles

In the CockroachDB Cloud Console, users must be assigned **roles** that allow them to perform actions.

The following table describes the high level permissions given by each CockroachDB Cloud user role. Permissions are additive, so a user with multiple roles is given all permissions in each area across all assigned roles.

|                                                                                                                                                 | <InternalLink path="authorization#organization-member">Org. Member</InternalLink> | <InternalLink path="authorization#organization-admin">Org. Admin</InternalLink> | <InternalLink path="authorization#billing-coordinator">Billing Coord.</InternalLink> | <InternalLink path="authorization#billing-viewer">Billing Viewer</InternalLink> | <InternalLink path="authorization#cluster-creator">Cluster Creator</InternalLink> | <InternalLink path="authorization#cluster-operator">Cluster Operator</InternalLink> | <InternalLink path="authorization#cluster-admin">Cluster Admin</InternalLink> | <InternalLink path="authorization#cluster-developer">Cluster Developer</InternalLink> | <InternalLink path="authorization#cluster-monitor">Cluster Monitor</InternalLink> | <InternalLink path="authorization#metrics-viewer">Metrics Viewer</InternalLink> | <InternalLink path="authorization#folder-admin">Folder Admin</InternalLink> | <InternalLink path="authorization#folder-mover">Folder Mover</InternalLink> |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| **User/Access Management**                                                                                                                      |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| Assign and revoke roles                                                                                                                         | —                                                                                 | ✓                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Assign Cloud user and service account roles                                                                                                     | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage SQL users                                                                                                                                | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage Cloud users and service accounts                                                                                                         | —                                                                                 | ✓                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Apply roles at the <InternalLink path="folders">folder</InternalLink> scope                                                                     | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | ✓                                                                           | —                                                                           |
| **Cluster & Infrastructure**                                                                                                                    |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| Create cluster or <InternalLink version="cockroachcloud" path="private-clusters">private cluster</InternalLink>                                 | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | ✓                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Create / edit / delete cluster                                                                                                                  | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Edit / delete clusters created by this user                                                                                                     | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | ✓                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Create / delete / manage <InternalLink path="folders">folders</InternalLink>                                                                    | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | ✓                                                                           | —                                                                           |
| Move cluster between <InternalLink path="folders">folders</InternalLink>                                                                        | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | ✓                                                                           |
| Scale nodes                                                                                                                                     | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Upgrade CockroachDB                                                                                                                             | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Configure <InternalLink version="cockroachcloud" path="advanced-cluster-management#set-a-maintenance-window">maintenance windows</InternalLink> | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Use the <InternalLink version="cockroachcloud" path="provision-a-cluster-with-terraform">Cloud Terraform provider</InternalLink>                | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | ✓                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| **Monitoring & Observability**                                                                                                                  |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| View cluster details                                                                                                                            | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | ✓                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink version="cockroachcloud" path="cloud-org-audit-logs">audit logs</InternalLink>                                               | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink version="cockroachcloud" path="insights-page">insights</InternalLink>                                                        | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | ✓                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink version="cockroachcloud" path="jobs-page">jobs</InternalLink>                                                                | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | ✓                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink version="cockroachcloud" path="statements-page">sql activity</InternalLink>                                                  | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | ✓                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink version="cockroachcloud" path="metrics">metrics</InternalLink>                                                               | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | ✓                                                                               | —                                                                           | —                                                                           |
| Send <InternalLink version="cockroachcloud" path="alerts-page#send-a-test-alert">test alerts</InternalLink>                                     | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Access <InternalLink version="cockroachcloud" path="network-authorization#db-console">DB console</InternalLink>                                 | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | ✓                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| **Security**                                                                                                                                    |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| Configure <InternalLink version="cockroachcloud" path="cloud-sso-sql">cluster SSO</InternalLink>                                                | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage <InternalLink version="cockroachcloud" path="egress-perimeter-controls">egress perimeter controls</InternalLink>                         | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage <InternalLink version="cockroachcloud" path="network-authorization">network authorization</InternalLink>                                 | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View PCI status                                                                                                                                 | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| **Database & Data**                                                                                                                             |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| Manage databases                                                                                                                                | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View / restore <InternalLink version="cockroachcloud" path="backup-and-restore-overview">backups</InternalLink>                                 | —                                                                                 | —                                                                               | —                                                                                    | —                                                                               | —                                                                                 | ✓                                                                                   | ✓                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| **Billing & Licensing**                                                                                                                         |                                                                                   |                                                                                 |                                                                                      |                                                                                 |                                                                                   |                                                                                     |                                                                               |                                                                                       |                                                                                   |                                                                                 |                                                                             |                                                                             |
| Manage <InternalLink path="billing-management">billing</InternalLink>                                                                           | —                                                                                 | —                                                                               | ✓                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| View <InternalLink path="billing-management">billing</InternalLink> details                                                                     | —                                                                                 | —                                                                               | ✓                                                                                    | ✓                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage <InternalLink version="cockroachcloud" path="alerts-page#configure-alerts">email alerts</InternalLink>                                   | —                                                                                 | ✓                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |
| Manage CockroachDB <InternalLink version="stable" path="licensing-faqs#obtain-a-license">Self-Hosted cluster licenses</InternalLink>            | —                                                                                 | ✓                                                                               | —                                                                                    | —                                                                               | —                                                                                 | —                                                                                   | —                                                                             | —                                                                                     | —                                                                                 | —                                                                               | —                                                                           | —                                                                           |

Some roles can be assigned to users at specific levels of scope to provide more granular permission control:

| **Scope level** | **Description**                                                                                                                                                                                                            | **Applicable roles**                                                                                                                                                                                            |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Organization`  | Applies to the entire CockroachDB Cloud organization, including all clusters and folders                                                                                                                                   | `Cluster Operator`, `Cluster Admin`, `Cluster Creator`, `Cluster Developer`, `Cluster Monitor`, `Metrics Viewer`, `Billing Coordinator`, `Billing Viewer`, `Organization Admin`, `Folder Admin`, `Folder Mover` |
| `Folder`        | Applies to clusters within a specific <InternalLink path="folders">folder</InternalLink>. Only available as a selectable scope if folders have been created within the organization by a user with the `Folder Admin` role | `Cluster Operator`, `Cluster Admin`, `Cluster Creator`, `Cluster Developer`, `Cluster Monitor`, `Metrics Viewer`, `Folder Admin`, `Folder Mover`                                                                |
| `Cluster`       | Applies to a specific cluster                                                                                                                                                                                              | `Cluster Operator`, `Cluster Admin`, `Cluster Developer`, `Cluster Monitor`, `Metrics Viewer`                                                                                                                   |

To edit a user's role, perform the following steps:

1. On the **Access Management** page, locate the team member whose role you want to change. The **Role** column lists current roles assigned to each user.
2. In the row for the target member, click the three-dots **Action** button and select **Edit Roles**.
3. A number of fine-grained roles can be assigned to a given user. Each role is represented by a row. Each row has a **scope**, which is one of **Organization**, the name of a particular <InternalLink path="folders">folder</InternalLink>, or the name of a particular cluster. If the role is Cluster Admin, Cluster Operator, or Cluster Developer, assigning it at the organization scope means that it applies to all clusters in the organization.

<Note>
  When editing roles for a group in the **Groups** tab, the fields for that group's inherited roles are read-only, because inherited roles cannot be edited directly. Instead, you must either remove the role from the parent group from which it is inherited, or remove the member from the parent group.
</Note>

<Danger>
  An <InternalLink path="authorization#organization-admin">Organization Admin</InternalLink> can revoke the Organization Admin role from their own user, but cannot subsequently re-assign the administrator role to themselves.
</Danger>

### Remove a team member

1. On the **Access Management** page, locate the team member you want to remove.
2. In the **Action** column, click the three dots to view the allowed actions.
3. Click **Remove Member** and confirm.

### Revoke a pending invite

1. On the **Access Management** page, locate the team member whose pending invite you want to revoke.
2. In the **Action** column, click the three dots to view the allowed actions.
3. Click **Revoke Invite**.

### Delete an email address

This is not currently available through the CockroachDB Cloud Console. To remove an email address from your account, [contact Support](https://support.cockroachlabs.com/).

### Delete an organization

<Danger>
  Deleting an organization will delete all clusters and user data within the organization. This action cannot be reversed. To delete a single cluster instead, see <InternalLink path="cluster-management#delete-cluster">Cluster Management</InternalLink>.
</Danger>

If you are sure you want to delete the organization, proceed with the following steps:

1. Navigate to the **Information** page for the organization you want to delete.
2. Click **Delete**.
3. Enter the name of the organization.
4. Click **Delete**.

   You will be automatically logged out of your account.

## Manage service accounts

The access management model for service accounts is unified with the [user model](#manage-an-organization’s-users). This means that service accounts may have all of the same <InternalLink path="authorization#organization-user-roles">access roles</InternalLink>. However, service accounts and users still differ in the actions they can perform: only users can access the console, and only service accounts can access the API. The console and API differ in functionality.

### Create a service account

1. On the **Access Management** page, select the **Service Accounts** tab.
2. Click **Create**.
3. Enter a **Account name** and **Description**.
4. Create and export an **API key**.
5. Confirm creation of the service account.

<Note>
  Service accounts, like users, are given only the **Organization Member** role by default upon creation. This role assigns no access in the organization. After it is created, you can assign additional roles to the service account.
</Note>

### Edit roles on a service account

1. On the **Access Management** page, select the **Service Accounts** tab.
2. In the row for the target service account, click, click the three-dots **Action** button and select **Edit Roles**.
3. A number of fine-grained roles can be assigned to a given service account. These are the same <InternalLink path="authorization#organization-user-roles">roles that can be assigned to users</InternalLink>. Each role is represented by a row. Each row has a **scope**, which is either **Organization** or the name of a particular cluster. If the role is Cluster Admin, Cluster Operator, or Cluster Developer, assigning it at the organization scope means that it applies to all clusters in the organization.

   The fields for a group's inherited roles are read-only, because inherited roles cannot be edited directly. Instead, you must either remove the role from the parent group from which it is inherited, or remove the member from the parent group.

### API access

Each service account can have one or more API keys. API keys are used to authenticate and authorize service accounts when using the API. All API keys created by the account are listed under **API Access**.

We recommend creating service accounts with the [principle of least privilege](https://wikipedia.org/wiki/Principle_of_least_privilege), and giving each application that accesses the API its own service account and API key. This allows fine-grained access to the cluster.

#### Create API keys

To create an API key:

1. On the **Access Management** page, select the **Service Accounts** tab.
2. Click the service account for which you want to create an API key to bring up the **Service Account Details** page.
3. Click **Create API Key**.
4. Enter the **API key name** and click **Create**. The name should identify how the API key will be used. For example, you could name your API key for the application that will use the key.
5. Copy the **Secret key** and store it in a secure location. There is a **Copy** button to the right of the displayed secret key that will copy the secret key to your OS clipboard.

   The secret key contains the API key and secret. It should never be shared or publicly accessible. Anyone with the secret key can use the API with the permissions of the service account.

<Danger>
  The secret key will not be available after closing the **Create API key** dialog. If you have lost your secret key, you should [delete the API key](#delete-api-keys) and create a new one.
</Danger>

6. Click **Done**.

#### Delete API keys

To delete an API key associated with a service account:

1. On the **Access Management** page, select the **Service Accounts** tab.
2. Click the service account for which you want to create an API key to bring up the **Service Account Details** page.
3. Click the **Action** button for the API key ID in the **API Access** table.
4. Select **Delete**.
5. In the **Delete API key** dialog enter the name of the service account to confirm the delete operation, then click **Delete**.

#### Edit API key names

To change the API key name for an existing API key:

1. On the **Access Management** page, select the **Service Accounts** tab.
2. Click the service account for which you want to create an API key to bring up the **Service Account Details** page.
3. Find the API key ID in the **API Access** table.
4. Click the **Action** button.
5. Select **Edit**.
6. In the **Edit API key name** dialog modify the API key name and click **Save changes**.

## Manage SQL users on a cluster

* [View all SQL users in your cluster](#view-all-sql-users-in-your-cluster)
* [Change a SQL user's password](#change-a-sql-user’s-password)
* [Remove a SQL user](#remove-a-sql-user)

### Create a SQL user

<Danger>
  By default, a new SQL user created using the UI or Cloud API is granted the SQL `admin` role. An `admin` SQL user has full privileges for all databases and tables in the cluster, and can create additional SQL users and manage their privileges. When possible, it is best practice to limit each user's privileges to the minimum necessary for their tasks, in keeping with the [Principle of Least Privilege (PoLP)](https://wikipedia.org/wiki/Principle_of_least_privilege).

  Refer to: <InternalLink version="cockroachcloud" path="managing-access#manage-sql-users-on-a-cluster">Manage SQL users on a cluster</InternalLink>
</Danger>

<Tabs>
  <Tab title="Use the CockroachDB Cloud Console">
    <Note>
      Only <InternalLink path="authorization#organization-admin">Organization Admins</InternalLink> and <InternalLink path="authorization#cluster-admin">Cluster Admins</InternalLink> can create SQL users using the Cloud Console or API. These SQL users default to the `Admin` role. For granular provisioning of SQL user privileges, refer to documentation on <InternalLink version="cockroachcloud" path="managing-access?filters=client#create-a-sql-user">using the cluster's SQL interface</InternalLink>.
    </Note>

    1. Navigate to your cluster's **SQL Users** page in the **Security** section of the left side navigation.
    2. In the left navigation bar, click **SQL Users**.
    3. Click **Add User**. The **Add User** dialog displays.
    4. Enter a username and click **Generate & Save Password**.
    5. Copy the generated password to a secure location, such as a password manager.
    6. Click **Close**.

       Currently, all new users are created with SQL admin privileges. For more information and to change the default settings, see [Grant privileges to a SQL user](#grant-privileges-to-a-sql-user) and [Use SQL roles to manage access](#use-sql-roles-to-manage-access).
  </Tab>

  <Tab title="Use the SQL client">
    Once you have <InternalLink path="connect-to-your-cluster">connected to the cluster's SQL client</InternalLink>, you can create a new user.

    To create a new user, use the <InternalLink version="stable" path="create-user">`CREATE USER... WITH PASSWORD`</InternalLink> statement:

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    > CREATE USER <username> WITH PASSWORD '<password';
    ```

    <Note>
      Be sure to create a password for each new user. Without a password, or being enrolled in cluster single sign-on (SSO), a user cannot connect to the cluster or access the DB Console. To add or change a password for a user, use the <InternalLink version="stable" path="alter-user">`ALTER USER`</InternalLink> statement.
    </Note>
  </Tab>
</Tabs>

### View all SQL users in your cluster

<Tabs>
  <Tab title="Use the CockroachDB Cloud Console">
    To view a list of all of the users in your cluster, navigate to the **SQL Users** page.

    On the **SQL Users** page, you can do the following:

    * [Create a user](#create-a-sql-user)
    * [Change a user's password](#change-a-sql-user’s-password)
    * [Remove a user](#remove-a-sql-user)
  </Tab>

  <Tab title="Use the SQL client">
    To list all the users in your cluster, use the <InternalLink path="show-users">`SHOW USERS`</InternalLink> statement:

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    > SHOW USERS;
    ```
  </Tab>
</Tabs>

### Change a SQL user's password

<Tabs>
  <Tab title="Use the CockroachDB Cloud Console">
    <Note>
      Only users with the <InternalLink path="authorization#organization-admin">Organization Admin</InternalLink>, or <InternalLink path="authorization#cluster-admin">Cluster Admin</InternalLink> can change a user's password. If you do not have the required permissions, ask a user with one of the required roles to change the password.
    </Note>

    To change a user's password:

    1. Navigate to the **SQL Users** page.
    2. In the row of the user whose password needs to be changed, click the **...** button.
    3. From the dropdown, select **Change Password**.
    4. Click **Generate & save password**.
    5. Copy the generated password and save it in a secure location.
  </Tab>

  <Tab title="Use the SQL client">
    To change a user's password, use the <InternalLink version="stable" path="alter-user">`ALTER USER`</InternalLink> statement:

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    > ALTER USER <user> WITH PASSWORD '<new password';
    ```
  </Tab>
</Tabs>

### Remove a SQL user

<Tabs>
  <Tab title="Use the CockroachDB Cloud Console">
    To remove a user:

    1. Navigate to the **SQL Users** page.
    2. In the row of the user you want to remove, click the **...** button.
    3. From the dropdown, select **Delete SQL User**.
    4. Click **Delete**.
  </Tab>

  <Tab title="Use the SQL client">
    To remove a user, use the <InternalLink version="stable" path="drop-user">`DROP USER`</InternalLink> statement:

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    > DROP USER <user>;
    ```

    <Note>
      All of a user's privileges must be [revoked](#revoke-a-sql-user’s-privileges) before the user can be dropped.
    </Note>
  </Tab>
</Tabs>

### Grant privileges to a SQL user

Access to the data in your cluster is controlled by <InternalLink version="stable" path="security-reference/authorization#managing-privileges">privileges</InternalLink>. When a user connects to a database, either via the CockroachDB SQL client or a PostgreSQL driver or ORM, CockroachDB checks the user's privileges for each statement executed. If the user does not have sufficient privileges for a statement, CockroachDB returns an error.

To grant a user privileges for specific databases and tables in your cluster, use the <InternalLink version="stable" path="grant">`GRANT`</InternalLink> statement. For example, to assign a user all privileges for all tables in a database:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> GRANT ALL ON DATABASE <database> TO <user>;
```

To assign a user more limited privileges for one table in a database:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> GRANT SELECT, INSERT ON TABLE <database>. TO <user>;
```

For more details, see <InternalLink version="stable" path="security-reference/authorization#managing-privileges">Privileges</InternalLink> and <InternalLink version="stable" path="grant">`GRANT`</InternalLink>.

### View a SQL user's privileges

To show privileges granted to a user, use the <InternalLink version="stable" path="show-grants">`SHOW GRANTS`</InternalLink> statement:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW GRANTS ON DATABASE <database> FOR <user>;
```

### Revoke a SQL user's privileges

To revoke privileges from a user, use the <InternalLink version="stable" path="revoke">`REVOKE`</InternalLink> statement:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> REVOKE INSERT ON TABLE <database>. FROM <user>;
```

### Use SQL roles to manage access

Role-based access control lets you simplify how you manage privileges. In essence, a role is a group containing any number of other roles and users as members. You can assign privileges to a role, and all direct and indirect members of the role will inherit the privileges.

Once you have <InternalLink path="connect-to-your-cluster">connected to the cluster</InternalLink>, you can set up roles:

* To create a role, use the <InternalLink version="stable" path="create-role">`CREATE ROLE`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > CREATE ROLE <role>;
  ```
* To grant privileges to a role, use the <InternalLink version="stable" path="grant">`GRANT <privilege>`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > GRANT <privilege> ON DATABASE <database> TO <role>;
  ```
* To add a user (or another role) to a role, use the <InternalLink version="stable" path="grant">`GRANT <role>`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > GRANT <role> TO <user or role>;
  ```
* To revoke privileges from a role, use the <InternalLink version="stable" path="revoke">`REVOKE <privilege>`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > REVOKE INSERT ON TABLE <database>. FROM <role>;
  ```
* To remove a user (or another role) from a role, use the <InternalLink version="stable" path="revoke">`REVOKE <role>`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > REVOKE <role> FROM <user or role>;
  ```
* To list all roles in your cluster, use the <InternalLink version="stable" path="show-roles">`SHOW ROLES`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > SHOW ROLES;
  ```
* To remove a role, use the <InternalLink version="stable" path="drop-role">`DROP ROLE`</InternalLink> statement:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > DROP ROLE <role>;
  ```

<Note>
  All of a role's privileges must be [revoked](#revoke-a-sql-user’s-privileges) before the role can be dropped.
</Note>

## See also

* <InternalLink version="stable" path="connection-parameters">Client Connection Parameters</InternalLink>
* <InternalLink path="connect-to-your-cluster">Connect to Your CockroachDB Advanced Cluster</InternalLink>
