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

# Authenticate User Groups

> Enable Group Provider in the database to authenticate, and authorize user groups from external authentication systems.

Enable Group Provider in the database to authenticate, and authorize user groups from external authentication systems.

From v3.5.0 onwards, the database supports Group Provider to collect group information from external authentication systems for user group management.

**A group provider is not the only source of groups**

A security integration can also take a login's groups from the identity provider that authenticated it, without any group provider: an LDAP integration from the group membership attribute of the user's own entry, and a JWT or OAuth 2.0 integration from a claim of the verified token. Set `group_source` on the integration; see [Authenticate with Security Integration](/documents/4.2/administration/user_privs/authentication/security_integration.md). Groups resolved that way are used for exactly the same things as the groups of a group provider.

## Overview

To deepen its integration with external user authentication and authorization systems, such as LDAP and Apache Ranger, the database supports collecting user group information for a better experience on the collective user management.

With a group provider, you can fetch the group information from external user systems for different purposes. Group information is independent and can be integrated flexibly into authentication, authorization, or other processes without being tightly coupled to any specific workflow.

A Group Provider is essentially a mapping between users and groups. Any process that requires group information can query this mapping as needed.

### Workflow

The following flow chart uses LDAP and Apache Ranger as an example to explain the workflow of Group Provider.

![Group Provider](https://mintcdn.com/mirrorship-docs/8gpPdHU-sBXASb5i/documents/images/106745c9e37c7edc5aa3cb6f.png?fit=max\&auto=format\&n=8gpPdHU-sBXASb5i\&q=85\&s=2d4e31bec73b6d15a8eab80c27cdf4a7)

## Create a group provider

The database supports three types of group providers:

* **LDAP group provider**: Search and match users with groups in your LDAP service
* **Unix group provider**: Search and match users with groups in your operating system
* **File group provider**: Search and match users with groups defined by a file

### Syntax

* LDAP group provider:

```SQL theme={null}
CREATE GROUP PROVIDER <group_provider_name> 
PROPERTIES (
    "type" = "ldap",
    ldap_info,
    ldap_search_group_arg,
    ldap_search_attr,
    [ldap_cache_attr]
)

ldap_info ::=
    "ldap_conn_url" = "",
    "ldap_bind_root_dn" = "",
    "ldap_bind_root_pwd" = "",
    "ldap_bind_base_dn" = "",
    ["ldap_conn_timeout" = "",]
    ["ldap_conn_read_timeout" = ""]
    ["ldap_ssl_conn_allow_insecure" = ""]
    ["ldap_ssl_conn_trust_store_path" = ""]
    ["ldap_ssl_conn_trust_store_pwd" = ""]

ldap_search_group_arg ::= 
    { "ldap_group_dn" = "" 
    | "ldap_group_filter" = "" }, 
    "ldap_group_identifier_attr" = ""

ldap_search_user_arg ::=
    "ldap_group_member_attr" = "",
    "ldap_user_search_attr" = ""

ldap_cache_arg ::= 
    ["ldap_cache_refresh_interval" = "",]
    ["ldap_cache_max_stale_time" = ""]
```

* Unix group provider:

```SQL theme={null}
CREATE GROUP PROVIDER <group_provider_name> 
PROPERTIES (
    "type" = "unix"
)
```

* File group provider:

```SQL theme={null}
CREATE GROUP PROVIDER <group_provider_name> 
PROPERTIES (
    "type" = "file",
    "group_file_url" = ""
)
```

### Parameters

#### `type`

The type of the group provider to create. Valid values:

* `ldap`: Creates an LDAP group provider. When this value is set, you need to specify `ldap_info`, `ldap_search_group_arg`, `ldap_search_user_arg`, and optionally `ldap_cache_arg`.
* `unix`: Creates a Unix group provider.
* `file`: Creates a File group provider. When this value is set, you need to specify `group_file_url`.

#### `group_file_url`

The URL or relative path (under `fe/conf`) to the file that defines the user groups.

**Note**

A group file contains a list of groups and their members. You can define a group in each line where the group name and members are separated by a colon. Multiple users are separated by commas. Example: `group_name:user_1,user_2,user_3`.

An `http://` or `https://` URL is fetched with the connect and read timeouts set by the FE configuration items `group_provider_http_connect_timeout_ms` (default 5000) and `group_provider_http_read_timeout_ms` (default 30000). If the server does not answer within them, the statement fails and the group provider keeps its previous configuration.

#### `ldap_info` parameter group

The information used to connect to your LDAP service.

##### `ldap_conn_url`

The URL of your LDAP server. Format: `ldap://<ldap_server_host>:<ldap_server_port>)`.

##### `ldap_bind_root_dn`

The admin Distinguished Name (DN) of your LDAP service.

##### `ldap_bind_root_pwd`

The admin password of your LDAP service.

##### `ldap_bind_base_dn`

The base DN of the LDAP user for which the cluster searches.

##### `ldap_conn_timeout`

Optional. The timeout duration for the connection to your LDAP service.

##### `ldap_conn_read_timeout`

Optional. The timeout duration for the read operations in the connection to your LDAP service.

##### `ldap_ssl_conn_allow_insecure`

Optional. Whether to allow non-encrypted connections to the LDAP server. Default value: `true`. Setting this value to `false` indicates that SSL encryption is required to access LDAP.

##### `ldap_ssl_conn_trust_store_path`

Optional. Local path to store the SSL CA certificate of the LDAP server. Supports pem and jks formats. You do not need to set this item if the certificate is issued by a trusted organization.

##### `ldap_ssl_conn_trust_store_pwd`

Optional. The password used to access the locally stored SSL CA certificate of the LDAP server. pem-formatted certificates do not require a password. Only jsk-formatted certificates do.

#### `ldap_search_group_arg` parameter group

The arguments used to control how the database searches for a group.

**Note**

You can only specify either `ldap_group_dn` or `ldap_group_filter`. Specifying both is not supported.

##### `ldap_group_dn`

The DN of the group to be searched for. The group will be queried directly using this DN. Example: `"cn=ldapgroup1,ou=Group,dc=starrocks,dc=com;cn=ldapgroup2,ou=Group,dc=starrocks,dc=com"`.

##### `ldap_group_filter`

A customized group filter that can be recognized by the LDAP server. It will be sent directly to your LDAP server for searching for the group. Example: `(&(objectClass=groupOfNames)(cn=testgroup))`.

##### `ldap_group_identifier_attr`

The attribute used as the identifier for the group name.

#### `ldap_search_user_arg` parameter group

The arguments used to control how the database identifies for a user in a group.

##### `ldap_group_member_attr`

The attribute that represents group members. Valid values: `member` and `memberUid`.

##### `ldap_user_search_attr`

Specifies how to extract the user identifier from the member attribute value. You can explicitly define an attribute (for example, `cn` or `uid`) or use a regular expression.

**Note**

**DN Matching Mechanism**

* **When `ldap_user_search_attr` is configured**, the system extracts the specified value from group member DNs and uses it as usernames, and uses login username as key during group search.
* **When `ldap_user_search_attr` is not configured**, the system uses the complete DN directly as user identifier, and uses the DN recorded during authentication as key during group search.

This design enables LDAP Group Provider to adapt to different LDAP environments, especially complex environments like Microsoft AD.

**Tip**

**Interaction with `authentication_ldap_simple_bind_dn_pattern`**

When using DN pattern authentication (e.g., `uid=${USER}@abc.com,ou=People,dc=example,dc=com`) where the `${USER}` substitution is embedded within a larger attribute value:

* **Recommended**: Do not configure `ldap_user_search_attr`. The system will use the complete DN for group matching, which avoids extraction errors.
* **If you must configure it**: Use a regex that extracts only the username portion. For example, if the DN pattern is `uid=${USER}@abc.com,ou=People,dc=example,dc=com`, set `ldap_user_search_attr` to `uid=([^,@]+)@abc.com` to extract only the `${USER}` part. A simple `uid` or `uid=([^,]+)` would incorrectly extract `alice@abc.com` instead of `alice`.

#### `ldap_cache_arg` parameter group

The argument used to define the cache behavior for the LDAP group information.

##### `ldap_cache_refresh_interval`

Optional. The interval at which the database automatically refreshes the cached LDAP group information. Unit: Seconds. Default: `300`.

##### `ldap_cache_max_stale_time`

Optional. How long the last successfully built cache keeps being served while refreshes keep failing. Unit: Seconds. Default: `3600`.

If a refresh cannot reach the LDAP server, the database keeps serving the previous cache until it has been stale for longer than this value, after which the cache is dropped and every user resolves to an empty group set. Set this item to `0` to drop the cache as soon as a refresh fails.

**Note**

Dropping the cache immediately turns a brief LDAP outage into a cluster-wide login failure when `permitted_groups` is configured, because an empty group set can never intersect the allowed list. Raising this value trades a longer window of stale group information for tolerance of directory downtime.

### Example

Suppose an LDAP server contains the following group and member information.

```Plain theme={null}
-- Group information
# testgroup, Group, starrocks.com
dn: cn=testgroup,ou=Group,dc=starrocks,dc=com
objectClass: groupOfNames
cn: testgroup
member: uid=test,ou=people,dc=starrocks,dc=com
member: uid=tom,ou=people,dc=starrocks,dc=com

-- User information
# test, People, starrocks.com
dn: cn=test,ou=People,dc=starrocks,dc=com
objectClass: inetOrgPerson
cn: test
uid: test
sn: FTE
userPassword:: 
```

Create a group provider `ldap_group_provider` for members in `testgroup`:

```SQL theme={null}
CREATE GROUP PROVIDER ldap_group_provider 
PROPERTIES(
    "type"="ldap", 
    "ldap_conn_url"="ldap://xxxx:xxx",
    "ldap_bind_root_dn"="cn=admin,dc=starrocks,dc=com",
    "ldap_bind_root_pwd"="123456",
    "ldap_bind_base_dn"="dc=starrocks,dc=com",
    "ldap_group_filter"="(&(objectClass=groupOfNames)(cn=testgroup))",
    "ldap_group_identifier_attr"="cn",
    "ldap_group_member_attr"="member",
    "ldap_user_search_attr"="uid=([^,]+)"
)
```

The above example uses `ldap_group_filter` to search for a group with the `groupOfNames` objectClass and a `cn` of `testgroup`. Therefore, `cn` is specified in `ldap_group_identifier_attr` to identify the group. `ldap_group_member_attr` is set to `member` so that the `member` attribute is used in the `groupOfNames` objectClass to identify members. `ldap_user_search_attr` is set to an expression `uid=([^,]+)`, which is used to identify users in the `member` attribute.

### Microsoft AD Environment Example

Suppose a Microsoft AD server contains the following group and member information:

```Plain theme={null}
-- Group information
# ADGroup, Groups, company.com
dn: CN=ADGroup,OU=Groups,DC=company,DC=com
objectClass: group
cn: ADGroup
member: CN=John Doe,OU=Users,DC=company,DC=com
member: CN=Jane Smith,OU=Users,DC=company,DC=com

-- User information
# John Doe, Users, company.com
dn: CN=John Doe,OU=Users,DC=company,DC=com
objectClass: user
cn: John Doe
sAMAccountName: johndoe
```

Create a Group Provider for Microsoft AD environment:

```SQL theme={null}
CREATE GROUP PROVIDER ad_group_provider 
PROPERTIES(
    "type"="ldap", 
    "ldap_conn_url"="ldap://ad.company.com:389",
    "ldap_bind_root_dn"="CN=admin,OU=Users,DC=company,DC=com",
    "ldap_bind_root_pwd"="password",
    "ldap_bind_base_dn"="DC=company,DC=com",
    "ldap_group_filter"="(&(objectClass=group)(cn=ADGroup))",
    "ldap_group_identifier_attr"="cn",
    "ldap_group_member_attr"="member"
    -- Note: Do not configure ldap_user_search_attr, system will use complete DN for matching
)
```

In this example, since `ldap_user_search_attr` is not configured, the system will:

1. During group cache construction, directly use the complete DN (for example, `CN=John Doe,OU=Users,DC=company,DC=com`) as user identifier.
2. During group search, use the DN recorded during authentication as key to search user's groups.

This approach is particularly suitable for Microsoft AD environments, as group members in AD may lack simple username attributes.

## Alter a group provider

You can update the properties of an existing group provider without dropping and recreating it. The new configuration is validated and warmed up before it takes effect: the old instance keeps serving requests until the new one is ready, so group lookups never return empty during the change.

### Syntax

```SQL theme={null}
ALTER GROUP PROVIDER <group_provider_name> SET
(
    "<property_key>" = "<property_value>"
    [, "<property_key>" = "<property_value>" ...]
)
```

### Notes

* Only the listed properties are changed; properties that are not listed keep their previous values.
* The `type` property cannot be changed. Drop and recreate the provider if you need to switch its type.
* `SET` adds or overwrites a property, but it cannot remove one. Two properties that are not allowed to coexist therefore cannot be swapped with `ALTER`: an LDAP group provider accepts exactly one of `ldap_group_dn` and `ldap_group_filter`, so moving from one to the other means dropping and recreating the provider.
* A property that the provider type does not define and that the provider does not already have is rejected. Property names are matched without regard to case, so `SET ("LDAP_BIND_ROOT_PWD" = ...)` updates `ldap_bind_root_pwd`; a misspelled name fails the statement instead of being stored beside the property you meant to change.
* The new configuration is verified synchronously. If it is not usable (for example, the LDAP bind credentials are wrong or the server is unreachable), the statement fails and the provider keeps its previous configuration.
* Credentials are never echoed back. `SHOW CREATE GROUP PROVIDER` prints `***` instead of the values of `ldap_bind_root_pwd` and `ldap_ssl_conn_trust_store_pwd`, and the statement recorded in the audit log has them redacted.

### Example

```SQL theme={null}
-- Rotate the LDAP bind password
ALTER GROUP PROVIDER ldap_group_provider SET ("ldap_bind_root_pwd" = "<new_password>");

-- Adjust the cache refresh interval
ALTER GROUP PROVIDER ldap_group_provider SET ("ldap_cache_refresh_interval" = "10");

-- Update multiple properties at once
ALTER GROUP PROVIDER ldap_group_provider SET (
    "ldap_conn_url" = "ldaps://new-host:636",
    "ldap_ssl_conn_trust_store_path" = "/etc/ssl/new-truststore.jks"
);
```

## View group providers

```SQL theme={null}
-- List every group provider with its type. The Comment column is always NULL: no statement sets a comment.
SHOW GROUP PROVIDERS;

-- Show the statement that would recreate one group provider. Credentials such as
-- `ldap_bind_root_pwd` and `ldap_ssl_conn_trust_store_pwd` are printed as `***`, so the output cannot be
-- replayed as-is - fill the passwords back in before reusing it.
SHOW CREATE GROUP PROVIDER <group_provider_name>;
```

Both statements require the `SECURITY` privilege on the SYSTEM level.

## Drop a group provider

```SQL theme={null}
DROP GROUP PROVIDER [IF EXISTS] <group_provider_name>;
```

Dropping a group provider takes effect immediately: users who log in afterwards no longer carry the groups
it resolved, so any role that was granted `TO EXTERNAL GROUP` for those groups stops applying. Security
integrations keep the dropped name in their `group_provider` property, and simply resolve no groups through
it. To change the properties of a group provider, use [ALTER GROUP PROVIDER](#alter-a-group-provider)
instead of dropping and recreating it.

## Combine group provider with a security integration

After creating the group provider, you can combine it with a security integration to allow users specified by the group provider to log in to the database. For more information on creating a security integration, see [Authenticate with Security Integration](/documents/4.2/administration/user_privs/authentication/security_integration.md).

### Syntax

```SQL theme={null}
ALTER SECURITY INTEGRATION <security_integration_name> SET
(
    "group_provider" = "",
    "permitted_groups" = ""
)
```

### Parameters

#### `group_provider`

The name of the group provider(s) to be combined with the security integration. Multiple group providers are separated by commas. Once set, the database will record the user's group information under each specified provider upon login.

When this property is not set, the security integration falls back to the FE configuration item `group_provider`, the cluster-wide default list. Note that versions earlier than v4.2 consulted no group provider at all in that case, so setting the FE configuration item takes effect for such an integration only from v4.2 onwards.

#### `permitted_groups`

Optional. The name of group(s) whose members are allowed to log in to the database. Multiple groups are separated by commas. Make sure that the specified groups can be retrieved by the combined group provider(s).

### Example

```SQL theme={null}
ALTER SECURITY INTEGRATION LDAP SET
(
        "group_provider"="ldap_group_provider",
        "permitted_groups"="testgroup"
);
```

## Grant role to a user group

You can grant roles to a user group via [GRANT](/documents/4.2/sql-reference/sql-statements/account-management/GRANT.md).

The following example grants the role `example_role` to the user group `analysts`:

```SQL theme={null}
GRANT example_role TO EXTERNAL GROUP analysts;
```

## Combine group provider with external authorization system (Apache Ranger)

Once you configure the associated group provider in the security integration, the database will record the user's group information upon login. This group information will then be automatically included in the authorization process with Ranger, eliminating the need for additional configuration.

For more instructions on integrating the database with Ranger, see [Manage permissions with Apache Ranger](/documents/4.2/administration/user_privs/authorization/ranger_plugin.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.