AuthLDAPURL ldap://ldap.your-domain.com:389/o=stooges?uid?sub AuthLDAPBindDN "cn=StoogeAdmin,o=stooges" AuthLDAPBindPassword secret1 AuthLDAPGroupAttribute memberUid AuthLDAPGroupAttributeIsDN off Require ldap-group cn=users,ou=group,o=stooges Require ldap-attribute gidNumber=100 Satisfy any </Directory> ... |
Concurrent File and LDAP authentication: |
Apache can use both File and LDAP authentication concurently. This is sometimes required to run cron jobs with a login where you do not want to use a system login or login managed by a directory server in another department.
<Directory /ABC> Order deny,allow Deny from All AuthType Basic AuthBasicProvider file ldap AuthName "Directory services login" AuthBasicAuthoritative off AuthUserFile /srv/htpasswd AuthGroupFile /dev/null AuthzLDAPAuthoritative off AuthLDAPURL "ldap://ldap.megacorp.com:389/ou=person,o=megacorp.com,c=us?uid?sub" # This user created for local cron jobs. It is not a system user and allows # the cron job to perform its task. # This user is not in the LDAP directory but in the password file /srv/htpasswd Require user cronuserjobx Require ldap-user usera userb </Directory> |
Debugging Apache Authentication: |
Set LogLevel debug when debugging authentication. This will log all the LDAP connection events and the LDAP attributes requested.
Authenticating with Microsoft Active directory using Microsoft's "Unix services for Windows":
Restart Apache after editing the configuration file: service httpd restart for configuration changes to take effect.
See /var/log/httpd/error_log for configuration errors.
Links: |
Using NIS for Apache Authentication: |
This method authenticates using Apache on Linux and an NIS server. The advantage of using NIS, is the comonality of computer system accounts and web site logins. This configuration requires that the system the Apache web server is running on, must be using NIS authentication for system logins.
This requires a NIS server. See the YoLinux.com NIS configuration tutorial.
Requires the Linux RPM package mod_perl and the following Perl modules:
Download / Install Perl modules:
Apache 2.2 | Apache 2.0 |
---|---|
Apache2-AuthenNIS: (CPAN)
|
Apache-AuthenNIS: (CPAN)
|
Or install from CPAN via the internet:
Test Perl module:
#!/usr/bin/perl BEGIN{push @INC, "/usr/lib/perl5/site_perl/5.8.8/Apache2";} eval "use Apache2::AuthenNIS"; $hasApacheAuth = $@ ? 0 : 1; printf "Apache2::AuthenNIS". ($hasApacheAuth ? "" : " not") . " installed"; printf "\n"; |
#!/usr/bin/perl BEGIN{push @INC, "/usr/lib/perl5/site_perl/5.8.5/Apache";} eval "use Apache::AuthenNIS"; $hasApacheAuth = $@ ? 0 : 1; printf "Apache::AuthenNIS". ($hasApacheAuth ? "" : " not") . " installed"; printf "\n"; |
.. ... <Directory /home/domain/public_html/membersonly> AuthType Basic AuthName "Add your login message here." PerlAuthenHandler Apache2::AuthenNIS - or Apache::AuthenNIS PerlSetVar AllowAlternateAuth no require valid-user </Directory> ... .. |
.. ... <Directory /home/domain/public_html/membersonly> AuthType Basic AuthName "Add your login message here." PerlAuthenHandler Apache2::AuthenNIS - or Apache::AuthenNIS PerlSetVar AllowAlternateAuth no require user greg phil bob </Directory> ... .. |
.. ... <Directory /home/domain/public_html/membersonly> AuthType Basic AuthName "Add your login message here." PerlAuthenHandler Apache2::AuthenNIS - or Apache::AuthenNIS PerlAuthzHandler Apache2::AuthzNIS - or Apache::AuthzNIS PerlSetVar AllowAlternateAuth no require group accounting </Directory> ... .. |
.. ... <IfModule mod_userdir.c> UserDir public_html </IfModule> <Directory /home/*/public_html> AuthType Basic AuthName "Add your login message here." PerlAuthenHandler Apache2::AuthenNIS - or Apache::AuthenNIS PerlSetVar AllowAlternateAuth no require user valid-user AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> ... .. |
Also see YoLinux SysAdmin: Perl Admin
Links:
[Potential Pitfall]: This method of authentication will fail if using "adjunct password maps". This Perl module requires the use of the library call yp_match() which must have access to the encrypted passwords. If "adjunct password maps" are used, then this is not accessible to processes other than root thus the web server daemon process apache will not be able to access the data required. Test your system using the command ypcat passwd | head. If the second field is prefixed with "##", then this perl module will not work. If the second field is an encrypted password, then this perl module can work.
CGI to allow users to modify their NIS Passwords: |
For those users who get a shell of /sbin/nologin, the "cgipaf" web interface is ideal for user management of NIS passwords. Cgipaf uses PHP, cgi (written in C) and your system PAM authentication (or /etc/passwd, /etc/shadow files). Cgipaf also can manage mail accounts using procmail.
Download from http://www.wagemakers.be/english/programs/cgipaf
Installation/configuration:
File: /etc/httpd/conf.d/cgipaf.conf (Red Hat style systems)
Alias /NIS/ "/srv/cgipaf/" <Directory "/srv/cgipaf"> SSLRequireSSL Options Indexes FollowSymLinks AllowOverride None Order allow, deny Allow from all </Directory> |
The PHP pages reside in /srv/cgipaf/. The compiled C cgi will reside in /var/www/cgi-bin. The configuration file will be/etc/cgipaf/cgipaf.conf.
See the web page at http://localhost/NIS/
Using a MySQL database for Apache Authentication: |
Two Apache modules are available for database authentication:
.. |
Directives:
Directive | Description |
---|---|
AuthMySQLEnable On | If 'Off', MySQL authentication will pass on the authentication job to the other authentication modules i.e password files. |
AuthMySQLHosthost_name | Name of MySQL Database hosr. i.e. 'localhost' |
AuthMySQLPortTCP_Port_number | Port number of MySQL Database. Default: 3306 |
AuthMySQLDBdatabase_name | Name of MySQL Database. |
AuthMySQLUser user_id | MySQL Database login id. |
AuthMySQLPassworduser_password | MySQL Database login password. Plain text. |
AuthMySQLUserTableuser_table_name | Name of MySQL Databse table in the database which holds the user name and passwords. |
AuthMySQLGroupTablegroup_table_name | Databse table holding group info. |
AuthMySQLNameFielduser_field_name | If not using default field name 'user_name', then specify. Not case sensitive id CHAR or VARCHAR. |
AuthMySQLPasswordFieldpassword_field_name | If not using default field name 'user_passwd', then specify. Passwords are case sensitive. |
AuthMySQLGroupFieldgroup_field_name | If not using default field name 'groups', then specify. |
AuthMySQLNoPasswd Off | Off: Passwords can be null (''). On: password must be specified. |
AuthMySQLPwEncryptionnone | Options: none, crypt, scrambled (MySQL password encryption), md5, aes, sha. If you are going to use plain-text passwords for mysql authentication, you must include this directive with the argument "none". |
AuthMySQLSaltFieldsalt_string mysql_column_name | Salt field to be used for crypt and aes. |
AuthMySQLAuthoritativeon | Authenticate using other authentication modules after the user is successfully authenticated by the MySQL auth module. Default on: request is not passed on. |
AuthMySQLKeepAlive Off | Off: Close the MySQL link after each authentication request. |
MySQL Admin:
Links:
Login URL Tricks: |
Here is a trick to incorporate a login and password into a URL. Typicall one would attempt to enter the password protected area of the web site and the user would be confronted with a login dialog box into which one would enter the user id and password. Another option is to enter a URL with the login and password embedded.
http://login-id:password@UrlOfDomain.com/protectedPath/WebPage.html
Links: |
转:http://www.yolinux.com/TUTORIALS/LinuxTutorialApacheAddingLoginSiteProtection.html