GithubHelp home page GithubHelp logo

geoffreywiseman / tunnel-boring-machine Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 3.0 90 KB

A ruby application for managing SSH tunnels.

Home Page: http://geoffreywiseman.github.com/tunnel-boring-machine

License: The Unlicense

Ruby 100.00%

tunnel-boring-machine's Introduction

Tunnel Boring Machine

Build Status Dependency Status Code Climate

Tunnel Boring Machine is a ruby application to manage SSH tunnels, which you can use to achieve something a little like a VPN, wherein SSH access to a server can give you access to the network beyond that server.

I use SSH tunnels on a regular basis to access resources at client sites that are not exposed directly to the internet as a whole. Managing those tunnels as a series of bash scripts or aliases became cumbersome. I wanted / needed something better, and the tunnel boring machine has evolved from that need.

Current Status

It's pretty early days. I'm using this myself, and I've shared it so other people can use it, but its advantages over a shell script are still fairly thin. There are some enhancements that I have planned that might make the case much stronger, but we'll see.

Installing

It is bundled as a ruby gem, so if you have Ruby and RubyGems installed, simply run:

gem install tbm

If you prefer, you can certainly download it and build it yourself, or simply invoke the ruby code from the command-line.

Invocation

For the time being, TBM is a simple command you invoke to open the tunnels you need, then you cancel with ^C to close the tunnels that you had opened. Something like this:

$ tbm dev-nginx

Eventually, I expect that TBM will become a little more interactive, allowing you to open additional tunnels without closing the ones you already opened, close a tunnel without closing all of them, and so forth. Whether it does this as an interactive program, a shell command that interacts with a running process is all TBD.

Configuration

You configure the tunnel boring machine by creating a configuration file in YAML form at ~/.tbm. At the moment, you can't have multiple configuration files, change the location of the configuration file or anything of that nature.

An example configuration file follows:

dev.example.com:
  jira: 2222
  teamcity:
    tunnel: 8888
    alias: tc
  jdbc-as400:
    as400: [ 449, 8470, 8471, 8476 ]
    alias: [ ju, ussi ]
  qa:
    tunnel: 8080
  staging (stage, st): 8080:80
  5250: 8023:as400:23
  webfacing: as400:10905

I have documented the configuration file format on the website.

License

I've put it under the UNLICENSE. Basically, I don't care if you use it, bundle it inside commercial software, or otherwise make use of it, and I don't offer any kind of warranty or support guarantees, nor do I guarantee that any of the projects dependencies are suited for whatever purpose you have in mind. That's all up to you. That said, if you want to talk about it, see the next section.

Contact

If you're using TBM and you want to talk about it or make suggestions, get in touch with me on Twitter or send me an email. If there's enough interest, I'd be happy to set up a group, but for the time being that seems like overkill.

tunnel-boring-machine's People

Contributors

geoffreywiseman avatar eliotk avatar mattdoller avatar rtlechow avatar

Stargazers

Saeed Kefayati avatar Dmitry Shitov avatar Marcos Lorenzo avatar Sebastian Daniel avatar  avatar Rob Marano avatar  avatar Oliver Thomsen avatar Michael Vincent avatar  avatar

Watchers

 avatar Michael Vincent avatar James Cloos avatar  avatar  avatar

tunnel-boring-machine's Issues

Better Handling for Common Host in Config

If most of your tunnels are to a single host, the "host:" line gets a little irritating, there's a lot of repetition there. Would it be good to have a default host? Or should host be the topmost configuration element, and target names be under that?

dev.mycompany.com:
    dashboard:
        alias: db 
        forward: 3000
    qa: [8080,8443]
    prod:
        forward: 
           prod: [ 8080, 8443 ]
    staging:
            alias: stage
            forward: staging:8080

That would make it hard to support multiple hosts under a single target name in the future, but that's a far-flung possibility, and possibly not even a great idea.

Add --verbose switch

Extra information, particularly the parsing of the config, could be displayed. Put more thought into the existing output, consider if it should be more compact, or if we need multiple levels of verbosity.

Document TBM Config File Format

The updated config file format is pretty flexible and deserves half-decent documentation, which should either go in gh-pages or the wiki or both. I'm leaning towards gh-pages, leaving the wiki more for interested developers than for end users.

Unhandled Exception Net::SSH::Disconnect

/Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/transport/packet_stream.rb:87:in next_packet': connection closed by remote host (Net::SSH::Disconnect) from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/transport/session.rb:172:inblock in poll_message'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/transport/session.rb:167:in loop' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/transport/session.rb:167:inpoll_message'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:454:in dispatch_incoming_packets' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:216:inpreprocess'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:200:in process' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:inblock in loop'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in loop' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:inloop'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/machine.rb:54:in forward_ports' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/machine.rb:26:inblock in bore'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh.rb:199:in start' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/machine.rb:24:inbore'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/cli.rb:41:in parse_and_run' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/bin/tbm:5:in<top (required)>'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/bin/tbm:23:in load' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/bin/tbm:23:in

'
from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in eval' from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in'

2.0

Adding support for an Interactive Mode to TBM, so that you can reopen tunnels, add more tunnels to open connections, etc.

Handle Psych Syntax Error

If the .tunnels file can't be parsed properly, Psych throws a Psych::SyntaxError. That's fine, but stack traces make crappy error messages, so catch and be more graceful.

Deal with ENETDOWN Error

Got this stack trace:

/Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffered_io.rb:65:in `recv': Network is down - recvfrom(2) (Errno::ENETDOWN)
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffered_io.rb:65:in `fill'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:231:in `block in postprocess'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:227:in `each'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:227:in `postprocess'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:206:in `process'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `block in loop'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/machine.rb:54:in `forward_ports'
    from /Users/geoffrey/.rvm/gems/ruby-1.9.3-p392/gems/tbm-0.3.0/lib/TBM/machine.rb:26:in `block in bore'

Improve Code Climate Results

Code Climate thinks the configuration parser is complex. It might be right. Think about it, decide what, if anything to do about it.

Error in display of tunnels opened

There's something wrong with the output of the server:

Opened connection to user@host:
    tunneled port 8080 to forward:8080

Not sure why it would say "forward" here -- should probably be "host". I'm doing some fancy footwork to avoid using 'localhost' where it is a little confusing, and I'm probably doing something wrong there. Also, 'tunneled' should be 'tunnelled'.

Interactive Mode

Allow tunnels to be invoked in interactive mode if nothing specified on command-line.

Include the version number in the prompt, like:
tunnels-1.0#

Move tunnelling code out of CLI

For purely aesthetic reasons, I don't want the tunneling code in the CLI. The CLI's class should be dedicated to human/computer interface, not networking. The networking code either belongs in 'Target', or in an entirely new class.

Add --help switch

So that new users can get some level of easy refresher on how to use this thing.

Support for Multiple Targets on Same Host

As long as both targets are on the same host, this is reasonably easy to accomplish, and worth doing. If they involve multiple hosts, that's a different story, filed separately.

Travis CI

Build with Travis. Add badge to readme.

List Tunnels

Display the named tunnels that are available to open. Indicate if any are active right now.

Target Aliases

Allow the definition of aliases for targets, so that you can have a formal name like 'teamcity' and a shorter version like 'tc' for day-to-day use.

Multi-Process architecture

Restructure tunnels so that it's not an interactive program, but rather a multi-process app where a command-line (e.g. Thor-based) interacts with a back-end process that stays alive while there's an open tunnel, does keep-alives. This way the commands terminate rather than "using up" a shell.

Net::SSH Updated

Figure out why, and probably update TBM to use the latest patch version.

Better Readme Explanation

A better explanation in the readme about how to use TBM, how to configure it, what a configuration file looks like, etc. That could go in the wiki, but at this stage, I think a better readme is sufficient.

Better Error Handling for Failed Connections

There's a few symptoms of a failed ssh tunnel, and in none of those cases is a stack trace justified.

I can't guarantee that I'll catch every error, but I can at least catch the ones that I've seen myself:
Connection reset by peer - recvfrom(2) (Errno::ECONNRESET)
Operation timed out - recvfrom(2) (Errno::ETIMEDOUT)

Define Named Tunnels

Use the app to define named tunnels, rather than editing a configuration file.

New Config File Format

Although this will also solve #26, this has other effects, and deserves its own description. Basically, when looking over some example configuration files, I saw a lot of host repetition, and put some more thought into what this configuration file should look like for my current needs.

This format might be worse for someone else's needs, but at the moment, my own needs and those of my coworkers are the most important, because we're the most likely users.

user@ssh-host:
    name: port
    name: local-port:remote-port
    name: local-port:remote-host:remote-port
    name:
        alias: alias
        forward: port
    name: [port,port]
    name:
        alias: [alias1, alias2]
        remote-host: [port,port,port]

This gives the flavour of the config changes without showing all of the available options.

Basically, putting the host at the top level with an optional username and reducing the overall amount of config for my common cases.

Open Multiple Targets with Different Hosts

Not sure how easy it is to balance two SSH connections unless I go multi-process or multi-thread. Gotta do some experiments to see how well this works, if at all.

Can't put a milestone on this one until I've done some research on the required effort.

Different Ports Client/Server

The port mapped locally doesn't have to be the same as the server-mapped port.

I haven't figured out what this should look like yet.

Different Port Syntax

forward: '8080 -> 8888'

Feels clunky, but fairly compact.

'Map' instead of 'Forward'

map: { 8080: 8088 }

Then what do you do if it's a different server?

Another Level of Hash

teamcity:
    host: dev
    forward:
        8080: 8111
tomcat
    host: gateway
    forward:
        staging: { 8000 : 8080, 8001: 8443 }
        production { 8100: 8080, 8101: 8443 }

Shorter Configuration for Aliases

Might be nice to support aliases with a shorter configuration form if that's all you need.

Something like:

teamcity (tc, ci): 8888

Improve 'localhost:<port>' message

When TBM prints its port forwards to a remote host, it refers to it the way you would in an ssh tunnel config, as 'localhost'. That's always been a little confusing in that it's localhost with respect to the machine you're tunneling into, but it's not your localhost port.

That's made more confusing by TBM config, which doesn't force you to totally grok that by allowing you not to even make the localhost reference. So TBM should either not mention localhost in that scenario, or be more explicit by using the remote host's name instead.

Target Inclusion

Might be nice if you were able to include one target within another to avoid duplication when you have overlapping sets of tunnels you might want to use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.