Giter Club home page Giter Club logo

sirtunnel's Introduction

What is it?

If you have a webserver running on one computer (say your development laptop), and you want to expose it securely (ie HTTPS) via a public URL, SirTunnel allows you to easily do that.

How do you use it?

If you have:

  • A SirTunnel server instance listening on port 443 of example.com.
  • A copy of the sirtunnel.py script available on the PATH of the server.
  • An SSH server running on port 22 of example.com.
  • A webserver running on port 8080 of your laptop.

And you run the following command on your laptop:

ssh -tR 9001:localhost:8080 example.com sirtunnel.py sub1.example.com 9001

Now any requests to https://sub1.example.com will be proxied to your local webserver.

How does it work?

The command above does 2 things:

  1. It starts a standard remote SSH tunnel from the server port 9001 to local port 8080.
  2. It runs the command sirtunnel.py sub1.example.com 9001 on the server. The python script parses sub1.example.com 9001 and uses the Caddy API to reverse proxy sub1.example.com to port 9001 on the server. Caddy automatically retrieves an HTTPS cert for sub1.example.com.

Note: The -t is necessary so that doing CTRL-C on your laptop stops the sirtunnel.py command on the server, which allows it to clean up the tunnel on Caddy. Otherwise it would leave sirtunnel.py running and just kill your SSH tunnel locally.

How is it different?

There are a lot of solutions to this problem. In fact, I've made something of a hobby of maintaining a list of the ones I've found so far.

The main advantages of SirTunnel are:

  • Minimal. It leverages Caddy and whatever SSH server you already have running on your server. Other than that, it consists of a 50-line Python script on the server. That's it. Any time you spend learning to customize and configure it will be time well spent because you're learning Caddy and your SSH server.
  • 0-configuration. There is no configuration on the server side. Not even CLI arguments.
  • Essentially stateless. The only state is the certs (which is handled entirely by Caddy) and the tunnel mappings, which are ephemeral and controlled by the clients.
  • Automatic HTTPS certificate management. Some other solutions do this as well, so it's important but not unique.
  • No special client is required. You can use any standard SSH client that supports remote tunnels. Again, this is not a unique feature.

Running the server

Assuming you already have an ssh server running, getting the SirTunnel server going consists of simply downloading a copy of Caddy and running it with the provided config. Take a look at install.sh and run_server.sh for details.

Note: Caddy needs to bind to port 443, either by running as root (not recommended), setting the CAP_NET_BIND_SERVICE capability on the Caddy binary (what the install.sh script does), or changing caddy_config.json to bind to a different port (say 9000) and using something like iptables to forward to that port.

Future Features

SirTunnel is intended to be a minimal tool. As such, I'm unlikely to add many features moving forward. However, the simplicity makes it easier to modify for your needs. For example, see this fork which adds functionality to help multiple users avoid overwriting each others' tunnels:

https://github.com/matiboy/SirTunnel

sirtunnel's People

Contributors

anderspitman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sirtunnel's Issues

Server setup - digital ocean example

I'm hoping to run the server on a Digital Ocean droplet. Is the following a good plan?

  • Create a new droplet (let's assume I use my SSH key instead of password-based)
  • Create a dedicated sirtunnel user so I'm not running as root
  • Create an SSH keypair id_sirtunnel for this new user. The private key is what will be used by users/clients
  • Clone SirTunnel to the droplet, run the install.sh and then run_server.sh
  • Register a dedicated domain for this (let's say rarkinstunnel.com)
  • Configure a wildcard DNS entry for rarkinstunnel.com pointing to my droplet IP
  • ssh -i ~/.ssh/id_sirtunnel -tR 9001:localhost:8080 rarkinstunnel.com sirtunnel.py sub1.rarkinstunnel.com 9001

Is that enough, including for Caddy to somehow fetch certs from LetsEncrypt for rarkinstunnel.com?

BTW I'm not sure I understand the 9001 port, which I've copied directly from your example. Does that need to be unique for each different user/tunnel I wish to run?

"remote port forwarding failed"

If my connection doesn't clean up well/network issue, I sometimes get this error:

Warning: remote port forwarding failed for listen port 11369

I have to change the port or restart / kill process with SirTunnel. Is there a way to have SirTunnel force override the port so this issue can be avoided?

Where do I need to run SirTunnel server instance and SSH server port 22?

Basically I have no idea what I'm doing.

From the section How do you use it? I still don't really understand where should I run those command.

let's say, I have a webserver running on PC and a Raspberry Pi.

Can you please kindly elaborate where should I run

  • run_server.sh
  • SSH server running on port 22 of example.com

And also do I need to have the PATH of sirtunnel.py in both Pi and PC?

Many thanks

Saved me!

this is an amazing project! saved me when i needed to do some forwarding

Opinion on URL routing

I'd like to know your opinion on implementing URL routing on top of tunnelling. This is my use case. I have a few IoT devices and each has a webserver installed on it. Now, I want to achieve remote access to the web dashboard and have the SSH access to it too by having a common DNS.

For example, lets say www.example.com is the domain. I want to access the IoT device's dashboard by www.example.com/DeviceId/web and for SSH, www.example.com/DeviceId/ssh

As far as I know, ngrok has this option available but expensive. I'd like to know if above use case can be achieved using this code with necessary changes.

Invalid traversal path

Caddy error when starting ssh script;

request error{"error": "invalid traversal path at: config/apps/http/servers/sirtunnel/routes", "status_code": 500}

caddy_config.json:

{
  "apps": {
    "http": {
      "servers": {
        "[server_hostname]": {
          "listen": [":443"],
          "routes": [
          ]
        }
      }
    }
  }
}

Port 80 listening issue?

Hello! This seems pretty slick. I've had issues with serveo and localtunnel in the past. Hoping this will be "the answer."

I can get things working with this json config:

{
  "apps": {
    "http": {
      "servers": {
        "sirtunnel": {
          "listen": [":4443"],
          "routes": [
          ]
        }
      }
    }
  }
}

I've got nginx running on this system and need to use a non-standard port. The issue I get now is when I try to connect to sir tunnel, it looks like caddy is throwing this error:

2023/08/13 21:56:38.564 ERROR   admin.api       request error   {"error": "loading new config: http app module: start: tcp: listening on :80: listen tcp :80: bind: address already in use", "status_code": 500}

I'm currently exploring caddy docs trying to figure this out. Thought I'd ask here in the event someone knew how to change this. I think this is the last piece of the puzzle.

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.