Active Directory user authentication

You can configure Elastic Stack security features to communicate with Active Directory to authenticate users. See Configuring an Active Directory realm.

The security features use LDAP to communicate with Active Directory, so active_directory realms are similar to ldap realms. Like LDAP directories, Active Directory stores users and groups hierarchically. The directory’s hierarchy is built from containers such as the organizational unit (ou), organization (o), and domain controller (dc).

The path to an entry is a Distinguished Name (DN) that uniquely identifies a user or group. User and group names typically have attributes such as a common name (cn) or unique ID (uid). A DN is specified as a string, for example "cn=admin,dc=example,dc=com" (white spaces are ignored).

The security features supports only Active Directory security groups. You cannot map distribution groups to roles.

When you use Active Directory for authentication, the username entered by the user is expected to match the sAMAccountName or userPrincipalName, not the common name.

The Active Directory realm authenticates users using an LDAP bind request. After authenticating the user, the realm then searches to find the user’s entry in Active Directory. Once the user has been found, the Active Directory realm then retrieves the user’s group memberships from the tokenGroups attribute on the user’s entry in Active Directory.

Configuring an Active Directory realm

To integrate with Active Directory, you configure an active_directory realm and map Active Directory users and groups to roles in the role mapping file.

  1. Add a realm configuration of type active_directory to elasticsearch.yml under the xpack.security.authc.realms.active_directory namespace. At a minimum, you must specify the Active Directory domain_name. If you are configuring multiple realms, you should also explicitly set the order attribute to control the order in which the realms are consulted during authentication.

    See Active Directory realm settings for all of the options you can set for an active_directory realm.

    Binding to Active Directory fails if the domain name is not mapped in DNS. If DNS is not being provided by a Windows DNS server, add a mapping for the domain in the local /etc/hosts file.

    For example, the following realm configuration configures Elasticsearch to connect to ldaps://example.com:636 to authenticate users through Active Directory:

    1. xpack:
    2. security:
    3. authc:
    4. realms:
    5. active_directory:
    6. my_ad:
    7. order: 0
    8. domain_name: ad.example.com
    9. url: ldaps://ad.example.com:636

    The realm order controls the order in which the configured realms are checked when authenticating a user.

    If you don’t specify the URL, it defaults to ldap:<domain_name>:389.

    When you configure realms in elasticsearch.yml, only the realms you specify are used for authentication. If you also want to use the native or file realms, you must include them in the realm chain.

  2. If you are authenticating users across multiple domains in a forest, extra steps are required. There are a few minor differences in the configuration and the way that users authenticate.

    Set the domain_name setting to the forest root domain name.

    You must also set the url setting, since you must authenticate against the Global Catalog, which uses a different port and might not be running on every Domain Controller.

    For example, the following realm configuration configures Elasticsearch to connect to specific Domain Controllers on the Global Catalog port with the domain name set to the forest root:

    1. xpack:
    2. security:
    3. authc:
    4. realms:
    5. active_directory:
    6. my_ad:
    7. order: 0
    8. domain_name: example.com
    9. url: ldaps://dc1.ad.example.com:3269, ldaps://dc2.ad.example.com:3269
    10. load_balance:
    11. type: "round_robin"

    The domain_name is set to the name of the root domain in the forest.

    The url value used in this example has URLs for two different Domain Controllers, which are also Global Catalog servers. Port 3268 is the default port for unencrypted communication with the Global Catalog; port 3269 is the default port for SSL connections. The servers that are being connected to can be in any domain of the forest as long as they are also Global Catalog servers.

    A load balancing setting is provided to indicate the desired behavior when choosing the server to connect to.

    In this configuration, users will need to use either their full User Principal Name (UPN) or their Down-Level Logon Name. A UPN is typically a concatenation of the username with @<DOMAIN_NAME such as johndoe@ad.example.com. The Down-Level Logon Name is the NetBIOS domain name, followed by a \ and the username, such as AD\johndoe. Use of Down-Level Logon Name requires a connection to the regular LDAP ports (389 or 636) in order to query the configuration container to retrieve the domain name from the NetBIOS name.

  3. (Optional) Configure how Elasticsearch should interact with multiple Active Directory servers.

    The load_balance.type setting can be used at the realm level. Two modes of operation are supported: failover and load balancing. See Active Directory realm settings.

  4. (Optional) To protect passwords, encrypt communications between Elasticsearch and the Active Directory server.

  5. Restart Elasticsearch.
  6. Configure a bind user.

    The Active Directory realm authenticates users using an LDAP bind request. By default, all of the LDAP operations are run by the user that Elasticsearch is authenticating. In some cases, regular users may not be able to access all of the necessary items within Active Directory and a bind user is needed. A bind user can be configured and is used to perform all operations other than the LDAP bind request, which is required to authenticate the credentials provided by the user.

    The use of a bind user enables the run as feature to be used with the Active Directory realm and the ability to maintain a set of pooled connections to Active Directory. These pooled connection reduce the number of resources that must be created and destroyed with every user authentication.

    The following example shows the configuration of a bind user through the user of the bind_dn and secure_bind_password settings:

    1. xpack:
    2. security:
    3. authc:
    4. realms:
    5. active_directory:
    6. my_ad:
    7. order: 0
    8. domain_name: ad.example.com
    9. url: ldaps://ad.example.com:636
    10. bind_dn: es_svc_user@ad.example.com

    This is the user that all Active Directory search requests are executed as. Without a bind user configured, all requests run as the user that is authenticating with Elasticsearch.

    The password for the bind_dn user should be configured by adding the appropriate secure_bind_password setting to the Elasticsearch keystore. For example, the following command adds the password for the example realm above:

    1. bin/elasticsearch-keystore add \
    2. xpack.security.authc.realms.active_directory.my_ad.secure_bind_password

    When a bind user is configured, connection pooling is enabled by default. Connection pooling can be disabled using the user_search.pool.enabled setting.

  7. Map Active Directory users and groups to roles.

    An integral part of a realm authentication process is to resolve the roles associated with the authenticated user. Roles define the privileges a user has in the cluster.

    Since with the active_directory realm the users are managed externally in the Active Directory server, the expectation is that their roles are managed there as well. In fact, Active Directory supports the notion of groups, which often represent user roles for different systems in the organization.

    The active_directory realm enables you to map Active Directory users to roles via their Active Directory groups or other metadata. This role mapping can be configured via the role-mapping APIs or by using a file stored on each node. When a user authenticates against an Active Directory realm, the privileges for that user are the union of all privileges defined by the roles to which the user is mapped.

    Within a mapping definition, you specify groups using their distinguished names. For example, the following mapping configuration maps the Active Directory admins group to both the monitoring and user roles, maps the users group to the user role and maps the John Doe user to the user role.

    Configured via the role-mapping API:

    1. PUT /_security/role_mapping/admins
    2. {
    3. "roles" : [ "monitoring" , "user" ],
    4. "rules" : { "field" : {
    5. "groups" : "cn=admins,dc=example,dc=com"
    6. } },
    7. "enabled": true
    8. }

    The Active Directory distinguished name (DN) of the admins group.

    1. PUT /_security/role_mapping/basic_users
    2. {
    3. "roles" : [ "user" ],
    4. "rules" : { "any": [
    5. { "field" : {
    6. "groups" : "cn=users,dc=example,dc=com"
    7. } },
    8. { "field" : {
    9. "dn" : "cn=John Doe,cn=contractors,dc=example,dc=com"
    10. } }
    11. ] },
    12. "enabled": true
    13. }

    The Active Directory distinguished name (DN) of the users group.

    The Active Directory distinguished name (DN) of the user John Doe.

    Or, alternatively, configured via the role-mapping file:

    1. monitoring:
    2. - "cn=admins,dc=example,dc=com"
    3. user:
    4. - "cn=users,dc=example,dc=com"
    5. - "cn=admins,dc=example,dc=com"
    6. - "cn=John Doe,cn=contractors,dc=example,dc=com"

    The name of the role.

    The Active Directory distinguished name (DN) of the admins group.

    The Active Directory distinguished name (DN) of the users group.

    The Active Directory distinguished name (DN) of the user John Doe.

    For more information, see Mapping users and groups to roles.

  8. (Optional) Configure the metadata setting in the Active Directory realm to include extra properties in the user’s metadata.

    By default, ldap_dn and ldap_groups are populated in the user’s metadata. For more information, see User metadata in Active Directory realms.

User metadata in Active Directory realms

When a user is authenticated via an Active Directory realm, the following properties are populated in the user’s metadata:

Field

Description

ldap_dn

The distinguished name of the user.

ldap_groups

The distinguished name of each of the groups that were resolved for the user (regardless of whether those groups were mapped to a role).

This metadata is returned in the authenticate API and can be used with templated queries in roles.

Additional metadata can be extracted from the Active Directory server by configuring the metadata setting on the Active Directory realm.

Load balancing and failover

The load_balance.type setting can be used at the realm level to configure how the security features should interact with multiple Active Directory servers. Two modes of operation are supported: failover and load balancing.

See Load balancing and failover.

Setting up SSL between Elasticsearch and Active Directory

See Encrypting communications between Elasticsearch and Active Directory.