error in hook during the `git push` via SSH

Issue #148 new
Oleg Pivovarov created an issue

I deployed the Kallithea, and clone the bare git repository via ssh.

git clone ssh://git@192.168.0.1/home/git/repositories/my_project

During the "git push", I get an error:

> git push origin master
Enter passphrase for key '/home/r2d2/.ssh/id_rsa': 
Counting objects: 3, done.
Writing objects: 100% (3/3), 184 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Traceback (most recent call last):
remote:   File "hooks/pre-receive", line 34, in <module>
remote:     main()
remote:   File "hooks/pre-receive", line 30, in main
remote:     _handler(repo_path, push_data, os.environ)
remote:   File "/srv/www/htdocs/Kallithea-0.2.1/kallithea/lib/hooks.py", line 373, in <lambda>
remote:     handle_git_receive(repo_path, revs, env, hook_type='pre'))
remote:   File "/srv/www/htdocs/Kallithea-0.2.1/kallithea/lib/hooks.py", line 396, in handle_git_receive
remote:     extras = _extract_extras(env)
remote:   File "/srv/www/htdocs/Kallithea-0.2.1/kallithea/lib/utils2.py", line 644, in _extract_extras
remote:     raise Exception('Missing key %s in os.environ %s' % (e, rc_extras))
remote: Exception: Missing key 'username' in os.environ {}

how to fix it?

Comments (6)

  1. Mads Kiilerich

    Kallithea doesn't have ssh support yet.

    It is possible the git hooks somehow should handle direct access without Kallithea - I don't know what that should be.

  2. Teemu Vesala

    There is workaround if you don't need Kallithea's access control. This is short instructions how we I managed to get it working. NOTE! If you have strict security requirements, store the API key outside the hooks directory. This is still our proof of concept, and security is not considered. 1) Remove the hooks 2) Create the API key with the user who has admin rights 3) Create the following kind post-receive hook:

    #!/usr/bin/env bash
    # If you are using virtual environment, activate it. Otherwise remove the next line.
    source /path/to/kallithea-venv/bin/
    # Invalidates the cache of the repository. If your Kallithea is not at 127.0.0.1 port 5000, change the apihost value.
    kallithea-api --apihost=http://127.0.0.1:5000/ --apikey=<API KEY> invalidate_cache repoid:<REPOSITORY NAME>
    

    Hopefully this helps you to proceed. This seems to work, but I still can't give 100% guarantee.

  3. Teemu Vesala

    Yes. That works. Thanks. So change the last line with that. Security risks are reduced right away.

  4. Log in to comment