

# Router users and routing layer privileges

In a database cluster group for Aurora with routing enabled, each login at the routing endpoint uses two database accounts with the same name. The routing layer checks the login against the router user, and the member cluster user controls what the login can read and write on each member cluster.

## Router users and member cluster users
<a name="databaseclustergroups-managing-router-users-and-member-cluster-users"></a>

A client that connects through the routing endpoint needs both of the following accounts:
+ A **router user**, at the routing endpoint. The routing layer checks the login and the routing layer privileges against it.
+ A **member cluster user** with the same name, on every member cluster that the client must reach. Each member cluster matches the user's host part against the client's IP address, which the routing layer forwards. A host part of `%` matches every client; a narrower host part matches only clients in its range. Each member cluster checks data privileges against this user, for routed and pinned sessions alike.

The routing layer doesn't copy users or roles from the member clusters, and a router user that you create isn't copied to them. Statements reach each member cluster as the client's user, so audit logs show that user. The following table shows the result for each account state.


| Same-named member cluster user | Routed session | 
| --- | --- | 
| Exists, with a grant on the object on the member cluster | Works | 
| Exists, without the grant | The member cluster refuses the statement | 
| Doesn't exist | Can't reach or pin to that member cluster | 
| Exists, but there's no router user | The login fails | 

A login with no router user fails with error `1045`. A statement without a grant on the object on the member cluster returns the member cluster's own access error.

The group's first administrative router user is created with the group, from `AdminUsername` and `AdminUserPassword`. It holds `dbclustergroup_super_admin` with the grant option, its host part is `%`, and its password doesn't expire. The member clusters' own administrative user and password don't sign in at the routing endpoint. We recommend that you don't use this user in applications. Create a separate router user for each administrator, with only the privileges that each one needs. You can't grant role membership to this user. To list the router users, read [router\_user\_definition](databaseclustergroups-sysviews-router-user-definition.md) at the routing endpoint.

Amazon RDS calls this user the admin user. You choose its name with the `AdminUsername` parameter. A group with routing turned on must have an admin user. To create a group with routing, specify `AdminUsername` and `AdminUserPassword`.

Supply the name and the password together. There are two exceptions, where you send the password on its own: a password change on an existing group, and a restore, where the password changes the password of the inherited admin user. A group that never had routing has no admin user, unless you restored it from a group that had one. After you disable routing, the group keeps its admin user name, and you can't change it. Admin user credentials sent while routing stays off fail.

The name has 1 to 32 characters and begins with a letter. It can't be a name that the engine reserves, such as `rdsadmin` or `root`, or a name that begins with `rds_` or `aurora_`.

The password has 8 to 41 printable ASCII characters. It can't contain a space, a forward slash (`/`), an at sign (`@`), or a double quotation mark (`"`).

The name can't be changed after the group has one. To change it, create a new group. You can change the password at any time while the group is available, as described in [Changing group settings](databaseclustergroups-group-lifecycle.md#databaseclustergroups-group-lifecycle-modify).

A restored group keeps the admin user name of its source. Send that same name with a new password to change the password as part of the restore, or omit both. The restore fails if you send a different name. If the source has no admin user and you restore with routing on, supply a name and password.

## Routing layer privileges
<a name="databaseclustergroups-router-users-privileges"></a>

Routing layer privileges are database privileges for administering the routing layer, separate from IAM permissions. You grant them to router users at the routing endpoint, never to member cluster users, and you grant data privileges on the member clusters. The routing layer enforces routing layer privileges. Each member cluster enforces data privileges, including table permissions. A new router user holds no routing layer privileges. The following table lists the routing layer privileges.


| Routing layer privilege | What it allows | 
| --- | --- | 
| dbclustergroup\_super\_admin | Full administration of the routing layer. It implies every other routing layer privilege. | 
| dbclustergroup\_user\_admin | Create, alter, rename, and drop router users, change other router users' passwords, and read router\_user\_definition | 
| dbclustergroup\_metadata\_admin | Read and write data mappings, and create, alter, and drop scaleout tables and routing functions | 
| dbclustergroup\_move\_admin | Run the data movement statements (ALTER DBCLUSTERGROUP MOVE, CUTOVER JOB, and CANCEL JOB). Changing data\_mappings directly needs dbclustergroup\_metadata\_admin. Reading data\_mappings needs dbclustergroup\_metadata\_read\_only. | 
| dbclustergroup\_process\_admin | View other router users' connections and queries in router\_processlist | 
| dbclustergroup\_connection\_admin | End other router users' connections or cancel their queries | 
| dbclustergroup\_metadata\_read\_only | Read data\_mappings, member\_cluster\_mappings, and move\_info, without write access. | 

To change another router user's password, you need `dbclustergroup_user_admin` and the grant option on every routing layer privilege that the other user holds. Otherwise the statement fails with error 1227, `Access denied; you need GRANT OPTION on all privileges the target holds`. You can always change your own password.

`GRANT ALL` doesn't include `dbclustergroup_super_admin`. Grant `dbclustergroup_super_admin` by name.

To grant or revoke a routing layer privilege, you must hold that privilege with the grant option, or hold `dbclustergroup_super_admin` with the grant option. `dbclustergroup_user_admin` doesn't by itself let you grant or revoke any privilege.

The routing layer refuses a statement from a router user that doesn't hold the statement's routing layer privilege. For the privilege that each statement needs, see [Privileges](databaseclustergroups-sql-reference.md#databaseclustergroups-sql-privileges) in the SQL reference. The following privilege rules apply to common tasks:
+ **DDL on member tables.** DDL runs on each member cluster with the member cluster user's privileges. Use a direct connection or a pinned session. Scaleout table and routing function statements at the routing endpoint need `dbclustergroup_metadata_admin`.
+ **Data mapping writes.** These need `dbclustergroup_metadata_admin`, because a mapping decides where every query goes. Grant it to as few accounts as possible. A user that only moves data needs `dbclustergroup_move_admin` and not `dbclustergroup_metadata_admin`. `dbclustergroup_move_admin` applies to every object in the group.
+ **Creating router users.** A holder of `dbclustergroup_user_admin` can create a router user for any member cluster user name. That router user gets the member cluster user's data privileges. Grant it to as few accounts as possible.
+ **Operations that need no privilege.** Any router user can pin a session, set a session variable, read its own connections in `router_processlist`, and run `SHOW GRANTS` for itself. `SHOW GRANTS FOR` another router user needs `dbclustergroup_user_admin`. A pinned session runs with the member cluster user's grants on that member cluster. Those grants decide what a pin can do. For when to pin, see [Session pinning](databaseclustergroups-sessions.md#databaseclustergroups-session-pinning).
+ **Statement text.** A holder of `dbclustergroup_process_admin` can read the statement text of other router users' connections, so don't put secrets in SQL statements.

A holder of `dbclustergroup_super_admin` with the grant option, such as the administrative router user, can grant any routing layer privilege. To keep access reviews simple, record which router user holds it, and grant from that user. In scripts and access reviews, keep each privilege name in one place that you can change. Don't repeat it as a literal across statements and templates. Grant and revoke routing layer privileges as follows.

At the routing endpoint, grant and revoke routing layer privileges with global scope, `ON *.*`. Use `WITH GRANT OPTION` only for router users that must grant the privilege to other router users.

```sql
-- Grant a routing layer privilege
GRANT dbclustergroup_user_admin ON *.* TO '{{USER}}'@'{{HOST}}';
-- Grant a privilege that the user can grant to other router users
GRANT dbclustergroup_user_admin ON *.* TO '{{USER}}'@'{{HOST}}' WITH GRANT OPTION;
-- Revoke a privilege and its grant option
REVOKE dbclustergroup_user_admin ON *.* FROM '{{USER}}'@'{{HOST}}';
-- Revoke only the grant option of each routing layer privilege
REVOKE GRANT OPTION ON *.* FROM '{{USER}}'@'{{HOST}}';
```

Don't use `GRANT ALL ON *.*`, because it grants every routing layer privilege except `dbclustergroup_super_admin`, including `dbclustergroup_user_admin`.

The routing endpoint refuses a data privilege `GRANT` with `ERROR 1227 (42000): Access denied; unknown privilege '{{PRIVILEGE}}'`. Grant data privileges to the member cluster user on each member cluster. The routing endpoint refuses a role grant with error `1227`, `SET ROLE` with error `1235`, and `SET DEFAULT ROLE` with a syntax error, `1064`.

## Creating a router user
<a name="databaseclustergroups-router-users-create"></a>

Create the member cluster users first, so that the router user's traffic never reaches a member cluster without one. Before you create a router user, check which member clusters already have a user with that name, because the new router user gets all of that user's data privileges. We recommend one user name for each person or application, used at the routing endpoint and on every member cluster.

**To create a router user and its member cluster users**

1. On every member cluster (direct), create the member cluster user, and grant it the data privileges that the application needs on the databases on the member cluster.

1. At the routing endpoint, as a router user with `dbclustergroup_user_admin`, create the router user with the same name.

1. At the routing endpoint, sign in as the new user, and read one row from each mapped database. A row from each database means that both accounts work.

You manage router users with SQL at the routing endpoint, one user at a time, so an CloudFormation or Terraform template that creates a group doesn't create its router users. Router users sign in with a password. IAM database authentication for router users isn't available at preview, as described in [IAM database authentication](databaseclustergroups-iam.md#databaseclustergroups-iam-db-auth). Kerberos and Active Directory aren't available for router users. You can't make a member cluster the sign-in authority for the group. The statements for steps 1 and 2, and the password methods, are as follows.

**Step 1.** On each member cluster's cluster endpoint (direct), as a user that can create users, create the member cluster user and grant its data privileges. Routed sessions don't use this password.

```sql
CREATE USER IF NOT EXISTS '{{APP_USER}}'@'%' IDENTIFIED BY RANDOM PASSWORD;
GRANT SELECT, INSERT, UPDATE, DELETE ON {{CLUSTER_DB}}.* TO '{{APP_USER}}'@'%';
```

**Step 2.** At the routing endpoint, create the router user. Give it the narrowest host part that its clients need: the address range of the application's subnet, or the IP address of an administrator's host. Use `%` only for a router user that must connect from any address. The routing layer matches the host part against the client IP address and doesn't resolve host names.

```sql
CREATE USER '{{APP_USER}}'@'{{HOST}}' IDENTIFIED BY '{{PASSWORD}}';
```

Router users can use the following authentication plugins:
+ `caching_sha2_password`, the default, for MySQL 8.0 and later clients and current drivers.
+ `mysql_native_password`, only for clients that don't support `caching_sha2_password`.

The routing layer refuses other plugins, such as `sha256_password`, and, at preview, `AWSAuthenticationPlugin` for IAM database authentication. For more information, see [IAM database authentication](databaseclustergroups-iam.md#databaseclustergroups-iam-db-auth).

The following account names are reserved on member clusters. The routing layer matches each name exactly. Before you add a cluster to a group, rename any account of your own that has one of these names.


| Reserved account | Purpose | 
| --- | --- | 
| rds\_aurora\_sd\_guard\_admin | A service account on each member cluster | 
| rds\_aurora\_data\_movement\_admin | The service's data movement account on each member cluster | 

You can't use a superuser role such as `rdsadmin`, or a service account, as a router user. On Aurora MySQL, the reserved accounts stay local to their member cluster: `rdsadmin`, `rdsproxyadmin`, `rdsrepladmin`, `rdsrepladmin_priv_checks_user`, `rds_superuser_role`, `rds_aurora_data_movement_admin`, `rds_aurora_sd_guard_admin`, and the `AWS_` service integration accounts. The `AWS_` accounts are `AWS_COMPREHEND_ACCESS`, `AWS_LAMBDA_ACCESS`, `AWS_LOAD_S3_ACCESS`, `AWS_SAGEMAKER_ACCESS`, `AWS_SELECT_S3_ACCESS`, and `AWS_BEDROCK_ACCESS`. None of them can sign in as a router user. To run a task that needs one of them, connect to the member cluster endpoint directly.