allow to only set APPSEC_URL (#65)

This commit is contained in:
blotus 2024-02-22 15:03:56 +01:00 committed by GitHub
parent cce2ea3946
commit 654bc2ce39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -118,6 +118,14 @@ function csmod.init(configFile, userAgent)
end
end
if runtime.conf["API_URL"] == "" and runtime.conf["APPSEC_URL"] == "" then
ngx.log(ngx.ERR, "Neither API_URL or APPSEC_URL are defined, remediation component will not do anything")
end
if runtime.conf["API_URL"] == "" and runtime.conf["APPSEC_URL"] ~= "" then
ngx.log(ngx.ERR, "Only APPSEC_URL is defined, local API decisions will be ignored")
end
return true, nil
@ -228,6 +236,9 @@ local function stream_query(premature)
-- As this function is running inside coroutine (with ngx.timer.at),
-- we need to raise error instead of returning them
if runtime.conf["API_URL"] == "" then
return
end
ngx.log(ngx.DEBUG, "running timers: " .. tostring(ngx.timer.running_count()) .. " | pending timers: " .. tostring(ngx.timer.pending_count()))
@ -360,6 +371,9 @@ local function stream_query(premature)
end
local function live_query(ip)
if runtime.conf["API_URL"] == "" then
return true, nil, nil
end
local link = runtime.conf["API_URL"] .. "/v1/decisions?ip=" .. ip
local res, err = get_remediation_http_request(link)
if not res then
@ -439,6 +453,9 @@ end
function csmod.SetupStream()
-- if it stream mode and startup start timer
if runtime.conf["API_URL"] == "" then
return
end
ngx.log(ngx.DEBUG, "timer started: " .. tostring(runtime.timer_started) .. " in worker " .. tostring(ngx.worker.id()))
if runtime.timer_started == false and runtime.conf["MODE"] == "stream" then
local ok, err
@ -456,6 +473,10 @@ function csmod.allowIp(ip)
return true, nil, "Configuration is bad, cannot run properly"
end
if runtime.conf["API_URL"] == "" then
return true, nil, nil
end
csmod.SetupStream()
local key = item_to_string(ip, "ip")

View file

@ -45,6 +45,7 @@ function config.loadConfig(file)
local valid_truefalse_values = {'false', 'true'}
local default_values = {
['ENABLED'] = "true",
['API_URL'] = "",
['REQUEST_TIMEOUT'] = 500,
['STREAM_REQUEST_TIMEOUT'] = 15000,
['BOUNCING_ON_TYPE'] = "ban",