You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

02_federation.mkd 19KB

12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. ## Federating Gitblit
  2. *SINCE 0.6.0*
  3. A Gitblit federation is a mechanism to clone repositories and keep them in sync from one Gitblit instance to another. Federation can be used to maintain a mirror of your Gitblit instance, to aggregate repositories from developer workstations, or to initially clone groups of repositories to developer workstations. If you are/were a Subversion user you might think of this as [svn-sync](http://svnbook.red-bean.com/en/1.5/svn.ref.svnsync.html), but better.
  4. If your Gitblit instance allows federation and it is properly registered with another Gitblit instance, each of the *non-excluded* repositories of your Gitblit instance can be mirrored, in their entirety, to the pulling Gitblit instance. You may optionally allow pulling of user accounts and backup of server settings.
  5. The federation feature should be considered a security backdoor and enabled or disabled as appropriate for your installation.<br/>
  6. Please review all the documentation to understand how it works and its limitations.
  7. ![block diagram](fed_aggregation.png "Gitblit Federation Aggregation")
  8. ### Origin Gitblit Instance Requirements
  9. - *git.enableGitServlet* must be true, all Git clone and pull requests are handled through Gitblit's JGit servlet
  10. - *federation.passphrase* must be non-empty
  11. - The Gitblit origin instance must be http/https accessible by the pulling Gitblit instance.<br/>That may require configuring port-forwarding on your router and/or opening ports on your firewall.
  12. #### federation.passphrase
  13. The passphrase is used to generate permission tokens that can be shared with other Gitblit instances.
  14. The passphrase value never needs to be shared, although if you give another Gitblit instance the *ALL* federation token then your passphrase will be transferred/backed-up along with all other server settings.
  15. This value can be anything you want: an integer, a sentence, an haiku, etc. You should probably keep the passphrase simple and use standard Latin characters to prevent Java properties file encoding errors. The tokens generated from this value are affected by case, so consider this value CASE-SENSITIVE.
  16. The federation feature is completely disabled if your passphrase value is empty.
  17. **NOTE**:<br/>
  18. Changing your *federation.passphrase* will break any registrations you have established with other Gitblit instances.
  19. ### Pulling Gitblit Instance Requirements
  20. - consider setting *federation.allowProposals=true* to facilitate the registration process from origin Gitblit instances
  21. - properly registered Gitblit instance including, at a minimum, url, *federation token*, and update frequency
  22. ### Controlling What Gets Pulled
  23. If you want your repositories (and optionally users accounts and settings) to be pulled by another Gitblit instance, you need to register your origin Gitblit instance with a pulling Gitblit instance by providing the url of your Gitblit instance and a federation token.
  24. Gitblit generates the following standard federation tokens:
  25. %BEGINCODE%
  26. String allToken = SHA1(passphrase + "-ALL");
  27. String usersAndRepositoriesToken = SHA1(passphrase + "-USERS_AND_REPOSITORIES");
  28. String repositoriesToken = SHA1(passphrase + "-REPOSITORIES");
  29. %ENDCODE%
  30. The *ALL* token allows another Gitblit instance to pull all your repositories, user accounts, and server settings.<br/>
  31. The *USERS_AND_REPOSITORIES* token allows another Gitblit instance to pull all your repositories and user accounts.<br/>
  32. The *REPOSITORIES* token only allows pulling of the repositories.
  33. Individual Gitblit repository configurations such as *description* and *accessRestriction* are always mirrored.
  34. If *federation.passphrase* has a non-empty value, the federation tokens are displayed in the log file and are visible, to administrators, in the web ui.
  35. The three standard tokens grant access to ALL your non-excluded repositories. However, if you only want to specify different groups of repositories to be federated then you need to define *federation sets*.
  36. #### Federation Sets
  37. Federation Sets (*federation.sets*) are named groups of repositories. The Federation Sets are defined in `gitblit.properties` and are available for selection in the repository settings page. You can assign a repository to one or more sets and then distribute the federation token for the set. This allows you to grant federation pull access to a subset of your available repositories. Tokens for federation sets only grant pull access for the member repositories.
  38. ### Federation Proposals (Origin Gitblit Instance)
  39. Once you have properly setup your passphrase and can see your federation tokens, you are ready to share them with a pulling Gitblit instance.
  40. The registration process can be partially automated by sending a *federation proposal* to the pulling Gitblit instance.<br/>
  41. To send a proposal:
  42. 1. Login to your Gitblit instance as an administrator
  43. 2. Select and click the *propose* link for the appropriate token at the bottom of the repositories page
  44. 3. Confirm the publicly accessible url of your (origin) Gitblit instance
  45. 4. Enter the url of the pulling Gitblit instance you want to federate with
  46. 5. Optionally enter a message for the administrators
  47. 6. Click *propose*
  48. Not all Gitblit instances accept *federation proposals*, there is a setting which allows Gitblit to outright reject them. In this case an email or instant message to the administrator of the other Gitblit instance is required. :)
  49. If your proposal is accepted, the proposal is cached to disk on the pulling Gitblit server and, if properly configured, the administrators of that Gitblit server will receive an email notification of your proposal.
  50. Your proposal includes:
  51. 1. the url of your Gitblit instance
  52. 2. the federation token you selected and its type
  53. 3. the list of your *non-excluded* repositories, and their configuration details, that you propose to share
  54. Submitting a proposal does not automatically register your server with the pulling Gitblit instance.<br/>
  55. Registration is a manual process for an administrator.
  56. ### Federation Proposals (Pulling Gitblit Instance)
  57. If your Giblit instance has received a *federation proposal*, you will be alerted to that information the next time you login to Gitblit as an administrator.
  58. You may view the details of a proposal by scrolling down to the bottom of the repositories page and selecting a proposal. Sample registration settings will be generated for you that you may copy & paste into either your `gitblit.properties` file or your `web.xml` file.
  59. ### Excluding Repositories (Origin Gitblit Instance)
  60. You may exclude a repository from being pulled by any federated Gitblit instance by setting its *federation strategy* to EXCLUDE in the repository's settings page.
  61. ### Excluding Repositories (Pulling Gitblit Instance)
  62. You may exclude repositories to pull in a federation registration. You may exclude all or you may exclude based on a simple fuzzy pattern. Only one wildcard character may be used within each pattern. Patterns are space-separated within the exclude and include fields.
  63. federation.example.exclude = skipit.git
  64. **OR**
  65. federation.example.exclude = *
  66. federation.example.include = somerepo.git someotherrepo.git
  67. **OR**
  68. federation.example.exclude = *
  69. federation.example.include = common/* library/*
  70. ### Tracking Status (Pulling Gitblit Instance)
  71. Below the repositories list on the repositories page you will find a section named *federation registrations*. This section enumerates the other gitblit servers you have configured to periodically pull. The *status* of the latest pull will be indicated on the left with a colored circle, similar to the status of an executed unit test or Hudson/Jenkins build. You can drill into the details of the registration to view the status of the last pull from each repository available from that origin Gitblit instance. Additionally, you can specify the *federation.N.notifyOnError=true* flag, to be alerted via email of regressive status changes to individual registrations.
  72. ### Tracking Status (Origin Gitblit Instance)
  73. Origin Gitblit instances can not directly track the success or failure status of Pulling Gitblit instances. However, the Pulling Gitblit instance may elect to send a status acknowledgment (*federation.N.sendStatus=true*) to the origin Gitblit server that indicates the per-repository status of the pull operation. This is the same data that is displayed on the Pulling Gitblit instances ui.
  74. ### How does it work? (Origin Gitblit Instances)
  75. A pulling Gitblit instance will periodically contact your Gitblit instance and will provide the token as proof that you have granted it federation access. Your Gitblit instance will decide, based on the supplied token, if the requested data should be returned to the pulling Gitblit instance. Gitblit data (user accounts, repository metadata, and server settings) are serialized as [JSON](http://json.org) using [google-gson](http://google-gson.googlecode.com) and returned to the pulling Gitblit instance. Standard Git clone and pull operations are used to transfer commits.
  76. The federation process executes using an internal administrator account, *$gitblit*. All the normal authentication and authorization processes are used for federation requests. For example, Git commands are authenticated as *$gitblit / token*.
  77. While the *$gitblit* account has access to all repositories, server settings, and user accounts, it is prohibited from accessing the web ui and it is disabled if *federation.passphrase* is empty.
  78. ### How does it work? (Pulling Gitblit Instances)
  79. Federated repositories defined in `gitblit.properties` are checked after Gitblit has been running for 1 minute. The next registration check is scheduled at the completion of the current registration check based on the registration's specified frequency.
  80. - The shortest frequency allowed is every 5 minutes
  81. - Decimal frequency values are cast to integers
  82. - Frequency values may be specified in mins, hours, or days
  83. - Values that can not be parsed default to 60 minutes
  84. After a repository has been cloned it is flagged as *isFederated* (which identifies it as being sourced from another Gitblit instance), *isFrozen* (which prevents Git pushes to this mirror) and *federationStrategy=EXCLUDED* (which prevents this repository from being pulled by another federated Gitblit instance).
  85. #### Origin Verification
  86. During a federated pull operation, Gitblit does check that the *origin* of the local repository starts with the url of the federation registration.<br/>
  87. If they do not match, the repository is skipped and this is indicated in the log.
  88. #### User Accounts
  89. By default all user accounts except the *admin* account are automatically pulled when using the *ALL* token or the *USERS_AND_REPOSITORIES* token. You may exclude a user account from being pulled by a federated Gitblit instance by checking *exclude from federation* in the edit user page.
  90. The pulling Gitblit instance will store a registration-specific `users.properties` file for the pulled user accounts and their repository permissions. This file is stored in the *federation.N.folder* folder.
  91. If you specify *federation.N.mergeAccounts=true*, then the user accounts from the origin Gitblit instance will be integrated into the `users.properties` file of your Gitblit instance and allow sign-on of those users.
  92. **NOTE:**<br/>
  93. Upgrades from older Gitblit versions will not have the *#notfederated* role assigned to the *admin* account. Without that role, your admin account WILL be transferred with an *ALL* or *USERS_AND_REPOSITORIES* token.<br/>
  94. Please consider adding the *#notfederated* role to your admin account!
  95. #### Server Settings
  96. Server settings are only pulled when using the *ALL* token.
  97. The pulling Gitblit instance will store a registration-specific `gitblit.properties` file for all pulled settings. This file is stored in the *federation.N.folder* folder.
  98. These settings are unused by the pulling Gitblit instance.
  99. ### Collisions and Conflict Resolution
  100. Gitblit does **not** detect conflict and it does **not** offer conflict resolution of repositories, users, or settings.
  101. If an object exists locally that has the same name as the remote object, it is assumed they are the same and the contents of the remote object are merged into the local object. If you can not guarantee that this is the case, then you should not store any federated repositories directly in *git.repositoriesFolder* and you should not enable *mergeAccounts*.
  102. By default, federated repositories can not be pushed to, they are read-only by the *isFrozen* flag. This flag is **ONLY** enforced by Gitblit's JGit servlet. If you push to a federated repository after resetting the *isFrozen* flag or via some other Git access technique then you may break Gitblit's ability to continue pulling from the origin repository. If you are only pushing to a local branch then you might be safe.
  103. ## Federation Pull Registration Keys
  104. <table>
  105. <tr><th>federation.N.url</th>
  106. <td>string</td>
  107. <td>the url of the origin Gitblit instance *(required)*</td>
  108. </tr>
  109. <tr><th>federation.N.token</th>
  110. <td>string</td>
  111. <td>the token provided by the origin Gitblit instance *(required)*</td>
  112. </tr>
  113. <tr><th>federation.N.frequency</th>
  114. <td>x [mins/hours/days]</td>
  115. <td>the period to wait between pull executions</td>
  116. </tr>
  117. <tr><th>federation.N.folder</th>
  118. <td>string</td>
  119. <td>the destination folder, relative to *git.repositoriesFolder*, for these repositories.<br/>default is *git.repositoriesFolder*</td>
  120. </tr>
  121. <tr><th>federation.N.bare</th>
  122. <td>boolean</td>
  123. <td>if **true** *(default)*, each repository is cloned as a bare repository (i.e. no working folder).</td>
  124. </tr>
  125. <tr><th>federation.N.mirror</th>
  126. <td>boolean</td>
  127. <td>if **true** *(default)*, each repository HEAD is reset to *origin/master* after each pull. The repository is flagged *isFrozen* after the initial clone.<p>If **false**, each repository HEAD will point to the FETCH_HEAD of the initial clone from the origin until pushed to or otherwise manipulated.</td>
  128. </tr>
  129. <tr><th>federation.N.mergeAccounts</th>
  130. <td>boolean</td>
  131. <td>if **true**, merge the retrieved accounts into the `users.properties` of **this** Gitblit instance.<br/>*default is false*</td>
  132. </tr>
  133. <tr><th>federation.N.sendStatus</th>
  134. <td>boolean</td>
  135. <td>if **true**, send the status of the federated pull to the origin Gitblit instance.<br/>*default is false*</td>
  136. </tr>
  137. <tr><th>federation.N.include</th>
  138. <td>string array<br/>(space-delimited)</td>
  139. <td>list of included repositories *(wildcard and fuzzy matching supported)*</td>
  140. </tr>
  141. <tr><th>federation.N.exclude</th>
  142. <td>string array<br/>(space-delimited)</td>
  143. <td>list of excluded repositories *(wildcard and fuzzy matching supported)*</td>
  144. </tr>
  145. <tr><th>federation.N.notifyOnError</th>
  146. <td>boolean</td>
  147. <td>if **true**, send an email to the administrators on an error.<br/>*default is false*</td>
  148. </tr>
  149. </table>
  150. ## Example Federation Pull Registrations
  151. These examples would be entered into the `gitblit.properties` file of the pulling gitblit instance.
  152. #### (Nearly) Perfect Mirror Example
  153. ![block diagram](fed_mirror.png "Gitblit Mirror")
  154. This assumes that the *token* is the *ALL* token from the origin gitblit instance.
  155. The repositories, example1_users.properties, and example1_gitblit.properties will be put in *git.repositoriesFolder* and the origin user accounts will be merged into the local user accounts, including passwords and all roles. The Gitblit instance will also send a status acknowledgment to the origin Gitblit instance at the end of the pull operation. The status report will include the state of each repository pull (EXCLUDED, SKIPPED, NOCHANGE, PULLED, MIRRORED). This way the origin Gitblit instance can monitor the health of its mirrors.
  156. This example is considered *nearly* perfect because while the origin Gitblit's server settings are pulled and saved locally, they are not merged with your server settings so its not a true mirror, but its likely the mirror you'd want to configure.
  157. federation.example1.url = https://go.gitblit.com
  158. federation.example1.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4
  159. federation.example1.frequency = 120 mins
  160. federation.example1.folder =
  161. federation.example1.bare = true
  162. federation.example1.mirror = true
  163. federation.example1.mergeAccounts = true
  164. federation.example1.sendStatus = true
  165. #### Just Repositories Example
  166. This assumes that the *token* is the *REPOSITORIES* token from the origin gitblit instance.<br/>
  167. The repositories will be put in *git.repositoriesFolder*/example2.
  168. federation.example2.url = https://tomcat.gitblit.com/gitblit
  169. federation.example2.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4
  170. federation.example2.frequency = 120 mins
  171. federation.example2.folder = example2
  172. federation.example2.bare = true
  173. federation.example2.mirror = true
  174. #### All-but-One Repository Example
  175. This assumes that the *token* is the *REPOSITORIES* token from the origin gitblit instance.<br/>
  176. The repositories will be put in *git.repositoriesFolder*/example3.
  177. federation.example3.url = https://tomcat.gitblit.com/gitblit
  178. federation.example3.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4
  179. federation.example3.frequency = 120 mins
  180. federation.example3.folder = example3
  181. federation.example3.bare = true
  182. federation.example3.mirror = true
  183. federation.example3.exclude = somerepo.git
  184. #### Just One Repository Example
  185. This assumes that the *token* is the *REPOSITORIES* token from the origin gitblit instance.<br/>
  186. The repositories will be put in *git.repositoriesFolder*/example4.
  187. federation.example4.url = https://tomcat.gitblit.com/gitblit
  188. federation.example4.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4
  189. federation.example4.frequency = 120 mins
  190. federation.example4.folder = example4
  191. federation.example4.bare = true
  192. federation.example4.mirror = true
  193. federation.example4.exclude = *
  194. federation.example4.include = somerepo.git
  195. ## Federation Client
  196. Instead of setting up a full-blown pulling Gitblit instance, you can also use the [federation client](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) command-line utility. This is a packaged subset of the federation feature in a smaller, simpler command-line only tool.
  197. The *federation client* relies on many of the same dependencies as Gitblit and will download them on first execution.
  198. ### federation.properties
  199. You may use the `federation.properties` file to configure one or more Gitblit instances that you want to pull from. This file is a subset of the standard `gitblit.properties` file.
  200. By default this tool does not daemonize itself; it executes and then quits. This allows you to use the native scheduling feature of your OS. Of course, if you'd rather use Gitblit's scheduler you may use that by specifying the `--daemon` parameter.
  201. ### Command-Line Parameters
  202. Instead of using `federation.properties` you may directly specify a Gitblit instance to pull from with command-line parameters.
  203. java -jar fedclient.jar --url https://go.gitblit.com --mirror --bare --token 123456789
  204. --repositoriesFolder c:/mymirror
  205. java -jar fedclient.jar --url https://go.gitblit.com --mirror --bare --token 123456789
  206. --repositoriesFolder c:/mymirror --daemon --frequency "24 hours"