Skip to main content

JWThenticator plugin for NETunnel

Project description

NETunnel-JWThenticator

An authentication plugin of NETunnel that uses JWThenticator to provide key-based authentication between peers.

The plugin designed to be used in a server-server NETunnel models (although it can be used in a client-server model as well) where each machine has a web server that exposes a JWThenticator and a NETunnel service. The web server protects the NETunnel routes by verifying that the JWT token in every request's Authorization header is signed by the local JWThenticator service.

When a new peer is registered on a NETunnel server, you'll need to provide a key, which you're obligated to make sure it is registered on the remote JWThenticator server. The plugin will make a request to the remote JWThenticator server for a refresh token, using the provided key. The refresh token will be stored as the auth data of this peer, and for every new request, the plugin will make sure there is a valid JWT token that it received from the remote JWTheneticator server using the refresh token.

Getting Started

Installing

pip install netunnel-jwthenticator

Usage

The plugin was designed to be used in a server-server model of NETunnel, so the examples will focus on that. Each machine should have a running JWThenticator server and a NETunnel server with this plugin activated:

python -m netunnel.server --auth-plugin netunnel_jwthenticator.JWThenticatorAuthServer

Make sure both the JWThenticator and NETunnel are listening only on localhost, and have your web server proxy NETunnel on /netunnel and JWThenticator on /jwthenticator. expose only the "public" routes for JWThenticator:

  • /authenticate
  • /refresh
  • /validate
  • /jwks

As for NETunnel, have your web server expose the following routes only after validating the JWT token of each request:

  • /version
  • /channels
  • /channels/*

For example, for an NGINX web server, you could use the auth_request directive to achieve that:

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    server {
        listen 443 ssl;

        location /netunnel/ {
            auth_request _jwthenticator_validate;
            if ($uri !~ "^/netunnel/version$|^/netunnel/channels$|^/netunnel/channels/.+$") {
                return 403;
            }
            rewrite /netunnel/(.*) /$1 break;
            proxy_pass http://127.0.0.1:4040;

            # support websockets
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }

        location /jwthenticator/ {
            if ($uri !~ "^/jwthenticator/authenticate$|^/jwthenticator/refresh$|^/jwthenticator/validate$|^/jwthenticator/jwks$") {
                return 403;
            }
            rewrite /jwthenticator/(.*) /$1 break;
            proxy_pass http://127.0.0.1:5050;
        }

        location _jwthenticator_validate {
            internal;
            proxy_pass_request_body off;
            proxy_set_header Content-Length "";
            proxy_pass http://127.0.0.1:5050/validate_request;
        }
    }
}

Custom URIs

If you wish to use different URIs than /netunnel and /jwthenticator, you can do so for NETunnel, you'll anyway need to provide the full URL when registering the peer. As for JWThenticator, the plugin assumes the remote JWThenticator is at /jwthenticator, so you'll have to initialize it differently by either providing the following flag to netunnel server: --auth-data '{"remote_uri": "<new-uri>"}' or by settings the following environment before starting the server: export JWTHENTICATOR_URI=<new-uri>

Changelog

1.0.1

First release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netunnel-jwthenticator-1.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

netunnel_jwthenticator-1.0.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file netunnel-jwthenticator-1.0.1.tar.gz.

File metadata

  • Download URL: netunnel-jwthenticator-1.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.8

File hashes

Hashes for netunnel-jwthenticator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dde39120c501cb66170c1b5136fd5916e494007b76cbba39831ca5c2bd4eec3a
MD5 06e508687ab01e2f5a4a7f813f982426
BLAKE2b-256 5eb04f5b784db64e5f9ffde8f4fa57c10e0462b6bf4e98ba4695ef36cf45d016

See more details on using hashes here.

File details

Details for the file netunnel_jwthenticator-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: netunnel_jwthenticator-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.8

File hashes

Hashes for netunnel_jwthenticator-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 778d07a45578bc7ef5a7bc6a8e1f601d77a414f1618ee4a9504ea663d36733a8
MD5 aa277109c9a782639a346159fa913de9
BLAKE2b-256 478324e9dabe7afa6fb66c8702beccbec2d485136ccbdd72b69b01e2dfeecb2b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page