Как разрешить доступ только пользователям из определенной группы (apache2, mysqli)?

Я пытаюсь настроить систему аутентификации на основе базовой аутентификации apache2. Для этого я настроил mod_authn_dbd для использования базы данных mysqli, настроенной следующим образом: https://www.howtoforge.de/anleitung/passwort-geschutzte-verzeichnisse-auf-apache2-mit-mod_auth_mysql-debian-squeeze/.

Затем я настроил свой site.conf следующим образом:

      <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin admin@exmpl.de
    DocumentRoot /var/www/html
    ServerName exmpl.de

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
DBDriver mysql 
 DBDParams "dbname=db user=usr pass=pass"
 
 DBDMin 4 
 DBDKeep 8 
 DBDMax 20 
 DBDExptime 300
 
 <Directory "/var/www/html"> 
 # mod_authn_core and mod_auth_basic configuration 
 # for mod_authn_dbd 
 AuthType Basic 
 AuthName "Users only"
 
 # To cache credentials, put socache ahead of dbd here 
 AuthBasicProvider socache dbd
 
 # Also required for caching: tell the cache to cache dbd lookups! 
 AuthnCacheProvideFor dbd 
 AuthnCacheContext my-server
 
 # mod_authz_core configuration 
 Require valid-user
 
 # mod_authn_dbd SQL query to authenticate a user 
 AuthDBDUserPWQuery "SELECT passwd FROM mysql_auth WHERE username = %s" 
</Directory>
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

который отлично работает с моей базой данных:

      create table mysql_auth (
username varchar(255) not null,
passwd varchar(255),
groups varchar(255),
primary key (username)
);

Теперь я хотел добавить возможность сделать определенные папки и их содержимое доступными только для пользователей определенной группы, поэтому я добавил:

      <Directory "/var/www/html/folder1/folder2">
  # mod_authn_core and mod_auth_basic configuration
  # for mod_authn_dbd
  AuthType Basic
  AuthName group specific area
  AuthBasicProvider dbd

  # mod_authn_dbd SQL query to authenticate a logged-in user
  AuthDBDUserPWQuery \
    "SELECT password FROM mysql_auth WHERE username = %s"

  # mod_authz_core configuration for mod_authz_dbd
  Require dbd-group groupname

  # mod_authz_dbd configuration
  AuthzDBDQuery "SELECT groups FROM mysql_auth WHERE user = %s"

</Directory>

( https://httpd.apache.org/docs/current/mod/mod_authz_dbd.html ), в результате чего я получаю это сообщение после повторного включения site.conf и попытки перезапустить apache2:

      Mar 23 23:31:12 v*** apachectl[1665]: AH00526: Syntax error on line 70 of /etc/apache2/sites-enabled/site.conf:
Mar 23 23:31:12 v*** apachectl[1665]: Unknown Authz provider: dbd-group

Даже «Требовать имя группы группы» не работает. Я действительно не знаю, что я делаю не так. Есть идеи?

Заранее спасибо.

1 ответ

Я нашел свою ошибку: я не сделал «a2enmod authz_dbd»

Другие вопросы по тегам