Out of the box, mercurial-server supports two kinds of users: 'root' users and normal users. If you followed the steps above, you are a 'root' user because your key is under keys/root, while the other user you gave access to is a normal user since their key is under keys/users.Keys that are not in either of these directories will by default have no access to anything. Mercurial is dedicated to speed and efficiency with a sane user interface. It is written in Python. Mercurial's implementation and data structures are designed to be fast. You can generate diffs between revisions, or jump back in time within seconds. What is SourceTree? A free Git GUI client for Windows and macOS. Use the full capability of Git. Mercurial downloads. Windows users are likely to enjoy the TortoiseHg GUI the most. It integrates Mercurial directly into your explorer. # Debian/Ubuntu $ apt-get install mercurial # Fedora $ dnf install mercurial # Gentoo $ emerge mercurial # Mac OS (homebrew) $ brew install mercurial # FreeBSD $ cd /usr/ports/devel/mercurial $ make. TortoiseHg is a GUI front-end for Mercurial that runs on Microsoft Windows (on which it integrates directly with File Explorer), Mac OS X, and Linux. It is written in PyQt (except the Windows shell extension), and the underlying client can be used on the command line. It is often recommended and preferred for working with Mercurial on Windows. This is a brief list of its features.

Sharing Mercurial repositories with mercurial-server

Step 3 - Install Mercurial. You can use Mercurial from the command line or you can use one of several GUI-based tools such as Sourcetree. These instructions assume you are using Mercurial from the command-line. Files that start with a. (period) are hidden files in Mac OSX. By default, the Finder does not show hidden files.

Copyright © 2009 Paul Crowley, LShift Ltd

Table of Contents

About mercurial-server
Step by step
Initial access to mercurial-server
Creating repositories
Adding other users
Access control
Using access.conf
/etc/mercurial-server and hgadmin
File and branch conditions
Logging
How mercurial-server works
Security
License and thanks

Home page: http://www.lshift.net/mercurial-server.html

mercurial-server gives your developers remote read/write access tocentralized Mercurialrepositories using SSH public key authentication; it provides convenientand fine-grained key management and access control.

Though mercurial-server is currently targeted at Debian-based systems suchas Ubuntu, other users have reported success getting it running on otherUnix-based systems such as Red Hat. Running it on a non-Unix system such asWindows is not supported. You will need root privileges to install it.

mercurial-server authenticates users not using passwords but using SSHpublic keys; everyone who wants access to a mercurial-server repositorywill need such a key. In combination with ssh-agent (orequivalents such as the Windows program Pageant),this means that users will not need to type in a password to access therepository. If you're not familiar with SSH public keys, the OpenSSH PublicKey Authentication tutorial may be helpful.

In what follows, we assume that your username is jay, that you usually sit at a machine calledspoon and you haveinstalled mercurial-server on jeeves using the package management system (see the README for more on installation). We assume that you have created your SSH public key, set up your SSH agent with this key, and that this key gives you access to jeeves.

You can now create repositories on the remote machine and have completeread-write access to all of them.

To store a repository on the server, clone it over.

At this stage, no-one but you has any access to any repositories youcreate on this system. In order to give anyone else access, you'll need acopy of their SSH public key; we'll assume you have that key in~/sam-saucer-key.pub. To manage access, you make changes to the special hgadmin repository.

Sam can now read and write to yourssh://[email protected]/jays/project repository.Most other changes to access control can be made simply by making andpushing changes to hgadmin, and you can use Mercurial tocooperate with other root users in the normal way.

If you prefer, you could give them access bylogging into jeeves,putting the key in the right place under /etc/mercurial-server/keys, and re-runningsudo -u hg /usr/share/mercurial-server/refresh-auth.However, using hgadmin is usually more convenient if you need to make more than a very few changes; it also makes it easier to share administration with others and provides a log of all changes.

Out of the box, mercurial-server supports two kinds of users: 'root' users and normal users. If you followed the steps above, you are a 'root' user because your key is under keys/root, while the other user you gave access to is a normal user since their key is under keys/users. Keys that are not in either of these directories will by default have no access to anything.

Root users can edit hgadmin, create new repositories and read and write to existing ones. Normal users cannot access hgadmin or create new repositories, but they can read and write to any other repository.

mercurial-server offers much more fine-grained access control than this division into two classes of users. Let's suppose you wish to give Pat access to the widget repository, but no other. We first copy Pat's SSH public key into the keys/pat directory in hgadmin. This tells mercurial-server about Pat's key, but gives Pat no access to anything because the key is not under either keys/root or keys/users. To grant this key access, we must give mercurial-server a new access rule, so we create a file in hgadmin called access.conf, with the following contents:

Pat will have read and write access to the widget repository as soon as we add, commit, and push these files.

Each line of access.conf has the following syntax:

Blank lines and lines that start with # are ignored. Rule isone of

  • init: allow reads, writes, and the creation of new repositories
  • write: allow reads and writes
  • read: allow only read operations
  • deny: deny all requests

A condition is a globpattern matched against a relative path. The two mostimportant conditions are

  • user=globpattern: path to the user's key
  • repo=globpattern: path to the repository

* only matches one directory level, where **matches as many as you want. More precisely, * matches zero ormore characters not including / while ** matcheszero or more characters including /. Soprojects/* matches projects/foo but not projects/foo/bar, whileprojects/** matches both.

When considering a request, mercurial-server steps through all the rules in/etc/mercurial-server/access.conf and then all therules in access.conf in hgadminlooking for a rule which matches on every condition. The first matchdetermines whether the request will be allowed; if there is no match ineither file, the request will be denied.

By default, /etc/mercurial-server/access.conf has thefollowing rules:

These rules ensure that root users can do any operation on any repository,that no other users can access the hgadmin repository,and that those with keys in keys/users can read or write to any repositorybut not create repositories. Some examples of how these rules work:

Mercurial For Mac Guide

  • User root/jay creates a repositoryfoo/bar/baz. This matches the firstrule and so will be allowed.
  • User root/jay changes repositoryhgadmin. Again, this matches thefirst rule and so will be allowed; later rules have no effect.
  • User users/sam tries to readrepository hgadmin. This does notmatch the first rule, but matches the second, and so will be denied.
  • User users/sam tries to createrepository sams-project. This doesnot match the first two rules, but matches the third; this is awrite rule, which doesn't grant the privilege to createrepositories, so the request will be denied.
  • User users/sam writes to existingrepository projects/main. Again,this matches the third rule, which allows the request.
  • User pat tries to write to existingrepository widget. Until we changethe access.conf file in hgadmin, this will match no rule, and so willbe denied.
  • Any request from a user whose key not under the keys directory at all will always be denied,no matter what rules are in effect; because of the way SSH authenticationworks, they will be prompted to enter a password, but no password willwork. This can't be changed.

mercurial-server consults two distinct locations to collect information about what to allow: /etc/mercurial-server and its own hgadmin repository. This is useful for several reasons:

  • Some users may not need the convenience of access control via mercurial; for these users updating /etc/mercurial-server may offer a simpler route.
  • /etc/mercurial-server is suitablefor management with tools such as Puppet
  • If a change to hgadmin leaves you 'locked out', /etc/mercurial-server allows you a way back in.
  • At install time, all users are 'locked out', and so some mechanism to allow some users in is needed.

Rules in /etc/mercurial-server/access.conf are checked before those in hgadmin, and keys in /etc/mercurial-server/keys will be present no matter how hgadmin changes.

We anticipate that once mercurial-server is successfully installed andworking you will usually want to use hgadmin for mostaccess control tasks. Once you have the right keys andaccess.conf set up in hgadmin, youcan delete /etc/mercurial-server/access.conf and allof /etc/mercurial-server/keys,turning control entirely over to hgadmin.

/etc/mercurial-server/remote-hgrc.d is in theHGRCPATH for all remote access to mercurial-serverrepositories. This directory contains the hooks that mercurial-server uses foraccess control and logging. You can add hooks to this directory, but obviouslybreaking the existing hooks will disable the relevant functionality andisn't advisable.

mercurial-server supports file and branch conditions, which restrict anoperation depending on what files it modifies and what branch the work ison.

Caution

The way these conditions work is subtle and can be counterintuitive. Unlessyou need what they provide, ignore this section, stick to user and repoconditions, and then things are likely to work the way you would expect. Ifyou do need what they provide, read what follows very carefully.

File and branch conditions are added to the conditions against which a rulematches, just like user and repo conditions; they have this form:

  • file=globpattern: file within the repo
  • branch=globpattern: Mercurial branch name

However, in order to understand what effect adding these conditions willhave, it helps to understand how and when these rules are applied.

The rules file is used to make three decisions:

  • Whether to allow a repository to be created
  • Whether to allow any access to a repository
  • Whether to allow a changeset
Mercurial mac gui

When the first two of these decisions are being made, nothing is knownabout any changsets that might be pushed, and so all file and branchconditions automatically succeed for the purpose of such decisions. For thethird condition, every file changed in the changeset must be allowed by awrite or init rule for the changesetto be allowed.

Mercurial Mac Gui

This means that doing tricky things with file conditions can havecounterintuitive consequences:

  • You cannot limit read access to a subset of a repository with a readrule and a file condition: any user who has access to a repository can readall of it and its full history. Such a rule can only have the effect ofmasking a later write rule, as in this example:

    allows all users to read specialrepo, and to write to all filesexcept that any changeset which writes todontwritethis will be rejected.

  • For similar reasons, don't give init rules file conditions.
  • Don't try to deny write access to a particular file on a particularbranch—a developer can write to the file on another branch and then mergeit in. Either deny all writes to the branch from that user, or allow themto write to all the files they can write to on any branch.

    This rule grants users whose keys are in the docs subdirectory the power to push changesetsinto any repository only if those changesets are on thedocs branch and they affect only those files directlyunder the docs directory. However,the rules below have more counterintuitive consequences.

    These rules grant users whose keys are in the docs subdirectory the power to change any file directly under the docs directory, or any file at all in the docs branch. Indirectly, however, this adds up to the power to change any file on any branch, simply by making the change on the docs branch and then merging the change into another branch.

Every successful access is logged in a file called~hg/repos/repository/.hg/servelog. The log records the time as aUTC ISO 8601 time, the operation ('push' or 'pull'), the path to the key asused in the access rules, and the hex changeset ID.

All of the repositories controlled by mercurial-server are owned by asingle user, the hg user, which is why all URLs formercurial-server repositories start with ssh://[email protected].Each SSH key that has access to the repository has an entry in~hg/.ssh/authorized_keys; this is how the SSH daemonknows to give that key access. When the user connects over SSH, theircommands are run in a custom restricted shell; this shell knows which keywas used to connect, determines what the user is trying to do, checks theaccess rules to decide whether to allow it, and if allowed invokesMercurial internally, without forking.

This restricted shell also ensures that certain Mercurial extensions areloaded when the user acts on a repository; these extensions check theaccess control rules for any changeset that the user tries to commit, andlog all pushes and pulls into a per-repository access log.

refresh-auth recurses through the /etc/mercurial-server/keys and the keys directory in thehgadmin repository, creating an entry in~hg/.ssh/authorized_keys for each one. This is redoneautomatically whenever a change is pushed to hgadmin.

mercurial-server relies entirely on sshd to grant access to remote users.As a result, it runs no daemons, installs no setuid programs, and no partof it runs as root except the install process: all programs run as the userhg. Any attack on mercurial-server can only be started if the attackeralready has a public key in ~hg/.ssh/authorized_keys,otherwise sshd will bar the way.

No matter what command the user tries to run on the remote system via SSH,mercurial-server is run. It parses the command line the user asked for, andinterprets and runs the corresponding operation itself if access isallowed, so users can only read and add to history within repositories;they cannot run any other command. In addition, every push and pull islogged with a datestamp, changeset ID and the key that performed theoperation.

However, while the first paragraph holds no matter what bugsmercurial-server contains, the second depends on the relevant code beingcorrect; though the entire codebase is short, mercurial-server is a fairlynew program and may harbour bugs. Backups are essential!

This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at your option)any later version.

This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License formore details.

Youtube video to mp3 mac. You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc., 51Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Thanks for reading this far. If you use mercurial-server, please tell me aboutit.

Paul Crowley, <[email protected]>, 2009

Coments are closed
Scroll to top