显式代理 SAML 认证(Windows ADFS)
显式代理 SAML 认证(Windows ADFS)
网络需求
在防火墙上启用显示代理,并且配置基于 AD FS 的 SAML SSO 进行用户验证。
网络拓扑

- FortiGate 的 LAN 口 port2 连接 Windows AD 服务器和 Windows AD 电脑。
- FortiGate 的 WAN 口 port1 连接 Internet。
- port2 上启用 explicit proxy 和 captive portal,验证通过 SAML SSO 完成。SAML SSO 由 Windows AD 服务器上的 AD FS 提供。
- Windows AD 电脑上设置 FortiGate 的 port2 作为上网的代理服务器。
- 完成配置后,Windows AD 服务器作为 SAML IdP(提供验证服务),FortiGate 作为 SAML SP(发起验证请求)。
配置步骤
Windows 服务器配置
- 在本示例中,Windows AD 服务器的 OS 是 Windows 2019, version 1809。FortiGate 是 VM 7.0.12,SAML SSO 验证服务由 Windows AD 服务器上的 AD FS (Active Directory Federation Service) 提供。
- Windows AD 服务器和 FortiGate 的时间需要在同一时区,时间差默认不能超过 15 秒。建议都使用 NTP。可以在 FortiGate 上修改时间差的容忍值。
安装 LDAP 服务
- LDAP 服务由 Active Direcotry Domain Service,或者 Active Directory Lightweight Directory Services 提供。
- 在本示例中,Windows 服务器 10.10.186.5 已经安装了 Active Direcotry Domain Service。
安装 AD Certificate Services 证书服务
AD FS 服务需要用到 SSL 证书,如果没有证书,可以在 Windows Server 上安装 AD DC,然后在 AD DC 上为 AD FS 服务新建证书。
如果你已经有供 AD FS 服务使用 SSL 证书,或者已经安装了 AD DC,可以跳过这一步。
你也可以使用 openssl 或者其他工具为 AD FS 服务生成证书,然后将证书导入 AD FS,将 CA 导入 Windows AD 服务器。
在 Server Manager 中安装” Active Directory Certificate Services”。

Features: 直接 Next。
Role Services: Certification Authority。

使用默认配置,完成安装。
配置 AD 证书服务
重要
如果你已经有供 AD FS 服务使用 SSL 证书,可以跳过这一步。
打开 AD CS configuration。
Credentials: 默认。

Role Serivces 选择 Certificateion Authority。

Setup Type 选择 Enternprise CA。

CA Type 选择 Root CA。

使用默认配置,完成 AD CS 的配置。






在 AD 证书服务中创建证书模板
重要
如果你已经有供 AD FS 服务使用 SSL 证书,可以跳过这一步。
在 Windows CMD 中运行 certsrv.msc。
右键点击 Certificate Templates,点击 Manage。

右键点击 Computer,点击 Duplicate Template。

在 General 标签页,给模板取名,并且选中” Publish certificate in Active Directory”。

在 Request Handling 标签页,选中” Allow private key to be exported”。

在 Subject Name 标签页,设置 Subject name format: Common name。

在 Security 标签页,点击 Add…。

修改 Select this object type: Computers。

Enter the ojbect names to select 中找到 AD 证书服务器。

赋予 AD 证书服务器 Full Control。

点击 OK 完成证书模板配置。
回到 certsrv.msc。
右键点击 Certificate Templates,点击 New > Certificate Template to Issue。

选中刚才创建的证书模板。点击 OK。

在列表中可以看到发布的证书模板。

为 AD FS 创建证书
重要
如果你已经有供 AD FS 服务使用 SSL 证书,可以跳过这一步。
在 Windows CMD 中运行 certlm.msc。
右键点击 Personal, 点击 All Taks > Request New Certificate…

点击 Next。


选中刚才创建的证书模板,点击 Enroll。

可以在 Personal > Certificate 中看到新创建的证书,这个证书将会提供给 AD FS 使用。

这是生成的证书,供参考:AD FS SSL.cer。
安装 AD FS
重要
如果你已经安装了 AD FS,可以跳过这一步。
在 Server Manager 中安装 Active Direcotry Federation Services。选择默认配置,完成安装。

初始化 AD FS
在 Server Manger 点击 Configure the federation service on this server,初始化 AD FS。

Welcome,保持默认。

Connect to AD DS,保持默认。

Specify Service Properties:SSL Certificate: 选择刚才生成的证书;Federation Service Display Name:可按需输入。这些字符将出现在 SSO 登陆页面。

Specify Service Account,可以使用普通的 AD user 账号,也可以是 AD admin 账号。

Specify Database,创建一个数据库即可。然后 Next,完成配置。

配置 FortiGate 作为 SAML SP
导入 AD FS 的证书
进入 Windows AD FS Management,点击 Service > Certificates,右键点击 Token-signing 的证书,点击 View Certificate…

在 Details 标签页,点击 Copy to File…

以 Base-64 的格式保存。

然后将证书以 Remote Certificate 的方式导入到防火墙。

配置 user saml,输入 SP 和 IdP URL
现在我们可以在 user saml 中配置 SP 和 IdP 的 URL。
config user saml edit "saml_user" set cert "Fortinet_CA_SSL" set entity-id "https://fgt.wtao.local:7831/XX/YY/ZZ/saml/metadata/" set single-sign-on-url "https://fgt.wtao.local:7831/XX/YY/ZZ/saml/login/" set single-logout-url "https://fgt.wtao.local:7831/XX/YY/ZZ/saml/logout/" set idp-entity-id "http://win2019.wtao.local/adfs/services/trust" set idp-single-sign-on-url "https://win2019.wtao.local/adfs/ls/" set idp-single-logout-url "https://win2019.wtao.local/adfs/ls/" set idp-cert "REMOTE_Cert_1" set digest-method sha1 set adfs-claim enable set user-claim-type name set group-claim-type group next end配置解释:
entity-id, single-sign-on-url, single-logout-url 中写的是 FortiGate 的 SP URL,这是由需要用到 SAML SSO 的服务预定义的。例如:
explicit proxy 需要 SAML SSO 时,这 3 项是:
# 10.10.186.1是电脑访问的,位于防火墙上的提供explicit proxy的接口IP地址。 # 它也可以是FQDN - 用户电脑、防火墙(SP)和AD FS(IdP)需要能够解析到相同的IP地址。 # 7831是固定端口 set entity-id "https://10.10.186.1:7831/XX/YY/ZZ/saml/metadata/" set single-sign-on-url "https://10.10.186.1:7831/XX/YY/ZZ/saml/login/" set single-logout-url "https://10.10.186.1:7831//XX/YY/ZZ/saml/logout/"captive portal 需要 SAML SSO 时,这 3 项是
# 10.10.186.1是防火墙上进行captive portal验证的接口IP地址,1003是固定端口。 set entity-id "https://10.10.186.1:1003/remote/saml/metadata/" set single-sign-on-url "https://10.10.186.1:1003/remote/saml/login/" set single-logout-url "https://10.10.186.1:1003/remote/saml/logout/"SSL VPN 需要 SAML SSO 时,这 3 项是
# sslvpn.mycompany.com 是用户访问的SSL VPN地址,10443是SSL VPN服务端口 set entity-id "https://sslvpn.mycompany.com:10443/remote/saml/metadata/" set single-sign-on-url "https://sslvpn.mycompany.com:10443/remote/saml/login/" set single-logout-url "https://sslvpn.mycompany.com:10443/remote/saml/logout/"
idp-entity-id, idp-single-sign-on-url, idp-single-logout-url 写的是 AD FS 提供 IdP 服务的 URL,这 3 个 URL 在 AD FS 安装后是固定的。所有使用 AD FS 的 SP 都是用相同的这 3 个 URL。
重要
防火墙和用户电脑都必须能够解析 AD FS 的主机名。
set idp-entity-id "http://win2019.wtao.local/adfs/services/trust" set idp-single-sign-on-url "https://win2019.wtao.local/adfs/ls/" set idp-single-logout-url "https://win2019.wtao.local/adfs/ls/"他们可以在 AD FS 的 metadata file 中找到(参考文档 FortiGate SSL VPN Authentication with AD FS),AD FS 的 metadata file 可以在 https://win2019.wtao.local/FederationMetadata/2007-06/FederationMetadata.xml 打开。
idp-entity-id: 搜索 'entityID'。

idp-single-sign-on-url: 搜索 'SingleSignOnService',找到 'Binding'属性旁边的'Location' 属性。

idp-single-logout-url: 搜索 'SingleLogoutService',找到 'Binding'属性旁边的'Location' 属性。

配置 AD FS 作为 SAML IdP
AD FS 上的 Relying Party Trust 定义了 AD FS 为哪个 SP 提供服务,当我们把防火墙配置成为 SAML SP 后,需要把那 3 个 SP URL 写入到 AD FS 的 Relying Party Trust。
添加 Relying Party Trust
进入 AD FS Management。

select 'Claims Aware' and click 'Start’。

选择“Enter data about the relying party manually”。


保持默认,Next。

Configure URL, 选择” Enable support for the SAML 2.0 WebSSO protocol”,输入防火墙上 user saml 中的 entity-id,
https://fgt.wtao.local:7831/XX/YY/ZZ/saml/metadata/。
Configure Identifiers 中,还是输入防火墙上 user saml 中的 entity-id:
https://fgt.wtao.local:7831/XX/YY/ZZ/saml/metadata/,点击 Add,再点击 Next。
Choose Access Control Policy 选择 Permit everyone。

Ready to Add Trust,先不填写,Next。

取消“Configure claims issuance policy for this application”,点击 Close。

配置 Relying Party Trust > Claim Issuance Policy
在 Relying Party Trust,右键点击刚才创建的 relying party trust,点击“Edit Claim Issuance Policy”。

click on 'Add Rule’。

Claim rule template: Send LDAP Attributes as Claims。

Configure Claim Rule:

- Claim rule name: 按需取名。
- Attribute store: Active Directory。
- Mapping of LDAP attributes to outgoing claim types:
- User-Principal-Name: username (手动输入)
- User-Principal-Name: Name ID (有预选项)
- User-Principal-Name: Name(有预选项)
点击 Finish 保存。
配置 Relying Party Trust > SP URL
在 Relying Party Trust 中将防火墙的 SP URL 输入。
在 Relying Party Trust,右键点击刚才创建的 relying party trust,点击” Properties”。

Endpoint 标签页, 点击 Add SAML…

- Endpoint type: SAML Assertion Consumer
- Binding: POST
- Set the trusted URL as default: 选中
- Index: 1
- Trusted URL: 输入防火墙上 user saml 中的 single-sign-on-url, https://fgt.wtao.local:7831/XX/YY/ZZ/saml/login/
点击 OK。

再次点击 Add SAML…

- Endpoint type: SAML Logout
- Binding: POST
- Trusted URL: 输入防火墙上 user saml 中的 single-logout-url, https://fgt.wtao.local:7831/XX/YY/ZZ/saml/logout/
- Response URL: 如果防火墙说明文档中没有提供,可以尝试填写 https://fgt.wtao.local:7831/XX/YY/ZZ/logout
点击 OK,这是完成配置的 Endpoitns 标签页。点击 OK。

配置 Relying Party Trust >SHA 和防火墙证书
在 Relying Party Trust,右键点击刚才创建的 relying party trust,点击” Properties”。

在 Advanced 标签页,将 Secure hash algorithm 设置为 SHA-1,

explicit proxy 使用 AD FS 作为 SAML SSO 时,,因此需要将防火墙上的 Forinet_CA_SSL 导入 AD FS。
在防火墙上下载 Forinet_CA_SSL。

在 Signature 标签页,导入 Forinet_CA_SSL。

配置 FortiGate 启用 explicit proxy 和 captive portal
启用 explicity proxy 和 captive portal。在内网口 port2 上启用 explicit-web-proxy 和 proxy-captive-portal。
# Enable the web proxy: config system settings set gui-explicit-proxy enable end config web-proxy explicit set status enable set http-incoming-port 8080 set unknown-http-version best-effort end # Enable the proxy captive portal: config system interface edit "port2" set explicit-web-proxy enable set proxy-captive-portal enable next end配置 LDAP 服务器和 LDAP 用户组。
# Configure the LDAP server config user ldap edit "ldap-10.10.186.5" set server "10.10.186.5" set cnid "userPrincipalName" set dn "dc=wtao,dc=local" set type regular set username "cn=administrator,cn=users,dc=wtao,dc=local" set password password_of_the_user set group-search-base "cn=users,dc=wtao,dc=local" next end config user group edit "ldap-group-saml" set member "ldap-10.10.186.5" next end配置 authentication scheme, rule 和 setting。
config authentication scheme edit "auth_scheme_saml" set method saml set saml-server "saml_user" set user-database "ldap-10.10.186.5" next end config authentication rule edit "auth_rule_saml" set srcaddr "all" set active-auth-method "auth_scheme_saml" next end config firewall address edit "fgt.wtao.local" set type fqdn set fqdn "fgt.wtao.local" end config authentication setting set active-auth-scheme "auth_scheme_saml" set captive-portal "fgt.wtao.local" end配置 proxy-policy。proxy-policy #2,访问 Windows AD FS 服务器时,不需要用户名;proxy-policy #1,访问外网时,需要用户名,触发 SAML SSO 验证。
config firewall address edit "win2019.wtao.local_IP" set type iprange set start-ip 10.10.186.5 set end-ip 10.10.186.5 next end config firewall proxy-policy edit 2 set name "bypass" set proxy explicit-web set dstintf "port2" set srcaddr "all" set dstaddr "win2019.wtao.local_IP" set service "webproxy" set action accept set schedule "always" set logtraffic all set ssl-ssh-profile "certificate-inspection" set comment "no user identity is required for traffic to AD FS" next edit 1 set name "proxy" set proxy explicit-web set dstintf "port1" set srcaddr "all" set dstaddr "all" set service "webproxy" set action accept set schedule "always" set logtraffic all set groups "ldap-group-saml" set ssl-ssh-profile "certificate-inspection" next end配置防火墙策略。firewall policy#1,访问外网时,需要用户名。
config firewall policy edit 1 set name "LANtoWAN" set srcintf "port2" set dstintf "port1" set action accept set srcaddr "all" set dstaddr "all" set schedule "always" set service "ALL" set logtraffic all set nat enable set groups "ldap-group-saml" next end
电脑上设置使用防火墙作为上网代理
在 Windows AD 电脑上设置使用 FortiGate 的 LAN port2 作为上网代理服务器。

当 Windows AD 电脑访问公网网站时,会被重定向到 AD FS SAML 登陆页面。登陆页面的标题文字是在” 1.7 初始化 AD FS”中设置的。用户名的格式是 UPN (User Principal Name)。

结果验证
GUI > Dashboard > Users & Devices > Firewall Users 显示登陆的用户。

diag wad user list 会显示用户详情。
FGVM01TM23001796 # diag wad user list ID: 2, VDOM: root, IPv4: 10.10.186.10 user name : user1@wtao.local worker : 0 duration : 70 auth_type : IP auth_method : SAML pol_id : 1 g_id : 2 user_based : 0 expire : no LAN: bytes_in=319243 bytes_out=17951352 WAN: bytes_in=17925608 bytes_out=277637 FGVM01TM23001796 #
故障排查
下面的错误表明在步骤“配置 Relying Party Trust > Claim Issuance Policy”时,缺少 User-Principal-Name: Name 的映射。加上后,问题可以解决。
Authentication failed.
user.saml.saml_user.user-name='http://schemas.xmlsoap.org/ws/2005/05/identity/claims/**name**' was NOT FOUND in the SAML Assertion Response.
Please check with the Administrator.