adutil - Active Directory 实用工具简介

适用于:SQL Server - Linux

adutil 工具是一种命令行接口 (CLI) 实用工具,用于配置和管理 Linux 上的 SQL Server 和容器的 Windows Active Directory 域,而无需在 Windows 和 Linux 计算机之间切换以管理 Active Directory。

对 adutil 的支持仅限于 SQL Server 用例。

无需使用 adutil 为 Linux 上的 SQL Server 或容器启用 Active Directory 身份验证。 你还可以使用 ktpass 之类的实用工具,如教程:对 Linux 上的 SQL Server 使用 Active Directory 身份验证中所述。

adutil 工具设计为一系列命令和子命令,其中包含可指定为进一步输入的额外标志。 每个顶级命令表示管理功能的一个类别。 在该类别中,每个子命令均为操作。 本文介绍如何下载和开始使用 adutil。

为安全套接字层 (SSL) LDAP 配置 adutil

你应使用 LDAP over SSL (LDAPS) 而不是轻型目录访问协议 (LDAP)。 若要详细了解 LDAP,请参阅轻型目录访问协议 (LDAP)

可以在 adutil.json 配置文件中将 useLdaps 选项设置为 true,在 mssql 用户下运行时该文件位于 /var/opt/mssql/.adutil/adutil.json。 此 JSON 代码示例显示了如何配置设置:

{
    "useLdaps": "true"
}

默认情况下,useLDAPS 设置设为 false。 配置此设置并使用 mssql-conf 创建 keytab(密钥表)时,请确保以用户 mssql 的身份运行 mssql-conf,你可以通过运行以下命令来执行此操作:

sudo su mssql

若要使用 mssql-conf 设置密钥表,请参阅使用 mssql-conf 创建 SQL Server 服务密钥表文件

安装 adutil

如果在安装时没有接受 EULA,则在首次运行 adutil 命令时,必须使用 --accept-eula 标志来运行该命令(适用于所有分发版)。

  1. 下载 Microsoft Red Hat 存储库配置文件。

    sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo
    
  2. 如果安装了早期预览版本的 adutil,请使用以下命令删除所有旧 adutil 包 。

    sudo yum remove adutil-preview
    
  3. 运行以下命令以安装 adutil。 ACCEPT_EULA=Y 接受 adutil 的 EULA。 EULA 位于路径 /usr/share/adutil/ 中。

    sudo ACCEPT_EULA=Y yum install -y adutil
    

使用 adutil 管理 Windows Active Directory

请确保将 adutil 下载到已加入 Active Directory 域的主机。 你还需要使用 kinit 命令和特权域帐户获取或续订 Kerberos TGT(票证授予票证)。 使用的帐户必须具有在域上创建帐户和服务主体名称 (SPN) 的权限。

下面是一些可以使用 adutil 执行的操作示例。 要查看顶级命令列表,请键入 adutil --help。 此命令会显示可用于管理 Active Directory 并与之交互的顶级命令。

$ adutil --help
adutil - A general AD utility
  Usage:
    adutil [account|delegation|group|keytab|machine|ou|spn|user|config]
  Subcommands:
    account      Functions for generic account operations
    delegation   Functions for configuring delegation permissions
    group        Functions for group management
    keytab       Functions for keytab management
    machine      Functions for managing machine accounts
    ou           Functions for managing organizational units
    spn          Functions for service principal name (SPN) management
    user         Functions for user account management
    config       Functions for modifying adutil configuration
  Flags:
       --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.

如果需要获取下一级别命令的帮助,可以运行下面的“帮助”选项:

$ adutil spn --help
spn - Functions for service principal name (SPN) management
  Usage:
    spn [add|addauto|delete|search|show]
  Subcommands:
    add       Adds the provided SPNs to an account
    addauto   Automatically generate SPNs based on SPN component inputs and add them to an account
    delete    Deletes the provided SPNs from an account
    search    Search for an SPN by name or list all SPNs in the directory
    show      Get the list of SPNs assigned to an account
  Flags:
    --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.
$ adutil spn search --help
search - Search for an SPN by name or list all SPNs in the directory
  Usage:
     search [name]
  Positional Variables:
    name   OPTIONAL: Name of the SPN to search for in the directory. * can be used as a wildcard
  Flags:
    --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -n --name          OPTIONAL: Name of the SPN to search for in the directory. * can be used as a wildcard
    -f --filter        OPTIONAL: Filter for the search (User,Machine,Group)
    -o --ouname        OPTIONAL: Distinguished name of OU in which SPNs should be searched. If omitted, the entire directory will be searched.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.

示例

每个命令都已记录下来,以便你可以立即开始。 下面是在配置或管理 Linux 上的 SQL Server 和容器的 Active Directory 身份验证时使用 adutil 的一些典型活动:

  • 在 Active Directory 中创建帐户:

    adutil user create --name sqluser --distname CN=sqluser,CN=Users,DC=CONTOSO,DC=COM
    
  • 创建与帐户或服务关联的 SPN:

    adutil spn addauto -n sqluser -s MSSQLSvc -H mymachine.contoso.com -p 1433
    
  • 使用 adutil 创建 keytab:

    adutil keytab createauto -k /var/opt/mssql/secrets/mssql.keytab -p 1433 -H mymachine.contoso.com --password 'P@ssw0rd' -s MSSQLSvc
    

可以使用 man adutil 命令参阅 adutil 的参考手册页。