Edgewall Software

Changes between Version 6 and Version 7 of 0.12/TracStandalone


Ignore:
Timestamp:
Jul 16, 2012, 9:16:12 PM (12 years ago)
Author:
trac
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • 0.12/TracStandalone

    v6 v7  
    1 ** Note: this page was used to prepare the 0.12 version of wiki:/TracStandalone, see now directly that toplevel page **
     1** Note: this page documents the 0.12 version of Trac, see [[0.11/TracStandalone]] if you need the previous version **
    22= Tracd =
    33
     
    6161The spacing here is important.
    6262
     63{{{#!div
     64Once the service is installed, it might be simpler to run the Registry Editor rather than use the `reg add` command documented above.  Navigate to:[[BR]]
     65`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tracd\Parameters`
     66
     67Three (string) parameters are provided:
     68||!AppDirectory ||C:\Python26\ ||
     69||Application ||python.exe ||
     70||!AppParameters ||scripts\tracd-script.py -p 8080 ... ||
     71
     72Note 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.
     73(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.)
     74}}}
     75
    6376For 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:
    6477{{{
     
    7285Use [http://trac-hacks.org/wiki/WindowsServiceScript WindowsServiceScript], available at [http://trac-hacks.org/ Trac Hacks]. Installs, removes, starts, stops, etc. your Trac service.
    7386
     87=== Option 3 ===
     88
     89also cygwin's cygrunsrv.exe can be used:
     90{{{
     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
    7495== Using Authentication ==
    7596
    76 Using tracd with Apache .htpasswd files:
    77 
    78 To create a .htpasswd file using htpasswd:
    79 
    80 {{{
    81  $ sudo htpasswd -c /path/to/env/.htpasswd username
    82 }}}
    83 then for additional users:
    84 {{{
    85  $ sudo htpasswd /path/to/env/.htpasswd username2
    86 }}}
    87 then for starting the tracd (on windows skip the "=" after --basic-auth):
    88 {{{
    89 tracd -p 8080 --basic-auth=environmentname,/fullpath/environmentname/.htpasswd,/fullpath/environmentname /fullpath/environmentname
    90 }}}
    91 
    92  `environmentname` is the directory name of the Trac project folder, as opposed to `/fullpath/environmentname` which is the full path to the Trac project folder. See below for another example.
    93 
    94 Tracd provides support for both Basic and Digest authentication. The default is to use Digest; to use Basic authentication, replace `--auth` with `--basic-auth` in the examples below. (You must still specify a dialogic "realm", which can be an empty string by trailing the BASICAUTH with a comma.)
    95 
    96   ''Support for Basic authentication was added in version 0.9.''
    97 
    98 The general format for using authentication is (replace `--auth` with `--basic-auth` if you want to use Basic auth):
    99 
     97Tracd provides support for both Basic and Digest authentication. Digest is considered more secure. The examples below use Digest; to use Basic authentication, replace `--auth` with `--basic-auth` in the command line.
     98
     99The general format for using authentication is:
    100100{{{
    101101 $ tracd -p port --auth="base_project_dir,password_file_path,realm" project_path
    102102}}}
    103 
    104103where:
    105 
    106104 * '''base_project_dir''': the base directory of the project specified as follows:
    107    * when serving multiple projects: ''relative'' to the `project_bath`
     105   * when serving multiple projects: ''relative'' to the `project_path`
    108106   * when serving only a single project (`-s`): the name of the project directory
    109107 Don't use an absolute path here as this won't work. ''Note:'' This parameter is case-sensitive even for environments on Windows.
     
    112110 * '''project_path''': path of the project
    113111
     112 * **`--auth`** in the above means use Digest authentication, replace `--auth` with `--basic-auth` if you want to use Basic auth.  Although Basic authentication does not require a "realm", the command parser does, so the second comma is required, followed directly by the closing quote for an empty realm name.
     113
    114114Examples:
    115115
     
    134134}}}
    135135
    136 === Using a htpasswd password file ===
     136=== Basic Authorization: Using a htpasswd password file ===
    137137This section describes how to use `tracd` with Apache .htpasswd files.
    138138
     139  Note: It is necessary (at least with Python 2.6) to install the fcrypt package in order to
     140  decode the htpasswd format.  Trac source code attempt an `import crypt` first, but there
     141  is no such package for Python 2.6.
     142
    139143To create a .htpasswd file use Apache's `htpasswd` command (see [#GeneratingPasswordsWithoutApache below] for a method to create these files without using Apache):
    140 
    141144{{{
    142145 $ sudo htpasswd -c /path/to/env/.htpasswd username
     
    148151
    149152Then to start `tracd` run something like this:
    150 
    151153{{{
    152154 $ tracd -p 8080 --basic-auth="projectdirname,/fullpath/environmentname/.htpasswd,realmname" /fullpath/environmentname
     
    154156
    155157For example:
    156 
    157158{{{
    158159 $ tracd -p 8080 --basic-auth="testenv,/srv/tracenv/testenv/.htpasswd,My Test Env" /srv/tracenv/testenv
    159160}}}
    160 
    161161''Note:'' You might need to pass "-m" as a parameter to htpasswd on some platforms (OpenBSD).
    162162
    163 === Using a htdigest password file ===
     163=== Digest authentication: Using a htdigest password file ===
    164164
    165165If 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.
     
    169169=== Generating Passwords Without Apache ===
    170170
    171 If you don't have Apache available, you can use this simple Python script to generate your passwords:
     171Basic Authorization can be accomplished via this [http://aspirine.org/htpasswd_en.html online HTTP Password generator].  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.
     172
     173You can use this simple Python script to generate a '''digest''' password file:
    172174
    173175{{{
     
    203205}}}
    204206
    205 Note: If you use the above script you must use the --auth option to tracd, not --basic-auth, and you must set the realm in the --auth value to 'trac' (without the quotes). Example usage (assuming you saved the script as trac-digest.py):
     207Note: 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):
    206208
    207209{{{
     
    210212}}}
    211213
    212 
    213 Note: If you would like to use --basic-auth you need to use htpasswd tool from apache server to generate .htpasswd file. The remaining part is similar but make sure to use empty realm (i.e. coma after path). Make sure to use -m option for it.  If you do not have Apache, [trac:source:/tags/trac-0.11/contrib/htpasswd.py htpasswd.py] may help.  (Note that it requires a `crypt` or `fcrypt` module; see the source comments for details.)
    214 
    215 It is possible to use md5sum utility to generate digest-password file using such method:
    216 {{{
    217  $ printf "${user}:trac:${password}" | md5sum - >>user.htdigest
    218 }}}
    219 and manually delete " -" from the end and add "${user}:trac:" to the start of line from 'to-file'.
     214==== Using `md5sum`
     215It is possible to use `md5sum` utility to generate digest-password file:
     216{{{
     217user=
     218realm=
     219password=
     220path_to_file=
     221echo ${user}:${realm}:$(printf "${user}:${realm}:${password}" | md5sum - | sed -e 's/\s\+-//') > ${path_to_file}
     222}}}
     223
     224== Reference ==
     225
     226Here's the online help, as a reminder (`tracd --help`):
     227{{{
     228Usage: tracd [options] [projenv] ...
     229
     230Options:
     231  --version             show program's version number and exit
     232  -h, --help            show this help message and exit
     233  -a DIGESTAUTH, --auth=DIGESTAUTH
     234                        [projectdir],[htdigest_file],[realm]
     235  --basic-auth=BASICAUTH
     236                        [projectdir],[htpasswd_file],[realm]
     237  -p PORT, --port=PORT  the port number to bind to
     238  -b HOSTNAME, --hostname=HOSTNAME
     239                        the host name or IP address to bind to
     240  --protocol=PROTOCOL   http|scgi|ajp|fcgi
     241  -q, --unquote         unquote PATH_INFO (may be needed when using ajp)
     242  --http10              use HTTP/1.0 protocol version instead of HTTP/1.1
     243  --http11              use HTTP/1.1 protocol version (default)
     244  -e PARENTDIR, --env-parent-dir=PARENTDIR
     245                        parent directory of the project environments
     246  --base-path=BASE_PATH
     247                        the initial portion of the request URL's "path"
     248  -r, --auto-reload     restart automatically when sources are modified
     249  -s, --single-env      only serve a single project without the project list
     250  -d, --daemonize       run in the background as a daemon
     251  --pidfile=PIDFILE     When daemonizing, file to which to write pid
     252  --umask=MASK          When daemonizing, file mode creation mask to use, in
     253                        octal notation (default 022)
     254}}}
     255
     256Use the -d option so that tracd doesn't hang if you close the terminal window where tracd was started.
    220257
    221258== Tips ==
     
    236273 ''Support for `htdocs:` TracLinks syntax was added in version 0.10''
    237274
    238 === Using apache rewrite rules ===
    239 In some situations when you choose to use tracd behind apache, you might experience issues with redirects, like being redirected to URLs with the wrong host or protocol. In this case (and only in this case), setting the `[trac] use_base_url_for_redirect` to `true` can help, as this will force Trac to use the value of `[trac] base_url` for doing the redirects.
     275=== Using tracd behind a proxy
     276
     277In some situations when you choose to use tracd behind Apache or another web server.
     278
     279In this situation, you might experience issues with redirects, like being redirected to URLs with the wrong host or protocol. In this case (and only in this case), setting the `[trac] use_base_url_for_redirect` to `true` can help, as this will force Trac to use the value of `[trac] base_url` for doing the redirects.
     280
     281If you're using the AJP protocol to connect with `tracd` (which is possible if you have flup installed), then you might experience problems with double quoting. Consider adding the `--unquote` parameter.
     282
     283See also [trac:TracOnWindowsIisAjp], [trac:TracNginxRecipe].
     284
     285=== Authentication for tracd behind a proxy
     286It is convenient to provide central external authentication to your tracd instances, instead of using {{{--basic-auth}}}. There is some discussion about this in #9206.
     287
     288Below is example configuration based on Apache 2.2, mod_proxy, mod_authnz_ldap.
     289
     290First we bring tracd into Apache's location namespace.
     291
     292{{{
     293<Location /project/proxified>
     294        Require ldap-group cn=somegroup, ou=Groups,dc=domain.com
     295        Require ldap-user somespecificusertoo
     296        ProxyPass http://localhost:8101/project/proxified/
     297        # Turns out we don't really need complicated RewriteRules here at all
     298        RequestHeader set REMOTE_USER %{REMOTE_USER}s
     299</Location>
     300}}}
     301
     302Then 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:
     303{{{
     304#!python
     305from trac.core import *
     306from trac.config import BoolOption
     307from trac.web.api import IAuthenticator
     308
     309class MyRemoteUserAuthenticator(Component):
     310
     311    implements(IAuthenticator)
     312
     313    obey_remote_user_header = BoolOption('trac', 'obey_remote_user_header', 'false',
     314               """Whether the 'Remote-User:' HTTP header is to be trusted for user logins
     315                (''since ??.??').""")
     316
     317    def authenticate(self, req):
     318        if self.obey_remote_user_header and req.get_header('Remote-User'):
     319            return req.get_header('Remote-User')
     320        return None
     321
     322}}}
     323
     324Add this new parameter to your TracIni:
     325{{{
     326...
     327[trac]
     328...
     329obey_remote_user_header = true
     330...
     331}}}
     332
     333Run tracd:
     334{{{
     335tracd -p 8101 -r -s proxified --base-path=/project/proxified
     336}}}
    240337
    241338=== Serving a different base path than / ===
     
    246343
    247344----
    248 See also: TracInstall, TracCgi, TracModPython, TracGuide, [trac:TracOnWindowsStandalone?version=13#RunningTracdasservice Running tracd.exe as a Windows service], [trac:TracOnWindowsIisAjp], [trac:TracNginxRecipe]
     345See also: TracInstall, TracCgi, TracModPython, TracGuide, [trac:TracOnWindowsStandalone#RunningTracdasservice Running tracd.exe as a Windows service]