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.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file netunnel_jwthenticator-1.0.3.tar.gz.

File metadata

  • Download URL: netunnel_jwthenticator-1.0.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for netunnel_jwthenticator-1.0.3.tar.gz
Algorithm Hash digest
SHA256 76e3c0b10f7961ff772dec330573cd6be6905e648aca274f1468301484844008
MD5 7855ece82bfdafad547fd8148b911d16
BLAKE2b-256 c54e927cb69f97f10d21a6f4427d36dd5f3037f587771ee032cc64b5be2cecd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for netunnel_jwthenticator-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba19c541828806515c685cf29f0c955616eb120c85c3e270e59382ed4bf59a6d
MD5 cec5dcc2a47bc31768fcef14b11a2dc9
BLAKE2b-256 2b185a4557954c9d2695f442a3ce1a58a7f0cfb0c39cb19978ea177f087ed3b9

See more details on using hashes here.

Supported by

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