Giter Club home page Giter Club logo

pgrok's Introduction

pgrok banner

Poor man's ngrok

Sourcegraph

What?

The pgrok is a multi-tenant HTTP/TCP reverse tunnel solution through remote port forwarding from the SSH protocol.

This is intended for small teams that need to expose the local development environment to the public internet, and you need to bring your own domain name and SSO provider.

It gives stable subdomain for every user, and gated by your SSO through OIDC protocol.

Think of this as a bare-bones alternative to the ngrok's $39/user/month enterprise tier. Trying to put this behind a production system will blow up your SLA.

For individuals and production systems, just buy ngrok, it is still my favorite.

Why?

Stable subdomains and SSO are two things too expensive.

Why not just pick one from the Awesome Tunneling? Think broader. Not everyone is a dev who knows about server operations. For people working as community managers, sales, and PMs, booting up something locally could already be a stretch and requiring them to understand how to set up and fix server problems is a waste of team's productivity.

Copy, paste, and run is the best UX for everyone.

How?

Before you get started, make sure you have the following:

  1. A domain name (e.g. example.com, this will be used as the example throughout this section).
  2. A server (dedicated server, VPS) with a public IP address (e.g. 111.33.5.14).
  3. An SSO provider (e.g. Google, JumpCloud, Okta, GitLab, Keycloak) that allows you to create OIDC clients.
  4. A PostgreSQL server (Render, Vercel, Cloud SQL, self-host).

Note

  1. All values used in this document are just examples, substitute based on your setup.
  2. All examples in this document use HTTP for brevity, you may refer to our example walkthrough of setting HTTPS with Caddy and Cloudflare.

Set up the server (pgrokd)

  1. Add the following DNS records for your domain name:
    1. A record for example.com to 111.33.5.14 (with DNS only if using Cloudflare)
    2. A record for *.example.com to 111.33.5.14 (with DNS only if using Cloudflare)
  2. Set up the server with the single binary, Docker or Docker Compose.
  3. Alter your network security policy (if applicable) to allow inbound requests to port 2222 from 0.0.0.0/0 (anywhere).
  4. Download and install Caddy 2 on your server, and use the following Caddyfile config:
    http://example.com {
        reverse_proxy * localhost:3320
    }
    
    http://*.example.com {
        reverse_proxy * localhost:3000
    }
    
  5. Create a new OIDC client in your SSO with the Redirect URI to be http://example.com/-/oidc/callback.

Set up the client (pgrok)

  1. Go to http://example.com, authenticate with your SSO to obtain the token and URL (e.g. http://unknwon.example.com).
  2. Download the latest version of the pgrok:
    • For Homebrew:
      brew install pgrok
    • For others, download the archive from the Releases page.
  3. Initialize a pgrok.yml file with the following command (assuming you want to forward requests to http://localhost:3000):
    pgrok init --remote-addr example.com:2222 --forward-addr http://localhost:3000 --token {YOUR_TOKEN}
    • By default, the config file is created under the standard user configuration directory (XDG_CONFIG_HOME):
      • macOS: ~/Library/Application Support/pgrok/pgrok.yml
      • Linux: ~/.config/pgrok/pgrok.yml
      • Windows: %LOCALAPPDATA%\pgrok\pgrok.yml
    • Use --config flag to specify a different path for the config file.
  4. Launch the client by executing the pgrok or pgrok http command.
    • By default, pgrok expects the pgrok.yml is available under the standard user configuration directory, or under the home directory (~/.pgrok/pgrok.yml). Use --config flag to specify a different path for the config file.
    • Use the --debug flag to turn on debug logging.
    • Upon successful startup, you should see a log looks like:
      ๐ŸŽ‰ You're ready to go live at http://unknwon.example.com! remote=example.com:2222
      
  5. Now visit the URL.

As a special case, the first argument of the pgrok http can be used to specify forward address, e.g.

pgrok http 8080

Raw TCP tunnels

Important

You need to alter the server network security policy (if applicable) to allow additional inbound requests to port range 10000-15000 from 0.0.0.0/0 (anywhere).

Use the tcp subcommand to tunnel raw TCP traffic:

pgrok tcp 5432

Upon successful startup, you should see a log looks like:

๐ŸŽ‰ You're ready to go live at tcp://example.com:10086! remote=example.com:2222

The assigned TCP port on the server side is semi-stable, such that the same port number is used when still available.

Override config options

Following config options can be overridden through CLI flags for both http and tcp subcommands:

  • --remote-addr, -r -> remote_addr
  • --forward-addr, -f -> forward_addr
  • --token, -t -> token

HTTP dynamic forwards

Typical HTTP reverse tunnel solutions only support forwarding requests to a single address, pgrok can be configured to have dynamic forward rules when tunneling HTTP requests.

For example, if your local frontend is running at http://localhost:3000 but some gRPC endpoints need to talk to the backend directly at http://localhost:8080:

dynamic_forwards: |
  /api http://localhost:8080
  /hook http://localhost:8080

Then all requests prefixed with the path /api and /hook will be forwarded to http://localhost:8080 and all the rest are forwarded to the forward_addr (http://localhost:3000).

Vanilla SSH

Because the standard SSH protocol is used for tunneling, you may well just use the vanilla SSH client.

  1. Go to http://example.com, authenticate with your SSO to obtain the token and URL (e.g. http://unknwon.example.com).
  2. Launch the client by executing the ssh -N -R 0::3000 example.com -p 2222 command:
    1. Enter the token as your password.
    2. Use the -v flag to turn on debug logging.
    3. Upon successful startup, you should see a log looks like:
      Allocated port 22487 for remote forward to :3000
      
  3. Now visit the URL.

Explain it to me

pgrok network diagram

Contributing

Please read through our contributing guide and set up your development environment.

Sponsors

Credits

The project wouldn't be possible without reading function61/holepunch-server, function61/holepunch-client, and TCP/IP Port Forwarding.

License

This project is under the MIT License. See the LICENSE file for the full license text.

pgrok's People

Contributors

chenrui333 avatar christoph-wagner avatar cwww3 avatar czyt avatar deepsource-io[bot] avatar dependabot[bot] avatar jeroenhd avatar kalanchan avatar michalg91 avatar nycodeghg avatar unknwon avatar wuhan005 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  avatar  avatar  avatar

pgrok's Issues

docs: HTTPS example setup

Type out the question

what all changes needs to be done to make the setup https

Consent

  • I agree to follow the Code of Conduct
  • I understand a satisfying answer is not guaranteed

Method to sponsor the project and send some cash to the developer.

Version

1

Describe the bug

I found no method to financially support this project.

I would be interested in providing some capital to the developer and/or paying a bit for customization and assistance deploying. The project I plan to use this with is not an ngrok competitor and is a bit more specialized.

Is there a way that we could chat about such things?

To reproduce

Look for a sponsorship link.

Find no sponsorship link.

Expected behavior

A sponsorship link that provides a method for folks to send money to the developer using paypal or open collective or github sponsorship programs.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

config does not support pathing

Nitpicking i know..

pgrok --config $(PWD)/pgrok.example.yml does not work
pgrok --config pgrok.example.yml does not work

2023-03-30 11:40:05 FATA Failed to load config config=/Users/apple/.pgrok/pgrok.yml error="read file: open /Users/apple/.pgrok/pgrok.yml: no such file or directory"

Would be nice if the --config arg did allow overriding


Also pgrokd -config pgrokd.exmaple.yml uses a different arg syntax. Would be nice if we used "--" for all config args ?

Also fix the spelling of "exmaple"...

Consent

  • I agree to follow the Code of Conduct
  • I understand a satisfying answer is not guaranteed

400 bad request using Nginx

Version

1.4.1

Describe the bug

If I try to access the site via Nginx using a reverse proxy I get '400 bad request' returned to me.

This is weird because I can't track down what is causing this issue.

To reproduce

Install Pgrok via docker compose

Configure Pgrok as following:
https://pastebin.com/6Rqf1fSs

Nginx Config:
https://pastebin.com/ckfHC2iL

Expected behavior

Pgrok gets proxied.

Additional context

I can connect to Pgrok's front end if I navigate to it via the IP address however when I try to connect using the proxy passed nginx page I get the error.

https://tunnel.felixklg.dev/
vs http://51.89.149.136:3320/ (I took down access via IP after making this issue) (trust me bro, it worked)

Consent

Postgres connection does not work via a Unix Socket

Version

1.3.3

Describe the bug

When trying to connect to postgres via a unix socket, pgrok gets confused and does not connect.

panic: session: create table: failed to connect to `host=/var/run/postgresql user=pgrok database=run/postgresql:5432/pgrok`: server error (FATAL: database "run/postgresql:5432/pgrok" does not exist (SQLSTATE 3D000))

I tried to leave the port empty, but that also does not work.

To reproduce

Use this configuration:

{
  "database": {
    "database": "pgrok",
    "host": "/run/postgresql",
    "port": 5432,
    "user": "pgrok"
  }
}

I tested on NixOS, so the postgres socket path is probably different on other distros.

Expected behavior

pgrok should connect to postgres via a unix socket just fine.

Additional context

I think the port here should be optional, but I'm not sure and haven't tested that.

Consent

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.