I have Kerberos-based authentication with Apache/2.2.3 (Linux/SUSE). When user is trying to open some url, browser ask him about domain login and password like in HTTP Basic Auth. If user cancel such request 3 times Apache returns 401 Authorization Required
error page. My current virtual host config is
<Directory /home/user/www/current/public/>
Options -MultiViews +FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AuthType Kerberos
AuthName "Domain login"
KrbAuthRealms DOMAIN.COM
KrbMethodK5Passwd On
Krb5KeyTab /etc/httpd/httpd.keytab
require valid-user
</Directory>
I want to set nice custom 401 error page with some instructions for users. And I added such line in virtual host config:
ErrorDocument 401 /pages/401
It works, when user can't authorize apache redirects him to my nice page. But Apache doesn't ask user login\password as it did before. I want this functionality and nice error page simultaneously!
Is it possible to make it works properly?
Firstly, when I used
/pages/401
was dynamic backend-generated content. When I've created simple static401.html
and have settedwhole system started work properly. So the solution is: don't use dynamic pages for displaying 401 error, use static html.
The behavior you're describing is client side and has nothing to do with Apache, per se.
Here's what actually happens:
If access is granted Apache responds with 200, if access is not granted then it goes back to step 2 and continues. Its up to the User-Agent (i.e., your browser) how many times it will try. Your browser apparently stops at 3 tries. After that it keeps the result cached and just shows you the error page.
Browsers often cache results of these type of operations so this is normal. Did you quit your browser before trying again? That should clear the cached result.
If you want to see exactly the way Apache is behaving "in the raw", use the following:
Unauthenticated request:
Authenticated* request:
You will see the headers at the very top of the output for how Apache responds to authenticated vs unauthenticated requests. You should always see a 401 for unauth and 200 for auth. If that is not the case then it's either not configured right or there's something else going on.
*
curl
can do kerberos authentication by passing--negotiate
but I've never done it and don't have a valid test environment to try in. Read thecurl(1)
manual for more information.