README.LDAP 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. If you never heard about LDAP before, *DON'T* enable LDAP support in
  2. Pure-FTPd. LDAP is useless if you don't have to manage many shared accounts.
  3. But well... if you want to learn about LDAP anyway, here's a good starting
  4. point: http://www.openldap.org/
  5. ------------------------ LDAP SUPPORT ------------------------
  6. Pure-FTPd has a built-in support for LDAP directories. When LDAP is
  7. enabled, all account info is fetched from a central LDAP directory.
  8. To compile the server with LDAP support, you first have to build and install
  9. OpenLDAP. OpenLDAP is freely available from http://www.openldap.org/ and
  10. binary packages are included in many major distributions. But if you choose
  11. a binary form, don't forget to also install the development packages if they
  12. are available separately.
  13. Then, configure Pure-FTPd with --with-ldap and your favorite extra gadgets:
  14. ./configure --with-ldap --with-everything
  15. If your LDAP libraries are installed in a special path, you can specify it
  16. like this:
  17. ./configure --with-ldap=/usr/local/openldap
  18. In this example, headers (ldap.h and lber.h files) will be searched in
  19. /usr/local/openldap/include, while related libraries will be searched in
  20. /usr/local/openldap/lib .
  21. Then, install the server as usual:
  22. make install
  23. ------------------------ LDAP CONFIGURATION FILE ------------------------
  24. Before running the server, you have to create a configuration file. Why a
  25. configuration file instead of simple command-line options? you may ask.
  26. Because for security reasons, you may want to hide how to connect to your
  27. LDAP server. And as command-line options can be discovered by local users
  28. (with 'ps auxwww' for instance), it's more secure to use a configuration
  29. file for sensitive data. Keep the file only readable by root (chmod 600) .
  30. Here's a sample configuration file:
  31. LDAPServer ldap.c9x.org
  32. LDAPPort 389
  33. LDAPBaseDN cn=Users,dc=c9x,dc=org
  34. LDAPBindDN cn=Manager,dc=c9x,dc=org
  35. LDAPBindPW r00tPaSsw0rD
  36. LDAPDefaultUID 500
  37. LDAPForceDefaultUID False
  38. LDAPDefaultGID 100
  39. LDAPForceDefaultGID False
  40. Well... the keywords should be self-explanatory, but here we go for some
  41. details anyway:
  42. - LDAPScheme is the scheme (aka protocol) to connect with to the LDAP server.
  43. It defaults to 'ldap'. To connect to a server listening on TLS port, set it
  44. to 'ldaps' (and change the port below).
  45. - LDAPServer is the LDAP server name (hey!) . It defaults to 'localhost'.
  46. - LDAPPort is the connection port. It defaults to 389, the standard port.
  47. Port value should be changed for 'ldaps' connection (the TLS port for an
  48. LDAP server is usually 636).
  49. - LDAPBaseDN is the search starting point for users accounts. Your tree must
  50. have posixAccount objects under that node.
  51. - LDAPBindDN is the DN we should bind the server for simple authentication.
  52. If you don't need authentication (ie. anonymous users can browse that part
  53. of the LDAP directory), just remove that line.
  54. - LDAPBindPW is the plaintext password to bind the previous DN. The
  55. configuration file should be only readable by root if you are using
  56. LDAPBindDN/LDAPBindPW.
  57. - LDAPDefaultUID and LDAPDefaultGID are default values for objects without
  58. any entry for them.
  59. - LDAPForceDefaultUID and LDAPForceDefaultGID - These options both default to
  60. `False`. Any value other than `True` (case insensitive) is also treated as
  61. `False`. When set these options cause the respective uid or gid value returned
  62. by the LDAP server for a username to be ignored and instead use the value set
  63. by `LDAPDefaultUID` or `LDAPDefaultGID`. If the appropriate `LDAPDefaultXID`
  64. option is not set, these options have no effect.
  65. This is useful for allowing users to authenticate against LDAP but access or
  66. create content with common a set of ownership/permissions. It also provides a
  67. measure of security in that it prevents pure-ftpd processes from being created
  68. with arbitrary uid/gids that may conflict with local accounts.
  69. - LDAPFilter is the filter to use in order to find the object to authenticate
  70. against. The special sequence \L is replaced with the login of the user. The
  71. default filter is (&(objectClass=posixAccount)(uid=\L)) .
  72. - LDAPHomeDir is the attribute to get the home directory ('homeDirectory' by
  73. default) .
  74. - LDAPVersion is the protocol version to use. Version 3 is recommended and
  75. needed with OpenLDAP servers. It is the default.
  76. - LDAPUseTLS can be True or False. True means that the server should use TLS
  77. to connect to the LDAP server over ldap protocol. This property has no effect
  78. when ldaps protocol is used, as the connection is inherently secured with TLS.
  79. This was introduced in pure-ftpd 1.0.37.
  80. - LDAPAuthMethod can be BIND (experimental, but default if there is no
  81. LDAPBindDN) or PASSWORD (default if a LDAPBindDN is set). The former tries
  82. to authenticate users by binding, thus allowing to use an unprivileged LDAP
  83. account. The later requires a privileged LDAP accounts and the FTP server
  84. itself checks against the userPassword attribute.
  85. In fact, the only mandatory keyword is LDAPBaseDN. Other keywords are
  86. optional and defaults are ok for local testing.
  87. Save the configuration file anywhere. Let's say /etc/pureftpd-ldap.conf .
  88. Then, you have to run the pure-ftpd command with '-l ldap:' (it's an 'ell'
  89. not a 'one') followed by the path of that configuration file. Here's an
  90. example:
  91. pure-ftpd -l ldap:/etc/pureftpd-ldap.conf -B
  92. You can mix different authentication methods. For instance, if you want to
  93. use system (/etc/passwd) accounts when an account is not found in a LDAP
  94. directory, use -l ldap:/etc/pureftpd-ldap.conf -l unix
  95. ------------------------ THE LDAP SCHEMA ------------------------
  96. Pure-FTPd uses the standard 'posixAccount' class to locate accounts. With
  97. OpenLDAP, that class is defined in the 'nis' schema.
  98. FTP login names should match 'uid' attributes of 'posixAccount' instances.
  99. When a user logs in as 'joe', the following filter is used to locate Joe's
  100. account:
  101. (&(objectClass=posixAccount)(uid=joe))
  102. Here's a sample entry in LDIF format:
  103. dn: cn=Joe,dc=rtchat,dc=com
  104. objectClass: posixAccount
  105. cn: Joe
  106. uid: joe
  107. uidNumber: 500
  108. gidNumber: 100
  109. homeDirectory: /home/joe
  110. userPassword: {scrypt}$7$C6..../....YzvCLmJDYJpH76BxlZB9fCpCEj2AbGQHoLiG9I/VRO1$/enQ.o1BNtmxjxNc/8hbZq8W0JAqR5YpufJXGAdzmf3
  111. 'userPassword' is the password hashed with the system 'crypt' function,
  112. MD5, SHA, SMD5, SSHA, SCRYPT or ARGON2.
  113. Do not use MD5, SHA, SMD5 or SSHA except if you really have to. Use {crypt}
  114. with the strongest algorithm supported by your implementation. Or better,
  115. use {scrypt} or {argon2}.
  116. Please note that a login can only contains common characters: A...Z, a...z,
  117. 0...9, -, ., _, space, :, @ and ' . For paranoia purposes, other characters
  118. are forbidden.
  119. If you don't want to use posixAccount objects, you can edit src/log_ldap.h
  120. to customize attribute names.
  121. ----------- EXTENDED LDAP SCHEMA (QUOTAS, THROTTLING, RATIOS) ----------
  122. To enable quotas, download/upload rate throttling and/or download/upload
  123. ratios, an extended LDAP schema is needed. This modified schema also allows
  124. you to completely enable and disable users' FTP access by simply changing
  125. the "FTPStatus" field in their LDAP entry.
  126. Simply copy the included pureftpd.schema file to your OpenLDAP schema
  127. directory (/usr/local/etc/openldap/schema in this example) and add the
  128. appropriate line to your slapd.conf, like so:
  129. include /usr/local/etc/openldap/pureftpd.schema
  130. This schema defines a new objectClass, PureFTPdUser, which contains the
  131. *OPTIONAL* status, quota, throttling and ratio fields as in the example
  132. below:
  133. dn: uid=Ichiro,dc=gmo,dc=jp
  134. objectClass: PureFTPdUser
  135. objectClass: posixAccount
  136. cn: Ichiro
  137. uid: Ichiro
  138. uidNumber: 888
  139. gidNumber: 888
  140. homeDirectory: /home/ichiro
  141. userPassword: {crypt}$1$w58NLo5z$NHhr6GzSPw0qxaxs3PAaK/
  142. FTPStatus: enabled
  143. FTPQuotaFiles: 50
  144. FTPQuotaMBytes: 10
  145. FTPDownloadBandwidth: 50
  146. FTPUploadBandwidth: 50
  147. FTPDownloadRatio: 5
  148. FTPUploadRatio: 1
  149. The example is mostly self-explanatory. FTPQuotaMBytes is the quota size in
  150. megabytes. FTPDownloadBandwidth and FTPUploadBandwidth are in KB/sec.
  151. FTPStatus should be either "enabled" or "disabled". If the FTPStatus field
  152. exists and is set to anything except "enabled", the user will not be
  153. permitted to log in. If the FTPStatus field does not exist, the user *WILL*
  154. be allowed to log in as normal, to allow LDAP users without the PureFTPdUser
  155. objectClass.
  156. There are also optional FTPuid and FTPgid attributes. If present, they will
  157. override uidNumber and gidNumber values, so that you can have different
  158. uid/gid mapping for FTP and for other services.
  159. Please note that all of the FTP* LDAP fields are optional for the
  160. PureFTPdUser objectClass. You can have a user with just FTPQuotaFiles and
  161. FTPQuotaMBytes set, for example, if you only wish to enforce a quota, but
  162. not throttle the user's bandwidth or enforce ratios.
  163. Of course, you must make sure to enable the features you wish to use at
  164. compile time (--with-quotas, --with-throttling, --with-ratios) .
  165. ------------------------ ANONYMOUS USERS ------------------------
  166. If you want to accept anonymous users on your FTP server, you don't need to
  167. have any 'ftp' user in the LDAP directory. But you need to have a system
  168. 'ftp' account on the FTP server.
  169. ------------------------ ROOT USERS ------------------------
  170. If an LDAP user entry has a root (0) uidNumber and/or gidNumber, Pure-FTPd
  171. will refuse to log them in.
  172. Without this preventive restriction, if your LDAP server ever gets
  173. compromised, the attacker could also easily compromise the FTP server.
  174. ------------------------ ARGON2 ------------------------
  175. Password hashed with argon2i and argon2id can be used, provided that pure-ftpd
  176. was linked to libsodium.
  177. They are expected to be provided as a string, as returned by the
  178. crypto_pwhash_str() function or by its bindings.
  179. ------------------------ SCRYPT ------------------------
  180. Password hashed with scrypt can be used, provided that pure-ftpd was linked to
  181. libsodium.
  182. They are expected to be provided in escrypt format, as returned by the
  183. crypto_pwhash_scryptsalsa208sha256_str() function or by its bindings.
  184. For example, the string $7$C6..../....YzvCLmJDYJpH76BxlZB9fCpCEj2AbGQHoLiG9I/VRO1$/enQ.o1BNtmxjxNc/8hbZq8W0JAqR5YpufJXGAdzmf3
  185. would verify the password "test".