Skip to contentSkip to conversation

Secure central repositories by UNIX socket authentication

RFC In review Shawn O. Pearce 5 participants 16 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 Secure central repositories by UNIX socket authentication

This isn't anywhere near ready for application, but I'm floating it out there to see what people think. Its a cool new feature that will certainly *not* be in 1.5.4. :-)

In a central repository configuration users may not have access to write new objects into a Git repository, or to edit the refs, especially if the repository is being protected by an update hook (e.g. contrib/hooks/updated-paranoid).

This change allows any repository owner to setup a git-daemon that other users on the same host can connect through to perform upload-pack or receive-pack. It also allows the update hook to authorize the user via $GIT_REMOTE_USER. For example:

## Owner (not jdoe)
##
cat >foo.git/hooks/update <<'EOF'
#!/bin/sh
test -z "$GIT_REMOTE_USER" || exit
case "$GIT_REMOTE_USER" in

  jdoe)     exit 0;;
  spearce)  exit 0;;
  *)        exit 1

esac
EOF
chmod u+x foo.git/hooks/update
chmod 700 foo.git

  git daemon \
      --export-all \
      --enable=receive-pack \
      --base=`pwd` \
      --listen=/tmp/shawn-git

## Other User
##
git push jdoe@server:/tmp/shawn-git/foo.git master

allows user jdoe to push into foo.git, even though it is restricted. This works by:

*) git-push executes
"ssh jdoe@server git-receive-pack /tmp/shawn-git/foo.git"

*) git-receive-pack realizes its actually a socket, connects
to /tmp/shawn-git and asks for service "git-receive-pack" on directory "/foo.git"

*) git-daemon authenticates the user via the kernel's secure
peer id call and sets GIT_REMOTE_USER with their username.

*) git-daemon starts another git-receive-pack on foo.git, using
its normal access control and path resolving rules.

*) The first git-receive-pack acts as a shuttle to copy
data between the two peers.

*) The second git-receive-pack runs the update hook, which has
GIT_REMOTE_USER defined from git-daemon.

There's a few small problems with this, which is partly why this isn't ready for application yet:

1) Error messages from the pre-receive or update hooks don't make it back to the client as send-pack and receive-pack don't implement the sideband protocol. This is harder than it sounds as the pkt-line protocol they currently use for status can't be easily layered into a sideband protocol.

2) There is currently no "authorization" hook for upload-pack (aka the fetch server) like we have for receive-pack (aka the push server) so we cannot make use of $GIT_REMOTE_USER to perform user authorization. Currently Git relies on UNIX filesystem access, but this daemon approach bypasses those. There was a conversation on #git tonight about adding a hook that filters the list of allowed refs during fetch, for exactly this reason.

3) The system call to get the peer UID via the kernel is not POSIX so its implemented differently on basically every OS we support, if it is even implemented there. The patch below should provide support for Solaris 8/9/10, FreeBSD, Darwin/Mac OS X, and Linux. But is thus far only tested on Mac OS 10.4.

---

 Documentation/git-daemon.txt |   11 ++-
 Makefile                     |   14 ++-
 builtin-upload-archive.c     |    3 +
 daemon-redirect.c            |  282 ++++++++++++++++++++++++++++++++++++++++++
 daemon-redirect.h            |   12 ++
 daemon.c                     |  132 +++++++++++++++-----
 git-compat-util.h            |    1 +
 receive-pack.c               |    3 +
 upload-pack.c                |    3 +
 9 files changed, 429 insertions(+), 32 deletions(-)
 create mode 100644 daemon-redirect.c
 create mode 100644 daemon-redirect.h
Documentation/git-daemon.txt +9 -2
index fd83bc7..1f9d9a1 100644
@@ -15,7 +15,7 @@ SYNOPSIS
              [--reuseaddr] [--detach] [--pid-file=file]
              [--enable=service] [--disable=service]
 	     [--allow-override=service] [--forbid-override=service]
-	     [--inetd | [--listen=host_or_ipaddr] [--port=n] [--user=user [--group=group]]
+	     [--inetd | [--listen=host_or_ipaddr_or_path] [--port=n] [--user=user [--group=group]]
 	     [directory...]
 
 DESCRIPTION
@@ -79,12 +79,19 @@ OPTIONS
 	Have the server run as an inetd service. Implies --syslog.
 	Incompatible with --port, --listen, --user and --group options.
 
---listen=host_or_ipaddr::
+--listen=host_or_ipaddr_or_path::
 	Listen on an a specific IP address or hostname.  IP addresses can
 	be either an IPv4 address or an IPV6 address if supported.  If IPv6
 	is not supported, then --listen=hostname is also not supported and
 	--listen must be given an IPv4 address.
 	Incompatible with '--inetd' option.
++
+If the address is an absolute path in the filesystem then git-daemon
+listens on a UNIX domain socket at the given path.  This can be used
+to support authenticated redirection from linkgit:git-upload-pack[1]
+or linkgit:git-receive-pack[1].  Child processes (including hooks)
+can obtain the authenticated username from the `GIT_REMOTE_USER`
+environment variable.
 
 --port=n::
 	Listen on an alternative port.  Incompatible with '--inetd' option.
Makefile +13 -1
index a0c0998..6f8f3ad 100644
@@ -295,7 +295,8 @@ LIB_H = \
 	run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
 	tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \
 	utf8.h reflog-walk.h patch-ids.h attr.h decorate.h progress.h \
-	mailmap.h remote.h parse-options.h transport.h diffcore.h hash.h
+	mailmap.h remote.h parse-options.h transport.h diffcore.h hash.h \
+	daemon-redirect.h
 
 DIFF_OBJS = \
 	diff.o diff-lib.o diffcore-break.o diffcore-order.o \
@@ -309,6 +310,7 @@ LIB_OBJS = \
 	lockfile.o \
 	patch-ids.o \
 	object.o pack-check.o pack-write.o patch-delta.o path.o pkt-line.o \
+	daemon-redirect.o \
 	sideband.o reachable.o reflog-walk.o \
 	quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \
 	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
@@ -417,6 +419,7 @@ ifeq ($(uname_S),Darwin)
 	endif
 	NO_STRLCPY = YesPlease
 	NO_MEMMEM = YesPlease
+	HAVE_GETPEEREID = YesPlease
 endif
 ifeq ($(uname_S),SunOS)
 	NEEDS_SOCKET = YesPlease
@@ -426,6 +429,7 @@ ifeq ($(uname_S),SunOS)
 	NO_MEMMEM = YesPlease
 	NO_HSTRERROR = YesPlease
 	NO_MKDTEMP = YesPlease
+	HAVE_STREAMS_CONNLD = YesPlease
 	ifeq ($(uname_R),5.8)
 		NEEDS_LIBICONV = YesPlease
 		NO_UNSETENV = YesPlease
@@ -463,6 +467,7 @@ endif
 ifeq ($(uname_S),FreeBSD)
 	NEEDS_LIBICONV = YesPlease
 	NO_MEMMEM = YesPlease
+	HAVE_GETPEEREID = YesPlease
 	BASIC_CFLAGS += -I/usr/local/include
 	BASIC_LDFLAGS += -L/usr/local/lib
 endif
@@ -470,6 +475,7 @@ ifeq ($(uname_S),OpenBSD)
 	NO_STRCASESTR = YesPlease
 	NO_MEMMEM = YesPlease
 	NEEDS_LIBICONV = YesPlease
+	HAVE_GETPEEREID = YesPlease
 	BASIC_CFLAGS += -I/usr/local/include
 	BASIC_LDFLAGS += -L/usr/local/lib
 endif
@@ -659,6 +665,12 @@ else
 	BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in6
 endif
 endif
+ifdef HAVE_STREAMS_CONNLD
+	BASIC_CFLAGS += -DHAVE_STREAMS_CONNLD
+endif
+ifdef HAVE_GETPEEREID
+	BASIC_CFLAGS += -DHAVE_GETPEEREID
+endif
 ifdef NO_INET_NTOP
 	LIB_OBJS += compat/inet_ntop.o
 endif
builtin-upload-archive.c +3 -0
index 48ae09e..5599e3b 100644
@@ -5,6 +5,7 @@
 #include "builtin.h"
 #include "archive.h"
 #include "pkt-line.h"
+#include "daemon-redirect.h"
 #include "sideband.h"
 
 static const char upload_archive_usage[] =
@@ -35,6 +36,8 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
 
 	strcpy(buf, argv[1]); /* enter-repo smudges its argument */
 
+	if (redirect_execute("upload-archive", buf))
+		return 0;
 	if (!enter_repo(buf, 0))
 		die("not a git archive");
 
daemon-redirect.c new file +282 -0

282 lines not on this page · raw message

daemon-redirect.h new file +12 -0
new file mode 100644
index 0000000..5d85e10
@@ -0,0 +1,12 @@
+#ifndef DAEMON_REDIRECT_H
+#define DAEMON_REDIRECT_H
+
+#include "git-compat-util.h"
+
+extern int redirect_listen(const char *path);
+extern int redirect_accept(int, uid_t *);
+extern void redirect_unlisten(int, const char *);
+
+extern int redirect_execute(const char *, const char *);
+
+#endif
daemon.c +103 -29

266 lines not on this page · raw message

git-compat-util.h +1 -0
index b6ef544..892b7f9 100644
@@ -74,6 +74,7 @@
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
+#include <sys/un.h>
 #include <netdb.h>
 #include <pwd.h>
 #include <inttypes.h>
receive-pack.c +3 -0
index 3267495..6970979 100644
@@ -2,6 +2,7 @@
 #include "pack.h"
 #include "refs.h"
 #include "pkt-line.h"
+#include "daemon-redirect.h"
 #include "run-command.h"
 #include "exec_cmd.h"
 #include "commit.h"
@@ -469,6 +470,8 @@ int main(int argc, char **argv)
 	if (!dir)
 		usage(receive_pack_usage);
 
+	if (redirect_execute("receive-pack", dir))
+		return 0;
 	if (!enter_repo(dir, 0))
 		die("'%s': unable to chdir or not a git archive", dir);
 
upload-pack.c +3 -0
index 7e04311..8102126 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
+#include "daemon-redirect.h"
 #include "sideband.h"
 #include "tag.h"
 #include "object.h"
@@ -622,6 +623,8 @@ int main(int argc, char **argv)
 		usage(upload_pack_usage);
 	dir = argv[i];
 
+	if (redirect_execute("upload-pack", dir))
+		return 0;
 	if (!enter_repo(dir, strict))
 		die("'%s': unable to chdir or not a git archive", dir);
 	if (is_repository_shallow())
Signature · 1 line
1.5.4.rc4.1142.gf5a97
#1 lore raw
Quoted 8 lines · Shawn O. Pearce

This isn't anywhere near ready for application, but I'm floating it out there to see what people think. Its a cool new feature that will certainly *not* be in 1.5.4. :-)

In a central repository configuration users may not have access to write new objects into a Git repository, or to edit the refs, especially if the repository is being protected by an update hook (e.g. contrib/hooks/updated-paranoid).

Sorry, but I am puzzled about what this assumption is trying to achieve here.

If the configuration is based on central repository model, wouldn't the users who are participating in the project have write access to the repository by being in the project's group and the repository initialized with core.sharedrepository=true?

Quoted 3 lines

This change allows any repository owner to setup a git-daemon that other users on the same host can connect through to perform upload-pack or receive-pack.

My reading of this is that it creates a backdoor for people who cannot (either "are not allowed to", or "cannot be bothered to") create and maintain project specific access control by the traditional means of filesystem access control based on user groups, by allowing others to run controlled stuff under the repository owner's uid. In addition to having to worry about the in-repo data properly being protected from people outside the group, you now need to worry about the access through that backdoor does not extend outside of the repository. E.g. the repository owner's $HOME that is outside the repository would be writable that owner, but is not meant to be accessible by project participants. If you allow others to "run as" you, the only thing that forbids that process running as you from accessing $HOME is an additional audit of git-daemon and the programs it spawns.

In short, my initial reaction to this is not very supportive, not because of the way it is coded but because of its security design.

But I may probably have misread the intention.

#2 lore raw

git-daemon is insecure? (was: [RFC] Secure central repositories)

Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Shawn O. Pearce

This change allows any repository owner to setup a git-daemon that other users on the same host can connect through to perform upload-pack or receive-pack.

My reading of this is that it creates a backdoor for people who

[...]

Quoted 10 lines

In addition to having to worry about
the in-repo data properly being protected from people outside the group, you now need to worry about the access through that backdoor does not extend outside of the repository. E.g. the repository owner's $HOME that is outside the repository would be writable that owner, but is not meant to be accessible by project participants. If you allow others to "run as" you, the only thing that forbids that process running as you from accessing $HOME is an additional audit of git-daemon and the programs it spawns.

So you are partially suggesting that git-daemon isn't thought to be secure, and that anything readable by the user that git-daemon is running as is fully exposed to the public Internet. So the access control attempts relating to --base-path or the check for git-daemon-export-ok shouldn't really be trusted or relied upon.

If that really is the case, perhaps git-daemon should be audited and hardened further. Last I checked, we encouraged people to run it to offer anonymous access to repositories, and the documentation suggests there are publishing access controls that actually work. If those controls cannot be trusted then we shouldn't encourage running git-daemon on untrusted networks.

With regards to this patch, yes, you can export your entire $HOME and maybe expose things you shouldn't or didn't want to. But even without git installed you could do this:

cp /bin/bash /tmp/be-like-mike
chown $USER /tmp/be-like-mike
chmod 777 /tmp/be-like-mike
chmod u+s /tmp/be-like-mike
wall "try out /tmp/be-like-mike today"

but why would anyone do something that foolish? UNIX provides the tools to do this, because there are cases where it can be useful, but really, you have to be nuts to export all of $HOME.

Signature · 1 line
Shawn.
#3 lore raw

Re: git-daemon is insecure?

Quoted 2 lines · Shawn O. Pearce

With regards to this patch, yes, you can export your entire $HOME and maybe expose things you shouldn't or didn't want to.

That was not what I meant. git-daemon running as nobody.project will allow read access to project group's files, and the whitelisting and --base-path are ways to limit it to files that are in the repository. But the process still has the power to read files outside that can be read nobody user or project group, the only thing needed is for git-daemon and whatever it spawn to have bugs.

But the point is that "power to read files outside" is still limited to nobody.project, even if there are such bugs to allow it escape the whitelist/base-path jail. It won't extend to anybody's $HOME.

If you run git-daemon as spearce.spearce, you cannot rely on that built-in limitation.

#4 lore raw

Re: git-daemon is insecure?

Quoted 13 lines · Junio C Hamano
Quoted 2 lines · Shawn O. Pearce

With regards to this patch, yes, you can export your entire $HOME and maybe expose things you shouldn't or didn't want to.

That was not what I meant. git-daemon running as nobody.project will allow read access to project group's files, and the whitelisting and --base-path are ways to limit it to files that are in the repository. But the process still has the power to read files outside that can be read nobody user or project group, the only thing needed is for git-daemon and whatever it spawn to have bugs.

Quoted 7 lines

But the point is that "power to read files outside" is still limited to nobody.project, even if there are such bugs to allow it escape the whitelist/base-path jail. It won't extend to anybody's $HOME.

If you run git-daemon as spearce.spearce, you cannot rely on that built-in limitation.

Sure. Which is why I was planning on running git-daemon as gitadmin.gitadmin, with all central repos owned by gitadmin, and basically nothing else at all.

I can just as easily start lighthttpd on $HOME. Or Apache. Both are insane.

Signature · 1 line
Shawn.
#5 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Shawn O. Pearce

This isn't anywhere near ready for application, but I'm floating it out there to see what people think. Its a cool new feature that will certainly *not* be in 1.5.4. :-)

In a central repository configuration users may not have access to write new objects into a Git repository, or to edit the refs, especially if the repository is being protected by an update hook (e.g. contrib/hooks/updated-paranoid).

Quoted 7 lines

Sorry, but I am puzzled about what this assumption is trying to achieve here.

If the configuration is based on central repository model, wouldn't the users who are participating in the project have write access to the repository by being in the project's group and the repository initialized with core.sharedrepository=true?

Hmm. core.sharedrepository is sometimes a bad solution.

core.sharedrepository means I need to give write access to both the refs database and the object database to all members of the project. Some of whom may not be able to be trusted with tools like "rm", but who need real shell access to that system anyway. And sometimes management won't allow users to have two accounts on the same system (one that is fixed to git-shell, and one that has a real shell) because the world would implode if a user was given two different accounts for two different access purposes. I have no idea why that would happen, but someone paid 3x what I earn has figured that out.

Last I checked how UNIX filesystem access controls work, Git's core.sharedrepository cannot possibly prevent a user from doing something like this:

cd $repo_path
git log
... go to lunch ...
rm -rf *
git log
... bitch about how crappy git is ...

Now any "real" version control and SQL database system allows the administrator to restrict access to the database to avoid such mistakes. CVS has pserver; SVN can use Apache HTTPd or its own server; Perforce has its own server. PostgreSQL, Oracle, Informix, DB2, even MySQL don't allow users to directly read or modify the database files but instead ask them to go through authenticated socket based interfaces.

Under a DSCM one would say the central model is insane, and that every user should have their own repository, with write access limited to only that user. Obviously this is the model that kernel.org uses for kernel development, and that git itself uses for git development.

The problem is the purely distributed model falls apart when you have 50 "Aunt Tillies" making changes to the same 30 files at around the same time. Its bad enough that they have to have a local clone and push and fetch to share their changes. Trying to explain that you need to fetch+merge from Jane right now and Bob 3 minutes later, then back to Jane to get the changes you are working on in parallel is sheer chaos. Eyes gloss over and management declares "Git is crap; it cannot possibly be used in the enterprise".

How do you setup 50 URLs into all 50 user's .git/config? When a new user joins the project how do you get their URL into all existing user's trees? Its total chaos in the cube farm as they shout back and forth "Did you get Bob's changes? Jane's? Oh, maybe you didn't get Sally's too and that's why you aren't seeing X in there".

At day-job I manage two completely different workflows, but both are based upon Git.

Real developers who hack out program source code use a model much like kernel.org. Code is developed on topic branches, code is reviewed on topic branches at the individual change level, and code is merged from a developer's topic branch by a maintainer into a master branch. For convience sake we store all topic branches in a single central repository, so everyone just has to have the "origin" URL in their local repositories. We could deal with individual developer repos like kernel.org does. We choose not to simply because we also have to handle the next case, and its easier to not have individual developer repos.

Aunt Tillies (who far out number real developers) edit small text files through a fancy GUI tool. These folks don't really care about versions, topic branches, and really don't want to know. All they know is they have to edit "Foo.data_file" but to do so they need the changes just made to "Bar.data_file" 5 minutes ago. Usually they don't even know if Bob, Sally, Jane or Nick made that change, they just know they need it. And their collective changes (from all 50 Aunt Tillies) all have to somehow wind up in the same Git branch at the end of the day so a real developer/maintainer can pull it into a product build.

I've lived through the daily fires of these workflows over the past year and a half. Its mostly settled out to something that works very well for us, but its heavily based upon this concept of a central, shared repository. And to keep the auditors and management happy I cannot allow "rm -rf *" to be executed by a user who happens to have push access to that same repository.

We're not the only Git user that has a shared repository. Doesn't X.org use a shared repository model? I'm guessing that since they are an open source project they have less concerns about the "rm -rf *" case. Wasn't the receive-pack service added to git-daemon to allow users to push into a repository, but not actually have write access to its filesystem? Obviously someone else other than just me wants to safeguard the repository.

Signature · 1 line
Shawn.
#6 lore raw
Quoted 10 lines · Shawn O. Pearce

Hmm. core.sharedrepository is sometimes a bad solution.

core.sharedrepository means I need to give write access to both the refs database and the object database to all members of the project. Some of whom may not be able to be trusted with tools like "rm", but who need real shell access to that system anyway. And sometimes management won't allow users to have two accounts on the same system (one that is fixed to git-shell, and one that has a real shell) because the world would implode if a user was given two different accounts for two different access purposes.

Ok, that was the motiviation I did not get from your original message. It begins to make sense somewhat.

Another approach to do the same I can think of, without having to add 50 new accounts for 50 users, would be to collect a ssh key from each of these 50 users, and have 1 line per user in the authorized_keys file of gitadmin.gitadmin user (who owns the repository with the paranoia hook that decides the authorization aspect of the repository). The authentication would come from the environment="Name=value" option in the authorized_keys file. Each of your aunt tillies can push or fetch over ssh using the key she has in the gitadmin.gitadmin's authorized_keys file.

I suspect the "hackiness" factor from the aesthetics viewpoint is probably about the same, but this would work with the current code without patches, no?

#7 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 10 lines · Shawn O. Pearce

Hmm. core.sharedrepository is sometimes a bad solution.

core.sharedrepository means I need to give write access to both the refs database and the object database to all members of the project. Some of whom may not be able to be trusted with tools like "rm", but who need real shell access to that system anyway. And sometimes management won't allow users to have two accounts on the same system (one that is fixed to git-shell, and one that has a real shell) because the world would implode if a user was given two different accounts for two different access purposes.

Ok, that was the motiviation I did not get from your original message. It begins to make sense somewhat.

Quoted 9 lines

Another approach to do the same I can think of, without having to add 50 new accounts for 50 users, would be to collect a ssh key from each of these 50 users, and have 1 line per user in the authorized_keys file of gitadmin.gitadmin user (who owns the repository with the paranoia hook that decides the authorization aspect of the repository). The authentication would come from the environment="Name=value" option in the authorized_keys file. Each of your aunt tillies can push or fetch over ssh using the key she has in the gitadmin.gitadmin's authorized_keys file.

Yea. The downside to this is we have to maintain that authorized_keys file. Today each user can generate their own SSH key and upload to their own authorized_keys file.

I've had enough cases of users losing their SSH key and needing to recreate it that I'd rather not have to manage a 50 user long authorized_keys file.

I'm also not sure of what the performance implication is to SSH for authentication with 50 public keys in a single file. Does it slow down as its running a check against each key, or is there something smarter to filter the keys? From the description of the format in the OpenSSH manpage it doesn't look like its possible other than to probe every key in turn for every authentication attempt.

In other words, the authorized_keys is a nice feature, but it seems like its more useful for a remote backup job logging in as root, or a "vacation mode" where a coworker is permitted to execute a specific command while you are away. But maybe I'm missing something.

Quoted 3 lines

I suspect the "hackiness" factor from the aesthetics viewpoint is probably about the same, but this would work with the current code without patches, no?

Yes, it would, obviously. But it has the downside of needing to manage a single common authorized_keys file. Which is something I think I'd like to avoid.

It also doesn't do anything about upload-pack, as that has no hook to perform authorization. Of course just adding some sort of ref filtering hook to upload-pack is still a smaller patch than adding all this UNIX socket redirection and an upload-pack hook. :)

Signature · 1 line
Shawn.
#8 lore raw
Quoted 7 lines · Shawn O. Pearce
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Shawn O. Pearce

Hmm. core.sharedrepository is sometimes a bad solution.

core.sharedrepository means I need to give write access to both the refs database and the object database to all members of the project. Some of whom may not be able to be trusted with tools like "rm", but who need real shell access to that system anyway. And sometimes management won't allow users to have two accounts on the same system (one that is fixed to git-shell, and one that has a real shell) because the world would implode if a user was given two different accounts for two different access purposes.

Quoted 7 lines
Quoted 3 lines

Ok, that was the motiviation I did not get from your original message. It begins to make sense somewhat.

Another approach to do the same I can think of, without having to add 50 new accounts for 50 users, would be to collect a ssh key from each of these 50 users, and have 1 line per user in the authorized_keys file of gitadmin.gitadmin user (who owns the repository with the paranoia hook that decides the authorization aspect of the repository). The authentication would come from the environment="Name=value" option in the authorized_keys file. Each of your aunt tillies can push or fetch over ssh using the key she has in the gitadmin.gitadmin's authorized_keys file.

Yea. The downside to this is we have to maintain that authorized_keys file. Today each user can generate their own SSH key and upload to their own authorized_keys file.

I've had enough cases of users losing their SSH key and needing to recreate it that I'd rather not have to manage a 50 user long authorized_keys file.

For what it's worth, if you haven't seen gitosis yet, you might want to take a look - at least it makes managing the keys easy. http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way has a nice tutorial.

-- Asheesh.

Signature · 3 lines
He who despairs over an event is a coward, but he who holds hopes for
the human condition is a fool.
		-- Albert Camus
#9 lore raw
Quoted 10 lines · Asheesh Laroia
Quoted 4 lines · Shawn O. Pearce

I've had enough cases of users losing their SSH key and needing to recreate it that I'd rather not have to manage a 50 user long authorized_keys file.

For what it's worth, if you haven't seen gitosis yet, you might want to take a look - at least it makes managing the keys easy.
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
has a nice tutorial.

Yea, I've looked at it before. There's a few reasons I don't use gitosis, although it does look to be an excellent chunk of Git automation:

* Its access controls aren't as powerful

Frankly the contrib/hooks/update-paranoid script is a lot more powerful then gitosis is, in terms of how it controls what branches a user can modify, and even what files they can change on a particular branch. And yes, I really do have rulesets that bend that hook to its limits.

* It uses the OpenSSH authorized_keys file format

I'm required to use the F-Secure SSH commerical server at day-job, because its "more trusthworthy" than the portable OpenSSH distribution. It uses a different syntax for the authorized keys, but can do essentially the same restricted command concept.

* If its in git, I prefer raw repository access

gitosis yanks stuff out into normal files to access it at runtime, e.g. its configuration file. I've had bad experiences with CVS not properly updating its admin files when changes are made to them. The update-paranoid hook I use actually cats the objects right out of the admin ODB on demand, ensuring its always evaluating the most recent version of the access rules.

* Its Python based.

I don't grok Python, and would rather not learn to. So hacking on gitosis isn't something that I would be doing. Ditto with all of my day-job cohorts. We use Perl, Bourne shell, and Java, with some tiny amount of Tk thrown about (though I'd say I'm probably the only one there that even remotely groks Tcl/Tk).

But thanks for the pointer.

Now if others corrected all of the above in gitosis (except the last item of course, I don't expect it to be rewritten in one of my preferred languages) I'd reconsider using it, because inventing wheels sucks.

Signature · 1 line
Shawn.
#10 lore raw
In reply to Junio C Hamano
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Shawn O. Pearce

Hmm. core.sharedrepository is sometimes a bad solution.

core.sharedrepository means I need to give write access to both the refs database and the object database to all members of the project. Some of whom may not be able to be trusted with tools like "rm", but who need real shell access to that system anyway. And sometimes management won't allow users to have two accounts on the same system (one that is fixed to git-shell, and one that has a real shell) because the world would implode if a user was given two different accounts for two different access purposes.

...

Quoted 3 lines

Another approach to do the same I can think of, without having to add 50 new accounts for 50 users, would be to collect a ssh key from each of these 50 users,

Also, our network of servers and desktops is actually now managed entirely through Active Directory. So all possible users already have accounts on every server. Passwords are synchronized across the entire network.

In other words, all of the management overheads associated with user accounts has already been paid. Centralized SSH/SSL/PGP key management is only adding an additional burden. For my day-job anyway.

Signature · 1 line
Shawn.
#11 lore raw
In reply to Shawn O. Pearce

Hi,

Quoted 20 lines · Shawn O. Pearce

## Owner (not jdoe)
##
cat >foo.git/hooks/update <<'EOF'
#!/bin/sh
test -z "$GIT_REMOTE_USER" || exit
case "$GIT_REMOTE_USER" in

  jdoe)     exit 0;;
  spearce)  exit 0;;
  *)        exit 1

esac
EOF
chmod u+x foo.git/hooks/update
chmod 700 foo.git

  git daemon \
      --export-all \
      --enable=receive-pack \
      --base=`pwd` \
      --listen=/tmp/shawn-git
Quoted 3 lines

## Other User
##
git push jdoe@server:/tmp/shawn-git/foo.git master

I probably miss something, but if you already go through SSH, the $USER is set appropriately, no?

So you could do without git-daemon entirely, and replace the GIT_REMOTE_USER variable in the hook by USER.

Ciao,
Dscho

#12 lore raw
Quoted 22 lines · Johannes Schindelin
Quoted 20 lines · Shawn O. Pearce

## Owner (not jdoe)
##
cat >foo.git/hooks/update <<'EOF'
#!/bin/sh
test -z "$GIT_REMOTE_USER" || exit
case "$GIT_REMOTE_USER" in

  jdoe)     exit 0;;
  spearce)  exit 0;;
  *)        exit 1

esac
EOF
chmod u+x foo.git/hooks/update
chmod 700 foo.git

  git daemon \
      --export-all \
      --enable=receive-pack \
      --base=`pwd` \
      --listen=/tmp/shawn-git
Quoted 6 lines
Quoted 3 lines

## Other User
##
git push jdoe@server:/tmp/shawn-git/foo.git master

I probably miss something, but if you already go through SSH, the $USER is set appropriately, no?

Sure, $USER is set. For "jdoe". But due to the "chmod 700 foo.git" above jdoe isn't actually allowed access to the repository directory. So it doesn't matter what $USER is set to, jdoe cannot get to the files of the repository.

Quoted 2 lines

So you could do without git-daemon entirely, and replace the GIT_REMOTE_USER variable in the hook by USER.

No, you can't.

If you give write access to a repository such that a user can push into it, there is little point in using the update hook to control access to the repository. Why? Because anyone with write access can just use the standard Git commands (e.g. git --git-dir=foo.git branch -D next) to maniplate the repository in ways that the update hook wouldn't like.

So if you want to give out write access, but have it be limited to what git receive-pack will permit (especially when coupled with an update hook like contrib/hooks/update-paranoid) you need to limit what a user can do to *only* executing git-receive-pack, but you also need to allow that receive-pack to actually have write permission on the repository.

So you come down to four options:

1) Make git-receive-pack setuid to the repository owner. This is uh, ugly.

2) Use the SSH key feature to have remote users login as the repository owner, but use the authorized_keys file to force them to only execute git-shell.
This is uh, ugly, especially with 50+ users.

3) Export git-daemon over TCP and --enable=receive-pack. This doesn't get us any authentication. Sure the user is limited to what the update hook allows, but the update hook has no way to trust who the remote peer is. You might as well not bother.

4) Add full user authentication to git-daemon and then do #3. The user authentication can provide data down into the update hook, such as by setting the $GIT_REMOTE_USER environment variable. That's basically this change, except I'm using bog standard SSH to perform the authentication for me.

If we don't do something like this then I think we need to teach git-daemon how to accept SSL connections, and then once you give it SSL you need to implement peer authentication by certificates, and then have git_connect() in connect.c also implement setting up SSL connections, and doing peer authentication with certificates. Ick.

Relying on SSH is the better approach in my opinion. It comes with a set of well trusted servers (OpenSSH) and user client tools that many users and administrators already understand (e.g. ssh-agent).

Someone on #git yesterday mentioned that a problem half-deferred (user authentication) is a problem half-solved. I've half-deferred the authentication problem to SSH, much as we already have it deferred to SSH... :-)

Signature · 1 line
Shawn.
#13 lore raw
Quoted 2 lines · Shawn O. Pearce

So you come down to four options:

<snip>

How about gitosis? It requires only one extra user (usually called git), which is the owner of all repos. This user has git-shell as its login shell. All users are authorized by their ssh keys. The configuration and kyes are stored in the special repo called gitosis-admin. You can define what users to what repositories have read or write access. This is done by adding a user to one or more groups defined in gitosis configuration. You can have as much groups as you want. The default configuration looks like this:

[group gitosis-admin]
writable = gitosis-admin
members = your-name

It defines the gitosis-admin group, member of which can write to the gitosis-admin repo, and you are member of that group.

WRRNING: I have not used gitosis myself, but it looks worthy of a try.

Dmitry

#14 lore raw
In reply to Shawn O. Pearce

Hi,

Quoted 27 lines · Shawn O. Pearce
Quoted 26 lines · Johannes Schindelin
Quoted 23 lines · Shawn O. Pearce

## Owner (not jdoe)
##
cat >foo.git/hooks/update <<'EOF'
#!/bin/sh
test -z "$GIT_REMOTE_USER" || exit
case "$GIT_REMOTE_USER" in

  jdoe)     exit 0;;
  spearce)  exit 0;;
  *)        exit 1

esac
EOF
chmod u+x foo.git/hooks/update
chmod 700 foo.git

  git daemon \
      --export-all \
      --enable=receive-pack \
      --base=`pwd` \
      --listen=/tmp/shawn-git

## Other User
##
git push jdoe@server:/tmp/shawn-git/foo.git master

Quoted 7 lines
Quoted 2 lines

I probably miss something, but if you already go through SSH, the $USER is set appropriately, no?

Sure, $USER is set. For "jdoe". But due to the "chmod 700 foo.git" above jdoe isn't actually allowed access to the repository directory. So it doesn't matter what $USER is set to, jdoe cannot get to the files of the repository.

Ah, that's what I missed. I thought you already used git-shell, and did not really read the chmod part.

Quoted 10 lines

So if you want to give out write access, but have it be limited to what git receive-pack will permit (especially when coupled with an update hook like contrib/hooks/update-paranoid) you need to limit what a user can do to *only* executing git-receive-pack, but you also need to allow that receive-pack to actually have write permission on the repository.

So you come down to four options:

1) Make git-receive-pack setuid to the repository owner. This is uh, ugly.

Concur.

Quoted 4 lines

2) Use the SSH key feature to have remote users login as the repository owner, but use the authorized_keys file to force them to only execute git-shell.
This is uh, ugly, especially with 50+ users.

Slight variation: do not permit other users access to your machine, except via git-shell. Then you don't need chmod 0700.

Quoted 5 lines

3) Export git-daemon over TCP and --enable=receive-pack. This doesn't get us any authentication. Sure the user is limited to what the update hook allows, but the update hook has no way to trust who the remote peer is. You might as well not bother.

Right. --enable=receive-pack was meant for environments where you have to trust everybody anyway (think "Visual" SourceSafe, or PVCS with repositories on network shares).

Quoted 5 lines

4) Add full user authentication to git-daemon and then do #3. The user authentication can provide data down into the update hook, such as by setting the $GIT_REMOTE_USER environment variable. That's basically this change, except I'm using bog standard SSH to perform the authentication for me.

AFAIR the plan was to keep git-daemon as simple and stupid as possible; in particular _not_ to add any authentication.

Quoted 5 lines

If we don't do something like this then I think we need to teach git-daemon how to accept SSL connections, and then once you give it SSL you need to implement peer authentication by certificates, and then have git_connect() in connect.c also implement setting up SSL connections, and doing peer authentication with certificates. Ick.

I never tried anything like this, but it should not be _that_ difficult, should it? Of course, I should read up on it before I say something about it first ;-)

Ciao,
Dscho

#15 lore raw
Quoted 9 lines · Johannes Schindelin
Quoted 5 lines · Shawn O. Pearce

Sure, $USER is set. For "jdoe". But due to the "chmod 700 foo.git" above jdoe isn't actually allowed access to the repository directory. So it doesn't matter what $USER is set to, jdoe cannot get to the files of the repository.

Ah, that's what I missed. I thought you already used git-shell, and did not really read the chmod part.

No, I'm not using git-shell. I'm actually currently using a setuid git-receive-pack, which we've both agreed is horribly ugly. I want to get away from that mess.

Quoted 7 lines
Quoted 4 lines

2) Use the SSH key feature to have remote users login as the repository owner, but use the authorized_keys file to force them to only execute git-shell.
This is uh, ugly, especially with 50+ users.

Slight variation: do not permit other users access to your machine, except via git-shell. Then you don't need chmod 0700.

This isn't an option. At least 10% of the users need a real shell on this system, but cannot be trusted to not directly edit the repository. I'm also not able to get them different user accounts (one for git-shell, one for normal shell) because giving the same human two different user accounts on the same UNIX system will cause the world to explode. At least according to some management people who get paid 3x what I get paid.

Of course, note those same people have also said that a SAMBA server cannot run on a system unless it is a SAMBA server. Catch-22. You cannot run SAMBA unless you are already running SAMBA. :-\

Quoted 8 lines
Quoted 5 lines

4) Add full user authentication to git-daemon and then do #3. The user authentication can provide data down into the update hook, such as by setting the $GIT_REMOTE_USER environment variable. That's basically this change, except I'm using bog standard SSH to perform the authentication for me.

AFAIR the plan was to keep git-daemon as simple and stupid as possible; in particular _not_ to add any authentication.

Yup. I think its smart. Defer authentication off to the standard OS tools, so we don't have to deal with it in git itself.

Yet I'm offering a patch for comment that adds some level of authentication to git-daemon. At least it still just relies on UNIX uids and doesn't actually try to link to PAM. :-)

Signature · 1 line
Shawn.