Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
centos:mail_c7:dovecot_6 [28.07.2014 19:36. ] – [auth-system.conf.ext] django | centos:mail_c7:dovecot_6 [18.11.2024 07:08. ] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Dovecot, Authentifizierung(en) ====== | ====== Dovecot, Authentifizierung(en) ====== | ||
+ | {{: | ||
+ | ===== Authentifizierungsdaten ===== | ||
+ | Beim Betrieb unseres Dovecot-Mailservers sind wir auf folgende Daten angewiesen: | ||
+ | - **Username** : Der Username ist der Name, mit dem sich der Nutzer an unserem Mailserver anmeldet. Dies ist mindestens ein Username oder besser noch die eMail-Adresse des Endkunden, die dem Nutzerkonto primär zugewiesen ist. | ||
+ | - **Passwort** | ||
+ | - **UID** : User-ID, die beim Anlegen des Benutzerkontos, | ||
+ | - **GID** : Gruppen-ID, die beim Anlegen des Benutzerkontos, | ||
+ | - **Home-Verzeichnis**: | ||
===== Authentifizierungsquellen ===== | ===== Authentifizierungsquellen ===== | ||
Zeile 16: | Zeile 24: | ||
- **Test**, zu Testzwecken. | - **Test**, zu Testzwecken. | ||
+ | ===== Authentifizierungs-Anfragen ===== | ||
+ | Authentifizierungs-Anfragen, | ||
+ | * **passdb-lookup** : Der passdb-lookup wird von Dovecot immer dann ausgeführt, | ||
+ | * **userdb-lookup** : Bei einem userdb-lookup ermittelt unser Dovecot-Server die Umgebungsvariablen des genannten/ | ||
Zeile 59: | Zeile 71: | ||
django: | django: | ||
- | Der Username **django** kann zwar benutzt werden, nicht aber django@nausch.org | + | Der Username **django** kann zwar benutzt werden, nicht aber django@nausch.org. |
Über die Konfigurationsdatei // | Über die Konfigurationsdatei // | ||
Zeile 228: | Zeile 240: | ||
| | ||
| | ||
+ | |||
+ | ==== auth-sql.conf.ext ==== | ||
+ | Haben wir einen Mailserver mit vielen Maildomains und vielen Mailboxnutzern und ein Team von Mailadmins, wird die Pflege der Nutzerkonten über **[[centos: | ||
+ | |||
+ | Als einfache Lösung bietet sich nun die Datenhaltung in einer **[[centos: | ||
+ | |||
+ | Das für die Anbindung an unseren [[|MySQL-Datenbankserver]] benötigte Dovecot-Modul, | ||
+ | Falls wir das Paket noch nicht installiert haben, holen wir dies nun noch nach. | ||
+ | # yum install dovecot-mysql | ||
+ | |||
+ | Was uns das Paket alles mitgebracht hat, können wir mit der Option // | ||
+ | # rpm -qil dovecot-mysql | ||
+ | < | ||
+ | Epoch : 1 | ||
+ | Version | ||
+ | Release | ||
+ | Architecture: | ||
+ | Install Date: Wed 30 Jul 2014 10:23:58 PM CEST | ||
+ | Group : System Environment/ | ||
+ | Size : 19536 | ||
+ | License | ||
+ | Signature | ||
+ | Source RPM : dovecot-2.2.13-2.el7.centos.src.rpm | ||
+ | Build Date : Wed 30 Jul 2014 06:02:59 PM CEST | ||
+ | Build Host : vml000200.dmz.nausch.org | ||
+ | Relocations : (not relocatable) | ||
+ | Packager | ||
+ | Vendor | ||
+ | URL : http:// | ||
+ | Summary | ||
+ | Description : | ||
+ | This package provides the MySQL back end for dovecot-auth etc. | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | === dovecot-sql.conf.ext === | ||
+ | Bei der RPM-Installation unseres Dovecot-Servers, | ||
+ | # cp / | ||
+ | |||
+ | Die wichtigsten Konfigurationsparameter in dieser Datei, die wir unseren Bedürfnissen nach anpassen müssen sind: | ||
+ | * **driver** : Da wir eine mySQL-Datenbank verwenden, setzen wir den Parameter auf den Wert **mysql**. | ||
+ | * **connect** : Hier wird der Datenbank-Connector beschrieben: | ||
+ | * **// | ||
+ | * **// | ||
+ | * **// | ||
+ | * **// | ||
+ | * **default_pass_scheme** : | ||
+ | * **// | ||
+ | * **// | ||
+ | * **// | ||
+ | * **// | ||
+ | * **// | ||
+ | * **password_query** : SQL-Statement für den **// | ||
+ | * **user_query** : SQL_Statement für den **// | ||
+ | |||
+ | In der Konfigurationsdatei // | ||
+ | # vim / | ||
+ | <file bash / | ||
+ | # | ||
+ | # http:// | ||
+ | # | ||
+ | # For the sql passdb module, you'll need a database with a table that | ||
+ | # contains fields for at least the username and password. If you want to | ||
+ | # use the user@domain syntax, you might want to have a separate domain | ||
+ | # field as well. | ||
+ | # | ||
+ | # If your users all have the same uig/gid, and have predictable home | ||
+ | # directories, | ||
+ | # dir based on the username and domain. In this case, you won't need fields | ||
+ | # for home, uid, or gid in the database. | ||
+ | # | ||
+ | # If you prefer to use the sql userdb module, you'll want to add fields | ||
+ | # for home, uid, and gid. Here is an example table: | ||
+ | # | ||
+ | # CREATE TABLE users ( | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # home VARCHAR(255) NOT NULL, | ||
+ | # uid INTEGER NOT NULL, | ||
+ | # gid INTEGER NOT NULL, | ||
+ | # | ||
+ | # ); | ||
+ | |||
+ | # Database driver: mysql, pgsql, sqlite | ||
+ | # Django : 2013-02-06 | ||
+ | # default: #driver = | ||
+ | driver = mysql | ||
+ | |||
+ | # Database connection string. This is driver-specific setting. | ||
+ | # | ||
+ | # HA / round-robin load-balancing is supported by giving multiple host | ||
+ | # settings, like: host=sql1.host.org host=sql2.host.org | ||
+ | # | ||
+ | # pgsql: | ||
+ | # For available options, see the PostgreSQL documention for the | ||
+ | # | ||
+ | # Use maxconns=n (default 5) to change how many connections Dovecot can | ||
+ | # | ||
+ | # | ||
+ | # mysql: | ||
+ | # Basic options emulate PostgreSQL option names: | ||
+ | # host, port, user, password, dbname | ||
+ | # | ||
+ | # But also adds some new settings: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # the default my.cnf location | ||
+ | # | ||
+ | # | ||
+ | # You can connect to UNIX sockets by using host: host=/ | ||
+ | # Note that currently you can't use spaces in parameters. | ||
+ | # | ||
+ | # sqlite: | ||
+ | # The path to the database file. | ||
+ | # | ||
+ | # Examples: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # Django : 2013-02-06 | ||
+ | # default: #connect = | ||
+ | connect = host=mysql.dmz.nausch.org dbname=postfix user=dovecot_user password=GOMrG7l1bD74Ez81sUO | ||
+ | |||
+ | # Default password scheme. | ||
+ | # | ||
+ | # List of supported schemes is in | ||
+ | # http:// | ||
+ | # | ||
+ | # Django : 2013-02-06 | ||
+ | # default: # | ||
+ | default_pass_scheme = PLAIN | ||
+ | |||
+ | # passdb query to retrieve the password. It can return fields: | ||
+ | # | ||
+ | # user - user@domain from the database. Needed with case-insensitive lookups. | ||
+ | # | ||
+ | # | ||
+ | # The " | ||
+ | # e.g. " | ||
+ | # your user and domain names are in separate fields, you can return " | ||
+ | # and " | ||
+ | # | ||
+ | # The query can also return other fields which have a special meaning, see | ||
+ | # http:// | ||
+ | # | ||
+ | # Commonly used available substitutions (see http:// | ||
+ | # for full list): | ||
+ | # %u = entire user@domain | ||
+ | # %n = user part of user@domain | ||
+ | # %d = domain part of user@domain | ||
+ | # | ||
+ | # Note that these can be used only as input to SQL query. If the query outputs | ||
+ | # any of these substitutions, | ||
+ | # difficult to have eg. usernames containing ' | ||
+ | # | ||
+ | # Example: | ||
+ | # | ||
+ | # FROM users WHERE userid = ' | ||
+ | # | ||
+ | # | ||
+ | # SELECT username, domain, password \ | ||
+ | # FROM users WHERE username = ' | ||
+ | # Django : 2013-02-06 | ||
+ | # default: unset | ||
+ | password_query = SELECT username AS user, password, 10000 AS userdb_uid, 10000 AS userdb_gid, \ | ||
+ | CONCAT(' | ||
+ | |||
+ | # userdb query to retrieve the user information. It can return fields: | ||
+ | # uid - System UID (overrides mail_uid setting) | ||
+ | # gid - System GID (overrides mail_gid setting) | ||
+ | # home - Home directory | ||
+ | # mail - Mail location (overrides mail_location setting) | ||
+ | # | ||
+ | # None of these are strictly required. If you use a single UID and GID, and | ||
+ | # home or mail directory fits to a template string, you could use userdb static | ||
+ | # instead. For a list of all fields that can be returned, see | ||
+ | # http:// | ||
+ | # | ||
+ | # Examples: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | #user_query = \ | ||
+ | # SELECT home, uid, gid \ | ||
+ | # FROM users WHERE username = ' | ||
+ | # Django : 2013-02-06 | ||
+ | # default: unset | ||
+ | user_query = SELECT CONCAT('/ | ||
+ | CONCAT(' | ||
+ | |||
+ | # If you wish to avoid two SQL lookups (passdb + userdb), you can use | ||
+ | # userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll | ||
+ | # also have to return userdb fields in password_query prefixed with " | ||
+ | # string. For example: | ||
+ | # | ||
+ | # SELECT userid AS user, password, \ | ||
+ | # home AS userdb_home, | ||
+ | # FROM users WHERE userid = ' | ||
+ | |||
+ | # Query to get a list of all usernames. | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | Den notwendigen Datenbank-Systemuser legen wir nun noch auf unserem mySQL-Datenbankserver an. | ||
+ | |||
+ | === mySQL Datenbankuser anlegen === | ||
+ | Wie bereits erwähnt, nutzen wir für die Verwaltung unserer Maildomänen und deren Nutzerkonten sowie Aliasen eine [[centos: | ||
+ | |||
+ | Wir melden uns also als berechtigter Datenbankuser an der mySQL-Datenbank an. | ||
+ | # mysql -h localhost -u root -p | ||
+ | < | ||
+ | Welcome to the MySQL monitor. | ||
+ | Your MySQL connection id is 1942 | ||
+ | Server version: 5.1.67 Source distribution | ||
+ | |||
+ | Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. | ||
+ | |||
+ | Oracle is a registered trademark of Oracle Corporation and/or its | ||
+ | affiliates. Other names may be trademarks of their respective | ||
+ | owners. | ||
+ | |||
+ | Type ' | ||
+ | |||
+ | mysql> | ||
+ | </ | ||
+ | |||
+ | Als erstes legen wir den Dovecot-Systemusers an. | ||
+ | | ||
+ | |||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | | ||
+ | |||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | Dann setzen wir die Berechtigungen unseres neuen Datenbannutzers auf die Datenbank **postfix**. | ||
+ | | ||
+ | |||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | | ||
+ | |||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | Abschließend weisen wir noch die Berechtigungen zu. | ||
+ | | ||
+ | |||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | Zu guter Letzt melden wir uns wieder von unserem Datenbankhost ab. | ||
+ | | ||
+ | |||
+ | Bye | ||
+ | |||
+ | === auth-sql.conf.ext === | ||
+ | Die Definition des Mechanismus **SQL** wir über die Konfigurationsdatei // | ||
+ | # vim / | ||
+ | <file bash vim / | ||
+ | # | ||
+ | # < | ||
+ | |||
+ | passdb { | ||
+ | driver = sql | ||
+ | |||
+ | # Path for SQL configuration file, see example-config/ | ||
+ | args = / | ||
+ | } | ||
+ | |||
+ | # " | ||
+ | # needed information and there' | ||
+ | # < | ||
+ | #userdb { | ||
+ | # driver = prefetch | ||
+ | #} | ||
+ | |||
+ | userdb { | ||
+ | driver = sql | ||
+ | args = / | ||
+ | } | ||
+ | |||
+ | # If you don't have any user-specific settings, you can avoid the user_query | ||
+ | # by using userdb static instead of userdb sql, for example: | ||
+ | # < | ||
+ | #userdb { | ||
+ | #driver = static | ||
+ | #args = uid=vmail gid=vmail home=/ | ||
+ | #} | ||
+ | </ | ||
+ | |||
+ | === Speicherung von Passwörtern === | ||
+ | Bevor wir uns nun an die Konfiguration der SQL-Unterstützung an unserem Dovecot machen, wollen wir uns noch kurz überlegen, wie wir die Passworte in der Datenbank ablegen. Die vermutlich vordergründigste, | ||
+ | # grep django /etc/shadow | ||
+ | |||
+ | | ||
+ | |||
+ | Will nun der Server bei der Anmeldung überprüfen benötigt er was? Genau das Passwort in Klartext! denn Nur so ist er in der Lage, den Passworthash des übermittelten Klartextpasswortes mit dem Hash in seiner Datenbank zu vergleichen. Ist nun jemand in der Lage die Übertragung zu kompromittieren, | ||
+ | |||
+ | Mit Hilfe von CRAM((**C**hallenge**R**esponse**A**uthentication**M**ethod)) haben wir nun ein Authentifizierungsverfahren an der Hand, mit der wir das Vorgenannte Problem mit der Übertragung eines Passwortes elegant umschiffen. Denn beim Anmeldevorgang erzeugt der Server bei der Clientanfrage einen individuellen Sitzungsschlüssel, | ||
+ | |||
+ | <WRAP round important> | ||
+ | |||
+ | Nur so ist sichergestellt, | ||
+ | |||
+ | === 10-auth.conf == | ||
+ | Zur Aktivierung des Authentifizierungs-Mechanismus **SQL** müssen wir nun nur noch den richtigen **!include** in der Konfigurationsdatei // | ||
+ | # vim / | ||
+ | <code bash>... | ||
+ | |||
+ | #!include auth-deny.conf.ext | ||
+ | #!include auth-master.conf.ext | ||
+ | |||
+ | # Django : 2014-07-30 | ||
+ | # default: !include auth-system.conf.ext | ||
+ | # Umstellung auf den Authentifizierungs-Mechanismus SQL | ||
+ | #!include auth-system.conf.ext | ||
+ | !include auth-sql.conf.ext | ||
+ | #!include auth-ldap.conf.ext | ||
+ | #!include auth-passwdfile.conf.ext | ||
+ | #!include auth-checkpassword.conf.ext | ||
+ | #!include auth-vpopmail.conf.ext | ||
+ | #!include auth-static.conf.ext | ||
+ | </ | ||
+ | |||
+ | Ferner definieren wir in der // | ||
+ | # vim / | ||
+ | <code bash>... | ||
+ | |||
+ | # Space separated list of wanted authentication mechanisms: | ||
+ | # plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey | ||
+ | # | ||
+ | # NOTE: See also disable_plaintext_auth setting. | ||
+ | # Django : 2014-05-23 | ||
+ | # default: auth_mechanisms = plain | ||
+ | auth_mechanisms = plain login digest-md5 cram-md5 | ||
+ | |||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Somit ergibt sich folgende komplette Konfigurationsdatei | ||
+ | # vim / | ||
+ | <file bash / | ||
+ | ## Authentication processes | ||
+ | ## | ||
+ | |||
+ | # Disable LOGIN command and all other plaintext authentications unless | ||
+ | # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP | ||
+ | # matches the local IP (ie. you're connecting from the same computer), the | ||
+ | # connection is considered secure and plaintext authentication is allowed. | ||
+ | # See also ssl=required setting. | ||
+ | # | ||
+ | |||
+ | # Authentication cache size (e.g. 10M). 0 means it's disabled. Note that | ||
+ | # bsdauth, PAM and vpopmail require cache_key to be set for caching to be used. | ||
+ | # | ||
+ | # Time to live for cached data. After TTL expires the cached record is no | ||
+ | # longer used, *except* if the main database lookup returns internal failure. | ||
+ | # We also try to handle password changes automatically: | ||
+ | # authentication was successful, but this one wasn' | ||
+ | # For now this works only with plaintext authentication. | ||
+ | # | ||
+ | # TTL for negative hits (user not found, password mismatch). | ||
+ | # 0 disables caching them completely. | ||
+ | # | ||
+ | |||
+ | # Space separated list of realms for SASL authentication mechanisms that need | ||
+ | # them. You can leave it empty if you don't want to support multiple realms. | ||
+ | # Many clients simply use the first one listed here, so keep the default realm | ||
+ | # first. | ||
+ | # | ||
+ | |||
+ | # Default realm/ | ||
+ | # SASL realms and appending @domain to username in plaintext logins. | ||
+ | # | ||
+ | |||
+ | # List of allowed characters in username. If the user-given username contains | ||
+ | # a character not listed in here, the login automatically fails. This is just | ||
+ | # an extra check to make sure user can't exploit any potential quote escaping | ||
+ | # vulnerabilities with SQL/LDAP databases. If you want to allow all characters, | ||
+ | # set this value to empty. | ||
+ | # | ||
+ | |||
+ | # Username character translations before it's looked up from databases. The | ||
+ | # value contains series of from -> to characters. For example "# | ||
+ | # that '#' | ||
+ | # | ||
+ | |||
+ | # Username formatting before it's looked up from databases. You can use | ||
+ | # the standard variables here, eg. %Lu would lowercase the username, %n would | ||
+ | # drop away the domain if it was given, or " | ||
+ | # " | ||
+ | # | ||
+ | |||
+ | # If you want to allow master users to log in by specifying the master | ||
+ | # username within the normal username string (ie. not using SASL mechanism' | ||
+ | # support for it), you can specify the separator character here. The format | ||
+ | # is then < | ||
+ | # separator, so that could be a good choice. | ||
+ | # | ||
+ | |||
+ | # Username to use for users logging in with ANONYMOUS SASL mechanism | ||
+ | # | ||
+ | |||
+ | # Maximum number of dovecot-auth worker processes. They' | ||
+ | # blocking passdb and userdb queries (eg. MySQL and PAM). They' | ||
+ | # automatically created and destroyed as needed. | ||
+ | # | ||
+ | |||
+ | # Host name to use in GSSAPI principal names. The default is to use the | ||
+ | # name returned by gethostname(). Use " | ||
+ | # entries. | ||
+ | # | ||
+ | |||
+ | # Kerberos keytab to use for the GSSAPI mechanism. Will use the system | ||
+ | # default (usually / | ||
+ | # the auth service to run as root to be able to read this file. | ||
+ | # | ||
+ | |||
+ | # Do NTLM and GSS-SPNEGO authentication using Samba' | ||
+ | # ntlm_auth helper. < | ||
+ | # | ||
+ | |||
+ | # Path for Samba' | ||
+ | # | ||
+ | |||
+ | # Time to delay before replying to failed authentications. | ||
+ | # | ||
+ | |||
+ | # Require a valid SSL client certificate or the authentication fails. | ||
+ | # | ||
+ | |||
+ | # Take the username from client' | ||
+ | # X509_NAME_get_text_by_NID() which returns the subject' | ||
+ | # CommonName. | ||
+ | # | ||
+ | |||
+ | # Space separated list of wanted authentication mechanisms: | ||
+ | # plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey | ||
+ | # | ||
+ | # NOTE: See also disable_plaintext_auth setting. | ||
+ | # Django : 2014-05-23 | ||
+ | # default: auth_mechanisms = plain | ||
+ | auth_mechanisms = plain login digest-md5 cram-md5 | ||
+ | |||
+ | ## | ||
+ | ## Password and user databases | ||
+ | ## | ||
+ | |||
+ | # | ||
+ | # Password database is used to verify user's password (and nothing more). | ||
+ | # You can have multiple passdbs and userdbs. This is useful if you want to | ||
+ | # allow both system users (/ | ||
+ | # duplicating the system users into virtual database. | ||
+ | # | ||
+ | # < | ||
+ | # | ||
+ | # User database specifies where mails are located and what user/group IDs | ||
+ | # own them. For single-UID configuration use " | ||
+ | # | ||
+ | # < | ||
+ | |||
+ | #!include auth-deny.conf.ext | ||
+ | #!include auth-master.conf.ext | ||
+ | |||
+ | # Django : 2014-07-30 | ||
+ | # default: !include auth-system.conf.ext | ||
+ | # Umstellung auf den Authentifizierungs-Mechanismus passwd-file | ||
+ | #!include auth-system.conf.ext | ||
+ | !include auth-sql.conf.ext | ||
+ | #!include auth-ldap.conf.ext | ||
+ | #!include auth-passwdfile.conf.ext | ||
+ | #!include auth-checkpassword.conf.ext | ||
+ | #!include auth-vpopmail.conf.ext | ||
+ | #!include auth-static.conf.ext | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Testen der Authentifizierung ===== | ||
+ | Mit Hilfe des Befehls **doveadm** können wir sowohl den **// | ||
+ | |||
+ | Die Benutzereingaben sind in der Farbe < | ||
+ | |||
+ | Mit **// | ||
+ | < | ||
+ | <font style=" | ||
+ | </ | ||
+ | < | ||
+ | <font style=" | ||
+ | <font style=" | ||
+ | extra fields: | ||
+ | user=django@nausch.org</ | ||
+ | </ | ||
+ | |||
+ | Beim **// | ||
+ | < | ||
+ | <font style=" | ||
+ | </ | ||
+ | < | ||
+ | <font style=" | ||
+ | uid 10000 | ||
+ | gid 10000 | ||
+ | home / | ||
+ | mail</ | ||
+ | |||
+ | |||
+ | |||
+ | Haben wir die Benutzerauthentifizierung erfolgreich abgeschlossen, | ||
====== Links ====== | ====== Links ====== | ||
Zeile 233: | Zeile 759: | ||
* **[[wiki: | * **[[wiki: | ||
* **[[http:// | * **[[http:// | ||
- | |||
- | ~~DISCUSSION~~ | ||