add draft codes

This commit is contained in:
Luna 2022-12-06 00:36:15 -03:00
parent 1bd95f289d
commit 766b1d2aff
4 changed files with 114 additions and 0 deletions

11
docker-compose.yaml Normal file
View File

@ -0,0 +1,11 @@
version: "3.9"
services:
resty:
image: openresty/openresty:1.21.4.1-4-alpine
ports:
- "8696:80"
environment:
- 'LUA_PATH=/?.lua;/aproxy/?.lua'
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
- .:/aproxy:ro

44
main.lua Normal file
View File

@ -0,0 +1,44 @@
local CONFIG_PATH = ".;/etc/aproxy"
-- function loadConfig()
-- -- TODO load config_path
-- return require("./config.lua")
-- end
--
-- local config = loadConfig()
function log(msg)
ngx.log(ngx.STDERR, tostring(msg))
end
local WANTED_SCRIPTS = {
'scripts.webfinger_allowlist'
}
local compiled_chain = {}
for _, module_name in pairs(WANTED_SCRIPTS) do
log('load module', module_name)
mod = require(module_name)
log('load module', mod)
table.insert(compiled_chain, mod)
end
local function onRequest()
log('AWOOOOGA')
for _,mod in ipairs(compiled_chain) do
log(mod)
local mod_config = {accounts = {"a@a.com"}}
local result, body = mod.callback(mod_config)
log(result)
log(body)
if not result then
ngx.status = 400
ngx.say(body or "request denied")
ngx.exit(400)
end
end
end
return onRequest

15
nginx.conf Normal file
View File

@ -0,0 +1,15 @@
server {
listen 80;
lua_code_cache off;
location / {
default_type text/html;
# must happen before proxy_pass
access_by_lua_block {
require("aproxy.main")()
}
proxy_pass http://localhost:9999;
}
}

View File

@ -0,0 +1,44 @@
function webfingerCallback(cfg)
local args, err = ngx.req.get_uri_args()
if err == "truncated" then
return false, 'uri args too long'
end
local resource = args['resource']
if resource ~= nil then
for _, account in ipairs(cfg.accounts) do
if resource == account then
return true
end
end
end
return false
end
return {
name='WebfingerAllowlist',
author='luna@l4.pm',
title='Webfinger Allowlist',
description=[[
Prevent unecessary DB load by discarding requests to users that we know
won't exist.
Useful for small instances.
]],
apiVersion=1,
callback=webfingerCallback,
callbacks = {
['/.well-known/webfinger'] = webfingerCallback
},
config={
['accounts'] = {
type='table',
value={
type='string',
description='ap id'
},
description = 'list of account ids (in email@domain form) to pass through to AP'
}
},
}