Gitolite_Configuration.mdwn 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. Gitolite's configuration is stored in a special git repository called
  2. 'gitolite-admin.git'. Since server repositories are "bare", i.e. without a
  3. workspace, changing the configuration is done by pulling the repository, making
  4. changes, committing them and pushing back to the server. This is the gitolite
  5. admin's role.
  6. In order to access the server via SSH (needed for write access), you need to
  7. have its address. If you already have a registered domain name already, e.g.
  8. myproject.org, you can use that. Otherwise you can use the IP address for now.
  9. Actually, if you installed the server on the same computer you work on, you can
  10. simply use 'localhost' regardless of whether you have a domain name (of course
  11. remote access requires either the IP or a domain name).
  12. We will use an SSH address which has the form __ssh://user@host:port/path__.
  13. Since the standard SSH port is used, we can omit it. Assuming a local server
  14. installed on your personal computer) and assuming we called the gitolite user
  15. __git__, the address for write access to the gitolite configuration repository
  16. would be __ssh://git@localhost/gitolite-admin.git__.
  17. Assume the user 'alice', who is the gitolite admin, wants to edit the
  18. configuration as described above: pull, change, commit, push. And assume she has
  19. a folder 'git-repos' under her home folder, where she stores her local
  20. repositories and working trees. Then the process of editing the configuration
  21. may begin like this:
  22. $ cd ~/git-repos
  23. $ git clone ssh://git@localhost/gitolite-admin.git
  24. $ cd gitolite-admin
  25. If you use a remote server, make sure the server's firewall doesn't block SSH
  26. traffic (or try cloning first and see if it works).
  27. Since your SSH client doesn't know the host (i.e. the 'git' user) yet, you will
  28. be presented with the following dialog:
  29. Cloning into 'gitolite-admin'...
  30. The authenticity of host 'localhost (::1)' can't be established.
  31. ECDSA key fingerprint is 91:8d:b8:6f:d2:8e:5d:64:6c:d3:a7:7c:ec:c6:88:38.
  32. Are you sure you want to continue connecting (yes/no)?
  33. You have three options now:
  34. 1. Say 'no', add the key fingerprint to the list of known hosts and try again
  35. 2. Verify the key authenticity against the SSH server key, and then say 'yes'
  36. 3. Just say 'yes' and maybe verify it later
  37. [[TODO|TODO/OPEN]] __read about SSH and explain the risks etc. of these options__ If
  38. your server is 'localhost', i.e. your computer, then choosing 'yes' is safe.
  39. Once the host is trusted, you will not be asked anymore to confirm each
  40. connection.
  41. After choosing '__yes__', the following message will appear:
  42. Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
  43. remote: Counting objects: 6, done.
  44. remote: Compressing objects: 100% (4/4), done.
  45. remote: Total 6 (delta 0), reused 0 (delta 0)
  46. Receiving objects: 100% (6/6), done.
  47. For our example user Alice, the folder tree now looks like this:
  48. + /
  49. + home
  50. + alice
  51. + git-repos
  52. + gitolite-admin
  53. + .git
  54. + *(repository files)*
  55. + conf
  56. + *gitolite.conf*
  57. + keydir
  58. + *admin.pub*
  59. The *keydir* folder will contain the public SSH keys of all the people to whom
  60. you are going to give write access to your git server. Gitolite provides
  61. fine-grained control over who can do which changes to which repository. Right
  62. now the only known user is the admin, and the admin's key, *admin.pub*, is
  63. exactly the one you specified in the post-installation configuration.
  64. The *conf* folder will contain gitolite's configuration, e.g. the access rights
  65. of each user and each repository. Currently it contains a single configuration
  66. file, *gitolite.conf*. It should look like this:
  67. repo gitolite-admin
  68. RW+ = admin
  69. repo testing
  70. RW+ = @all
  71. What does it mean? At the end of the post-installation process, a setup script
  72. named __gl-setup__ was executed automatically. That script created the
  73. gitolite-admin repository and put the admin's publc key in the right place, but
  74. it also created an empty repository called 'testing'. That's right, for testing.
  75. At the moment, the admin user (alice) has full access to the gitolite-admin
  76. repository, and all registered users (currently it's just Alice) have full
  77. access to the testing repository.
  78. For now this file is fine (you can keep the testing repository for now, until
  79. you see everything works). But how do we make changes when we need to? Things we
  80. may want to do:
  81. - add a user
  82. - remove a user
  83. - add a repository
  84. - remove a repository
  85. - move an existing repository to gitolite
  86. - change a user's name
  87. - give an existing user some access rights to a repository
  88. - remove a user's access rights to a repository
  89. - define and use a user group (useful if several repositories have the same access configuration)
  90. Let's see how to do them. The complete documentation for *gitolite.conf* can be
  91. found on gitolite's website [here][conf]. You can ignore the warning at the top
  92. of that page: Gitolite 3 exists, but Debian 7 stable uses Gitolite 2.3. However
  93. you can get Gitolite 3 from the Debian Backports repository.
  94. The first 6 operations are briefly described above; for information on the
  95. others see gitolite's online documentation.
  96. The examples in this sections assume you start with 'gitolite-admin' as the
  97. current working directory (if you followed the commands so far, it is. Anyway
  98. you can execute `cwd` in the terminal or look at the shell prompt, and use
  99. `cd ~/git-repos/gitolite-admin` to move there).
  100. # Add a user
  101. Users are added simply by adding their public SSH keys to the gitolite-admin
  102. repository:
  103. 1. Obtain the user's public key, and (if necessary) rename is to 'USER.pub'
  104. where USER is a name chosen for that user. It doesn't need to be the user's
  105. local username or any other particular name - it just needs to be the same
  106. name you use later in the 'gitolite.conf' file.
  107. 2. Put the key inside the 'keydir' folder
  108. 3. Commit the change and push to the gitolite-admin repository
  109. For example, assume the admin Alice wants to add a user Bob, who is going to
  110. work with her on one of her projects. Bob is known on the web by his nickname
  111. 'h4ck3r', so Alice wants to use it as the user name. Bob sends his public key
  112. (commonly found at `~/.ssh/id_rsa.pub` on his machine) by e-mail (a telegraph is
  113. possible too, if you wish) to Alice, and she renames it to 'h3ck3r.pub' and
  114. copies it into the 'keydir' folder. Then she commits the change and pushes her
  115. cloned repository to the origin (either remote or localhost, depending on where
  116. gitolite was installed).
  117. Assuming the initial location of the key on Alice's machine is
  118. `~/Mail/bob_pubkey`, she can do the following:
  119. $ cp ~/Mail/bob_pubkey keydir/h4ck3r.pub
  120. $ git add keydir/h4ck3r.pub
  121. $ git commit
  122. $ git push origin master
  123. If the user has multiple SSH keys, they can be placed in separate folders or
  124. subfolders (the depth doesn't matter). But the files themselves need to have the
  125. same name. For example, assume Bob has two keys: One on his laptop and one on
  126. his PC. Then the keys may be placed in 'PC' and 'laptop' subfolders (or any
  127. other names), i.e.:
  128. - __keydir/laptop/h4ck3r.pub__ is Bob's public key from his laptop.
  129. - __keydir/PC/h3ck4r.pub__ is Bob's public key from his PC.
  130. # Remove a user
  131. You probably want to remove the user from 'gitolite.conf'. Then remove the
  132. user's SSH key from the gitolite-admin repository. For example, this is how
  133. Alice removes Clair from her Gitolite server:
  134. $ git rm keydir/clair.pub
  135. $ git commit
  136. $ git push origin master
  137. # Create a repository
  138. A repository is added by adding lines to the file 'gitolite.conf'. For example,
  139. lines like these:
  140. repo cool-project
  141. RW+ = alice
  142. RW = h4ck3r
  143. So the process would be:
  144. (edit the config file conf/gitolite.conf)
  145. $ git add conf/gitolite.conf
  146. $ git commit
  147. $ git push origin master
  148. # Remove a repository
  149. Removing a repository involves two steps:
  150. 1. Remove it from the config file
  151. 2. Delete it from the server
  152. If the server is local, login as the gitolite user (in our case __git__) or as
  153. root, and delete the repository folder. If the server is remote, use remote
  154. access, e.g. via SSH login.
  155. # Move an existing repository to gitolite
  156. First, add a new repository declaration to 'conf/gitolite.conf' as in the
  157. "Create a repository" section above. Then push your existing repository
  158. to the new remote you just created, and finally check the contents of
  159. the remote repo to make sure everything was pushed.
  160. cd ~/git-repos/cool-project
  161. git push --all ssh://git@localhost/cool-project.git
  162. git push --tags ssh://git@localhost/cool-project.git
  163. git ls-remote ssh://git@localhost/cool-project.git
  164. # Change a user's name
  165. The name of the admin user is 'admin', so you may wish to change it. Or you may
  166. wish to change a user's name for any other reason. The steps are:
  167. 1. Clone the gitolite-admin repository, if you haven't done it yet
  168. 2. Change the user's public key file user 'keydir' to the new name
  169. 3. Change all occurences of the user's name in gitolite.conf to the new name
  170. 4. Commit
  171. 5. Push
  172. If your server is in a remote location, a mistake in the process while changing
  173. the admin user's name may cause a situation where the admin user's access rights
  174. have been removed by mistake and __now nobody has access to the gitolite-admin
  175. repository__. If you want to change the admin user's name and you don't have
  176. physical access or SSH access to the server, it's safer to create a new dummy
  177. user and give that user full access to the 'gitolite-admin' repository, so you
  178. can always recover to the original state in case you make a mistake.
  179. [conf]: http://gitolite.com/gitolite/g2/conf.html
  180. # Change a repository's name
  181. 1. Change the name of the target repository folder
  182. 2. Update the name in gitolite.conf and push the change to gitolite-admin repo
  183. 3. In the local copy of old-name.git, you probably want to change the name to
  184. new-name.git as well and update the *origin* remote URL