libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
Login state injection (lws-login)
Collaboration diagram for Login state injection (lws-login):

Macros

#define LWS_LOGIN_HDR_STATE   "x-lws-login-state"
#define LWS_LOGIN_HDR_ADMIN   "x-lws-login-admin"
#define LWS_LOGIN_HDR_GRANT_LEVEL   "x-lws-login-grant-level"
#define LWS_LOGIN_HDR_SUB   "x-lws-login-sub"
#define LWS_LOGIN_HDR_SERVICE   "x-lws-login-service"
#define LWS_LOGIN_CALLBACK_SESSION_LIVE   (LWS_CALLBACK_USER + 1)

Enumerations

enum  lws_login_state {
  LWS_LOGIN_STATE_ANON = 0 , LWS_LOGIN_STATE_NO_GRANT = 1 , LWS_LOGIN_STATE_USER = 2 , LWS_LOGIN_STATE_APP_ADMIN = 3 ,
  LWS_LOGIN_STATE_GLOBAL_ADMIN = 4
}

Detailed Description

Login state injection

When a mount is guarded by the lws-login bouncer plugin, the bouncer authenticates the request, decides the requestor's role from the verified JWT grants, and stamps the cooked, trusted result onto the browser-side wsi as "extra onward headers" (set with lws_http_add_onward_header(), which first anti-spoofs any client-supplied copy; the bouncer also snips them on every path through its check, stamped or not). The HTTP/WS proxy paths then forward these to the backend app behind the mount, so the app does no JWT/grant work of its own – it just reads the headers.

The authoritative summary is the single header LWS_LOGIN_HDR_STATE, whose value is the stringified lws_login_state. The finer-grained LWS_LOGIN_HDR_GRANT_LEVEL (the raw integer grant level the bouncer used to decide the role for this mount) and LWS_LOGIN_HDR_SUB (the subject identity) are also injected for apps that want the detail. LWS_LOGIN_HDR_ADMIN is kept for back-compat and is exactly equivalent to state == LWS_LOGIN_STATE_GLOBAL_ADMIN.

The state, and the grant level, are about one service: the one the mount the request arrived on names in its "service-name". LWS_LOGIN_HDR_SERVICE says which, so a backend serving more than one mount, or wanting to be sure the mount it is behind is the one it expects, can check the state is about the grant it cares about.

Crucially, LWS_LOGIN_STATE_APP_ADMIN (admin of THIS app only) and LWS_LOGIN_STATE_GLOBAL_ADMIN (the TOFU "*" / "god" account, admin of the whole system) are distinct: a backend must not treat an app admin as a system-wide admin. The states are strictly ordered by privilege, so state >= LWS_LOGIN_STATE_APP_ADMIN selects "any kind of admin" and state == LWS_LOGIN_STATE_GLOBAL_ADMIN selects "system-wide only".

These headers are only trustworthy when they reach the backend through the bouncer's proxy path: the bouncer zaps any client-supplied copy first. A backend reachable directly (bypassing the mount) must not trust them.

Macro Definition Documentation

◆ LWS_LOGIN_HDR_STATE

#define LWS_LOGIN_HDR_STATE   "x-lws-login-state"

#include <lws-http.h>

Definition at line 780 of file lws-http.h.

◆ LWS_LOGIN_HDR_ADMIN

#define LWS_LOGIN_HDR_ADMIN   "x-lws-login-admin"

#include <lws-http.h>

Definition at line 781 of file lws-http.h.

◆ LWS_LOGIN_HDR_GRANT_LEVEL

#define LWS_LOGIN_HDR_GRANT_LEVEL   "x-lws-login-grant-level"

#include <lws-http.h>

Definition at line 782 of file lws-http.h.

◆ LWS_LOGIN_HDR_SUB

#define LWS_LOGIN_HDR_SUB   "x-lws-login-sub"

#include <lws-http.h>

Definition at line 783 of file lws-http.h.

◆ LWS_LOGIN_HDR_SERVICE

#define LWS_LOGIN_HDR_SERVICE   "x-lws-login-service"

#include <lws-http.h>

Definition at line 784 of file lws-http.h.

◆ LWS_LOGIN_CALLBACK_SESSION_LIVE

#define LWS_LOGIN_CALLBACK_SESSION_LIVE   (LWS_CALLBACK_USER + 1)

#include <lws-http.h>

LWS_LOGIN_CALLBACK_SESSION_LIVE - ask lws-login if a request has a session

Another protocol on the same vhost (eg, an interceptor that wants to wave logged-in users through) calls the vhost's "lws-login" protocol callback with this reason, user and in NULL and len 0, on the wsi of the request it is handling. It returns 0 only if the request carries an authentic, unexpired lws-login session, still backed by the auth server's records, holding at least the vhost's minimum grant level for the service the request's mount names; nonzero otherwise.

Unlike LWS_CALLBACK_HTTP_INTERCEPTOR_CHECK, which returns 0 for anything it lets through, an anonymous request lws-login would let through on an unauth-allow vhost or mount is not a session, and gets nonzero. It has no side effects on the request: nothing is stamped or snipped.

Definition at line 824 of file lws-http.h.

Enumeration Type Documentation

◆ lws_login_state

#include <lws-http.h>

enum lws_login_state - summary role of the identity reaching a backend

Value of LWS_LOGIN_HDR_STATE as injected by the lws-login bouncer into backend apps behind a protected mount. Members are ordered by privilege; higher == strictly more authority.

Enumerator
LWS_LOGIN_STATE_ANON 

No valid JWT. Only observable on mounts with unauth-allow=1.

LWS_LOGIN_STATE_NO_GRANT 

Valid JWT, but no grant (and no "*" wildcard) for this service.

LWS_LOGIN_STATE_USER 

Holds this service's grant at level >= 1 but < 2, no "*".

LWS_LOGIN_STATE_APP_ADMIN 

Holds this service's grant at level >= 2, no "*": admin of THIS app only, NOT a system-wide admin.

LWS_LOGIN_STATE_GLOBAL_ADMIN 

Holds the "*" wildcard grant (the TOFU "god" account): admin of the whole system. Any "*" level >= 1 qualifies.

Definition at line 793 of file lws-http.h.

793 {
806};
@ LWS_LOGIN_STATE_USER
Definition lws-http.h:799
@ LWS_LOGIN_STATE_NO_GRANT
Definition lws-http.h:797
@ LWS_LOGIN_STATE_ANON
Definition lws-http.h:795
@ LWS_LOGIN_STATE_APP_ADMIN
Definition lws-http.h:802
@ LWS_LOGIN_STATE_GLOBAL_ADMIN
Definition lws-http.h:805