Secure receive-pack to run setuid
PATCH 1/1 Secure receive-pack to run setuid
Some central repository type configurations are easier to setup and configure if all writes to the repository are made by the repository owner user. In many corporate settings this can easily be a single user account on the system, e.g. 'gitadmin'.
Since most writes to bare repositories are performed through receive-pack, one way to make them all occur as the admin user is to make the receive-pack executable owned by the admin account ('gitadmin') and mark it setuid. However that opens a huge security hole as any other user can create a repository with an evil world-executable update hook and then push into it. The hook would run as the repository owner ('gitadmin') and be allowed full access to its files.
If receive-pack is running setuid then we perform a strict set of checks to verify we will only execute hooks that are deemed safe, and we do so only from within a very restricted environment. If the hooks aren't safe then we drop the setuid privileges back to the real user and continue running normally.
The security of this still assumes that the central repository owner (e.g. 'gitadmin') won't run receive-pack themselves against untrusted repositories, as doing so means you are running someone else's hook as yourself. This however is smart practice anyway, even for non repository owners, as pushing to a repository you don't know implicitly runs hooks (as you) that you may not have control over.
I'm currently using this patch along with the contributed paranoid update hook (contrib/hooks/update-paranoid) to secure and control write access to a number of Git repositories in a corporate environment.
---
I'm not sure we should apply this. I'm using this patch myself, and it doesn't break anything for non-setuid use, so maybe its OK to apply. Certainly be nice if something like this was natively supported, but maybe my use case here is just too nuts to be in the main tree.
Of course I would also appreciate any auditing that others can do on this code. It looks correct to me, and has been beaten on pretty well, but it could benefit from more eyes.
Documentation/git-receive-pack.txt | 29 ++++++++ receive-pack.c | 128 ++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 0 deletions(-)
Documentation/git-receive-pack.txt +29 -0
@@ -146,6 +146,35 @@ if the repository is packed and is served via a dumb transport. #!/bin/sh exec git-update-server-info +SETUID BEHAVIOR +--------------- +If the git-receive-pack executable has the setuid bit enabled then +additional access control checks will be performed before entering +into the specified repository directory. + +If the program is running setuid root (uid 0): it will stat the +repository directory to determine the owner and then switch the +effective user ID to that owner ID. The real user ID will be kept +intact for use in hooks. Additional checks will be made as described +below. + +If the program's effective user ID is not the real user ID, but +the effective user ID is the repository owner, then access is +allowed only if the following are all true: + +* $GIT_DIR/hooks is owned by the repository owner, and is not + group or world writable. +* All of the hooks described above that are present in + $GIT_DIR/hooks are owned by the repository owner, and none + of them are group or world writable. +* At least one of $GIT_DIR/hooks/pre-receive or $GIT_DIR/hooks/update + exists and is executable by the repository owner. + +If the program's effective user ID is not the real user ID, and the +effective user ID is not the repository owner, then the effective user +ID is changed to the real user ID. This drop in privileges prevents an +evil local user from gaining control of the program's account by making +a repository with an evil hook, and then running receive-pack. SEE ALSO --------
receive-pack.c +128 -0
151 lines not on this page · raw message
Signature · 1 line
1.5.1.1.135.gf948