nosync-quiet option added courtesy Robin Johnson (Gentoo project)
[gitolite-doc.git] / docs / internals.mkd
blobee30fde6df27c833adcdc67526a0f7911c5f156a
1 # gitolite internals
3 This page is for people who may want to hack on **core** gitolite itself.
4 This is **not** the page for people who merely want to customise their site
5 (i.e., write their own VREFs, triggers, etc.); for that please start with the
6 [non-core](non-core) page.
8 ----
10 This document assumes you're familiar with the material in the [how does it
11 work](overview#how-does-it-work) section in the "overview" document, as well
12 as the [concepts](concepts) page.  If you're not familiar with ssh, and in particular
13 how programs like gitolite use ssh to simulate many users over one Unix user,
14 the [ssh](ssh) page has useful info.
16 <!--
18 I can't over-stress the importance of discussing any changes you propose on
19 the mailing list.  I'm pretty conservative about adding code to core, so
20 expect lots of push-back.  In general, if it can be done outside "core",
21 that's what I will suggest!
23 -->
25 # what is "core"
27 The core code consists mainly of `src/gitolite`, `src/gitolite-shell`, and all
28 the perl modules in `src/lib/Gitolite` except `src/lib/Gitolite/Triggers`.
30 That said, there are parts of non-core that, in a default (ssh) install, are
31 used frequently enough to be important (for example if you are reviewing
32 gitolite):
34 *   commands in `src/commands`: access, git-config, info, mirror, option,
35     owns, perms
36 *   triggers in `src/lib/Gitolite/Triggers`: Mirroring.pm, Shell.pm
37 *   triggers in `src/triggers` and `src/triggers/post-compile`: ssh-authkeys,
38     ssh-authkeys-shell-users, update-git-configs, set-default-roles, 
40 # entry points
42 ## gitolite
44 Most server-side operations that gitolite supports are invoked via the
45 `gitolite` command.  This includes initial setup and maintenance, some
46 built-in commands (run 'gitolite -h' to see them), and finally the commands in
47 `src/commands` (run 'gitolite help' to get a list).
49 ## gitolite-shell
51 All remote access is via the `gitolite-shell` command, (invoked, of course, by
52 sshd).  This includes both git operations (clone, fetch, push) as well as
53 gitolite commands that have been enabled for remote invocation.
55 For git operations, gitolite-shell does the initial access check ("is the user
56 even allowed to read/write this repo at all?") and then calls git proper.
58 Most of the code in this is housekeeping; the real action happens in one of
59 the modules.
61 # the Conf module
63 The `Conf` module and its child modules deal with the gitolite.conf file.
65 `Conf` is where the 'compile' command lands.  The parser for the conf file is
66 also in this module; each "recognised" line is passed to appropriate functions
67 in `Conf::Store`.
69 Please note the parser is a very simple line-oriented parser using simple
70 regexes; the DSL for the gitolite.conf file is intentionally very simple.
72 ## `Conf::Explode`
74 This deals with "exploding" the main gitolite.conf file into a single perl
75 list with all 'include' files recursively expanded.
77 ## `Conf::Sugar`
79 This calls `Conf::Explode` to get the full set of conf lines, then applies a
80 series of "syntactic sugar" transformations to them.  This keeps the main
81 parser simple, while allowing the administrator to take some shortcuts in
82 writing the rules.
84 Some transformations are built-in and hardcoded, but a site can add their own
85 site-local transformations if they like.
87 ## `Conf::Store`
89 `Conf::Store` is one of the two workhorses of gitolite.  It exports functions
90 related to processing parsed lines and storing the parsed output for later
91 use.  It also exports functions that deal with creating and setting up new
92 repos.
94 !!! note ""
95     The output of the compile step is essentially a set of perl hashes in
96     `Data::Dumper` format.  Rules that apply to more than one repo (i.e., the
97     repo name was a regex pattern or a group name) go into a "common" output
98     file (`~/.gitolite/conf/gitolite.conf-compiled.pm`), while rules that
99     apply to specific repos go into their own files
100     (`~/repositories/$REPONAME.git/gl-conf`).
102 From a security perspective, dealing with 'subconf' (see [delegation](deleg)
103 for details) happens in this module.
105 ## `Conf::Load`
107 `Conf::Load` is the other of the two workhorses of gitolite.
109 The most important function it exports is `access`, which is used by
110 `gitolite-shell` as well as by the update hook code to check for permissions.
111 This code has a few optimisations, including very simple, localised, caching
112 of parsed conf files when needed.
114 TODO: How the `access` function does its thing will be written up in more
115 detail as I find time, but TLDR: it calls `rules` which builds up a list of
116 the rules that apply.  Also see [this](conf#defining-user-and-repo) until I
117 manage to write it up in more detail.
119 Other functions are `git_config`, which returns a list of config values
120 specified in the conf file.
122 Finally, this is where all the "list-" commands that 'gitolite -h' shows you
123 (e.g., 'gitolite list-repos') land up.
125 # the Rc module
127 The rc file (`~/.gitolite.rc`) is processed here.  In addition, it also
128 declares a bunch of constants (like the all-important regex patterns to
129 validate user inputs of various kinds; all ending in `_PATT`).
131 The only complicated part of this is how the `non_core_expand` function takes
132 the `$non_core` variable (currently 63 lines long!) and converts it into a set
133 of arrays, one for each of the [triggers](triggers) types.  You can see the effect of
134 this logic by uncommenting something in the ENABLE list in the rc file, then
135 running `gitolite query-rc PRE_GIT`, etc.
137 (From a security point of view this is irrelevant.  Any inputs it receives
138 come from totally trusted sources -- either the gitolite source code or the rc
139 file).
141 Finally, the trigger function is also exported by this module.  This is the
142 function that actually runs all the programs tied to each trigger.
144 # the Hooks module
146 This is where the code for the update hook (all repos) and the post-update
147 hook (gitolite-admin repo only) can be found.
149 The post-update hook code is fairly straightforward, consisting essentially of
150 three shell commands.
152 The update hook code has a lot more "action", since this is where all access
153 checking for 'git push' goes.  Even that would not be much if it weren't for
154 VREFs, because then it's just one call to the access function (from the
155 `Conf::Load` module).
157 The only other thing of note in this module is how the "attempted access" is
158 determined.  Externally, we only know it's a "push" (i.e., a "W" in gitolite
159 permission terms).  We need to compare the old and the new SHAs in various
160 ways to determine if it's a rewind, or a delete, or a create, etc., which may
161 make a difference to the access.
163 TODO: expand on VREF handling.  For now please read [vref](vref) to get the
164 general idea of *what* it does, while I find time to write up the *how*.
166 # the rest...
168 ...is TBD (to be done).  Briefly, the Test module is for testing, the Common
169 module contains a whole bunch of common routines used all over -- many of them
170 not gitolite specific at all, Cache is not to be used for now (sorry,
171 bitrotted by now I think... I may need to take it out behind the woodshed one
172 of these days).
174 # security notes
176 All security issues should be reported directly to me (sitaramc@gmail.com),
177 and not to the mailing list.
179 (In the following text, the words MUST, SHOULD, etc. are loosely as defined in
180 RFC 2119).
182 1.  Gitolite MUST protect everything in `~/repositories` from people who do
183     not have command line access to the user hosting the service, and do not
184     have "push" access rights to the gitolite-admin repository.
186     Specifically, gitolite MUST prevent such users from doing anything except
187     the following:
189     *   perform git operations they are allowed to by gitolite.conf
190     *   run *gitolite* commands that are enabled for remote use
192 2.  People who have command line access are considered to be "in"; nothing in
193     gitolite attempts to protect from them (it's impossible anyway!)
195     But someone who does not have command line access, but *does* have push
196     access rights to the gitolite-admin repo (a "gitolite admin"), is a
197     special case.
199     Gitolite SHOULD prevent a gitolite admin from using that to pivot to
200     executing arbitrary commands on the server.  (This is why, for example,
201     the gitolite-admin repo can't have arbitrary "config" lines.)
203     However, many sites don't care about this distinction -- all their
204     gitolite admins already have shell access.
206     Thus, a violation of this is important and should be fixed, but not
207     considered critical.
209 3.  Gitolite SHOULD try to make sure that the *gitolite* commands shipped with
210     gitolite do not indirectly enable violation of the restrictions in the
211     first bullet.  The seriousness of failing this depends on the command in
212     question (is the command enabled in the default setup, or even if it is
213     not, is it a popular and widely used command, etc.)
215 4.  Gitolite SHOULD protect the local sysadmin from his own errors to some
216     extent.  For example, it should be possible to write a new "command" in
217     shell, without worrying about shell meta-characters sneaking in and
218     executing something; gitolite should prevent this from happening.
220 5.  As you probably [knew][auth] already, gitolite does not do authentication;
221     it only deals with authorisation.  Still, gitolite MAY help the
222     administrator to setup authentication (as the default setup does when used
223     in ssh mode), but it is not mandatory.  In particular, use in http-mode
224     leaves gitolite completely out of the authentication picture.
226 In order to achieve these goals, gitolite expects the files and directories on
227 the server to have sane permissions and ownerships.  A decent POSIX file
228 system, and a reasonable sshd config are also expected.
230 [auth]: concepts#authentication-and-authorisation
232 Finally, a note on a couple of related items:
234 *   Gitolite's stance on DOS (by authenticated users) is that if it is
235     fixable, it will be fixed, but it is not a critical issue, as long as the
236     log files cannot be tampered with.
238     A DOS by un-authenticated users is completely out of scope.
240 *   Gitolite cannot benefit from perl's taint mode, which was made for a
241     different threat model.
243     Gitolite's threat model implicitly trusts anyone who has shell access to
244     the server, including all programs already on the server.  It's only
245     remote users that are considered a threat.
247     Perl's taint mode treats *anything* outside the program itself as suspect.
248     So, the rc file, the compiled config, the various internal files gitolite
249     stores housekeeping information in, etc., would all need to be untainted.
251     Since gitolite gets "suspicious" input only in one place, it's easier to
252     check that rigorously enough rather than use taint mode.
254 # appendix A: accessing the documentation offline
256 The source code for the documentation is in
257 <https://github.com/sitaramc/gitolite-doc>.  Rendering it requires some work
258 (TBD: details).
260 For most purposes, it's simpler to clone
261 <https://github.com/sitaramc/sitaramc.github.com> and use the 'gitolite'
262 subdirectory within as your pre-rendered document base.  Open it in a
263 JS-enabled browser and you can even do searches.