Coder Social home page Coder Social logo

aman7123 / resty-yubikey-auth Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 108 KB

OpenResty YubiKey OTP: Lua script for integrating YubiKey OTP authentication into OpenResty. Features environment variable configuration and HTML login form.

Lua 99.50% Dockerfile 0.26% Shell 0.24%
lua nginx openresty openresty-lua yubico-otp yubikey

resty-yubikey-auth's Introduction

Openresty Yubikey OTP Auth

This is a plugin for OpenResty Nginx that 2FA with a YubiKey OTP. The plugin is designed to run within an Nginx block from a single call, providing a seamless and efficient authentication process.

Prerequisites

  • YubiKey
  • An existing Nginx deployment which is running from a docker compose
  • Setup a custom Dockerfile to build your Docker environment into Lua ENV variables
    • Check my entrypoint.sh as an example to creating the environment directives on OpenResty startup

Installation

This process will guide you through installing the plugin into the OpenResty Lua Path.

  1. Clone or download the repository.
  2. Add lua_package_path to the core Nginx configuration.
  • Make sure that persistent volume in Nginx is configured to a location like ./lua:/usr/local/openresty/nginx/lua:ro.
  • In nginx.conf setup lua_package_path '/usr/local/openresty/nginx/lua/plugins/?.lua;;';.
  • NOTE: It is recommended to use a custom path and add it to the lua_package_path directive as opposed to using some existing path in the ENV.
  1. Place the plugins/ folder for this repo into that lua/ directory for the docker compose.

Usage

Once installed, you can use the access_by_lua_file in your Nginx configuration. Here's an example:

server {
    listen 443 ssl;
    server_name example.com;

    error_log /usr/local/openresty/nginx/logs/error.log;
    access_log /usr/local/openresty/nginx/logs/otp-access.log main;

    # Configure OTP auth
    access_by_lua_file /usr/local/openresty/nginx/lua/plugins/yubikey-otp-authentication/main.lua;

    location / {
        proxy_pass http://localhost:8080$request_uri;
    }
}

Environment Variable Configuration

The plugin stores the the environment in code within env.lua. You can set the following environment variables:

Environment Variable Default Description
YUBIKEY_REQUEST_ID REQUIRED A unique ID which identifies you the requestor
YUBIKEYS_AUTHORIZED_KEYS REQUIRED Accepts a CSV of authorized YubiKey IDs
YUBIKEY_COOKIE_SECRET REQUIRED A secret used to encrypt the cookie
YUBIKEY_COOKIE_NAME OTP The name of the cookie
YUBIKEY_COOKIE_SAMESITE Strict Mozilla Cookie SameSite
YUBIKEY_COOKIE_SECURITY Secure Set env to "" to disable Mozilla Cookie Secure
YUBIKEY_COOKIE_TTL 1800 The time to live for the cookie in seconds

Verification Backend

This plugin utilizes the Yubico WSAPI to verify the OTP.

After verification from Yubico the YUBIKEYS_AUTHORIZED_KEYS from the environment is used to authorize the "user".

OTP Input Form

The plugin features an OTP input form that is displayed when authentication is required. The form is customizable to fit your application's look and feel. Checkout login_page.lua to review this feature.

resty-yubikey-auth's People

Contributors

aman7123 avatar

Stargazers

 avatar

Watchers

 avatar

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.