Configuring SingleStoreDB for Kerberos Authentication
Once you have generated an SPN and a keytab file on the Kerberos KDC server, you can configure SingleStoreDB to allow access for Kerberos-authenticated users.
Depending on your SingleStoreDB 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 SingleStoreDB
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 SingleStoreDB 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 SingleStoreDB, you must configure each SingleStoreDB 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 SingleStoreDB 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:
Ensure that the cluster is stopped before continuing.
Open the aggregator node’s
memsql.cnf
file in a text editor (typical location for this file).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 ...
Save the file.
Repeat this process for each aggregator node’s
memsql.cnf
file.After the
memsql.cnf
file has been updated for each aggregator node in the cluster, start the cluster.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 SingleStoreDB 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 SingleStoreDB 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 SingleStoreDB 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'@'%'
SingleStoreDB user is created and mapped to the user1@EXAMPLE.COM
Kerberos SPN. After the command has been run, all subsequent SingleStoreDB 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 SingleStoreDB 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 (/
). We recommend that the string should 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 SingleStoreDB. 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 SingleStoreDB 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 SingleStoreDB 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 SingleStoreDB as a Kerberos-authenticated User
After a SingleStoreDB user has been associated with a Kerberos SPN, you can connect to SingleStoreDB 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
Online Installation
For online installations where the target host can access the SingleStore YUM repository, perform the following steps.
Note: These steps are also provided in the self-managed deployment guides.
Add the SingleStore repository to your repository list.
sudo yum-config-manager --add-repo https://release.memsql.com/production/rpm/x86_64/repodata/memsql.repo
Verify that the SingleStore repo information is listed under
repolist
.sudo yum repolist
Verify that the
which
package installed. This is used during the install process to identify the correct package type for your installation.rpm -q which
If
which
is not installed, it must be installed before proceeding.If you cannot install
which
, you will have to specify the correct package during the deployment phase covered in the respective deployment guide.sudo yum install -y which
Install the SingleStore client.
sudo yum install -y singlestore-client
Offline Installation
For clusters that must be deployed in an environment without Internet access, download the SingleStore client package onto a host that can access the main deployment host.
Copy the SingleStore client package onto the target host (typically the main deployment host when deploying SingleStoreDB) and install the SingleStore client.
sudo rpm -ivh /tmp/singlestore-client-<version>-<commit-hash>.x86_64.rpm
Online Installation
For online installations where the target host can access the SingleStore APT repository, perform the following steps.
Note: These steps are also provided in the self-managed deployment guides.
SingleStore packages are signed to ensure integrity, so the GPG key needs to be added to this host. When done, verify that the SingleStore signing key has been added using
apt-key list
.wget -O - 'https://release.memsql.com/release-aug2018.gpg' 2>/dev/null | sudo apt-key add - && apt-key list
Verify that
apt-transport-https
is installed.apt-cache policy apt-transport-https
If
apt-transport-https
is not installed, it must be installed before proceeding.user-shell sudo apt -y install apt-transport-https
Add the SingleStore repository to retrieve its packages.
echo "deb [arch=amd64] https://release.memsql.com/production/debian memsql main" | sudo tee /etc/apt/sources.list.d/memsql.list
Install the SingleStore client.
sudo apt update && sudo apt -y install singlestore-client
Offline Installation
For clusters that must be deployed in an environment without Internet access, download the SingleStore client package onto a host that can access the main deployment host.
Copy the SingleStore client package onto the target host (typically the main deployment host when deploying SingleStoreDB) and install the SingleStore client.
sudo dpkg -i /tmp/singlestore-client_<version>_<commit-hash>_amd64.deb
Download the SingleStore Client
Download the SingleStore client tarball file onto a host that can access the main deployment host.
Transfer the SingleStore Client
Transfer the SingleStore client tarball file into a dedicated singlestore
directory on the target host (typically the main deployment host when deploying SingleStoreDB) that has been configured so that non-sudo
users can access it, such as /home/<user>/singlestore
or /opt/singlestore
.
Unpack the SingleStore Client
Unpack the SingleStore client tarball file into the singlestore
directory.
tar xzvf singlestore-client-<version>-<commit-hash>.x86_64.tar.gz
Using symbolic links (or "symlinks") can make using and upgrading the SingleStore client easier. Performing the following steps will allow the singlestore
command to be run from anywhere on the filesystem, even after an upgrade by updating the symlink.
Navigate to the directory that contains the unpacked SingleStore client tarball file and create a
singlestore-client
symlink that points to the SingleStore client directory.ln -s singlestore-client-<version>-<commit-hash> singlestore-client
Verify that the symlink has been created.
ls -l **** singlestore-client -> singlestore-client-1.0.6-c3803db03b
Update the
PATH
environment variable with the path to the newsinglestore-client
directory. This path can also be added to your shell startup file so you won't have to run this command each time you log in.export PATH=/home/<user>/singlestore/singlestore-client:$PATH
You may now run the
singlestore
command from anywhere on the filesystem.singlestore
Once the SingleStore client has been installed:
Obtain a ticket from the Kerberos server.
kinit <username>@<hostname> **** Password for <username>@<hostnae>:
Connect with the SingleStore client.
For a package-based installation of the SingleStore client.
singlestore -h<hostname> --plugin-dir=/usr/lib/singlestore-client/plugin/ -u<username>
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
Obtain a ticket from the Kerberos server.
kinit <username>@<hostname> **** Password for <username>@<hostname>:
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>;