本节介绍如何设置身份验证网关的每个组件。 使用的示例适用于 10.0.1.0 子网中的公共网络。 eth0 是连接到内部网络的盒子上的接口。 eth1 是连接到公共网络的接口。 此接口使用的 IP 地址为 10.0.1.1。 这些设置可以更改以适应您正在使用的网络。 网关盒使用了 Red Hat 7.1,因此很多示例都特定于 Red Hat。
要设置 netfilter,必须重新编译内核以包含 netfilter 支持。 有关配置和编译内核的更多信息,请参阅 Kernel-HOWTO。
这是我的内核配置的样子。
# # Networking options # CONFIG_PACKET=y # CONFIG_PACKET_MMAP is not set # CONFIG_NETLINK is not set CONFIG_NETFILTER=y CONFIG_NETFILTER_DEBUG=y CONFIG_FILTER=y CONFIG_UNIX=y CONFIG_INET=y CONFIG_IP_MULTICAST=y # CONFIG_IP_ADVANCED_ROUTER is not set # CONFIG_IP_PNP is not set # CONFIG_NET_IPIP is not set # CONFIG_NET_IPGRE is not set # CONFIG_IP_MROUTE is not set # CONFIG_INET_ECN is not set # CONFIG_SYN_COOKIES is not set # IP: Netfilter Configuration # CONFIG_IP_NF_CONNTRACK=y CONFIG_IP_NF_FTP=y CONFIG_IP_NF_IPTABLES=y CONFIG_IP_NF_MATCH_LIMIT=y CONFIG_IP_NF_MATCH_MAC=y CONFIG_IP_NF_MATCH_MARK=y CONFIG_IP_NF_MATCH_MULTIPORT=y CONFIG_IP_NF_MATCH_TOS=y CONFIG_IP_NF_MATCH_TCPMSS=y CONFIG_IP_NF_MATCH_STATE=y CONFIG_IP_NF_MATCH_UNCLEAN=y CONFIG_IP_NF_MATCH_OWNER=y CONFIG_IP_NF_FILTER=y CONFIG_IP_NF_TARGET_REJECT=y CONFIG_IP_NF_TARGET_MIRROR=y CONFIG_IP_NF_NAT=y CONFIG_IP_NF_NAT_NEEDED=y CONFIG_IP_NF_TARGET_MASQUERADE=y CONFIG_IP_NF_TARGET_REDIRECT=y CONFIG_IP_NF_NAT_FTP=y CONFIG_IP_NF_MANGLE=y CONFIG_IP_NF_TARGET_TOS=y CONFIG_IP_NF_TARGET_MARK=y CONFIG_IP_NF_TARGET_LOG=y CONFIG_IP_NF_TARGET_TCPMSS=y |
配置 netfilter 后,通过执行以下命令打开 IP 转发。
echo 1 > /proc/sys/net/ipv4/ip_forward |
为确保机器重启时启用 ip 转发,请将以下行添加到/etc/sysctl.conf.
net.ipv4.ip_forward = 1 |
如果正在使用 NocatAuth,您可以跳到 NoCatAuth 网关设置 部分。
需要安装 iptables。 要安装 iptables,可以使用发行版中的软件包或从源代码安装。 在新的内核中编译了上述选项并安装了 iptables 后,我设置了以下默认防火墙规则。
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A INPUT -i eth0 -m state --state NEW, INVALID -j DROP iptables -A FORWARD -i eth0 -m state --state NEW, INVALID -j DROP iptables -I FORWARD -o eth0 -j DROP iptables -I FORWARD -s 10.0.1.0/24 -d 10.0.1.1 -j ACCEPT |
上述命令也可以放在 initscript 中,以便在服务器重启时启动。 为确保已添加规则,请执行以下命令
iptables -v -t nat -L iptables -v -t filter -L |
为了保存这些规则,我使用了 Red Hat 的 init 脚本。
/etc/init.d/iptables save /etc/init.d/iptables restart |
现在,网关盒将能够进行网络地址转换 (NAT),但它将丢弃所有转发数据包,但来自公共网络内部并绑定到网关的数据包除外。
本节介绍如何设置动态插入和删除网关上的 Netfilter 规则所需的软件。
需要插入防火墙规则的 PAM 会话模块,以允许为经过身份验证的客户端转发。 要进行设置,只需获取 source 并通过运行以下命令进行编译。
gcc -fPIC -c pam_iptables.c ld -x --shared -o pam_iptables.so pam_iptables.o |
现在您应该有两个名为pam_iptables.so和pam_iptables.o. 复制pam_iptables.so到/lib/security/pam_iptables.so.
cp pam_iptables.so /lib/security/pam_iptables.so |
现在将防火墙脚本安装到 /usr/local/auth-gw。
mkdir /usr/local/auth-gw cp insFwall /usr/local/auth-gw |
为网关选择的身份验证客户端是 ssh,因此我们将以下行添加到/etc/pam.d/sshd.
session required /lib/security/pam_iptables.so |
现在,当用户使用 ssh 登录时,将添加防火墙规则。
要测试 pam_iptables 模块是否正常工作,请执行以下步骤
使用 ssh 登录到盒子。
使用命令 iptables -L -v 检查是否已添加规则。
注销盒子以确保删除规则。
本节介绍设置 NocatAuth 网关的过程。 要设置 NocatAuth,请获取 source 并按照以下步骤进行安装。
确保已安装 gpgv。 gpgv 是一个 PGP 签名验证器。 它是 gnupg 的一部分,可以在 http://www.gnupg.org/download.html 找到。
解压缩 NocatAuth tar 文件。
tar xvzf NocatAuth-x.xx.tar.gz |
如果您不希望 NoCatAuth 位于目录 /usr/local/nocat 中,请编辑 Makefile 并将 INST_PATH 更改为您希望 NoCatAuth 所在的目录。
接下来构建网关。
cd NoCatAuth-x.xx make gateway |
编辑 /usr/local/nocat.conf 文件。 有关 conf 文件中所需内容的详细信息,请参阅 INSTALL 文档。 示例 conf 文件如下所示
###### gateway.conf -- NoCatAuth Gateway Configuration. # # Format of this file is: Directive Value, one per # line. Trailing and leading whitespace is ignored. Any # line beginning with a punctuation character is assumed to # be a comment. Verbosity 10 #we are behind a NAT so put the gateway in passive mode GatewayMode Passive GatewayLog /usr/local/nocat/nocat.log LoginTimeout 300 ######Open Portal settings. HomePage http://www.itlab.musc.edu/ DocumentRoot /usr/local/nocat/htdocs SplashForm splash.html ###### Active/Passive Portal settings. TrustedGroups Any AuthServiceAddr egon.itlab.musc.edu AuthServiceURL https://$AuthServiceAddr/cgi-bin/login LogoutURL https://$AuthServiceAddr/forms/logout.html ###### Other Common Gateway Options. AllowedWebHosts egon.itlab.musc.edu ResetCmd initialize.fw PermitCmd access.fw permit $MAC $IP $Class DenyCmd access.fw deny $MAC $IP $Class |
现在您应该能够启动网关。 如果出现任何问题,请参阅解压缩的 NoCatAuth 目录中的 INSTALL 文档。 以下命令将启动网关
/usr/local/nocat/bin/gateway |
我使用以下内容安装了 DHCPdhcpd.conf文件。
subnet 10.0.1.0 netmask 255.255.255.0 { # --- default gateway option routers 10.0.1.1; option subnet-mask 255.255.255.0; option broadcast-address 10.0.1.255; option domain-name-servers 10.0.1.1; range 10.0.1.3 10.0.1.254; option time-offset -5; # Eastern Standard Time default-lease-time 21600; max-lease-time 43200; } |
然后使用 eth1(连接到公共网络的接口)运行服务器。
/usr/sbin/dhcpd eth1 |
描述了使用 PAM 和 NoCatAuth 身份验证服务进行身份验证。 这两个示例都是使用 LDAP 完成的。 除了 LDAP 之外的其他身份验证方式也可以使用。 请阅读 PAM 和 NoCatAuth 的文档,以查找使用其他身份验证源的步骤。
如前几节所示,我已将此网关设置为使用 LDAP 进行身份验证。 但是,您可以使用 PAM 允许的任何身份验证方式。 有关更多信息,请参阅 第 2.4 节。
为了使 PAM LDAP 进行身份验证,我安装了 OpenLDAP 并使用以下内容对其进行了配置/etc/ldap.conf.
# Your LDAP server. Must be resolvable without using LDAP. host itc.musc.edu # The distinguished name of the search base. base dc=musc,dc=edu ssl no |
以下文件用于配置 PAM 以进行 LDAP 身份验证。 这些文件由 Red Hat 的配置实用程序生成。
#%PAM-1.0 # This file is auto-generated. # User changes will be destroyed the next time authconfig is run. auth required /lib/security/pam_env.so auth sufficient /lib/security/pam_unix.so likeauth nullok auth sufficient /lib/security/pam_ldap.so use_first_pass auth required /lib/security/pam_deny.so account required /lib/security/pam_unix.so account [default=ok user_unknown=ignore service_err=ignore system_err=ignore] /lib/security/pam_ldap.so password required /lib/security/pam_cracklib.so retry=3 password sufficient /lib/security/pam_unix.so nullok use_authtok password sufficient /lib/security/pam_ldap.so use_authtok password required /lib/security/pam_deny.so session required /lib/security/pam_limits.so session required /lib/security/pam_unix.so session optional /lib/security/pam_ldap.so |
#%PAM-1.0 auth required /lib/security/pam_stack.so service=system-auth auth required /lib/security/pam_nologin.so account required /lib/security/pam_stack.so service=system-auth password required /lib/security/pam_stack.so service=system-auth session required /lib/security/pam_stack.so service=system-auth #this line is added for firewall rule insertion upon login session required /lib/security/pam_iptables.so debug session optional /lib/security/pam_console.so |
建议将 NoCatAuth 服务安装在网关之外的另一台服务器上。 我的示例中使用了单独的服务器。 为了设置 NoCatAuth 服务,您需要以下软件
启用 SSL 的 Web 服务器,最好带有注册的 SSL 证书。 我使用了 Apache + mod_ssl。
Perl 5(建议 5.6 或更高版本)
Net::LDAP、Digest::MD5、DBI 和 DBD::MySQL perl 模块(从 CPAN 获取) 您需要的模块取决于您将要使用的身份验证源。 在我的示例中,Net::LDAP 用作身份验证方式。
Gnu Privacy Guard (gnupg 1.0.6 或更高版本),可在 http://www.gnupg.org/download.html 获得
要安装,请解压缩 tar 文件。
$ tar zvxf NoCatAuth-x.xx.tar.gz |
如果您想更改 NoCatAuth 所在的路径,请编辑 Makefile 并将 INST_PATH 更改为所需的目录。
接下来运行命令: make authserv 这会将所有内容安装到 /usr/local/nocat 或您更改 INST_PATH 的位置。
然后运行 make pgpkey 对于大多数用途,默认值应该可以正常工作。 重要提示:请勿输入密码! 否则,当身份验证服务尝试加密消息并尝试从不存在的 tty 读取您的密码时,您将收到奇怪的消息
编辑 /usr/local/nocat/nocat.conf 以适应您的情况。 这是一个例子
###### authserv.conf -- NoCatAuth Authentication Service Configuration. # # Format of this file is: Directive Value, one per # line. Trailing and leading whitespace is ignored. Any # line beginning with a punctuation character is assumed to # be a comment. Verbosity 10 HomePage http://www.itlab.musc.edu/ DocumentRoot /usr/local/nocat/htdocs # LDAP source DataSource LDAP LDAPHost authldap.musc.edu LDAPBase dc=musc,dc=edu UserTable Member UserIDField User UserPasswdField Pass UserAuthField Status UserStampField Created GroupTable Network GroupIDField Network GroupAdminField Admin MinPasswdLength 8 # LocalGateway -- If you run auth service on the same subnet # (or host) as the gateway you need to specify the hostname # of the gateway. Otherwise omit it. (Requires Net::Netmask) # # LocalGateway 192.168.1.7 LoginForm login.html LoginOKForm login_ok.html FatalForm fatal.html ExpiredForm expired.html RenewForm renew.html PassiveRenewForm renew_pasv.html RegisterForm register.html RegisterOKForm register_ok.html RegisterFields Name URL Description UpdateForm update.html UpdateFields URL Description ###### Auth service user messages. Should be self-explanatory. # LoginGreeting Greetings! Welcome to the Medical University of SC's Network. LoginMissing Please fill in all fields! LoginBadUser That e-mail address is unknown. Please try again. LoginBadPass That e-mail and password do not match. Please try again. LoginBadStatus Sorry, you are not a registered co-op member. RegisterGreeting Welcome! Please enter the following information to register.RegisterMissing Name, E-mail, and password fields must be filled in. RegisterUserExists Sorry, that e-mail address is already taken. Are you already registered? RegisterBadUser The e-mail address provided appears to be invalid. Did you spell it correctly? RegisterInvalidPass All passwords must be at least six characters long. RegisterPassNoMatch The passwords you provided do not match. Please try again. RegisterSuccess Congratulations, you have successfully registered. UpdateGreeting Enter your E-mail and password to update your info. UpdateBadUser That e-mail address is unknown. Please try again. UpdateBadPass That e-mail and password do not match. Please try again. UpdateInvalidPass New passwords must be at least eight characters long. UpdatePassNoMatch The new passwords you provided do not match. Please try again. UpdateSuccess Congratulations, you have successfully updated your account. |
确保 /usr/local/nocat/pgp 归 Web 服务器用户所有。 (即..nobody 或 www-data)
将 etc/authserv.conf 添加到您的 apache httpd.conf 文件中。
Include /usr/local/nocat/etc/authserv.conf |
将您的 /usr/local/nocat/trustedkeys.pgp 复制到网关。 重新启动 apache 并尝试一下。 有关更多信息,请参阅 NoCatAuth 文档。 它可以在解压缩的 NoCatAuth 目录中的 docs/ 中找到。