Lua Support
Nauthilus has Lua 5.1 support in all areas of the service. To understand the interfaces, you must first get an idea of what happens with an incoming authentication request.
Authentication workflow
An incoming authentication request first enters the brute_force check. After that it continues with the features pipeline. After that has past, it continues to process the request in a password backend. When the final result for the request was obtained, it passes filters.
Filters may change the backend result in one or the other way (accepting a formely rejected message or vice versa). This is especially useful for other remote services that can influence the authentication process.
After all this has finished, it is possible to do some post actions, which are run independent of all other steps in the whole pipeline and therefore can not influence the final result anymore.
In the following sequence diagram you can see the processing of the request in more detail.
Additional things to know
When starting the server, it is possible to call an init script, which may be used to register prometheus elements, start connection tracker or define custom redis pools. The latter is interesting, if you prefer using other redis servers for all your custom Lua scripts.
While runtime...
When an incoming authentication request is started, a Lua context is created.
All parts of a request share that common request context. Lua scripts can set arbitrary data in the context and read/delete things from there.
Lua scripts can modify the final log line by adding key-value pairs from each script.
Configuration
For the configuration, please have a look for the configuration file document.
Lua components
Each component does provide a set of global functions, constants, ... and requires a well-defined response from each request.
Every Lua script that has been configured is pre-compiled and kept in memory for future use. To make script changes, you must reload the service.
Lua libraries
Nauthilus does automatically preload Lua modules.
This is the list of modules that are currently available:
| Loader name | Description |
|---|---|
| nauthilus_mail | E-Mail functions |
| nauthilus_password | Password compare and validation functions |
| nauthilus_redis | Redis related functions |
| nauthilus_misc | Country code and sleep functions |
| nauthilus_context | Global Lua context accross all States in Nauthilus |
| nauthilus_ldap | LDAP related functions |
| nauthilus_backend | Backend related functions |
| nauthilus_http_request | HTTP request header functions |
| nauthilus_http_response | HTTP response functions (headers, status, body; Filters/Features MUST NOT send a body) |
| nauthilus_prometheus | Prometheus metrics functions |
| nauthilus_soft_whitelist | Soft whitelist functions |
| nauthilus_brute_force | Brute force prevention functions |
| nauthilus_dns | DNS related functions |
| nauthilus_cache | In-process cache functions |
| nauthilus_psnet | Network connection manager functions |
| nauthilus_opentelemetry | OpenTelemetry tracing functions |
| nauthilus_util | Common utility functions |
| glua_crypto | gluacrpyto project on Github |
| glua_http | gluahttp project on Github |
In addition to these Nauthilus-specific modules, the gopher-lua-libs collection is automatically preloaded, providing access to modules like json, yaml, time, db, tcp, and more.
Example:
local nauthilus_redis = require("nauthilus_redis")
local nauthilus_builtin_context = require("nauthilus_context")
-- Gopher-Lua-Libs
local crypto = require("crypto")
local db = require("db")
local time = require("time")
-- Glua-Crypto
local crypto = require("glua_crypto") -- provides sha1 and others...