Configuring SingleStore for Kerberos Authentication

Once you have generated an SPN and a keytab file on the Kerberos KDC server, you can configure SingleStore to allow access for Kerberos-authenticated users.

Depending on your SingleStore cluster configuration, the SPN and keytab file may need to be configured on one or many aggregator nodes. For example, if your cluster contains one Master Aggregator and one child aggregator, you must configure both nodes to allow client connections for Kerberos-authenticated users.

The following steps describe how to use the SPN and keytab file created earlier.

Copying the Keytab File to SingleStore

A keytab file is a credential that can be used to access network resources, so it is important to consider the security implications of copying it from one location to another. Additionally, since a keytab file is a binary file, it must be transferred using a method that will not corrupt the file. For example, if FTP is configured to transfer as an ASCII file type instead of a binary file type, the keytab file will be corrupted.

Use a secure file transfer method, such as scp, to copy the keytab file from the KDC server to each SingleStore aggregator node. After the keytab file has been copied, its file path on the aggregator node will be used to configure the memsql.cnf file in the next step.

Configuring memsql.cnf

Before Kerberos-authenticated users can connect to SingleStore, you must configure each SingleStore aggregator node’s memsql.cnf file with two variables:

  • gssapi-keytab-path: The local path to the keytab file that was created on the KDC server and copied to the node. For example: /path/to/memsql.keytab

  • gssapi-principal-name: The SPN for SingleStore that was created on the KDC server. For example: memsql/host.domain.com@DOMAIN.COM

Note

You cannot use the SET GLOBAL VARIABLE command when setting these variables. They must be configured in the memsql.cnf file on the applicable node using the steps described below.

To set these variables in the memsql.cnf file:

  1. Ensure that the cluster is stopped before continuing.

  2. Open the aggregator node’s memsql.cnf file in a text editor (typical location for this file).

  3. Add the following line to the file anywhere below the [server] declaration:

    [server]
    ...
    gssapi-keytab-path = /path/to/memsql.keytab
    gssapi-principal-name = memsql/host.domain.com@DOMAIN.COM
    ...
  4. Save the file.

  5. Repeat this process for each aggregator node’s memsql.cnf file.

  6. After the memsql.cnf file has been updated for each aggregator node in the cluster, start the cluster.

  7. Verify that the change was successful by executing the following command on one of the affected nodes:

    SHOW GLOBAL VARIABLES LIKE 'gssapi%';
    +-----------------------+-------------------------------------+
    | Variable_name         | Value                               |
    +-----------------------+-------------------------------------+
    | gssapi_keytab_path    | /path/to/memsql.keytab              |
    | gssapi_principal_name | memsql/host.domain.com@DOMAIN.COM   |
    +-----------------------+-------------------------------------+
    2 rows in set (0.00 sec)

Granting a User Kerberos Authentication Permissions

Now that the SingleStore cluster has been configured, you can use the GRANT command to create a Kerberos-authenticated user and grant permissions. To grant permissions, you simply map a SingleStore user to their Kerberos SPN. You can map Kerberos SPNs in two ways: by providing the name of a single Kerberos SPN, or by using regular expressions to match with or more Kerberos SPNs.

Mapping a Single Kerberos Identity

The following example creates a new SingleStore user ('user1'@'%') authenticating via Kerberos on all databases, where the Kerberos SPN is user1@EXAMPLE.COM:

GRANT ALL ON *.* TO 'user1'@'%' IDENTIFIED WITH 'authentication_gss' AS 'user1@EXAMPLE.COM';

When this command is run, the 'user1'@'%' SingleStore user is created and mapped to the user1@EXAMPLE.COM Kerberos SPN. After the command has been run, all subsequent SingleStore connection attempts for 'user1'@'%' will require a Ticket Granting Ticket (TGT) from the KDC server for the user1@EXAMPLE.COM SPN. If a user attempts to connect with a TGT for a different SPN, the connection will fail.

Note

The recommended way to create users is through the CREATE USER command. Granting permissions to existing users should only use the existing username without the IDENTIFIED WITH clause.

GRANT DELETE ON db.* TO steve;

Mapping with Regular Expressions

You may also use regular expressions in the AS clause of the GRANT statement. This functionality is useful if you want to map a single SingleStore user to one or more Kerberos SPNs across multiple domains, or if you have other unique realm requirements.

Caution

When using a regular expression in a GRANT statement, confirm that the expression evaluates in an expected manner. Unintended results can occur without thoroughly validating a regular expression.

Regular expressions can only be used in the AS clause of the GRANT statement. By default, regular expressions are disabled in the AS clause.

To enable regular expressions support, the first character in your AS clause must start with a forward slash (/). SingleStore recommends that the string use standard ^ (start of line) and $ (end of line) operators to indicate when the regular expression should start and end.

Consider the following example that creates a new user:

GRANT ALL ON *.* to 'user1'@'%' IDENTIFIED WITH 'authentication_gss' AS '/^user1@EXAMPLE\.COM$';

This example creates the user via regular expression to match the user1@EXAMPLE.COM string in any Kerberos SPN that attempts to authenticate with SingleStore. It uses proper start-of-line and end-of-line operators to indicate that only the full user1@EXAMPLE.COM SPN will be matched. It’s possible to introduce unexpected behavior without providing these operators. Consider the following example:

GRANT ALL ON *.* to 'user1'@'%' IDENTIFIED WITH 'authentication_gss' AS '/user1@EXAMPLE\.COM$';

The example above differs from the previous example by omitting the ^ start of line operator. This simple omission introduces significant security implications, because another Kerberos SPN might contain the substring of user1@EXAMPLE.COM, such as other_user1@EXAMPLE.COM.

Always ensure that your regular expression produces the intended result.

Example: Optional Subdomain

The following example creates the SingleStore user 'user1'@'%' with a Kerberos SPN that contains an optional subdomain.

GRANT ALL ON *.* to 'user1'@'%' IDENTIFIED WITH 'authentication_gss' AS '/^user1@(SUBDOMAIN\.)?EXAMPLE\.COM$';

Example: Optional Domain Suffix

The following example creates the SingleStore user 'user1'@'%' with a Kerberos SPN across domains with different suffixes, namely .COM, .NET, or .ORG.

GRANT ALL ON *.* to 'user1'@'%' IDENTIFIED WITH 'authentication_gss' AS '/^user1@EXAMPLE\.(COM|NET|ORG)$';

Connecting to SingleStore as a Kerberos-authenticated User

After a SingleStore user has been associated with a Kerberos SPN, you can connect to SingleStore as that user. Before authenticating however, you must have a valid TGT in your credential cache. Depending on your domain and system configuration, there are a variety of ways to acquire a valid TGT. For example, the most common method on Linux/Unix is to execute kinit from the terminal. On Windows, TGT acquisition and renewal is typically done automatically, as per the Active Directory group policy configuration.

Option 1: Use the SingleStore Client

Install the SingleStore client via the following instructions.

Install SingleStore Client

Once the SingleStore client has been installed:

  1. Obtain a ticket from the Kerberos server.

    kinit <username>@<hostname>
    Password for <username>@<hostnae>:
  2. Connect with the SingleStore client.

    1. For a package-based installation of the SingleStore client.

      singlestore -h<hostname> --plugin-dir=/usr/lib/singlestore-client/plugin/ -u<username>
    2. For a tarball-based installation of the SingleStore client.

      singlestore -h<hostname> --plugin-dir=/path/to/singlestore-client/plugin/ -u<username>

Option 2: Use the MariaDB Client

  1. Obtain a ticket from the Kerberos server.

    kinit <username>@<hostname>
    Password for <username>@<hostname>:
  2. Connect with the MariaDB client.

    mysql --plugin-dir=/path/to/plugin-dir -u <username> --prompt="singlestore> "

Note that this authentication method requires you to specify the plugin directory that contains the auth_gssapi plugin for MariaDB, as described in Assumptions and Prerequisites. Depending on the host operating system, you must provide the appropriate GSSAPI authentication plugin version. MariaDB provides authentication plugins for 32-bit and 64-bit versions of each supported operating system.

To connect using ODBC, consider the following example:

Driver=<path-to-mariadb-odbc-connector>;Database=information_schema;ServerName=10.0.0.1;Port=3306;UID=myusername;Plugin_Dir=<path-to-gssapi-plugin-directory>;

Last modified: October 31, 2023

Was this article helpful?