Software /
code /
prosody-modules
File
mod_sentry/mod_sentry.lua @ 5193:2bb29ece216b
mod_http_oauth2: Implement stateless dynamic client registration
Replaces previous explicit registration that required either the
additional module mod_adhoc_oauth2_client or manually editing the
database. That method was enough to have something to test with, but
would not probably not scale easily.
Dynamic client registration allows creating clients on the fly, which
may be even easier in theory.
In order to not allow basically unauthenticated writes to the database,
we implement a stateless model here.
per_host_key := HMAC(config -> oauth2_registration_key, hostname)
client_id := JWT { client metadata } signed with per_host_key
client_secret := HMAC(per_host_key, client_id)
This should ensure everything we need to know is part of the client_id,
allowing redirects etc to be validated, and the client_secret can be
validated with only the client_id and the per_host_key.
A nonce injected into the client_id JWT should ensure nobody can submit
the same client metadata and retrieve the same client_secret
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Mar 2023 21:14:19 +0100 |
parent | 4995:cb3de818ff55 |
line wrap: on
line source
module:set_global(); local sentry_lib = module:require "sentry"; local hostname; local have_pposix, pposix = pcall(require, "util.pposix"); if have_pposix and pposix.uname then hostname = pposix.uname().nodename; end local loggingmanager = require "core.loggingmanager"; local errors = require "util.error"; local format = require "util.format".format; local default_config = assert(module:get_option("sentry"), "Please provide a 'sentry' configuration option"); default_config.server_name = default_config.server_name or hostname or "prosody"; local sentry = assert(sentry_lib.new(default_config)); local log_filters = { source = function (filter_source, name) local source = name:match(":(.+)$") or name; if filter_source == source then return true; end end; message_pattern = function (pattern, _, _, message) return not not message:match(pattern); end; }; local serialize = require "util.serialization".serialize; local function sentry_error_handler(e) module:log("error", "Failed to submit event to sentry: %s", e); end local function sentry_log_sink_maker(sink_config) local filters = sink_config.ignore or {}; local n_filters = #filters; local submitting; return function (name, level, message, ...) -- Ignore any log messages that occur during sentry submission -- to avoid loops if submitting then return; end for i = 1, n_filters do local filter = filters[i]; local matched; for filter_name, filter_value in pairs(filter) do local f = log_filters[filter_name]; if f and f(filter_value, name, level, message) then matched = true; else matched = nil; break; end end if matched then return; end end if level == "warn" then level = "warning"; end local event = sentry:event(level, name):message(format(message, ...)); local params = { ... }; for i = 1, select("#", ...) do if errors.is_error(params[i]) then event:add_exception(params[i]); end end submitting = true; event:send():catch(sentry_error_handler); submitting = false; end; end loggingmanager.register_sink_type("sentry", sentry_log_sink_maker); function new(conf) --luacheck: ignore 131/new conf = conf or {}; for k, v in pairs(default_config) do if conf[k] == nil then conf[k] = v; end end return sentry_lib.new(conf); end