Single Sign-On for Oracle Application Express (APEX) applications using Kerberos

Nov 4, 2019 | Publisher: nielsdebruijn | Category: Other |   | Views: 7199 | Likes: 1

Page 1 of 32 SINGLE SIGN-ON FOR (APEX) APPLICATIONS USING KERBEROS Author: Niels de Bruijn Version: 6.0 Date: 4-NOV-2019 Page 2 of 32 1 INTRODUCTION For APEX apps, you normally use a URL like /apex/f?p=xxx after which by default you have to authenticate yourself using username/password credentials. However, most end users of APEX applications already have authenticated themselves by logging on to the Windows domain, so why authenticate a second time to use the first APEX application? Wouldn’t it be nice if you could point your browser to an APEX app and you are instantly authenticated? A secure method to achieve this is to use the Kerberos protocol, which is the same protocol that Windows uses for authentication. In this document we will first describe how to install and setup the Apache module mod_auth_kerb in a Linux environment that performs the authentication against a Windows domain controller (chapter 3). For those of you who favor a Windows environment, chapter 4 describes how to setup IIS, that is used instead of Apache on Windows. Image 1: Recommended standard APEX architecture with Apache and ORDS. In this document we assume that you have setup a Windows domain controller with Active Directory (Windows Server 20xx) and you have Windows based client-PCs where you have to authenticate against the Windows domain. Also, make sure you have successfully installed and configured the Oracle Database with Oracle Application Express, Tomcat and Oracle REST Data Services (ORDS). Page 3 of 32 Remarks: - A Linux server must not be part of the Windows domain. - Install Apache with the mod_auth_kerb module on a Linux server. - For Windows environments, I recommend the usage of IIS with the tool ISAPI Rewrite instead of Apache (see chapter 4). - Use a firewall to restrict the communication with the server through port 443 (HTTPS). For Linux/Unix environments, you can use Samba 4 as Domain Controller. - Single Sign-On using Kerberos is one of the most secure authentication methods available. It has the major advantage that the password is not transmitted to the server. - Although not recommended and not part of the scope of this document: if you are not willing to install Apache, you can also setup Tomcat to get Kerberos authentication in place. - The described scenario for Single Sign-On in this document works for Desktop-PCs and Laptops having Windows installed. If you are using a smartphone or tablet, you will need to enter your Windows account in a prompted dialog, before you can access the APEX application. If you need a logon screen instead of a prompted dialog, you will need a Single Sign-On Server like Oracle Access Manager or implement something for this on Apache level. - Please be aware that this document is not about hardening your environment. For instance, you might not need all Apache modules that are installed by default. - In this case, the APEX URL (/apex) will be protected, but you can protect any other web application with this approach that lies behind the web server. Page 4 of 32 2 SETUP INDEPENDANT OF OPERATING SYSTEM 2.1 CONFIGURATION OF TOMCAT After installation of Tomcat, make sure you add the following attributes in the file server.xml: … … Some comments on the attributes: • acceptorThreadCount - The number of threads to be used to accept connections. Increase this value on a multi CPU Core machine. • acceptCount - The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. Set to 10 to protect server from getting overloaded. • maxConnections - The maximum number of connections that the server will accept at any given time. When this number has been reached, the server will accept, but not process, one further connection. Connections are passed on to available threads to perform the actual work. • maxThreads - The maximum number of request processing threads to be created by a connector, which therefore determines the maximum number of simultaneous requests that can be handled. • maxPostSize - The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. If not specified, this attribute is set to 2097152 (2 megabytes). • minSpareThreads - The minimum number of threads always kept running waiting for new requests. • connectionTimeout - The number of milliseconds a connector will wait, after accepting a connection, for the request URI line to be presented. • disableUploadTimeout - Set to false and use the value in connectionUploadTimeout as the upload timeout. • connectionUploadTimeout - Specifies the timeout, in milliseconds, to use while a data upload is in progress. This only takes effect if disableUploadTimeout is set to false. 2.2 CONFIGURATION OF ORACLE REST DATA SERVICES By default, the settings for the connection pool used by ORDS are set too small. You need to change these in the file defaults.xml: … 10 … 40 Page 5 of 32 … 10 … 50000 … Remarks: - Which initial size you choose for these parameters, depends on your specific use case. - Be aware that what you specify in defaults.xml applies to ALL connection pools three for APEX (apex_listener, apex_rest_public_user, apex_public_user) and optionally one for ORDS (ords_public_user). 2.3 CONFIGURATION OF APEX 2.3.1 SESSION TIMEOUT The session timeout is delegated to kerberos, so we have to disable the session timeouts for the APEX session cookie by setting it to 0. You can find this setting in the “security settings” section after logging on in the internal workspace, but be aware that this setting can be overridden on workspace and application level. There is also the attribute “Maximum Session Idle Time in Seconds”. By setting this to 0, you get the maximum session idle time, which is 12 hours. Even if you specify a value in seconds that exceeds 12 hours, APEX still enforces 12 hours, because it needs to clean up the sessions table once in a while. You can verify this by executing the following query in SQL Workshop: select to_char(session_idle_timeout_on, 'DD.MM.RRRR HH24:MI:SS') session_idle_timeout_on , session_max_idle_sec from apex_workspace_sessions order by session_idle_timeout_on desc 2.3.2 AUTHENTICATION SCHEME For each APEX application (including APEX itself), configure a authentication scheme that reads out the HTTP header variable „SSO_USER“. Page 6 of 32 Wenn SSO_USER is empty, the user will be redirected to a static HTML page (index.html) hosted by Apache. This page will inform the user that he or she is currently not logged on to the Windows domain. Note: if you are using an older version than APEX 4.2.3, the Schema Type “HTTP Header Variable” won’t be available. In this case, you will have to write a small PL/SQL function to achieve the same objective. With the following statement, you can read out the HTTP header variable using PL/SQL: owa_util.get_cgi_env('SSO_USER');. 2.4 CONFIGURATION OF CLIENT PC The web address of Apache should be listed in the intranet zone in Internet Explorer, otherwise you will be prompted to enter your Windows credentials if you try to access your APEX application: SSO_USER Page 7 of 32 Remark: first go to the server address using a Windows client with IE and then check if the “Local Intranet” zone is highlighted within Internet Options. When you are using Firefox, go to the URL about:config and set the attributes network.negotiate- auth.trusted-uris, network.negotiate-auth.delegation-uris and network.automatic-ntlm-auth.trusted-uris to When you are using Google Chrome on Windows, make sure that the domain is registered in the Windows Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome AuthSchemes = "negotiate,basic" AuthNegotiateDelegateWhitelist = * AuthServWhitelist = * Page 8 of 32 Important: make sure that all browser requests aren’t routed through a proxy server. So, if your browser was configured to use a proxy server, make sure that an exception for exists, otherwise you will get a “page not found” error, because the Kerberos ticket got lost along the way. Page 9 of 32 3 CONFIGURATION WHEN USING LINUX 3.1 ADD AN ENTRY IN DNS FOR THE WEBSERVER First add the fully qualified domain name (FQDN) as A-record (not as alias!) in your internal DNS server. In our example, we entered You can verify this by executing nslookup Remarks: - If the FQDN was registered as alias, the end user needs to authenticate himself through the Basic Authentication protocol and is requested to enter his username/password combination. The Kerberos authentication will not work in this case! - A PTR-record for the IP address of the physical host should exist (reverse lookup). - In our case, the physical server name equals the web address. Should the physical server name differ from the web address, register the physical server name as A-record and the web address as CNAME-record that points to the physical host (A-record). Only for the physical server name you will need to go through the various steps below. 3.2 CREATE A SERVICE USER IN ACTIVE DIRECTORY Add a computer account, like APEX_SSO in Active Directory. Use this account to create a keytab file with which Apache may verify if users are authenticated: ktpass -princ HTTP/ -mapuser "CN=APEX_SSO,CN=Computers,DC=mt-ag,DC=com" -crypto All -ptype KRB5_NT_SRV_HST -pass -out c:\ Remarks: - Although it is also possible to use a user account, we recommend the usage of a computer account, since with this account type it is not possible to logon on a client pc that is registered in a windows domain. - Our domain in this example is called MT-AG.COM and the web address we use to access APEX through Apache is Make sure that the domain is written in Page 10 of 32 uppercase. You can find the domain in the “Computer properties” dialog on your Windows client. - Run the command prompt in administrator mode on the domain controller, otherwise you will get a strange “abort” error message. - The password can be whatever you like it to be. - The address behind HTTP/ is the A-record in the DNS (in this case the physical host name). - Although we access APEX by using HTTPS, you still need to specify HTTP behind –princ. - The filename of the keytab-file can be chosen freely. - Windows 2003 Server is not aware of the option –crypto all, so use the legacy -crypto RC4- HMAC-NT instead. If possible, set -crypto to AES256-SHA1 to enforce a strong encryption. By doing so, make sure that the Windows (user) account supports it: Page 11 of 32 Copy over the keytab file to the Linux server where you want to install Apache. In our example, this is the directory /opt/httpkeytab. 3.3 INSTALL NTP The time on the Apache server should be kept in sync with the domain controller. You can achieve this by installing the NTP service: yum install ntp Make sure that it starts automatically upon server reboot: chkconfig ntpd on 3.4 INSTALL APACHE WITH MOD_AUTH_KERB By installing the module mod_auth_kerb, Apache will be installed as well: yum install mod_auth_kerb Make sure that Apache starts upon server reboot: chkconfig httpd on Remark: ntpq -p will show you the difference between times on the domain controller and the local server. This document does not describe how to configure Apache so it can be accessed through Port 443 using a valid SSL server certificate. We strongly recommend using HTTPS as the fallback authentication method “basic authentication” is otherwise insecure. 3.5 CONFIGURE KERBEROS ON THE APACHE SERVER Edit the file /etc/krb5.conf: [libdefaults] default_realm = MT-AG.COM dns_lookup_realm = false dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true [realms] MT-AG.COM = { kdc = Page 12 of 32 admin_server = MT-AG.COM default_domain = MT-AG.COM } [domain_realm] = MT-AG.COM = MT-AG.COM Remarks: - After kdc you can also state multiple hostnames, separated by a space. - The domain must be written in uppercase. - No reboot of Apache is needed since this configuration is read each time the authentication process takes place. - A good documentation of this file can be find here: 1.12/doc/admin/conf_files/krb5_conf.html 3.6 APACHE CONFIGURATION Add the following lines to the file /etc/httpd/conf/httpd.conf: # Load all necessary modules if not already loaded LoadModule auth_kerb_module /etc/httpd/modules/ LoadModule proxy_module /etc/httpd/modules/ LoadModule proxy_ajp_module /etc/httpd/modules/ LoadModule headers_module /etc/httpd/modules/ LoadModule rewrite_module /etc/httpd/modules/ # If Apache runs with a different address, enable the following line # LoadModule proxy_http_module /etc/httpd/modules/ # The default maximum size for a HTTP request header with 8190 is set too small and may result # into a Bad Request error message in the browser. As with Tomcat, we need to explicitly set # this value to 65536 to avoid problems. LimitRequestFieldSize 65536 # Depending on the version of Apache, you might need to have “RewriteEngine on” outside the # location block. RewriteEngine On # Enforce usage of https instead of http, no http access is allowed any # more and all requests are transparently rewritten as https. RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R,L] ProxyIOBufferSize 65536 # Protect all APEX specific requests AuthType Kerberos AuthName "Kerberos Login" KrbAuthRealms MT-AG.COM KrbServiceName HTTP/ Krb5KeyTab /opt/httpkeytab/ # set to off if you need the domain name as well KrbLocalUserMapping on require valid-user Page 13 of 32 RewriteEngine On # disable/enable the following lines if you want to pass the domain name as well # RewriteCond %{LA-U:REMOTE_USER} (.+)$ RewriteCond %{REMOTE_USER} (.+)@.* RewriteRule . - [E=RU:%1] # Introduce a new HTTP header variable SSO_USER as REMOTE_USER is overwritten by ORDS RequestHeader set SSO_USER %{RU}e # If SSO_USER is still empty, try this instead (works with Apache 2.1 and later): # RequestHeader set SSO_USER %{RU}s # If Apache runs with a different address, enable the following line # ProxyPreserveHost On ProxyPass ajp:// connectiontimeout=2100 timeout=2100 # If Apache runs with a different hostname as Tomcat, enable the following line # and enable communication between the two using either AJP or HTTP(S) # ProxyPassReverse http://:8080/apex # Add this line to prevent an error message “” from ORDS RequestHeader unset Origin # Display a nice message to end users when Tomcat is down due to maintenance ErrorDocument 503 /msgs/my_nice_maintenance_message.html # Static files of APEX Alias /i/ "/srv/www/htdocs/images/" # enable caching of static images AllowOverride None Order allow,deny Allow from all Options Indexes ExpiresActive on ExpiresDefault "access plus 8 hours" IndexOptions FancyIndexing # enable compression of static files AddOutputFilterByType DEFLATE text/html application/javascript text/plain text/css text/xml Save the file and restart Apache. Remarks: - All static files of APEX were copied to /srv/www/htdocs/images. You can find these in /images within the software directory of the APEX software. Page 14 of 32 Optionally, you can additionally require that the user is also a member of a certain group in Active Directory: ... # Load the required module LoadModule authz_ldap_module /etc/httpd/modules/ ... # LDAP server and search filter AuthLDAPUrl "ldap://,DC=MT-ag,DC=com?userPrincipalName?sub?(objectClass=user)" # User used for the inquiry AuthLDAPBindDN "CN=myldapuser,OU=Rollen,DC=mt-ag,DC=com" AuthLDAPBindPassword "mypassword" # The LDAP group the user hast to be member of require ldap-group "CN=myldapgruppe,OU=Gruppen,DC=mt-ag,DC=com" # require valid-user ... Page 15 of 32 4 CONFIGURATION WHEN USING WINDOWS 4.1 ADDITIONAL COMPONENTS To get SSO for APEX with IIS in front of it, the following components are required: • Nonstandard IIS components • Windows Authentication (under Security) • ISAPI Extensions (under Application Development) • ISAPI Filters (under Application Development) • Additional Software • Helicon ISAPI Rewrite ( • Tomcat Connector ( 4.1.1 INSTALL NON STANDARD IIS COMPONENTS To install the additional IIS components please open a PowerShell as administrator and enter the following line: Install-WindowsFeature -Name Web-Windows-Auth,Web-Basic-Auth,Web-ISAPI-Ext,Web-ISAPI-Filter 4.1.2 INSTALL HELICON ISAPI REWRITE The installation of the ISAPI Rewrite component is pretty straightforward, so there is no need to document this. Remarks: This product is needed to set the AD username in the HTTP header. 4.1.3 INSTALL TOMCAT CONNECTOR To use the better AJP protocol of Tomcat you need to install the Tomcat Connector for IIS. The installation of the Tomcat Connector is completely manual, so please follow the next steps to install it. First, we need to download the Tomcat Connector for Windows 64 bit. You can get the latest version from the Tomcat website > „Binary Releases for selected versions“. In the downloaded zip file is one dll which is need. In this documentation this file is present under following location: c:\inetpub\tomcat-connector\isapi_redirect.dll Page 16 of 32 ALLOW THE ISAPI EXTENSION TO RUN • To get Tomcat Connector working we need to do some things in the IIS Manager • Mark the webserver in the ‘Connections’ panel • Double click the ‘ISAPI and CGI Restrictions’ icon • Click ‘Add’ in the ‘Actions’ panel Page 17 of 32 • Browse to the isapi_redirect.dll in the Tomcat Connector folder, enter a description and enable ‘Allow extension path to execute’ ADD ISAPI FILTER • Mark the website you want to use for APEX in the ‘Connections’ panel • Open the ‘ISAPI Filters’ Page 18 of 32 • Click ‘Add’ in the ‘Actions’ panel • Set a ‘Filter name’ and browse to the isapi_redirect.dll in the Tomcat connector folder • Click on ‘OK’ to insert the filter Page 19 of 32 ADD SCRIPT MAP • In IIS Manager in ‚Connections‘ select the default website • Double click on ‚Handler Mappings‘ • Click on ‚Add Script Map…‘ in the ‚Actions‘ panel Page 20 of 32 • In the dialog, enter *.dll as ‚Request path‘ and the location oft he DLL file. Click on ‚OK‘. ADD APPLICATION • Right click the Website and click ‘Add Application’ Page 21 of 32 • Set the Alias to ‘jakarta’ (this name doesn’t show up in any URL or something but it is important for this documentation that you enter exactly this name) and browse to the Tomcat Connector folder • Click on ‘OK’ to create the Application Page 22 of 32 MIME TYPE FOR .LESS FILES • APEX uses .less files; unfortunately IIS on Windows Server 2012 does not support this file type by default, so you have to insert this file type in the ‘MIME Types’. Please also check if other MIME type extensions used by APEX like *.json, *.woff and *.woff2 are also registered. Depending on your Windows version, this might not be the case, although they are present by default on Windows Server 2016. • Click on ‘Add’ in the ‘Actions’ panel and insert the ‘File name extension’ .less and as ‘MIME type’ text/css. Page 23 of 32 4.2 CONFIGURE ADDITIONAL COMPONENTS 4.2.1 IIS AUTHENTICATION KERBEROS FOR WEBSITE To achieve SSO we need to enable Kerberos authentication for the website. For mobile devices and non-domain clients we enable Basic authentication, too. To encrypt the password, it is important to secure the channel via SSL. To prevent ‚Windows Authentication‘ to work with NTLM you can delete it in the ‚Providers‘ list (Mark ‚Windows Authentication‘ – ‚Actions‘ Panel – ‚Providers‘) Page 24 of 32 You just need “Negotiate”. You may ignore other providers, even though you will find “Negotiate:Kerberos” listed in “Available Providers”. FOR BASIC AUTHENTICATION SET DEFAULT DOMAIN To make it easier for non-domain clients we edit the ‘Basic Authentication’ component (Mark ‘Basic Authentication’ – ‘Actions’ panel – ‘Edit’) and enter the NETBIOS Domain name in the ‘Default domain’ field. Page 25 of 32 ANONYMOUS AUTHENTICATION FOR APEX STATIC IMAGES FOLDER To get better performance for ‘i’ (copy of ‘images’ folder from APEX) enable only ‘Anonymous Authentication’ for this subfolder. Remarks: the images directory is automatically being cached. If possible, any file is also sent compressed over the network. REDIRECT / TO /APEX To access the APEX system easier a redirect from the root directory to the /apex is a good solution. This means that the user only has to enter the hostname into the browser and get the APEX website. To archive this, you have to insert a ‘HTTP Redirect’ on the website. (Double klick ‘HTTP Redirect’ – ‘Actions’ panel – ‘Edit’) In the next screenshot you can see the settings. To finish this step klick ‘Apply’. Page 26 of 32 FRIENDLY ERROR MESSAGE DURING MAINTENANCE OF TOMCAT To get a specific error page for maintenance work you have to insert an additional error code in the IIS config. (Mark the server and double klick ‘Error Pages’ – ‘Actions’ panel – ‘Add’) Page 27 of 32 • In the next window you have to insert the ‘Status code’ 503 activate ‘try to return the error file in the client language’ and press the ‘Set’ button. • The settings for the next window you can see in the following screenshot. • Close both windows with ‘OK’ • You need to create the HTML page for the error code 503. To do this you have to go to ‘C:\inetpub\custerr\en-US\‘ and make a copy of the file ‘502.html’. After that rename the copy to ‘503.html’ and open it in an editor. The changes you have to make are marked bold. Filename: C:\inetpub\custerr\en-US\503.htm Maintenance Maintenance Maintenance Currently the APEX System is not available Page 29 of 32 FRIENDLY ERROR MESSAGE SHOULD AUTHENTIFICATION FAIL If authentication in APEX fails because the HTTP header variable wasn’t set, the user is redirected to the file ‘C:\inetpub\notauth\index.html’. To create this file, copy the file ‘C:\inetpub\custerr\en- US\503.htm’ to the folder ‘C:\inetpub\notauth’ and rename it to ‘index.html’. After that open the file in an editor and change the marked entries. Filename: C:\inetpub\notauth\index.html Authentification Error Server Error Authentification Error Please ask your local IT department. • You have to change the authentication method for the the ‘notauth’ folder (Mark website/notauth and double klick ‘Authentication’) • Enable ‘Anonymous Authentication’ and disable all other Page 30 of 32 4.2.2 CONFIGURE ISAPI REWRITE To configure ISAPI Rewrite start ISAPI_Rewrite Manager. In the free edition you can only use the root folder ‚IIS Web Sites‘. Click on ‚Edit‘ to enter the config file. The following lines enables the rewrite engine of ISAPI Rewrite and transfer the REMOTE_USER to the SSO_USER header variable for Kerberos and Basic authentication. # Helicon ISAPI_Rewrite configuration file # Version ## Acivates rewrite mechanism RewriteEngine On LogLevel error RewriteLogLevel 0 ## Set header variable "SSO_USER" if user authenticates via basic authentication RewriteCond %{REMOTE_USER} (.*) RewriteHeader SSO_USER: (.*) %1 ## Set header variable "SSO_USER" if user authenticates via kerberos authentication RewriteCond %{REMOTE_USER} \\(.*) RewriteHeader SSO_USER: (.*) %1 4.2.3 CONFIGURE TOMCAT CONNECTOR The last step to get this work is to create the following config files in the Tomcat Connector folder. ISAPI_REDIRECT.PROPERTIES # The path to the ISAPI Redirector Extension, relative to the website # This must be in a virtual directory with execute privileges extension_uri=/jakarta/isapi_redirect.dll # Full path to the log file for the ISAPI Redirector log_file=C:\inetpub\tomcat-connector\log\isapi.log # Log level (debug, info, warn, error or trace) log_level=error # Full path to the file worker_file=C:\inetpub\tomcat-connector\ # Full path to the file worker_mount_file=C:\inetpub\tomcat-connector\ URIWORKERMAP.PROPERTIES /apex = apex /apex/* = apex WORKERS.PROPERTIES worker.list=apex worker.apex.type=ajp13 worker.apex.port=8009 worker.apex.max_packet_size=65536 Page 31 of 32 5 WHATS HAPPENING? 5.1 APACHE WEBSERVER If you would like to see what’s happening in the background, you can set the log level of Apache to debug and inspect the log files. Edit the file: /etc/httpd/conf/httpd.conf and change the row containing „LogLevel“ to „LogLevel debug“. Save the file and restart Apache: service httpd restart The log files you need to inspect are called access_log and error_log. If the Kerberos authentication works, you should see the username appear in the access_log file: An extensive blog post about Kerberos based authentication can be found here: To check if kerberos without mod_auth_kerb works, just run the following commands on the server where the Apache web server is running: kinit ndbruijn@MT-AG.COM kinit -k -t /opt/httpkeytab/ HTTP/ klist 5.2 WINDOWS CLIENT With the Windows client utility klist, you can find out which Kerberos tickets the Windows Domain User currently has. If all was setup correctly, you should see a ticket for in the output. 6 OTHER USEFUL LINKS SSO configured in Tomcat instead of Apache: More SSO options: General guidelines to install/configure Apache, ORDS and Tomcat without SSO: Looking for fallback authentication with APEX? Here are two solutions, but remember that you will have to configure Apache/IIS to allow access in certain cases if the user is not logged on to the Kerberos domain: Page 32 of 32 Authentication with mod_auth_kerb not working with AD users that are member to many groups? Have a look here for a possible solution: directory.aspx Should you encounter any HTTP 413 “request entity too large” errors, this document might help you out: Disclaimer: Just to make sure: MT AG is not responsible for any damage, outages or loss of profit resulting from the usage of this document. Use it at your own risk. Have fun!

For APEX apps, you normally use a URL like <hostname>/apex/f?p=xxx after which by default you have to authenticate yourself using username/password credentials. However, most end users of APEX applications already have authenticated themselves by logging on to the Windows domain, so why authenticate a second time to use the first APEX application? Wouldn’t it be nice if you could point your browser to an APEX app and you are instantly authenticated? A secure method to achieve this is to use the Kerberos protocol, which is the same protocol that Windows uses for authentication. In this document we will first describe how to install and setup the Apache module mod_auth_kerb in a Linux environment that performs the authentication against a Windows domain controller (chapter 3). For those of you who favor a Windows environment, chapter 4 describes how to setup IIS, that is used instead of Apache on Windows.


Modal Header

Modal body