Leveraging BIG-IP APM for seamless client NTLM Authentication
Many customers express interest to use F5 Access Policy Manager for transparent seamless authentication for their users. There are a couple of leading use cases that drive that desired behavior:
- Providing silent seamless authentication to Windows-based applications such as Exchange or Sharepoint from the domain-joined machines. The premise is is that if the user is logged in to their domain-joined machine, no matter where they are, they should be able to perform seamless NTLM authentication to their applications such as Sharepoint based on the Windows Integrated Authentication settings.
- Providing SAML Identity Provider services with APM. When users access SAML-enabled applications, they are asking for SAML assertions. Because APM can act as either native SAML 2.0 IDP or as a proxy to other SAML IDPs such as ADFS, for example, customer desire silent authentication to those IDP services from the domain-joined machines in order to seamlessly enable to SaaS applications such as Office 365, SalesForce.com, Google Apps, etc.
APM can perform three types of 401-based challenge authentication: Basic, NTLM, and Kerberos. Basic always requires user’s intervention, but Kerberos and NTLM can enable users to seamlessly authenticate to the APM virtual server and allow it to either securely proxy connection to the backend application such as Sharepoint, leveraging Kerberos Constrained Delegation as the SSO mechanism, or acting as SAML IDP and issuing assertions to the SAML Service Providers based upon user identity extracted during NTLM authentication or Kerberos ticket.
Today, we are going to examine the second use case on how to configure APM to perform client NTLM authentication and use it in the context of sending a SAML assertion to the Office 365 service. It is assumed below that user knows how to configure APM for standard forms-based authentication and also has at least one existing policy(although you can create a new one from the scratch). One of the easiest ways to test this is to deploy the Office 365 configuration using the iApp and the modify configuration to enable NTLM authentication. The steps below assume that you either have a working Office 365 configuration based on the iApp, or you have an equivalent policy that you can modify.
- First, and foremost, we need to create an NTLM Machine Account object. Under Access Policy, go to Access Profiles->NTLM->Machine Account, and click on Create to join the BIG-IP to the domain and create unique computer object in Active Directory
Keep in mind that you will need to create a unique account in Active Directory for your BIG-IP. In the example above, the account name is bigip1.
- Create a “NTLM Auth Configuration” using the above machine account name. Under Access Policy, go to Access Profiles->NTLM->NTLM Auth Configuration and click on Create. Give the configuration the name, select the Machine Account Name value based on the object you created in Step 1, and add as many FQDNs for the AD domain controllers in your infrastructure
- Now we need to create an iRule that will help us handle NTLM authentication to the BIG-IP properly. You need to modify the sec on cline of the RULE_INIT event to match the name of the NTLM Auth configuration you created in step 2. You will also need to replace all instances of appname with a unique identifier. Go to Local Traffic->iRules->iRules List and click on Create. Give the iRule name of “ntlm-auth-iRule” and paste the iRule into the BIG-IP:
when RULE_INIT { set static::appname_ntlm_retries 2 set static::appname_ntlm_config "/Common/appname_ntlm_config" set static::appname_access_log_prefix "01490000:7:" set static::appname_ntlm_on_demand_prfx "$static::appname_access_log_prefix \[NTLM-ON-DEMAND\]" } when ACCESS_SESSION_STARTED { ACCESS::session data set "session.ntlm.last.retries" 0 } when HTTP_REQUEST { log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx Request: [HTTP::uri]" switch -glob -- [string tolower [HTTP::uri]] { "/ntlm/auth" { set sid [ACCESS::session sid] log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx sid: $sid" set referer [HTTP::header value Referer] log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx Referer: $referer" set x_session_id [ HTTP::header value X-Session-Id ] if { [ string length $x_session_id ] != 0 } { set sid $x_session_id } set retries [ACCESS::session data get -sid $sid "session.ntlm.last.retries"] log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx retries: $retries" set auth_result [ACCESS::session data get -sid $sid "session.ntlm.last.result"] log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx auth result: $auth_result" if { ($auth_result == 1) || ($retries == $static::appname_ntlm_retries) && ($auth_result != 1) } { ECA::disable log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx Redirect to: $referer" HTTP::redirect "$referer" } else { ECA::enable ECA::select select_ntlm:$static::appname_ntlm_config } unset x_session_id unset referer } default { ECA::disable } } } when CLIENT_ACCEPTED { set second_pass pass[IP::client_addr][TCP::client_port] # Check if this is the first or second time passing through this virtual if { [ table lookup $second_pass ] == "1" } { set wait_timeout 3000 set wait_delay 100 set wait_total 0 set disable_ssl disablessl[IP::client_addr][TCP::client_port] # Wait for SERVER_CONNECTED event to complete while { [ table lookup $disable_ssl ] != 0 && [ table lookup $disable_ssl ] != 1 && $wait_total < $wait_timeout } { set wait_total [ expr "$wait_total + $wait_delay" ] after $wait_delay } unset wait_delay wait_timeout # Check table value set by SERVER_CONNECTED to disable ssl set disable_ssl_value [ table lookup $disable_ssl ] if { $disable_ssl_value == "1" } { set command "SSL::disable" eval $command unset command } elseif { $disable_ssl_value != 0 } { log -noname accesscontrol.local1.notice "$static::appname_ntlm_on_demand_prfx Error: SERVER_CONNECTED event not completed after $wait_total ms" } table delete $disable_ssl table delete $second_pass unset disable_ssl wait_total } else { # This is the first time through this virtual. Set clientssl flag set client_ssl clientssl[IP::client_addr][TCP::client_port] if { [ catch { PROFILE::clientssl name } ] } { table add $client_ssl "0" } else { table add $client_ssl "1" } unset client_ssl } unset second_pass } when SERVER_CONNECTED { set client_ssl clientssl[IP::client_addr][TCP::client_port] set disable_ssl_value 0 # Check clientssl flag set from CLIENT_ACCEPTED. if { [ table lookup $client_ssl ] == "1" } { if { [ catch { PROFILE::serverssl name } ] } { # Clientssl is present but serverssl is not. Disable clientssl set disable_ssl_value 1 } table delete $client_ssl } set disable_ssl disablessl[IP::client_addr][TCP::client_port] table add $disable_ssl $disable_ssl_value unset disable_ssl unset client_ssl disable_ssl_value } when ECA_REQUEST_ALLOWED { log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx NTLM Auth succeed" ACCESS::session data set session.ntlm.last.username "[ECA::username]" ACCESS::session data set session.ntlm.last.domainname "[ECA::domainname]" ACCESS::session data set session.ntlm.last.machinename "[ECA::client_machine_name]" ACCESS::session data set session.ntlm.last.status "[ECA::status]" ACCESS::session data set session.ntlm.last.result 1 ACCESS::disable HTTP::header insert X-Session-Id $sid log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx use virtual: [ virtual name ]" # Set flag for next CLIENT_ACCEPTED telling it that it is the second pass through virtual set second_pass pass[IP::client_addr][TCP::client_port] table add $second_pass "1" unset second_pass # Connect to itself in order to generate HTTP response use virtual [ virtual name ] } when ECA_REQUEST_DENIED { log -noname accesscontrol.local1.debug "$static::appname_ntlm_on_demand_prfx NTLM Auth succeed" if { [ACCESS::session data get session.ntlm.last.retries] != $static::appname_ntlm_retries } { incr retries ACCESS::session data set session.ntlm.last.retries $retries } }
After creating this iRule, assign it to the APM Virtual Server.
- Now you can create or modify your existing policy as below. Let’s examine how the policy depicted below is structured. The assumption is that the policy is going to be used to authenticate both internal and external users. If the users are coming in from the internal corporate network, we want to steer them straight to the NTLM authentication, if not, we want to use forms-based login for to authenticate them. I’ve started the policy with IP Subnet Match action to steer clients from certain networks to the NTLM authentication. One the desired source networks are matched, we move on to an External Login Page object that will send user back to the APM virtual and request NTLM authentication.
Let’s examine how the policy depicted above is structured. The assumption is that the policy is going to be used to authenticate both internal and external users. If the users are coming in from the internal corporate network, we want to steer them straight to the NTLM authentication, if not, we want to use forms-based login for to authenticate them. I’ve started the policy with IP Subnet Match action to steer clients from certain networks to the NTLM authentication.
Once the desired source networks are matched, we create an External Login Page object that will send user back to the APM virtual and request NTLM authentication.
After sending the user to the “external login page”, which in fact is just a request to the same virtual server that is handled by the iRule that enables NTLM authentication between the client and BIG-IP, we need to check the status of the NTLM authentication, so we add the “NTLM Auth Result Check” action to see if the NTLM authentication was successful. If so, we need to populate the username session variable to enable APM to use it in session reporting/tracking, SAML assertion, SSO, etc.
Now you can assign necessary resources to the user session. In this example, we are assigning APM to act as the IDP to Office 365.
After you finished creating or modifying the Access Policy, make sure it is assigned to the APM virtual.
- Now we need to associate a ECA profile with the Virtual Server in order to enable NTLM functionality. This assignment needs to be performed via the command line. Establish an SSH connection in the box and enter TMSH and type the following commands, substituting the name of your virtual server for the highlighted portion
- /sys
- modify /ltm virtual NTLM-AUTH-vs profiles add { eca }
- save config
- list /ltm virtual NTLM-AUTH-vs
- Note the ‘eca’ profile associated with the virtual server
6. Next, we need to modify how the virtual server handles preservation of the original source port of the connection. This can be done either from the BIG-IP Administrative interface, or from the command line. Both examples are shown below.
- Command Line Interface
- Using the same SSH session as established in Step 5, type the following commands substituting the name of your virtual server for the highlighted portion:
- modify /ltm virtual NTLM-AUTH-vs source-port preserve-strict
- save /sys config
- Using the same SSH session as established in Step 5, type the following commands substituting the name of your virtual server for the highlighted portion:
- BIG-IP Administrative Interface
- From the main menu, go to Local Traffic > Virtual Servers > Virtual Server List.
- Click on the APM virtual server.
- Under Configuration, select Advanced.
- For Source Port, select Preserve Strict.
- Click Update.”
7. Last, but not least, you need ensure that the machine you’re using to achieve the silent sign-on has the APM Virtual FQDN added to its Local Intranet zone as per the picture below.
Voila! You should be all set. Point your browser on the machine to the FQDN of the APM Virtual Server where you assigned the new policy and iRule, and you should be silently authenticated. If you are interested in performing SSO to applications such as Sharepoint, you will need to setup Kerberos SSO in order to perform single sign-on to the Sharepoint based on the NTLM authentication.
- Noah_Hackl_6776NimbostratusSo it wasn't the version, it was the mismatched names on my ntlm auth config. Very important, maybe under emphasized here that the ntlm config name has to match the VS name. This manual page helped a great deal: https://support.f5.com/kb/en-us/products/big-ip_apm/manuals/product/apm-aaa-auth-config-11-3-0/4.htmlunique_1048502488
- Cody_GreenEmployeeNoah and Brad, If you're still seeing the TCL error: bad sid value length be sure you updated the Virtual Server Source Port settings to Preserve Strict.
- Julio_NavarroCirrostratusHello; I am getting the following err: [0x1e721a4:459] Internal error (ECA requested abort (Could not verify user (domain\myuser) credential (STATUS_NO_LOGON_SERVERS))) Please advise.
- @J Navarro - this error means that the NTLM authentication could not be performed for whatever reason. Please do open a support case to troubleshoot it - or double-check that your NTLM account is setup properly, etc. You might want to check tcpdump as well during the authentication process to see what is happening.
- Dave_Hart_85_14NimbostratusHi Michael, I would like to use client side NTLM to authenticate users from two different Active Directory domains. Could you tell me how to modify the irule to achieve this? I have created the Machine accounts and setup the two NTLM auth configs, but I can't figure out how to modify the irule. I have the setup working with one SAML IDP vip and one access poilicy that will assign a SAML resource for two service providers. I would like to continue to use one vip and one access policy if possible.
- AlgebraicMirrorAltostratusThank you! This worked for me, and I was able to get NTLM working on a custom policy I set up. This seems pretty complicated though considering how common front side NTLM seems to be among various clients. Is there any chance F5 could build this into the product, perhaps in the 401 response as an additional "NTLM" option in the dropdown?
- AlgebraicMirrorAltostratusOne other question: is it required to make the "Port translation" setting on the virtual server "preserve-strict"? Preserve-strict always makes me nervous, because if some other connection already uses the same ephemeral port you just tried to connect with, then strict means you won't translate the port and will just send the client a TCP RST (reset), breaking their connection. So is it absolutely required that it be "preserve-strict", and if so why?
- Felix_MarwedeNimbostratusHi, I have a problem using this with our Sharepoint. In the step "External Logon Page - iRule" (The External Logon Page Object), I need to dynamically set the URI (FQDN of APM Virtual Server) as the Sharepoint uses different URLs. Two questions: - How can I set an URI like http:\\$hostname\nltm\auth instead of a complete http:\\fixed.url\nltm\auth - Is there a chance for the NTLM authentication with different URLs? Is there a specific APM cookie that is set and its value could be replaced by the IP address or another value to be recognised by F5. I am asking because when using a different URL to the same APM virtual server, the NTLM authentication begins again (also an alternative Logon Page, if the NTLM authentication was not succesful) Thanks for your feedback!
- Josiah_39459Historic F5 AccountIf this isn't working in v12.0, please try replacing these lines: @@set static::appname_access_log_prefix "01490000:7:" set static::appname_ntlm_on_demand_prfx "$static::appname_access_log_prefix \[NTLM-ON-DEMAND\]"@@ with the single line @@set static::appname_ntlm_on_demand_prfx "01490000:7: \[NTLM-ON-DEMAND\]"@@ Please report back feedback since as far as I know no one has tested this yet in v12 yet.
- @felix - why does your Sharepoint use different URLs? Curious about that setup. If you are only using it for the sharepoint, you can try to set the domain cookie under the Access Policy. My default, APM Policy will set a host-level cookie - so if you have two URLs - sharepoint.company.com and library.company.com, this would require two different access sessions, setting a domain-level cookie, or setting up multi-domain SSO. The easiest test to see if you can avoid the problem is to setup domain level cookie just to ensure that it would address the issue. Then, if it works, you can try to setup Multiple Domains under SSO and configure each cookie for the host-level entry