Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to only set APPSEC_URL #65

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/crowdsec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/crowdsec/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down