authentication.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. {
  2. title: 'User Authentication',
  3. crumbs: [
  4. { "User's Guide": '../users/' },
  5. ],
  6. }
  7. <h1>User Authentication</h1>
  8. <p>Authentication is the process by which a client's identity and capabilities are verified before granting
  9. access to server resources. Authentication is essential when you have content that you wish to protect and
  10. provide only to specific, approved clients.</p>
  11. <p>GoAhead implements a powerful and flexible authentication framework that verifies username and password and
  12. verifies client capabilities using a role based authorization mechanism.</p>
  13. <h2>Authentication Schemes</h2>
  14. <p>GoAhead provides several authentication protocol schemes.</p>
  15. <ul>
  16. <li><a href="#form">Web Form Authentication</a></li>
  17. <li><a href="#basic">Basic Authentication</a></li>
  18. <li><a href="#digest">Digest Authentication</a></li>
  19. </ul>
  20. <p>The Form authentication scheme uses a HTML web form for the user to enter their username and password
  21. credentials and HTTP Post requests to submit to the server for verification. It may also be used
  22. programmatically va HTTP POST requests.</p>
  23. <p>
  24. <p>The Basic and Digest authentication are HTTP protocol mechanisms defined by the <a href=
  25. "http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP/1.1 RFC2616</a> specification. Because they operate
  26. at the protocol level, they offer a lower level of capability and flexibility. When a client attempts to access
  27. secured content, the client's browser displays a generic pop-up dialog box to prompt for the user's
  28. credentials.</p>
  29. <div class="ui icon message">
  30. <i class="warning icon"></i>
  31. <div class="content">
  32. <div class="header">SECURITY NOTE</div>
  33. <p>You should only use Basic and Digest authentication as a last resort. Basic and Digest authentication
  34. standards employ weak ciphers, repeatedly send credentials over the wire and and are not sufficiently
  35. secure. Basic authentication transmits passwords as clear-text in each and every request. Digest
  36. authentication uses the weak MD5 cipher, and both require use of SSL on all requests to be minimally
  37. secure. Further, both Basic and Digest do not provide a reliable log out mechanism. Logout works on some
  38. browsers but not on others or even different versions of the same browser. We strongly recommend
  39. using Form authentication, with "blowfish" encryption for a more usable, secure and reliable
  40. solution.</p>
  41. </div>
  42. </div>
  43. <a name="configuration"></a>
  44. <h2>Configuration</h2>
  45. <p>Authentication is controlled by two configuration files:</p>
  46. <ul>
  47. <li><i>auth.txt</i> &mdash; which contains authorization directives</li>
  48. <li><i>route.txt</i> &mdash; which contains URI routing directives</li>
  49. </ul>
  50. <p>Together these two files define the authentication scheme to be used for each and every request to
  51. GoAhead. When GoAhead is run, the auth.txt and route.txt file are read and authenticated routes are created
  52. for each specified URI pattern. When client requests are received, they are matched against the URI routes
  53. to find the required authentication scheme. This enables great flexibility as different requests can use
  54. different authentication schemes.</p>
  55. <h3>Authorization Configuration</h3>
  56. <p>The <i>auth.txt</i> file contains <i>user</i> and <i>role</i> definitions to establish an authentication
  57. database. If running on a Unix system, the standard Unix user database may be used instead of defining users in
  58. <i>auth.txt</i>.</p>
  59. <h4>User directive</h4>
  60. <p>Users can be defined via the <i>user</i> directive. This specifies the username, encrypted password
  61. and the authentication roles played by the user.</p>
  62. <h4>Role directive</h4>
  63. <p>Roles can be defined via the <i>role</i> directive. This specifies the role name and a set of ability
  64. words. URI routes may require that a user has certain abilities before access is granted.</p>
  65. <pre class="ui code segment">
  66. role name=manager abilities=view,edit,delete
  67. user name=joshua password=2fd6e47ff9bb70c0465fd2f5c8e5305e roles=manager
  68. </pre>
  69. <h3>Routing</h3>
  70. <p>The <i>route.txt</i> file contains <i>route</i> definitions that specify how each request URI will
  71. be processed and what, if any, kind of authentication will be required for the request. For example:</p>
  72. <pre class="ui code segment">
  73. route uri=/private/ auth=digest abilities=edit
  74. route uri=/cgi-bin handler=cgi
  75. </pre>
  76. <p>The <i>auth</i> keyword takes an argument set to <i>digest</i>, <i>basic</i> or <i>form</i>. The
  77. <i>abilities</i> keyword takes a comma separated list of ability words.</p>
  78. <a id="form"></a>
  79. <h2 >Form Authentication</h2>
  80. <p>The Form authentication scheme uses a standard web page form that prompts for the user to enter their
  81. name and password. This scheme allows the user login interface to have the same look and feel as the rest of the
  82. web application. </p>
  83. <p>The Form authentication scheme submits the username and password to GoAhead via a standard Http POST
  84. request. GoAhead analyzes the user and password, and if authenticated, a login session is created and a cookie
  85. is returned to the users's browser. Subsequent requests that include the cookie will be automatically
  86. authenticated and served. Because the username and password are sent in the clear, it is
  87. important that Form authentication only be used over SSL connections.</p>
  88. <p>The form authentication scheme is enabled via the <i>auth=digest</i> keyword on required routes.
  89. For example:</p>
  90. <pre class="ui code segment">
  91. route uri=/ auth=form handler=continue redirect=401@/login.html
  92. </pre>
  93. <h3>Secure Form-based Authentication</h3>
  94. <p>To effectively secure an application using Form authentication requires five routes to implement
  95. the login and logout process. These are:</p>
  96. <ul>
  97. <li>Route to redirect all HTTP traffic over SSL</li>
  98. <li>Route for the login page which must be accessible when unauthenticated</li>
  99. <li>Route for the login service</li>
  100. <li>Route for the logout service</li>
  101. <li>Route to require authentication for all URIs</li>
  102. </ul>
  103. <p>For example:</p>
  104. <pre class="ui code segment">
  105. route uri=/ protocol=http redirect=*@https handler=redirect
  106. route uri=/pub/
  107. route uri=/proc/login methods=POST handler=proc redirect=200@/ redirect=401@/pub/login.html
  108. route uri=/proc/logout methods=POST handler=proc redirect=200@/pub/login.html
  109. route uri=/ auth=form handler=continue redirect=401@/pub/login.html
  110. </pre>
  111. <h3>Redirect over SSL</h3>
  112. <pre class="ui code segment">route uri=/ protocol=http redirect=*@https handler=redirect</pre>
  113. <p>This directive is responsible for redirecting all HTTP traffic over SSL.
  114. The <i>uri=/</i> defines a URI prefix. Since all URIs start with <i>/</i>, this route will match all requests
  115. that use http:// and not https://.</p>
  116. <h3>Unauthenticated Access to the Login Page</h3>
  117. <pre class="ui code segment">route uri=/pub/</pre>
  118. <p>This directive permits unauthenticated access to any documents in the <i>/pub</i> directory. This is
  119. where the <i>login.html</i> form and any required CSS or Javascript files should be located.</p>
  120. <h3>The Login Service</h3>
  121. <pre class="ui code segment">route uri=/proc/login methods=POST handler=proc redirect=200@/ redirect=401@/pub/login.html</pre>
  122. <p>This directive defines the login service route. The proc handler bind the login service to the URI
  123. <i>/proc/login</i>. This service expects a POST request with username and password form fields. If the
  124. user authenticates, the
  125. user is redirected via <i>redirect=200@/</i>. The redirection form is: STATUS@URI. If the user credentials
  126. cannot be authenticated successfully, the user is redirected back to the login page
  127. via: <i>redirect=401@/pub/login.html</i>.</p>
  128. <h3>The Logout Service</h3>
  129. <pre class="ui code segment">route uri=/proc/logout methods=POST handler=proc redirect=200@/pub/login.html</pre>
  130. <p>This directive defines the logout service. This simply deletes the user's login session and redirects
  131. the user back to the login page.</p>
  132. <h3>Authentication Required</h3>
  133. <pre class="ui code segment">route uri=/ auth=form handler=continue redirect=401@/pub/login.html</pre>
  134. <p>This final directive defines a route that matches all other URIs and stipulates form-based authentication.
  135. The <i>continue</i>
  136. handler authenticates the user and if the user is successfully authenticated, processing continues on
  137. to let other handlers service the request and generate a response. If authentication fails, the user
  138. is redirected back to the login page.</p>
  139. <h3>Web Form</h3>
  140. <p>Here is a minimal example login form:</p>
  141. <pre class="ui code segment">
  142. &lt;html&gt;&lt;head&gt;&lt;title&gt;login.html&lt;/title&gt;&lt;/head&gt;
  143. &lt;body&gt;
  144. &lt;p&gt;Please log in&lt;/p&gt;
  145. &lt;form name="details" method="post" <b>action="/auth/login"</b>&gt;
  146. Username &lt;input type="text" <b>name="username"</b> value=''&gt;&lt;br/&gt;
  147. Password &lt;input type="password" <b>name="password"</b> value=''&gt;&lt;br/&gt;
  148. &lt;input type="submit" name="submit" value="OK"&gt;
  149. &lt;/form&gt;
  150. &lt;/body&gt;
  151. &lt;/html&gt;
  152. </pre>
  153. <p>The two submitted fields must be named <em>username</em> and <em>password</em>. </p>
  154. <h3>Securing the Password</h3>
  155. <p><b>SECURITY WARNING:</b> The Form authentication scheme submits the user password as plain text. To secure
  156. communications, the Form authentication scheme should be used over a secure connection using TLS/SSL.</p>
  157. <a name="basic"></a>
  158. <h2>Basic Authentication</h2>
  159. <p>Basic authentication was the original HTTP/1.0 authentication scheme. It captures usernames and
  160. passwords via a fixed browser-based popup dialog and then transmits credentials
  161. using a trivial encoding that is no better than using plain text.</p>
  162. <p><b>SECURITY WARNING</b>: You should not use Basic Authentication if at all possible. It transmits
  163. user credentials with each request, has no encryption for the password and does not have a means
  164. for users to reliably logout. If you must use Basic Authentication, use it over
  165. TLS/SSL which will encrypt the password over the wire.</p>
  166. <h3>Basic Authentication Directives</h3>
  167. <p>GoAhead basic authorization is defined by specifying <i>auth=basic</i> in the required routes in
  168. <i>route.txt</i>. For example:</p>
  169. <pre class="ui code segment">
  170. # In auth.txt
  171. role name=operator abilities=start,stop
  172. user name=julie password=9d8873a123eb506e7f8e84d1f2a26916 roles=operator
  173. # In route.txt
  174. route uri=/machinery auth=basic abilities=start,stop
  175. </pre>
  176. <p>This example restricts access to URIs beginning with "/machinery". It permits access to the users with
  177. the <i>start, stop</i> abilities. This means that the user "julie" will be granted access once authenticated.</p>
  178. <p>The <i>auth=basic</i>keyword specifies that basic authorization is being
  179. used. The Authentication Realm used by Basic and Digest authentication is set when GoAhead is built via
  180. the <em>realm</em> property in the main.me configuration file. The realm is used in combination with
  181. the username and password to encrypt the password.</p>
  182. <a id="digest"></a>
  183. <h2>Digest Authentication</h2>
  184. <p>The Digest authentication scheme
  185. cryptographic techniques is a minor improvement over the Basic scheme. It captures usernames and
  186. passwords via a fixed browser-based popup dialog and then transmits credentials
  187. using the weak MD5 encoding format.</p>
  188. <p><b>SECURITY WARNING</b>: You should not use Digest Authentication if at all possible. It transmits
  189. user credentials with each request, has weak encryption for the password and does not have a means
  190. for users to reliably logout. If you must use Digest Authentication, use it over
  191. TLS/SSL which will securely encrypt the credentials over the wire.</p>
  192. <p>GoAhead digest authorization is very similar to Basic authentication and is
  193. is controlled by the <i>auth=digest</i> keyword on required routes.</p>
  194. <a id="stores"></a>
  195. <h2 >Password Stores</h2>
  196. <p>GoAhead can be built to retrieve passwords from the Unix system password database or from password text
  197. configuration file.
  198. The Unix system password database is managed via the <a href="http://kb.iu.edu/data/anpn.html">PAM</a>
  199. interface. GoAhead can be configured to use PAM with the command:</p>
  200. <pre class="ui code segment">configure --set pam=true</pre>
  201. <h3>Determining Abilities with PAM</h3>
  202. <p>When using PAM, <i>user</i> records are not required in auth.txt. However, to determine the users's
  203. abilities, the Unix group membership for the user and role definitions are used. For each Unix group that
  204. the user is a member of, a corresponding <i>role</i> in auth.txt is checked. If a role of the same name as the
  205. group exists, the abilities specified by that role are added to the set of abilities for the user. In other
  206. words, you should create a role definition for each group in <i>auth.txt</i> that will specify the abilities for
  207. users in that Unix group. For example, say a user joshua was a member of the Unix group "staff". The following
  208. auth.txt definitions would give joshua the abilities: <i>add,edit,delete</i>.</p>
  209. <pre class="ui code segment">
  210. Role staff add,edit,delete
  211. </pre>
  212. <a name="gopass"></a>
  213. <h2 >Password Program</h2>
  214. <p>To create the required encrypted password fields for <i>user</i> definitions, the <em>gopass</em> program
  215. is used. It can generate passwords and edit the <i>auth.txt</i> with updated user definitions.
  216. The command line syntax for gopass is:</p>
  217. <pre class="ui code segment">
  218. gopass [--cipher cipher] [--file path] [--password password] realm user roles...
  219. </pre>
  220. <p>The file parameter specifies the name of the authentication file which is typically "auth.txt".
  221. If the --file option is omitted, the calculated hash for the password will be displayed to the console.
  222. If the --password option is omitted, gopass will prompt for the password.
  223. The realm is the name specified by the <em>realm</em> property in the main.me configuration
  224. file when GoAhead was built. It defaults to: "example.com". You may set this to any string you like.
  225. If you are using Basic or Digest authentication, this string will be displayed at the top of the login
  226. popup dialog. If using Form authentication, it is never displayed to the user and is only used to salt
  227. the encryption of the passwords.</p>
  228. <p>The gopass program supports the MD5 and Blowfish ciphers. MD5 must be used if you are using digest
  229. authentication. If using a web-based authentication scheme, it is strongly advised that you use the
  230. blowfish cipher as it is much more resistant to cracking the password hashes.</p>
  231. <p><b>SECURITY WARNING</b>: it is essential that the authentication file be stored outside
  232. the DocumentRoot or any directory serving content.</p>