diff --git a/.gitignore b/.gitignore index 590e195..3ea3c64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,2 @@ -ngrok -device.crt -device.csr -device.key -rootCA.key -rootCA.srl -rootCA.pem \ No newline at end of file +bin +certificate diff --git a/Dockerfile b/Dockerfile index 8e06ea3..f34dc0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,19 @@ -FROM debian:jessie -MAINTAINER Joeri Verdeyen +FROM ubuntu:18.04 RUN apt-get update && \ - apt-get install -y build-essential golang git mercurial && \ - mkdir -p /release + apt-get install -y build-essential golang git -ENV NGROK_VERSION 1.7 RUN git clone https://github.com/inconshreveable/ngrok.git /ngrok -RUN cd /ngrok; git checkout -fq $NGROK_VERSION -ADD *.sh / +ADD scripts/*.sh / ENV TLS_KEY **None** ENV TLS_CERT **None** ENV CA_CERT **None** ENV DOMAIN **None** -ENV TUNNEL_ADDR :4443 -ENV HTTP_ADDR :80 -ENV HTTPS_ADDR :443 +ENV TUNNEL_PORT :4443 +ENV HTTP_PORT :80 +ENV HTTPS_PORT :443 VOLUME ["/ngrok/bin"] diff --git a/README.md b/README.md index 675f673..b8f57b1 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,156 @@ -ngrok-server -============ +# ngrok-server -Create a self signed certificate (docker host) ---------------------------------- +This repository gathers scripts, instructions and a `Dockerfile` to help setting up [`ngrok`](https://ngrok.com) on your own server and domain!! (So excited!!) - NGROK_DOMAIN="ngrok.yourdomain.com" +Most of the instructions come from [this amazing post](https://www.svenbit.com/2014/09/run-ngrok-on-your-own-server/). - openssl genrsa -out rootCA.key 2048 - openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem - openssl genrsa -out device.key 2048 - openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr - openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000 +## Requirements -Building the binaries (docker host) ---------------------- +- [`docker`](https://www.docker.com/) +- Access to a computer with ip publicly available. +- A domain you can change the DNS configuration. - docker run -it -v /tmp/bin:/ngrok/bin \ - -e CA_CERT="`awk 1 ORS='\\n' rootCA.pem`" \ - yappabe/ngrok-server -Server and client binaries will be available in `/tmp/bin` on the host. +## Client and Server -Building the Mac OS X binaries (Mac) -------------------------------- +There are 2 pieces of software you will need to be able to use `ngrok` on your own server: `ngrok` and `ngrokd`. - git clone https://github.com/inconshreveable/ngrok.git ngrok - cd ngrok +`ngrok` is the client, the software you will run on the computer you want to expose to the internet. If you have a server running at `http://localhost:8080` and you want to make it publicly available, you need to run the client. -You should copy the generated certificate to your Mac and place it in `ngrok/assets/client/tls/ngrokroot.crt` +`ngrokd` is the server, the software you will probably run on someone else computer (aka cloud) with a publicly available ip address. - scp xxx@yourserver:/home/user/rootCA.pem assets/client/tls/ngrokroot.crt - make release-client - cp ./bin/ngrok /usr/local/bin/ngrok - chmod +x /usr/local/bin/ngrok -Running the server (docker host) ------------------- +## Building the docker image - docker run -d --net host \ - -e TLS_CERT="`awk 1 ORS='\\n' device.crt`" \ - -e TLS_KEY="`awk 1 ORS='\\n' device.key`" \ - -e CA_CERT="`awk 1 ORS='\\n' rootCA.pem`" \ - -e DOMAIN="$NGROK_DOMAIN" \ - yappabe/ngrok-server +You can use an already built docker image or build it yourself. +To pull a built image from docker hub, run: -Environment Variables ---------------------- +```bash +docker pull murilopolese/ngrok-server +``` - TLS_CERT TLS cert file for setting up tls connection - TLS_KEY TLS key file for setting up tls connection - CA_CERT CA cert file for compiling ngrok - DOMAIN domain name that ngrok running on - TUNNEL_ADDR address that ngrok server's control channel listens to, ":4443" by default - HTTP_ADDR address that ngrok server's http tunnel listents to, ":80 by default" - HTTPS_ADDR address that ngrok server's https tunnel listents to, ":80 by default" +If you want o build yourself, you can run: +```bash +docker build -t yourname/ngrok-server:version . +``` -Client configuration (Mac) ---------------------- +## Generating self signed certificates - cat >~/.ngrok < /ngrok/assets/client/tls/ngrokroot.crt - -if [ ! -f /ngrok/bin/ngrokd ]; then - echo "=> Compiling ngrok binary files" - cd /ngrok; make release-server release-client - echo "=> Successfully built the binaries" -fi - -if [ "${TLS_KEY}" == "**None**" ]; then - echo "Please specify TLS_KEY" - exit 1 -fi - -if [ "${TLS_CERT}" == "**None**" ]; then - echo "Please specify TLS_CERT" - exit 1 -fi - -if [ "${DOMAIN}" == "**None**" ]; then - echo "Please specify DOMAIN" - exit 1 -fi - -echo -e "${TLS_KEY}" > /server.key -echo -e "${TLS_CERT}" > /server.crt - -echo "=> Running ngrok server" -/ngrok/bin/ngrokd -tlsKey=/server.key -tlsCrt=/server.crt -domain="${DOMAIN}" -httpAddr=${HTTP_ADDR} -httpsAddr=${HTTPS_ADDR} -tunnelAddr=${TUNNEL_ADDR} diff --git a/build.sh b/scripts/build.sh similarity index 100% rename from build.sh rename to scripts/build.sh diff --git a/scripts/generate_certificates.sh b/scripts/generate_certificates.sh new file mode 100755 index 0000000..f11ab9c --- /dev/null +++ b/scripts/generate_certificates.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +mkdir -p certificate + +openssl genrsa -out certificate/rootCA.key 2048 +openssl req -x509 -new -nodes -key certificate/rootCA.key -subj "/CN=$DOMAIN" -days 5000 -out certificate/rootCA.pem +openssl genrsa -out certificate/device.key 2048 +openssl req -new -key certificate/device.key -subj "/CN=$DOMAIN" -out certificate/device.csr +openssl x509 -req -in certificate/device.csr -CA certificate/rootCA.pem -CAkey certificate/rootCA.key -CAcreateserial -out certificate/device.crt -days 5000 diff --git a/run-client.sh b/scripts/run-client.sh similarity index 57% rename from run-client.sh rename to scripts/run-client.sh index b505d0f..b8da201 100755 --- a/run-client.sh +++ b/scripts/run-client.sh @@ -4,7 +4,8 @@ set -e /build.sh cat > /root/.ngrok < /server.key echo -e "${TLS_CERT}" > /server.crt -exec /ngrok/bin/ngrokd -tlsKey=/server.key -tlsCrt=/server.crt -domain="${DOMAIN}" -httpAddr=${HTTP_ADDR} -httpsAddr=${HTTPS_ADDR} -tunnelAddr=${TUNNEL_ADDR} +exec /ngrok/bin/ngrokd -tlsKey=/server.key -tlsCrt=/server.crt -domain="${DOMAIN}" -httpAddr=${HTTP_PORT} -httpsAddr=${HTTPS_PORT} -tunnelAddr=${TUNNEL_PORT}