| 69 | | ||!AppParameters ||scripts\tracd-script.py -p 8080 ... || |
| 70 | | |
| 71 | | Note that, if the !AppDirectory is set as above, the paths of the executable ''and'' of the script name and parameter values are relative to the directory. This makes updating Python a little simpler because the change can be limited, here, to a single point. |
| 72 | | (This is true for the path to the .htpasswd file, as well, despite the documentation calling out the /full/path/to/htpasswd; however, you may not wish to store that file under the Python directory.) |
| 73 | | }}} |
| 74 | | |
| 75 | | For Windows 7 User, srvany.exe may not be an option, so you can use [http://www.google.com/search?q=winserv.exe WINSERV] utility and run: |
| 76 | | {{{ |
| 77 | | "C:\path\to\winserv.exe" install tracd -displayname "tracd" -start auto "C:\path\to\python.exe" c:\path\to\python\scripts\tracd-script.py <your tracd parameters>" |
| 78 | | |
| | 71 | ||!AppParameters ||scripts\tracd.exe -p 8080 ... || |
| | 72 | |
| | 73 | Note that, if the !AppDirectory is set as above, the paths of the executable ''and'' of the script name and parameter values are relative to the directory. This makes updating Python a little simpler because the change can be limited, here, to a single point. |
| | 74 | This is true for the path to the .htpasswd file as well, despite the documentation calling out the /full/path/to/htpasswd; however, you may not wish to store that file under the Python directory. |
| | 75 | }}} |
| | 76 | |
| | 77 | For Windows 7 User, srvany.exe may not be an option, so you can use [https://www.google.com/search?q=winserv.exe WINSERV] utility and run: |
| | 78 | {{{#!cmd |
| | 79 | "C:\path\to\winserv.exe" install tracd -displayname "tracd" -start auto "C:\path\to\python.exe" c:\path\to\python\scripts\tracd.exe <your tracd parameters>" |
| 82 | | === Option 2 === |
| 83 | | |
| 84 | | Use [http://trac-hacks.org/wiki/WindowsServiceScript WindowsServiceScript], available at [http://trac-hacks.org/ Trac Hacks]. Installs, removes, starts, stops, etc. your Trac service. |
| 85 | | |
| 86 | | == Using Authentication == |
| | 83 | === Option 2 |
| | 84 | |
| | 85 | Use [https://trac-hacks.org/wiki/WindowsServiceScript WindowsServiceScript], available at [https://trac-hacks.org/ Trac Hacks]. Installs, removes, starts, stops, etc. your Trac service. |
| | 86 | |
| | 87 | === Option 3 |
| | 88 | |
| | 89 | also cygwin's cygrunsrv.exe can be used: |
| | 90 | {{{#!sh |
| | 91 | $ cygrunsrv --install tracd --path /cygdrive/c/Python27/Scripts/tracd.exe --args '--port 8000 --env-parent-dir E:\IssueTrackers\Trac\Projects' |
| | 92 | $ net start tracd |
| | 93 | }}} |
| | 94 | |
| | 95 | == Using Authentication |
| | 96 | |
| | 97 | Tracd allows you to run Trac without the need for Apache, but you can take advantage of Apache's password tools (`htpasswd` and `htdigest`) to easily create a password file in the proper format for tracd to use in authentication. It is also possible to create the password file without `htpasswd` or `htdigest`; see below for alternatives. |
| | 98 | |
| | 99 | {{{#!div style="border: 1pt dotted; margin: 1em" |
| | 100 | **Attention:** Make sure you place the generated password files on a filesystem which supports sub-second timestamps, as Trac will monitor their modified time and changes happening on a filesystem with too coarse-grained timestamp resolution (like `ext2` or `ext3` on Linux, or HFS+ on OSX). |
| | 101 | }}} |
| | 149 | {{{#!sh |
| | 150 | $ sudo htpasswd -c /path/to/env/.htpasswd username |
| | 151 | }}} |
| | 152 | then for additional users: |
| | 153 | {{{#!sh |
| | 154 | $ sudo htpasswd /path/to/env/.htpasswd username2 |
| | 155 | }}} |
| | 156 | |
| | 157 | Then to start `tracd` run something like this: |
| | 158 | {{{#!sh |
| | 159 | $ tracd -p 8080 --basic-auth="project,/fullpath/environmentname/.htpasswd,realmname" /path/to/project |
| | 160 | }}} |
| | 161 | |
| | 162 | For example: |
| | 163 | {{{#!sh |
| | 164 | $ tracd -p 8080 --basic-auth="project,/srv/tracenv/testenv/.htpasswd,My Test Env" /path/to/project |
| | 165 | }}} |
| | 166 | |
| | 167 | '''Note:''' You might need to pass "-m" as a parameter to htpasswd on some platforms (OpenBSD). |
| | 168 | |
| | 169 | === Digest authentication: Using a htdigest password file |
| | 170 | |
| | 171 | If you have Apache available, you can use the htdigest command to generate the password file. Type 'htdigest' to get some usage instructions, or read [https://httpd.apache.org/docs/2.0/programs/htdigest.html this page] from the Apache manual to get precise instructions. You'll be prompted for a password to enter for each user that you create. For the name of the password file, you can use whatever you like, but if you use something like `users.htdigest` it will remind you what the file contains. As a suggestion, put it in your <projectname>/conf folder along with the [TracIni trac.ini] file. |
| | 172 | |
| | 173 | Note that you can start tracd without the `--auth` argument, but if you click on the ''Login'' link you will get an error. |
| | 174 | |
| | 175 | === Generating Passwords Without Apache |
| | 176 | |
| | 177 | Basic Authorization can be accomplished via this [http://aspirine.org/htpasswd_en.html online HTTP Password generator] which also supports `SHA-1`. Copy the generated password-hash line to the .htpasswd file on your system. Note that Windows Python lacks the "crypt" module that is the default hash type for htpasswd. Windows Python can grok MD5 password hashes just fine and you should use MD5. |
| | 178 | |
| | 179 | Trac also provides `htpasswd` and `htdigest` scripts in [https://trac.edgewall.org/browser/trunk/contrib contrib] (also available in the tar or zip archive): |
| | 180 | {{{#!sh |
| | 181 | $ ./contrib/htpasswd.py -cb htpasswd user1 user1 |
| | 182 | $ ./contrib/htpasswd.py -b htpasswd user2 user2 |
| | 183 | }}} |
| | 184 | |
| | 185 | {{{#!sh |
| | 186 | $ ./contrib/htdigest.py -cb htdigest trac user1 user1 |
| | 187 | $ ./contrib/htdigest.py -b htdigest trac user2 user2 |
| | 188 | }}} |
| | 189 | |
| | 190 | ==== Using `md5sum` |
| | 191 | |
| | 192 | It is possible to use `md5sum` utility to generate digest-password file: |
| | 193 | {{{#!sh |
| | 194 | user= |
| | 195 | realm= |
| | 196 | password= |
| | 197 | path_to_file= |
| | 198 | echo ${user}:${realm}:$(printf "${user}:${realm}:${password}" | md5sum - | sed -e 's/\s\+-//') > ${path_to_file} |
| | 199 | }}} |
| | 200 | |
| | 201 | == Reference |
| | 202 | |
| | 203 | Here's the online help, as a reminder (`tracd -h` or `tracd --help`): |
| 132 | | $ sudo htpasswd -c /path/to/env/.htpasswd username |
| 133 | | }}} |
| 134 | | then for additional users: |
| 135 | | {{{ |
| 136 | | $ sudo htpasswd /path/to/env/.htpasswd username2 |
| 137 | | }}} |
| 138 | | |
| 139 | | Then to start `tracd` run something like this: |
| 140 | | {{{ |
| 141 | | $ tracd -p 8080 --basic-auth="projectdirname,/fullpath/environmentname/.htpasswd,realmname" /fullpath/environmentname |
| 142 | | }}} |
| 143 | | |
| 144 | | For example: |
| 145 | | {{{ |
| 146 | | $ tracd -p 8080 --basic-auth="testenv,/srv/tracenv/testenv/.htpasswd,My Test Env" /srv/tracenv/testenv |
| 147 | | }}} |
| 148 | | ''Note:'' You might need to pass "-m" as a parameter to htpasswd on some platforms (OpenBSD). |
| 149 | | |
| 150 | | === Digest authentication: Using a htdigest password file === |
| 151 | | |
| 152 | | If you have Apache available, you can use the htdigest command to generate the password file. Type 'htdigest' to get some usage instructions, or read [http://httpd.apache.org/docs/2.0/programs/htdigest.html this page] from the Apache manual to get precise instructions. You'll be prompted for a password to enter for each user that you create. For the name of the password file, you can use whatever you like, but if you use something like `users.htdigest` it will remind you what the file contains. As a suggestion, put it in your <projectname>/conf folder along with the [TracIni trac.ini] file. |
| 153 | | |
| 154 | | Note that you can start tracd without the --auth argument, but if you click on the ''Login'' link you will get an error. |
| 155 | | |
| 156 | | === Generating Passwords Without Apache === |
| 157 | | |
| 158 | | Basic Authorization can be accomplished via this [http://www.4webhelp.net/us/password.php online HTTP Password generator]. Copy the generated password-hash line to the .htpasswd file on your system. |
| 159 | | |
| 160 | | You can use this simple Python script to generate a '''digest''' password file: |
| 161 | | |
| 162 | | {{{ |
| 163 | | #!python |
| 164 | | from optparse import OptionParser |
| 165 | | # The md5 module is deprecated in Python 2.5 |
| 166 | | try: |
| 167 | | from hashlib import md5 |
| 168 | | except ImportError: |
| 169 | | from md5 import md5 |
| 170 | | realm = 'trac' |
| 171 | | |
| 172 | | # build the options |
| 173 | | usage = "usage: %prog [options]" |
| 174 | | parser = OptionParser(usage=usage) |
| 175 | | parser.add_option("-u", "--username",action="store", dest="username", type = "string", |
| 176 | | help="the username for whom to generate a password") |
| 177 | | parser.add_option("-p", "--password",action="store", dest="password", type = "string", |
| 178 | | help="the password to use") |
| 179 | | parser.add_option("-r", "--realm",action="store", dest="realm", type = "string", |
| 180 | | help="the realm in which to create the digest") |
| 181 | | (options, args) = parser.parse_args() |
| 182 | | |
| 183 | | # check options |
| 184 | | if (options.username is None) or (options.password is None): |
| 185 | | parser.error("You must supply both the username and password") |
| 186 | | if (options.realm is not None): |
| 187 | | realm = options.realm |
| 188 | | |
| 189 | | # Generate the string to enter into the htdigest file |
| 190 | | kd = lambda x: md5(':'.join(x)).hexdigest() |
| 191 | | print ':'.join((options.username, realm, kd([options.username, realm, options.password]))) |
| 192 | | }}} |
| 193 | | |
| 194 | | Note: If you use the above script you must set the realm in the `--auth` argument to '''`trac`'''. Example usage (assuming you saved the script as trac-digest.py): |
| 195 | | |
| 196 | | {{{ |
| 197 | | $ python trac-digest.py -u username -p password >> c:\digest.txt |
| 198 | | $ tracd --port 8000 --auth=proj_name,c:\digest.txt,trac c:\path\to\proj_name |
| 199 | | }}} |
| 200 | | |
| 201 | | ==== Using `md5sum` |
| 202 | | It is possible to use `md5sum` utility to generate digest-password file: |
| 203 | | {{{ |
| 204 | | $ printf "${user}:trac:${password}" | md5sum - >>user.htdigest |
| 205 | | }}} |
| 206 | | and manually delete " -" from the end and add "${user}:trac:" to the start of line from 'to-file'. |
| 207 | | |
| 208 | | == Reference == |
| 209 | | |
| 210 | | Here's the online help, as a reminder (`tracd --help`): |
| 211 | | {{{ |
| 212 | | Usage: tracd [options] [projenv] ... |
| 213 | | |
| 214 | | Options: |
| | 205 | usage: tracd [-h] [--version] [-e PARENTDIR | -s] |
| | 206 | [-a DIGESTAUTH | --basic-auth BASICAUTH] [-p PORT] [-b HOSTNAME] |
| | 207 | [--protocol {http,https,scgi,ajp,fcgi}] [--certfile CERTFILE] |
| | 208 | [--keyfile KEYFILE] [-q] [--base-path BASE_PATH] |
| | 209 | [--http10 | --http11] [-r | -d] [--pidfile PIDFILE] [--umask MASK] |
| | 210 | [--group GROUP] [--user USER] |
| | 211 | [envs ...] |
| | 212 | |
| | 213 | positional arguments: |
| | 214 | envs path of the project environment(s) |
| | 215 | |
| | 216 | options: |
| | 217 | -h, --help show this help message and exit |
| 224 | | --protocol=PROTOCOL http|scgi|ajp |
| 225 | | -q, --unquote unquote PATH_INFO (may be needed when using ajp) |
| 226 | | --http10 use HTTP/1.0 protocol version (default) |
| 227 | | --http11 use HTTP/1.1 protocol version instead of HTTP/1.0 |
| 228 | | -e PARENTDIR, --env-parent-dir=PARENTDIR |
| 229 | | parent directory of the project environments |
| 230 | | --base-path=BASE_PATH |
| | 229 | --protocol {http,https,scgi,ajp,fcgi} |
| | 230 | the server protocol (default: http) |
| | 231 | --certfile CERTFILE PEM certificate file for HTTPS |
| | 232 | --keyfile KEYFILE PEM key file for HTTPS |
| | 233 | -q, --unquote unquote PATH_INFO (may be needed when using the ajp |
| | 234 | protocol) |
| | 235 | --base-path BASE_PATH |
| 233 | | -s, --single-env only serve a single project without the project list |
| 234 | | }}} |
| 235 | | |
| 236 | | == Tips == |
| 237 | | |
| 238 | | === Serving static content === |
| 239 | | |
| 240 | | If `tracd` is the only web server used for the project, |
| 241 | | it can also be used to distribute static content |
| 242 | | (tarballs, Doxygen documentation, etc.) |
| 243 | | |
| 244 | | This static content should be put in the `$TRAC_ENV/htdocs` folder, |
| 245 | | and is accessed by URLs like `<project_URL>/chrome/site/...`. |
| 246 | | |
| 247 | | Example: given a `$TRAC_ENV/htdocs/software-0.1.tar.gz` file, |
| 248 | | the corresponding relative URL would be `/<project_name>/chrome/site/software-0.1.tar.gz`, |
| 249 | | which in turn can be written as `htdocs:software-0.1.tar.gz` (TracLinks syntax) or `[/<project_name>/chrome/site/software-0.1.tar.gz]` (relative link syntax). |
| 250 | | |
| 251 | | ''Support for `htdocs:` TracLinks syntax was added in version 0.10'' |
| | 240 | -d, --daemonize run in the background as a daemon |
| | 241 | --pidfile PIDFILE file to write pid when daemonizing |
| | 242 | --umask MASK when daemonizing, file mode creation mask to use, in |
| | 243 | octal notation (default: 022) |
| | 244 | --group GROUP the group to run as |
| | 245 | --user USER the user to run as |
| | 246 | }}} |
| | 247 | |
| | 248 | Use the -d option so that tracd doesn't hang if you close the terminal window where tracd was started. |
| | 249 | |
| | 250 | == Tips |
| | 251 | |
| | 252 | === Serving static content |
| | 253 | |
| | 254 | If `tracd` is the only web server used for the project, it can also be used to distribute static content, such as tarballs, Doxygen documentation, etc. |
| | 255 | |
| | 256 | This static content should be put in the `$TRAC_ENV/htdocs` folder, and is accessed by URLs like `<project_URL>/chrome/site/...`. |
| | 257 | |
| | 258 | Example: given a `$TRAC_ENV/htdocs/software-0.1.tar.gz` file, the corresponding relative URL would be `/<project_name>/chrome/site/software-0.1.tar.gz`, which in turn can be written as `htdocs:software-0.1.tar.gz` (TracLinks syntax) or `[/<project_name>/chrome/site/software-0.1.tar.gz]` (relative link syntax). |
| 263 | | === Serving a different base path than / === |
| 264 | | Tracd supports serving projects with different base urls than /<project>. The parameter name to change this is |
| 265 | | {{{ |
| | 270 | === Authentication for tracd behind a proxy |
| | 271 | |
| | 272 | It is convenient to provide central external authentication to your tracd instances, instead of using `--basic-auth`. See also [trac:#9206]. |
| | 273 | |
| | 274 | Below is example configuration based on Apache 2.2, mod_proxy, mod_authnz_ldap. |
| | 275 | |
| | 276 | First we bring tracd into Apache's location namespace. |
| | 277 | |
| | 278 | {{{#!apache |
| | 279 | <Location /project/proxified> |
| | 280 | Require ldap-group cn=somegroup, ou=Groups,dc=domain.com |
| | 281 | Require ldap-user somespecificusertoo |
| | 282 | ProxyPass http://localhost:8101/project/proxified/ |
| | 283 | # Turns out we don't really need complicated RewriteRules here at all |
| | 284 | RequestHeader set REMOTE_USER %{REMOTE_USER}s |
| | 285 | </Location> |
| | 286 | }}} |
| | 287 | |
| | 288 | Then we need a single file plugin to recognize HTTP_REMOTE_USER header as valid authentication source. HTTP headers like '''HTTP_FOO_BAR''' will get converted to '''Foo-Bar''' during processing. Name it something like '''remote-user-auth.py''' and drop it into '''proxified/plugins''' directory: |
| | 289 | {{{#!python |
| | 290 | from trac.core import * |
| | 291 | from trac.config import BoolOption |
| | 292 | from trac.web.api import IAuthenticator |
| | 293 | |
| | 294 | class MyRemoteUserAuthenticator(Component): |
| | 295 | |
| | 296 | implements(IAuthenticator) |
| | 297 | |
| | 298 | obey_remote_user_header = BoolOption('trac', 'obey_remote_user_header', 'false', |
| | 299 | """Whether the 'Remote-User:' HTTP header is to be trusted for user logins |
| | 300 | (''since ??.??').""") |
| | 301 | |
| | 302 | def authenticate(self, req): |
| | 303 | if self.obey_remote_user_header and req.get_header('Remote-User'): |
| | 304 | return req.get_header('Remote-User') |
| | 305 | return None |
| | 306 | |
| | 307 | }}} |
| | 308 | |
| | 309 | Add this new parameter to your TracIni: |
| | 310 | {{{#!ini |
| | 311 | [trac] |
| | 312 | ... |
| | 313 | obey_remote_user_header = true |
| | 314 | ... |
| | 315 | }}} |
| | 316 | |
| | 317 | Run tracd: |
| | 318 | {{{#!sh |
| | 319 | tracd -p 8101 -s proxified --base-path=/project/proxified |
| | 320 | }}} |
| | 321 | |
| | 322 | Note that if you want to install this plugin for all projects, you have to put it in your [TracPlugins#Plugindiscovery global plugins_directory] and enable it in your global `trac.ini`. |
| | 323 | |
| | 324 | Global config (e.g. `/srv/trac/conf/trac.ini`): |
| | 325 | {{{#!ini |
| | 326 | [components] |
| | 327 | remote-user-auth.* = enabled |
| | 328 | [inherit] |
| | 329 | plugins_dir = /srv/trac/plugins |
| | 330 | [trac] |
| | 331 | obey_remote_user_header = true |
| | 332 | }}} |
| | 333 | |
| | 334 | Environment config (e.g. `/srv/trac/envs/myenv`): |
| | 335 | {{{#!ini |
| | 336 | [inherit] |
| | 337 | file = /srv/trac/conf/trac.ini |
| | 338 | }}} |
| | 339 | |
| | 340 | === Serving a different base path than / |
| | 341 | |
| | 342 | Tracd supports serving projects with different base urls than /<project>. The parameter name to change this is: |
| | 343 | {{{#!sh |