git-remote-only 687 B

12345678910111213141516171819
  1. #!/usr/bin/env python
  2. #
  3. # Restrict an ssh authorized_keys entry to be used only for git push
  4. # and git fetch. Use thusly:
  5. #
  6. # command="git-remote-only /path/to/repository.git alice@example.org" ssh-rsa ABCDEF....== alice@example.org dedicated git key
  7. #
  8. # You might also want options like no-port-forwarding,no-X11-forwarding,no-agent-forwarding.
  9. import os, sys, shlex
  10. os.environ.update(GIT_REMOTE_ONLY_COMMAND = " ".join(sys.argv))
  11. cmd = shlex.split(os.getenv("SSH_ORIGINAL_COMMAND", ""))
  12. if len(cmd) == 2 and cmd[0] in ("git-upload-pack", "git-receive-pack") and cmd[1] == sys.argv[1]:
  13. os.execv("/usr/bin/" + cmd[0], cmd)
  14. sys.exit("Not authorized: {}".format(" ".join(cmd)))