注意:
- Oracle 提供的免费实验室环境中提供了此教程。
- 它使用 Oracle Cloud Infrastructure 身份证明、租户和区间的示例值。完成实验室时,请将这些值替换为特定于云环境的值。
在 Oracle Linux 上安装 FreeIPA 服务器
简介
FreeIPA 是适用于 Linux 网络环境的开源身份和验证管理系统。该服务器将 389 Directory Server 作为中央数据存储,提供完整的多主 LDAPv3 功能。
除了本教程的范围之外,FreeIPA 还通过 ISC 绑定服务器提供 MIT Kerberos 单点登录验证、Dogtag 证书颁发机构以及可选的域名管理。
本教程说明如何安装 FreeIPA 并配置包含的 LDAP 目录。
目标
在本教程中,您将学习如何:
- 安装 FreeIPA 服务器
- 禁用匿名绑定
- 添加用户和组
先决条件
-
最少一个 Oracle Linux 系统
-
每个系统都应安装 Oracle Linux 并进行以下配置:
- 具有 sudo 访问权限的非 root 用户帐户
- 访问 Internet
- 指向服务器 IP 地址的 FQDN(全限定域名)
有关 FreeIPA 要求的更多信息,请参见上游的快速入门指南。
部署 Oracle Linux
注:如果在您自己的租户中运行,请在部署实验环境之前阅读 linux-virt-labs
GitHub 项目 README.md 并完成先决条件。
-
在 Luna Desktop 上打开一个终端。
-
克隆
linux-virt-labs
GitHub 项目。git clone https://github.com/oracle-devrel/linux-virt-labs.git
-
转到工作目录。
cd linux-virt-labs/ol
-
安装所需集合。
ansible-galaxy collection install -r requirements.yml
-
更新 Oracle Linux 实例配置。
cat << EOF | tee instances.yml > /dev/null compute_instances: 1: instance_name: "freeipa" type: "server" EOF
-
部署实验室环境。
ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e "@instances.yml"
免费的实验环境需要额外的变量
local_python_interpreter
,该变量为在 localhost 上运行的播放设置ansible_python_interpreter
。此变量是必需的,因为环境安装了适用于 Python 的 Oracle Cloud Infrastructure SDK 的 RPM 程序包,该程序包位于 python3.6 模块下。默认部署配置使用 AMD CPU 和 Oracle Linux 8。要使用 Intel CPU 或 Oracle Linux 9,请将
-e instance_shape="VM.Standard3.Flex"
或-e os_version="9"
添加到部署命令。重要提示:等待手册成功运行并到达暂停任务。在手册的这一阶段,Oracle Linux 安装已完成,实例已准备就绪。记下之前的剧集,其中输出其部署的节点的公共和专用 IP 地址,以及运行实验时所需的任何其他部署信息。
确认服务器 DNS 配置
FreeIPA 服务器需要有效的 DNS 设置。使用 ipa
命令行工具注册的客户机通过 /etc/ipa/default.conf
文件中定义的 xmlrpc_url
和 domain
参数查找服务器。
-
打开终端并通过 SSH 连接到 freeipa 实例。
ssh oracle@<ip_address_of_instance>
-
验证服务器的主机名。
sudo hostname
输出不应返回
localhost
或localhost6
。
确认全限定域名 (Full Qualified Domain Name,FQDN)。
FreeIPA 在安装期间验证的 FQDN 的限制为 64 个字符。如果 FQDN 超过 64 个字符,则使用 sudo hostnamectl set-hostname NAME
(其中 NAME
是 FQDN)将其缩短。
-
验证 FQDN 及其长度。
hostname -f
-
获取 FQDN 的长度
echo $(hostname -f) | wc -m
确认名称解析。
-
获取服务器的 IP 地址。
ip -4 -o addr show ens3 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
其中
ens3
是系统上网络接口的名称。 -
验证正向 DNS 配置。
host $(hostname -f)
验证正向 DNS 配置的另一种方法是使用
dig +short $(hostname -f) A
。host
和dig
都是bind-utils
软件包的一部分,该软件包提供了用于查询 DNS 名称服务器的不同实用程序。 -
验证反向 DNS 配置(PTR 记录)。
host $(hostname -i)
另一种方法是使用
dig +short -x $(hostname -i)
。
打开所需的防火墙端口
FreeIPA 要求多个端口处于打开状态并且可用于与其服务通信。
服务 | 端口 | 协议 |
---|---|---|
HTTP/HTTPS | 80,443 | TCP |
LDAP/LDAP | 389,636 | TCP |
Kerberos | 88,464 | TCP 和 UDP |
DNS | 53 | TCP 和 UDP |
NTP | 123 | UDP |
Oracle Linux 提供了 freeipa-4
服务来打开这些必需的端口。有关详细信息,请参见 /usr/lib/firewalld/services/freeipa-4.xml
。freeipa-4
服务将替换已过时的 freeipa-ldap
和 freeipa-ldaps
服务。
-
添加
firewalld
服务。sudo firewall-cmd --permanent --add-service=freeipa-4
-
重新加载 firewalld 服务,以使更改生效。
sudo firewall-cmd --reload
安装所需的软件包
-
启用 FreeIPA 模块流和配置文件。
Oracle Linux 8:
sudo dnf module enable -y idm:DL1
Oracle Linux 9 和 Oracle Linux 10:
由于 FreeIPA 软件包是 AppStream 系统信息库的一部分,因此在 Oracle Linux 9 上无需执行任何操作。
-
为没有集成 DNS 服务的 FreeIPA 服务器安装软件包。
sudo dnf install -y ipa-server
注意:在本教程中,我们不会使用集成的 DNS 服务。如果需要,请将软件包
ipa-server-dns
添加到安装列表中。
安装和配置 FreeIPA 服务器
-
运行安装实用程序。
sudo ipa-server-install
该脚本首先提供安装日志文件位置以及 FreeIPA 服务器包含的内容的摘要。
输出示例:
[oracle@freeipa ~]$ sudo ipa-server-install The log file for this installation can be found in /var/log/ipaserver-install.log ============================================================================== This program will set up the IPA Server. Version 4.9.8 This includes: * Configure a stand-alone CA (dogtag) for certificate management * Configure the NTP client (chronyd) * Create and configure an instance of Directory Server * Create and configure a Kerberos Key Distribution Center (KDC) * Configure Apache (httpd) * Configure SID generation * Configure the KDC to enable PKINIT ...
然后,脚本使用多个提示设置服务器的配置。终端显示对括号内提示的缺省响应,按
Enter
可接受缺省响应。 -
接受
no
的默认响应以配置集成的 DNS 服务。Do you want to configure integrated DNS (BIND)? [no]:
-
接受默认主机、域和领域名称。
这些是在本实验开始时验证的值。建议的配置是领域名称与包含所有大写字母的主 DNS 域名匹配。
Enter the fully qualified domain name of the computer on which you're setting up server software. Using the form <hostname>.<domainname> Example: master.example.com. Server host name [freeipa.lv.vcn.oraclevcn.com]: The domain name has been determined based on the host name. Please confirm the domain name [lv.vcn.oraclevcn.com]: The kerberos protocol requires a Realm name to be defined. This is typically the domain name converted to uppercase. Please provide a realm name [LV.VCN.ORACLEVCN.COM]:
-
输入并确认目录服务器超级用户和 FreeIPA
admin
用户的密码。Directory Server 超级用户映射到目录中的
cn=Directory Manager
。Certain directory server operations require an administrative user. This user is referred to as the Directory Manager and has full access to the Directory for system management tasks and will be added to the instance of directory server created for IPA. The password must be at least 8 characters long. Directory Manager password: Password (confirm): The IPA server requires an administrative user, named 'admin'. This user is a regular system account used for IPA server administration. IPA admin password: Password (confirm):
-
接受用于设置 NETBIOS 域名和用于配置 chrony 的
no
的默认值。NetBIOS domain name [LV]: Do you want to configure chrony with NTP server or pool address? [no]:
-
该脚本提供服务器配置的摘要。
-
输入
yes
以接受服务器配置。Continue to configure the system with these values? [no]: yes
-
该脚本将继续配置服务器。
完成此操作可能需要几分钟的时间。
... Client configuration complete. The ipa-client-install command was successful Please add records in this file to your DNS system: /tmp/ipa.system.records.mv9i0ec2.db ============================================================================== Setup complete Next steps: 1. You must make sure these network ports are open: TCP Ports: * 80, 443: HTTP/HTTPS * 389, 636: LDAP/LDAPS * 88, 464: kerberos UDP Ports: * 88, 464: kerberos * 123: ntp 2. You can now obtain a kerberos ticket using the command: 'kinit admin' This ticket will allow you to use the IPA tools (e.g., ipa user-add) and the web user interface. Be sure to back up the CA certificates stored in /root/cacert.p12 These files are required to create replicas. The password for these files is the Directory Manager password The ipa-server-install command was successful
完成后,脚本提供:
- 总结。
- 要添加到 DNS 系统的记录列表。
- 建议备份生成的 CA 证书。
所需的网络端口已使用
freeipa-4
firewalld
服务打开。
测试 FreeIPA 服务器
FreeIPA 安装包括一个命令行客户机和一个用于与服务器交互的 WebUI。使用 WebUI 超出本教程的范围。
访问命令行接口 (Command-Line Interface,CLI)
-
针对 Kerberos 领域验证
admin
用户。kinit admin
出现提示时,输入在安装和配置步骤期间创建的
admin
用户的密码。然后,kinit
命令生成 Kerberos 票证。 -
列出请求单的信息
klist
输出示例:
[oracle@freeipa ~]$ sudo klist Ticket cache: KCM:0 Default principal: admin@LV.VCN.ORACLEVCN.COM Valid starting Expires Service principal 09/28/2022 14:05:46 09/29/2022 13:05:53 krbtgt/LV.VCN.ORACLEVCN.COM@LV.VCN.ORACLEVCN.COM
-
获取 FreeIPA 服务器上所有现有用户的列表。
ipa user-find
结果将返回
admin
用户,这是当前唯一存在的用户。输出示例:
[oracle@freeipa ~]$ sudo ipa user-find -------------- 1 user matched -------------- User login: admin Last name: Administrator Home directory: /home/admin Login shell: /bin/bash Principal alias: admin@LV.VCN.ORACLEVCN.COM, root@LV.VCN.ORACLEVCN.COM UID: 872200000 GID: 872200000 Account disabled: False ---------------------------- Number of entries returned 1 ----------------------------
安全设置和强化
以下是安全使用 FreeIPA 服务器的几种方法。
禁用匿名绑定
FreeIPA LDAP 服务器启用匿名绑定作为缺省值,从而公开特定的配置设置和目录值。
nsslapd-allow-anonymous-access
属性控制此行为。可接受的值包括:
on
:允许所有匿名绑定(默认)rootdse
:仅允许对根 DSE 信息进行匿名绑定off
:禁止任何匿名绑定
建议在禁用匿名绑定时使用 rootdse
而不是 off
,因为使用 off
也会阻止外部客户机检查服务器配置。非域客户机(如 LDAP 和 Web 客户机)通过读取根 DSE 文件获取连接详细信息来匿名连接。
-
检查是否已启用匿名绑定。
ldapsearch -x -h $(hostname -f) -b dc=lv,dc=vcn,dc=oraclevcn,dc=com
-x
设置简单或匿名验证。-h
设置 LDAP 服务器主机。-b
设置搜索的基本 dn。
密钥设置(包括 FreeIPA 服务器的基本 dn)存储在
/etc/ipa/default.conf
文件中。输出示例:
... # Default SMB Group, groups, accounts, lv.vcn.oraclevcn.com dn: cn=Default SMB Group,cn=groups,cn=accounts,dc=lv,dc=vcn,dc=oraclevc n,dc=com cn: Default SMB Group description: Fallback group for primary group RID, do not add users to this gr oup objectClass: top objectClass: ipaobject objectClass: posixgroup objectClass: ipantgroupattrs ipaUniqueID: 0c9cf178-4324-11ed-bf0b-02001704fe22 gidNumber: 921600001 ipaNTSecurityIdentifier: S-1-5-21-2697967063-3375457457-2974965896-1001 # search result search: 2 result: 0 Success # numResponses: 110 # numEntries: 109
搜索结果将返回 LDAP 目录的整个树。
-
修改配置并禁用匿名绑定。
ldapmodify
命令接受 LDIF 文件,其中包含要执行或从标准输入读取操作的更改。-
创建 LDIF 文件。
cat << 'EOF' | tee ~/disable_anon_bind.ldif > /dev/null dn: cn=config changetype: modify replace: nsslapd-allow-anonymous-access nsslapd-allow-anonymous-access: rootdse EOF
通过在一行中用短划线
-
字符分隔多个属性,可以更改这些属性。每个附加更改都从属性更改类型开始,并提供所需的属性。 -
应用 LDIF 更改。
ldapmodify -x -D "cn=Directory Manager" -W -H ldap:// -ZZ -f ~/disable_anon_bind.ldif
-x
设置简单或匿名验证。-D
设置绑定 dn。-W
提示您输入 LDAPadmin
口令。-H
使用 LDAP 统一资源标识符 (Uniform Resource Identifier,URI) 进行连接,而不是使用 LDAP 服务器主机。-ZZ
启动 TLS 请求并强制成功响应。
注:由于使用自签名证书,需要
-ZZ
。输出示例:
[oracle@freeipa ~]$ ldapmodify -x -D "cn=Directory Manager" -W -H ldap:// -ZZ -f ~/disable_anon_bind.ldif Enter LDAP Password: modifying entry "cn=config"
-
重新开始 FreeIPA 服务器。
sudo systemctl restart ipa.service
-
-
通过匿名查询目录来验证修改。
ldapsearch -x -h $(hostname -f) -b dc=lv,dc=vcn,dc=oraclevcn,dc=com
请注意响应
Anonymous access is not allowed
。输出示例:
[oracle@freeipa ~]$ ldapsearch -x -h freeipa.lv.vcn.oraclevcn.com -b dc=lv,dc=vcn,dc=oraclevcn,dc=com # extended LDIF # # LDAPv3 # base <dc=lv,dc=vcn,dc=oraclevcn,dc=com> with scope subtree # filter: (objectclass=*) # requesting: ALL # # search result search: 2 result: 48 Inappropriate authentication text: Anonymous access is not allowed. # numResponses: 1
-
使用验证验证验证查询目录是否有效。
ldapsearch -D uid=admin,cn=users,cn=accounts,dc=lv,dc=vcn,dc=oraclevcn,dc=com -W -H ldap://
输出示例:
... # freeipa.lv.vcn.oraclevcn.com + 389, subordinate-ids, dna, ipa, etc, lv.vcn.oraclevcn.com dn: dnaHostname=freeipa.lv.vcn.oraclevcn.com+dnaPortNum=389,cn=subord inate-ids,cn=dna,cn=ipa,cn=etc,dc=lv,dc=vcn,dc=oraclevcn,dc=com objectClass: dnaSharedConfig objectClass: top dnaHostname: freeipa.lv.vcn.oraclevcn.com dnaPortNum: 389 dnaSecurePortNum: 636 dnaRemainingValues: 32766 # search result search: 2 result: 0 Success # numResponses: 475 # numEntries: 474
验证是否已启用 TLS
从 Oracle Linux 8 开始,FreeIPA 使用系统范围的加密策略。有关更多详细信息,请参见 crypto-policies(7)
手册页。
-
列出当前系统范围的加密策略。
cat /etc/crypto-policies/config
-
列出加密策略详细信息。
cat /usr/share/crypto-policies/$(cat /etc/crypto-policies/config)/nss.txt
输出示例:
[oracle@freeipa ~]$ cat /usr/share/crypto-policies/$(cat /etc/crypto-policies/config)/nss.txt library= name=Policy NSS=flags=policyOnly,moduleDB config="disallow=ALL allow=HMAC-SHA256:HMAC-SHA1:HMAC-SHA384:HMAC-SHA512:CURVE25519:SECP256R1:SECP384R1:SECP521R1:aes256-gcm:chacha20-poly1305:aes256-cbc:aes128-gcm:aes128-cb > c:SHA256:SHA384:SHA512:SHA224:ECDHE-RSA:ECDHE-ECDSA:RSA:DHE-RSA:ECDSA:RSA-PSS:RSA-PKCS:tls-version-min=tls1.2:dtls-version-min=dtls1.2:DH-MIN=2048:DSA-MIN=2048:RSA-MIN=2048"
请注意,
DEFAULT
策略至少使用TLS 1.2
。
检查 FreeIPA 服务器状态
FreeIPA 服务器包括 ipactl
实用程序,用于查看已配置服务的状态。同一实用程序还可以启动、停止和重新启动整个 FreeIPA 服务器。如果需要 start
、stop
或 restart
单个组件,请使用 systemctl COMMAND name.service
。
-
显示所有服务的状态。
sudo ipactl status
输出示例:
[oracle@freeipa ~]$ sudo ipactl status Directory Service: RUNNING krb5kdc Service: RUNNING kadmin Service: RUNNING httpd Service: RUNNING ipa-custodia Service: RUNNING pki-tomcatd Service: RUNNING ipa-otpd Service: RUNNING ipa: INFO: The ipactl command was successful
使用
sudo ipactl --help
可查看其他命令选项。
创建用户和组
在完成 FreeIPA 服务器基本安装和配置后,下一步是处理身份管理,其中包括创建用户和组。在执行此操作之前,生成 Kerberos 令牌。
-
为用户
admin
生成令牌。kinit admin
-
获取现有令牌的列表。
klist
默认情况下,Kerberos 标记有效期为 24 小时。由于以前在名为“Access the Command-Line Interface (CLI)”的步骤中运行这些命令,因此列表显示原始令牌,而不是创建新令牌。
-
添加新用户组。
FreeIPA 将用户组定义为一组具有标准密码策略、特权和其他特征的用户。
用户组可以包括:
- users - 用户
- 其他用户组
- 存在于 FreeIPA 以外的外部用户
ipa group-add foo
输出示例:
[oracle@freeipa ~]$ ipa group-add foo ----------------- Added group "foo" ----------------- Group name: foo GID: 1326400003
FreeIPA 服务器支持三种组类型:
- POSIX(默认值)
- 非 POSIX
- 外部
组 foo
是 POSIX 用户组。要指定其他组类型,请使用以下选项之一:
--nonposix
以创建非 POSIX 组--external
创建外部组
-
获取所有现有用户组的列表。
ipa group-find
输出示例:
[oracle@freeipa ~]$ ipa group-find ---------------- 5 groups matched ---------------- Group name: admins Description: Account administrators group GID: 1326400000 Group name: editors Description: Limited admins who can edit other users GID: 1326400002 Group name: foo GID: 1326400003 Group name: ipausers Description: Default group for all users Group name: trust admins Description: Trusts administrators group ---------------------------- Number of entries returned 5 ----------------------------
FreeIPA 服务器在安装期间创建以下用户组。
admins
ipausers
trust admins
警告:请勿删除
admin
组,因为它包含默认的admin
用户。FreeIPA 服务器要求admin
组正确运行。 -
添加新用户帐户。
ipa user-add
该命令运行交互式脚本,提示 FreeIPA 创建用户帐户所需的最小数据集。
输出示例:
[oracle@freeipa ~]$ ipa user-add First name: Oracle Last name: User User login [ouser]: oracle ------------------- Added user "oracle" ------------------- User login: oracle First name: Oracle Last name: User Full name: Oracle User Display name: Oracle User Initials: OU Home directory: /home/oracle GECOS: Oracle User Login shell: /bin/sh Principal name: oracle@LV.VCN.ORACLEVCN.COM Principal alias: oracle@LV.VCN.ORACLEVCN.COM Email address: oracle@lv.vcn.oraclevcn.com UID: 1326400004 GID: 1326400004 Password: False Member of groups: ipausers Kerberos keys available: False
或者,使用多个选项运行命令允许在非交互模式下创建用户帐户。要获取可用选项的列表,请运行
ipa user-add --help
。 -
将新用户添加到新用户组。
ipa group-add-member foo --users=oracle
输出示例:
[oracle@freeipa ~]$ ipa group-add-member foo --users=oracle Group name: foo GID: 1326400003 Member users: oracle ------------------------- Number of members added 1 -------------------------
ipa
命令的功能比所示的功能多。有关其他命令,请运行 ipa help commands
获取综合列表。
后续步骤
本练习将结束,其中介绍了安装和使用 FreeIPA 服务器的基本知识。使用下面的链接进一步探索,或阅读产品手册页,因为 FreeIPA 除了此处介绍的内容之外,还有许多其他功能。
相关链接
更多学习资源
通过 docs.oracle.com/learn 浏览其他实验室,或者通过 Oracle Learning YouTube 频道访问更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 以成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。