authentication.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>User Authentication</title>
  5. <!-- Copyright Embedthis Software. All Rights Reserved. -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <meta charset="utf-8" />
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  10. <meta name="description" content="Simple, fast, secure embedded web server" />
  11. <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Open+Sans:300italic,400,300,700'
  12. rel='stylesheet' type='text/css'>
  13. <link href='https://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
  14. <link href="../images/favicon.ico" rel="shortcut icon" />
  15. <link href="../lib/semantic-ui/semantic.min.css" rel="stylesheet" type="text/css" />
  16. <link href="../css/all.min.css" rel="stylesheet" type="text/css" />
  17. <link href="../css/api.min.css" rel="stylesheet" type="text/css" />
  18. </head>
  19. <body class="show-sidebar">
  20. <div class="sidebar">
  21. <div class="ui large left vertical inverted labeled menu">
  22. <div class="item">
  23. <a href="../" class="logo">GoAhead Docs</a>
  24. </div>
  25. <div class="item">
  26. <a href="../">
  27. <b>General</b>
  28. </a>
  29. <div class="menu">
  30. <a class="item" href="../">GoAhead Overview</a>
  31. <a class="item" href="../users/features.html">GoAhead Features</a>
  32. <a class="item" href="https://embedthis.com/goahead/download.html">Download</a>
  33. <a class="item" href="../licensing/">Licensing</a>
  34. </div>
  35. </div>
  36. <div class="item">
  37. <a href="../start/">
  38. <b>Getting Started</b>
  39. </a>
  40. <div class="menu">
  41. <a class="item" href="../start/quick.html">Quick Start</a>
  42. <a class="item" href="../start/installing.html">Installing GoAhead</a>
  43. <a class="item" href="../start/running.html">Running GoAhead</a>
  44. <a class="item" href="../start/releaseNotes.html">Release Notes</a>
  45. <a class="item" href="../start/faq.html">GoAhead FAQ</a>
  46. <a class="item" href="../start/source.html">Building from Source</a>
  47. </div>
  48. </div>
  49. <div class="item">
  50. <a href="../users/"><b>User's Guide</b></a>
  51. <div class="menu">
  52. <a class="item" href="../users/ports.html">Ports and Binding</a>
  53. <a class="item" href="../users/routing.html">Routing Requests</a>
  54. <a class="item" href="../users/handlers.html">Request Handlers</a>
  55. <a class="item" href="../users/js.html">Embedded Javascript</a>
  56. <a class="item" href="../users/jst.html">Javascript Templates</a>
  57. <a class="item" href="../users/goactions.html">GoActions</a>
  58. <a class="item" href="../users/cgi.html">CGI Programs</a>
  59. <a class="item" href="../users/authentication.html">User Authentication</a>
  60. <a class="item" href="../users/logFiles.html">Log Files</a>
  61. <a class="item" href="../users/ssl.html">Secure Sockets (SSL)</a>
  62. <a class="item" href="../users/security.html">Security Considerations</a>
  63. <a class="item" href="../users/man.html">Man Pages</a>
  64. </div>
  65. </div>
  66. <div class="item">
  67. <a href="../developers/">Developer's Guide</a>
  68. <div class="menu">
  69. <a class="item" href="../developers/embedding.html">Embedding GoAhead</a>
  70. <a class="item" href="../developers/handlers.html">Creating GoAhead Handlers</a>
  71. <a class="item" href="../developers/authstore.html">Creating Password Verifiers</a>
  72. <a class="item" href="../developers/migrating.html">Migrating to GoAhead 3</a>
  73. <a class="item" href="../developers/rom.html">Serving Pages from ROM</a>
  74. </div>
  75. </div>
  76. <div class="item">
  77. <a href="../ref/">Reference Guide</a>
  78. <div class="menu">
  79. <a class="item" href="../ref/compatibility.html">Compatibility</a>
  80. <a class="item" href="../ref/native.html">API Library</a>
  81. <a class="item" href="../ref/architecture.html">GoAhead Architecture</a>
  82. <a class="item" href="../standards/http.html">HTTP References</a>
  83. </div>
  84. </div>
  85. <div class="item">
  86. <a href="../developers/project.html">Project Resources</a>
  87. <div class="menu">
  88. <a class="item" href="http://goo.gl/IGbiio">Official GoAhead News</a>
  89. <a class="item" href="https://embedthis.com/goahead/">GoAhead Web Site</a>
  90. <a class="item" href="https://github.com/embedthis/goahead">Source Code Repository</a>
  91. <a class="item" href="https://github.com/embedthis/goahead/issues/99">GoAhead Security Alerts</a>
  92. <a class="item" href="https://github.com/embedthis/goahead/issues">Project Issue Database</a>
  93. <a class="item" href="https://github.com/embedthis/goahead/releases">Change Log</a>
  94. <a class="item" href="https://github.com/embedthis/goahead/milestones">Roadmap</a>
  95. <a class="item" href="https://embedthis.com/developers/contributors.html">Contributors Agreement</a>
  96. </div>
  97. </div>
  98. <div class="item">
  99. <b>Links</b>
  100. <div class="menu">
  101. <a class="item" href="https://embedthis.com/">Embedthis Web Site</a>
  102. <a class="item" href="https://embedthis.com/blog/">Embedthis Blog</a>
  103. <a class="item" href="http://twitter.com/embedthat">Twitter</a>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="ui inverted masthead">
  109. <div class="ui fixed inverted menu">
  110. <div class="ui sidebar-launch button">
  111. <i class="icon list layout"></i>
  112. </div>
  113. <div class="right menu">
  114. <a class="item" href="https://embedthis.com/">Embedthis</a>
  115. <a class="item" href="https://embedthis.com/goahead/">GoAhead Site</a>
  116. <span class="desktop-only">
  117. <a class="item" href="http://goo.gl/9bL9rM">GoAhead News</a>
  118. <a class="item" href="https://github.com/embedthis/goahead">Repository</a>
  119. <a class="item" href="https://embedthis.com/blog/">Blog</a>
  120. <a class="item" href="https://twitter.com/embedthat">Twitter</a>
  121. </span>
  122. </div>
  123. </div>
  124. <div class="ui breadcrumb">
  125. <a class="section" href="../">Home</a>
  126. <div class="divider">/</div>
  127. <a class="section" href="../users/">
  128. User's Guide
  129. </a>
  130. <div class="divider">/</div>
  131. <a class="active section" href="authentication.html">User Authentication</a>
  132. </div>
  133. <iframe class="version desktop-only" src="../version.html"></iframe>
  134. </div>
  135. <div class="content">
  136. <h1>User Authentication</h1>
  137. <p>Authentication is the process by which a client's identity and capabilities are verified before granting
  138. access to server resources. Authentication is essential when you have content that you wish to protect and
  139. provide only to specific, approved clients.</p>
  140. <p>GoAhead implements a powerful and flexible authentication framework that verifies username and password and
  141. verifies client capabilities using a role based authorization mechanism.</p>
  142. <h2>Authentication Schemes</h2>
  143. <p>GoAhead provides several authentication protocol schemes.</p>
  144. <ul>
  145. <li><a href="#form">Web Form Authentication</a></li>
  146. <li><a href="#basic">Basic Authentication</a></li>
  147. <li><a href="#digest">Digest Authentication</a></li>
  148. </ul>
  149. <p>The Form authentication scheme uses a HTML web form for the user to enter their username and password
  150. credentials and HTTP Post requests to submit to the server for verification. It may also be used
  151. programmatically va HTTP POST requests.</p>
  152. <p>
  153. <p>The Basic and Digest authentication are HTTP protocol mechanisms defined by the <a href=
  154. "http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP/1.1 RFC2616</a> specification. Because they operate
  155. at the protocol level, they offer a lower level of capability and flexibility. When a client attempts to access
  156. secured content, the client's browser displays a generic pop-up dialog box to prompt for the user's
  157. credentials.</p>
  158. <div class="ui icon message">
  159. <i class="warning icon"></i>
  160. <div class="content">
  161. <div class="header">SECURITY NOTE</div>
  162. <p>You should only use Basic and Digest authentication as a last resort. Basic and Digest authentication
  163. standards employ weak ciphers, repeatedly send credentials over the wire and and are not sufficiently
  164. secure. Basic authentication transmits passwords as clear-text in each and every request. Digest
  165. authentication uses the weak MD5 cipher, and both require use of SSL on all requests to be minimally
  166. secure. Further, both Basic and Digest do not provide a reliable log out mechanism. Logout works on some
  167. browsers but not on others or even different versions of the same browser. We strongly recommend
  168. using Form authentication, with "blowfish" encryption for a more usable, secure and reliable
  169. solution.</p>
  170. </div>
  171. </div>
  172. <a name="configuration"></a>
  173. <h2>Configuration</h2>
  174. <p>Authentication is controlled by two configuration files:</p>
  175. <ul>
  176. <li><i>auth.txt</i> &mdash; which contains authorization directives</li>
  177. <li><i>route.txt</i> &mdash; which contains URI routing directives</li>
  178. </ul>
  179. <p>Together these two files define the authentication scheme to be used for each and every request to
  180. GoAhead. When GoAhead is run, the auth.txt and route.txt file are read and authenticated routes are created
  181. for each specified URI pattern. When client requests are received, they are matched against the URI routes
  182. to find the required authentication scheme. This enables great flexibility as different requests can use
  183. different authentication schemes.</p>
  184. <h3>Authorization Configuration</h3>
  185. <p>The <i>auth.txt</i> file contains <i>user</i> and <i>role</i> definitions to establish an authentication
  186. database. If running on a Unix system, the standard Unix user database may be used instead of defining users in
  187. <i>auth.txt</i>.</p>
  188. <h4>User directive</h4>
  189. <p>Users can be defined via the <i>user</i> directive. This specifies the username, encrypted password
  190. and the authentication roles played by the user.</p>
  191. <h4>Role directive</h4>
  192. <p>Roles can be defined via the <i>role</i> directive. This specifies the role name and a set of ability
  193. words. URI routes may require that a user has certain abilities before access is granted.</p>
  194. <pre class="ui code segment">
  195. role name=manager abilities=view,edit,delete
  196. user name=joshua password=2fd6e47ff9bb70c0465fd2f5c8e5305e roles=manager
  197. </pre>
  198. <h3>Routing</h3>
  199. <p>The <i>route.txt</i> file contains <i>route</i> definitions that specify how each request URI will
  200. be processed and what, if any, kind of authentication will be required for the request. For example:</p>
  201. <pre class="ui code segment">
  202. route uri=/private/ auth=digest abilities=edit
  203. route uri=/cgi-bin handler=cgi
  204. </pre>
  205. <p>The <i>auth</i> keyword takes an argument set to <i>digest</i>, <i>basic</i> or <i>form</i>. The
  206. <i>abilities</i> keyword takes a comma separated list of ability words.</p>
  207. <a id="form"></a>
  208. <h2 >Form Authentication</h2>
  209. <p>The Form authentication scheme uses a standard web page form that prompts for the user to enter their
  210. name and password. This scheme allows the user login interface to have the same look and feel as the rest of the
  211. web application. </p>
  212. <p>The Form authentication scheme submits the username and password to GoAhead via a standard Http POST
  213. request. GoAhead analyzes the user and password, and if authenticated, a login session is created and a cookie
  214. is returned to the users's browser. Subsequent requests that include the cookie will be automatically
  215. authenticated and served. Because the username and password are sent in the clear, it is
  216. important that Form authentication only be used over SSL connections.</p>
  217. <p>The form authentication scheme is enabled via the <i>auth=digest</i> keyword on required routes.
  218. For example:</p>
  219. <pre class="ui code segment">
  220. route uri=/ auth=form handler=continue redirect=401@/login.html
  221. </pre>
  222. <h3>Secure Form-based Authentication</h3>
  223. <p>To effectively secure an application using Form authentication requires five routes to implement
  224. the login and logout process. These are:</p>
  225. <ul>
  226. <li>Route to redirect all HTTP traffic over SSL</li>
  227. <li>Route for the login page which must be accessible when unauthenticated</li>
  228. <li>Route for the login service</li>
  229. <li>Route for the logout service</li>
  230. <li>Route to require authentication for all URIs</li>
  231. </ul>
  232. <p>For example:</p>
  233. <pre class="ui code segment">
  234. route uri=/ protocol=http redirect=*@https handler=redirect
  235. route uri=/pub/
  236. route uri=/proc/login methods=POST handler=proc redirect=200@/ redirect=401@/pub/login.html
  237. route uri=/proc/logout methods=POST handler=proc redirect=200@/pub/login.html
  238. route uri=/ auth=form handler=continue redirect=401@/pub/login.html
  239. </pre>
  240. <h3>Redirect over SSL</h3>
  241. <pre class="ui code segment">route uri=/ protocol=http redirect=*@https handler=redirect</pre>
  242. <p>This directive is responsible for redirecting all HTTP traffic over SSL.
  243. The <i>uri=/</i> defines a URI prefix. Since all URIs start with <i>/</i>, this route will match all requests
  244. that use http:// and not https://.</p>
  245. <h3>Unauthenticated Access to the Login Page</h3>
  246. <pre class="ui code segment">route uri=/pub/</pre>
  247. <p>This directive permits unauthenticated access to any documents in the <i>/pub</i> directory. This is
  248. where the <i>login.html</i> form and any required CSS or Javascript files should be located.</p>
  249. <h3>The Login Service</h3>
  250. <pre class="ui code segment">route uri=/proc/login methods=POST handler=proc redirect=200@/ redirect=401@/pub/login.html</pre>
  251. <p>This directive defines the login service route. The proc handler bind the login service to the URI
  252. <i>/proc/login</i>. This service expects a POST request with username and password form fields. If the
  253. user authenticates, the
  254. user is redirected via <i>redirect=200@/</i>. The redirection form is: STATUS@URI. If the user credentials
  255. cannot be authenticated successfully, the user is redirected back to the login page
  256. via: <i>redirect=401@/pub/login.html</i>.</p>
  257. <h3>The Logout Service</h3>
  258. <pre class="ui code segment">route uri=/proc/logout methods=POST handler=proc redirect=200@/pub/login.html</pre>
  259. <p>This directive defines the logout service. This simply deletes the user's login session and redirects
  260. the user back to the login page.</p>
  261. <h3>Authentication Required</h3>
  262. <pre class="ui code segment">route uri=/ auth=form handler=continue redirect=401@/pub/login.html</pre>
  263. <p>This final directive defines a route that matches all other URIs and stipulates form-based authentication.
  264. The <i>continue</i>
  265. handler authenticates the user and if the user is successfully authenticated, processing continues on
  266. to let other handlers service the request and generate a response. If authentication fails, the user
  267. is redirected back to the login page.</p>
  268. <h3>Web Form</h3>
  269. <p>Here is a minimal example login form:</p>
  270. <pre class="ui code segment">
  271. &lt;html&gt;&lt;head&gt;&lt;title&gt;login.html&lt;/title&gt;&lt;/head&gt;
  272. &lt;body&gt;
  273. &lt;p&gt;Please log in&lt;/p&gt;
  274. &lt;form name="details" method="post" <b>action="/auth/login"</b>&gt;
  275. Username &lt;input type="text" <b>name="username"</b> value=''&gt;&lt;br/&gt;
  276. Password &lt;input type="password" <b>name="password"</b> value=''&gt;&lt;br/&gt;
  277. &lt;input type="submit" name="submit" value="OK"&gt;
  278. &lt;/form&gt;
  279. &lt;/body&gt;
  280. &lt;/html&gt;
  281. </pre>
  282. <p>The two submitted fields must be named <em>username</em> and <em>password</em>. </p>
  283. <h3>Securing the Password</h3>
  284. <p><b>SECURITY WARNING:</b> The Form authentication scheme submits the user password as plain text. To secure
  285. communications, the Form authentication scheme should be used over a secure connection using TLS/SSL.</p>
  286. <a name="basic"></a>
  287. <h2>Basic Authentication</h2>
  288. <p>Basic authentication was the original HTTP/1.0 authentication scheme. It captures usernames and
  289. passwords via a fixed browser-based popup dialog and then transmits credentials
  290. using a trivial encoding that is no better than using plain text.</p>
  291. <p><b>SECURITY WARNING</b>: You should not use Basic Authentication if at all possible. It transmits
  292. user credentials with each request, has no encryption for the password and does not have a means
  293. for users to reliably logout. If you must use Basic Authentication, use it over
  294. TLS/SSL which will encrypt the password over the wire.</p>
  295. <h3>Basic Authentication Directives</h3>
  296. <p>GoAhead basic authorization is defined by specifying <i>auth=basic</i> in the required routes in
  297. <i>route.txt</i>. For example:</p>
  298. <pre class="ui code segment">
  299. # In auth.txt
  300. role name=operator abilities=start,stop
  301. user name=julie password=9d8873a123eb506e7f8e84d1f2a26916 roles=operator
  302. # In route.txt
  303. route uri=/machinery auth=basic abilities=start,stop
  304. </pre>
  305. <p>This example restricts access to URIs beginning with "/machinery". It permits access to the users with
  306. the <i>start, stop</i> abilities. This means that the user "julie" will be granted access once authenticated.</p>
  307. <p>The <i>auth=basic</i>keyword specifies that basic authorization is being
  308. used. The Authentication Realm used by Basic and Digest authentication is set when GoAhead is built via
  309. the <em>realm</em> property in the main.me configuration file. The realm is used in combination with
  310. the username and password to encrypt the password.</p>
  311. <a id="digest"></a>
  312. <h2>Digest Authentication</h2>
  313. <p>The Digest authentication scheme
  314. cryptographic techniques is a minor improvement over the Basic scheme. It captures usernames and
  315. passwords via a fixed browser-based popup dialog and then transmits credentials
  316. using the weak MD5 encoding format.</p>
  317. <p><b>SECURITY WARNING</b>: You should not use Digest Authentication if at all possible. It transmits
  318. user credentials with each request, has weak encryption for the password and does not have a means
  319. for users to reliably logout. If you must use Digest Authentication, use it over
  320. TLS/SSL which will securely encrypt the credentials over the wire.</p>
  321. <p>GoAhead digest authorization is very similar to Basic authentication and is
  322. is controlled by the <i>auth=digest</i> keyword on required routes.</p>
  323. <a id="stores"></a>
  324. <h2 >Password Stores</h2>
  325. <p>GoAhead can be built to retrieve passwords from the Unix system password database or from password text
  326. configuration file.
  327. The Unix system password database is managed via the <a href="http://kb.iu.edu/data/anpn.html">PAM</a>
  328. interface. GoAhead can be configured to use PAM with the command:</p>
  329. <pre class="ui code segment">configure --set pam=true</pre>
  330. <h3>Determining Abilities with PAM</h3>
  331. <p>When using PAM, <i>user</i> records are not required in auth.txt. However, to determine the users's
  332. abilities, the Unix group membership for the user and role definitions are used. For each Unix group that
  333. 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
  334. group exists, the abilities specified by that role are added to the set of abilities for the user. In other
  335. words, you should create a role definition for each group in <i>auth.txt</i> that will specify the abilities for
  336. users in that Unix group. For example, say a user joshua was a member of the Unix group "staff". The following
  337. auth.txt definitions would give joshua the abilities: <i>add,edit,delete</i>.</p>
  338. <pre class="ui code segment">
  339. Role staff add,edit,delete
  340. </pre>
  341. <a name="gopass"></a>
  342. <h2 >Password Program</h2>
  343. <p>To create the required encrypted password fields for <i>user</i> definitions, the <em>gopass</em> program
  344. is used. It can generate passwords and edit the <i>auth.txt</i> with updated user definitions.
  345. The command line syntax for gopass is:</p>
  346. <pre class="ui code segment">
  347. gopass [--cipher cipher] [--file path] [--password password] realm user roles...
  348. </pre>
  349. <p>The file parameter specifies the name of the authentication file which is typically "auth.txt".
  350. If the --file option is omitted, the calculated hash for the password will be displayed to the console.
  351. If the --password option is omitted, gopass will prompt for the password.
  352. The realm is the name specified by the <em>realm</em> property in the main.me configuration
  353. file when GoAhead was built. It defaults to: "example.com". You may set this to any string you like.
  354. If you are using Basic or Digest authentication, this string will be displayed at the top of the login
  355. popup dialog. If using Form authentication, it is never displayed to the user and is only used to salt
  356. the encryption of the passwords.</p>
  357. <p>The gopass program supports the MD5 and Blowfish ciphers. MD5 must be used if you are using digest
  358. authentication. If using a web-based authentication scheme, it is strongly advised that you use the
  359. blowfish cipher as it is much more resistant to cracking the password hashes.</p>
  360. <p><b>SECURITY WARNING</b>: it is essential that the authentication file be stored outside
  361. the DocumentRoot or any directory serving content.</p>
  362. </div>
  363. <div class="terms ui basic center aligned segment">
  364. <p>&copy; Embedthis Software, 2003-2015. All rights reserved.</p>
  365. </div>
  366. <script src="../lib/jquery/jquery.min.js"></script>
  367. <script src="../lib/semantic-ui/semantic.min.js"></script>
  368. <script src="../scripts/sidebar.min.js"></script>
  369. </body>
  370. </html>