SSH push/pull

685 views
Skip to first unread message

Matt Zuba

unread,
Dec 14, 2011, 1:26:44 PM12/14/11
to rhod...@googlegroups.com
I've created a script to handle accessing RhodeCode via SSH and would like to know if there are any volunteers that would like to play with it and test it out.

Some key features:
Admins can access the console as normal if needed (ssh hg@server) or via hg (hg clone ssh://hg@server/repo)
Verifies the user is still active/valid and they have permission to perform the action they are attempting to do.

The authorized_keys file needs to be manually modified for the time being.  I haven't yet had time to create an interface from within RhodeCode to allow users to add their own keys yet (like BitBucket).

I'll be getting the code up on BitBucket shortly.

Marcin Kuzminski

unread,
Dec 14, 2011, 9:17:19 PM12/14/11
to rhod...@googlegroups.com
Sounds very cool, it could be a major step for rhodecode having this, and a nice replacement/alternative for hg-server

Matt Zuba

unread,
Dec 15, 2011, 1:07:02 AM12/15/11
to rhod...@googlegroups.com
So I ran into an issue with trying to use hooks to verify a push/pull authorization and found that the pulllog hook runs before the hook to verify if a user can even pull, so it pollutes the journal with incorrect data.  I'm going to rework the code to not use hooks and just check for the raw commands being sent over SSH.  Once I get that working, I'll post the code. :(

Matt Zuba

unread,
Dec 16, 2011, 6:11:17 PM12/16/11
to rhod...@googlegroups.com
Here we go... pushed the library code into my fork of RhodeCode...


To use:

Plop the code below into some file (let's call it 'rhodecode_ssh').  Edit the config path and shebang path based on your environment.  Make the file executable (chmod +x rhodecode_ssh).  Then add the following before a public key in authorized_keys (changing [username] to that of the rhodecode user).  You can also add (symlink or otherwise) rhodecode_ssh to a directory on your system PATH (maybe /usr/local/bin) and then use only the script name instead of the whole path in the command line below:
command="/path/to/rhodecode_ssh [username]",no-port-forwarding,no-X11-forwarding,no-agent-forwarding

 
Code:
#!/path/to/python/exe/that/runs/rhodecode
# -*- coding: utf-8 -*-
import logging
from paste.deploy import appconfig
from rhodecode.config.environment import load_environment
from rhodecode.lib.ssh import SecureShell
from rhodecode.model import init_model
from sqlalchemy import engine_from_config 
 
if __name__ == "__main__":
    # Only log critical errors
    logging.basicConfig(level=logging.CRITICAL,
                        format="%(asctime)s %(levelname)-5.5s %(message)s")
    # Load the environment for RhodeCode so we can utilize it's database
    conf = appconfig('config:/path/to/production.ini')
    config = load_environment(conf.global_conf, conf.local_conf)
    engine = engine_from_config(conf, 'sqlalchemy.db1.')
    init_model(engine)
    shell = SecureShell(config)
    shell.serve()

Marcin Kuzminski

unread,
Jan 9, 2012, 10:37:38 AM1/9/12
to rhod...@googlegroups.com
Hi Matt.

This sounds great, how it's getting alone ?

Matt Zuba

unread,
Jan 9, 2012, 11:18:32 AM1/9/12
to rhod...@googlegroups.com
I haven't made much more progress.  I'm thinking I'm going to revert back to a hook based process if I can reorder the hooks in my code to force the auth hook first.  I think it's much cleaner to use the hooks than to intercept the raw wire commands.  However the current implementation is working well on my production machine (I think I needed a minor change because I coded it against 1.3, but we're running 1.2.3.

I still need to work on an admin interface for all of this though.

Bogdan Kulbida

unread,
Apr 2, 2013, 4:33:40 AM4/2/13
to rhod...@googlegroups.com
Hi Matt
We love such opportunity to have an admin UI to add ssh keys. It is revolutionary to have this feature. If you will implement it RhodeCode will the real competitor for the systems like BitBucket. Our group of developers love RhodeCode. Looking forward to hear from you soon about any progress on that. Thanks.

понедельник, 9 января 2012 г., 18:18:32 UTC+2 пользователь Matt Zuba написал:

Marcelo Bissaro

unread,
Apr 2, 2013, 10:35:58 AM4/2/13
to rhod...@googlegroups.com

 Just adding a thumbs up! I will love this feature too.
 
 Actually, we have some scripts that need to download the code from remote repository, and we are doing it using git clone ssh://path.to.repo instead of https. With this, we can configure public RSA keys between the servers, and everything works without the password's prompt.
 
 But with this approach, we bypass the rhodecode permissions schema (users, groups, etc)
 
 We can make it works using ~/.netrc with 700 permission as well, but as it requires the password to be placed in this file as plain text, and we decided to not use it.
 
 Add RSA public keys on Rhodecoce interface will be the most ellegant solution ever!

Marcelo



--
You received this message because you are subscribed to the Google Groups "rhodecode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rhodecode+...@googlegroups.com.
To post to this group, send email to rhod...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marcin Kuźmiński

unread,
Apr 2, 2013, 10:58:48 AM4/2/13
to rhod...@googlegroups.com

Just FYI there's another person working on ssh wrapper for rhodecode I'll update this topic when i have more info.

Stephan Jauernick

unread,
Apr 4, 2013, 4:27:35 AM4/4/13
to rhod...@googlegroups.com, mar...@python-works.com
Hi,

Due to private needs I am working on a SSH Wrapper, supporting hg/git, for RhodeCode, it supports the rhodecode permission system by intercepting the RAW commands from SSH.

This currently works via a API request. My next step is to implement the get_repo API call to check if the repo is actually accessable with the calling vcs and if locking needs to be handled. Also i need to do some code cleaning.

I looked at your code Matt and I think its a nice approach over using the API, will see if i can adapt it easily!

My code is in my own RhodeCode instance over at http://vcs.stejau.de/stephan/rhodecode-ssh.

Feel free to comment on it!

Future plans feature an integration into the RhodeCode UI(repo and userbased ro/rw keys)!

Kind Regards,
Stephan Jauernick

Matt Zuba

unread,
Apr 4, 2013, 4:19:44 PM4/4/13
to rhod...@googlegroups.com
The main thing that I needed to keep in mind when writing my SSH wrapper was the need to SSH into the account that also hosted the mercurial repositories (ie: like bitbucket, every repo goes through the 'hg' user, and the SSH key determines the user on the back end).  The SSH wrapper i wrote handles the ability to SSH in as if it was a normal SSH login, in addition to also sending mercurial commands via SSH.  Sorry I haven't been able to contribute more to this, I was hoping to get more done during my work day but we've had a lot of projects on-going and I'm the only one that uses SSH anyway, all of the other devs just use their Rhodecode logins (which is hooked to LDAP).


--
You received this message because you are subscribed to a topic in the Google Groups "rhodecode" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rhodecode/9-5ia1Q8yD4/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to rhodecode+...@googlegroups.com.

Илья Беда

unread,
May 10, 2013, 12:47:16 PM5/10/13
to rhod...@googlegroups.com
Hello.
I have done a lot of work for ssh integration.
Now i am having:
  1. Database models for RSA keys
  2. UI for RSA key add
  3. Auth backend for git and mercurial
  4. ssh wrapper based on Matt Zuba code
I have some problems in setting up .ssh/authorized_keys handler.
Now a do it manualy, but i want to do it automaticaly.
If some one could test my code, it will be greate.

Marcin Kuzminski

unread,
May 12, 2013, 7:13:56 PM5/12/13
to rhod...@googlegroups.com
Great work !

One thing worries me, it's 600 changesets behind the original repo, any chance this could be rebased on top of current beta branch (more specific the dev bookmark) ?

Marcin Kuzminski


--
Reply all
Reply to author
Forward
0 new messages