From 751223e99c67541dd409b8fba843951da9875dcc Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Jul 2018 11:14:54 +0100 Subject: [PATCH] [Feature] Add HTTP basic auth support to elastic and clickhouse plugins --- src/plugins/lua/clickhouse.lua | 27 +++++++++++++++++++++++++ src/plugins/lua/elastic.lua | 36 ++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index 82762edfe..913fedf20 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -63,6 +63,9 @@ local settings = { use_https = false, use_gzip = true, allow_local = false, + user = nil, + password = nil, + no_ssl_verify = false, } local clickhouse_schema = { @@ -304,6 +307,9 @@ local function clickhouse_send_data(task) gzip = settings.use_gzip, mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send data to clickhouse server %s: cannot make request", settings['server']) @@ -318,6 +324,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('attachments data', #attachment_rows), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send attachments to clickhouse server %s: cannot make request", settings['server']) @@ -332,6 +341,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('urls data', #urls_rows), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send urls to clickhouse server %s: cannot make request", settings['server']) @@ -346,6 +358,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('emails data', #emails_rows), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send emails to clickhouse server %s: cannot make request", settings['server']) @@ -360,6 +375,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('asn data', #asn_rows), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send asn info to clickhouse server %s: cannot make request", settings['server']) @@ -375,6 +393,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('symbols data', #symbols_rows), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send symbols info to clickhouse server %s: cannot make request", settings['server']) @@ -391,6 +412,9 @@ local function clickhouse_send_data(task) callback = gen_http_cb('domain specific data ('..k..')', #specific), mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(task, "cannot send data for domain %s to clickhouse server %s: cannot make request", k, settings['server']) @@ -784,6 +808,9 @@ if opts then callback = http_cb, mime_type = 'text/plain', timeout = settings['timeout'], + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, }) then rspamd_logger.errx(rspamd_config, "cannot create table %s in clickhouse server %s: cannot make request", elt, ip_addr) diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index 3a80256d2..f43393fe0 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -43,11 +43,15 @@ local settings = { kibana_file = rspamd_paths['PLUGINSDIR'] ..'/elastic/kibana.json', key_prefix = 'elastic-', expire = 3600, + timeout = 5.0, failover = false, import_kibana = false, use_https = false, use_gzip = true, allow_local = false, + user = nil, + password = nil, + no_ssl_verify = false, } local function read_file(path) @@ -108,7 +112,11 @@ local function elastic_send_data(task) task = task, method = 'post', gzip = settings.use_gzip, - callback = http_index_data_callback + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + callback = http_index_data_callback, + timeout = settings.timeout, }) end @@ -253,7 +261,11 @@ local function check_elastic_server(cfg, ev_base, _) ev_base = ev_base, config = cfg, method = 'get', - callback = http_callback + callback = http_callback, + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + timeout = settings.timeout, }) end @@ -308,7 +320,11 @@ local function initial_setup(cfg, ev_base, worker) body = table.concat(tbl, "\n"), method = 'post', gzip = settings.use_gzip, - callback = kibana_template_callback + callback = kibana_template_callback, + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + timeout = settings.timeout, }) else rspamd_logger.infox(rspamd_config, 'kibana template file %s not found', settings['kibana_file']) @@ -347,6 +363,10 @@ local function initial_setup(cfg, ev_base, worker) gzip = settings.use_gzip, body = ucl.to_format(template, 'json-compact'), method = 'put', + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + timeout = settings.timeout, }) -- create template mappings if not exist local template_url = connect_prefix .. ip_addr ..'/_template/rspamd' @@ -372,6 +392,10 @@ local function initial_setup(cfg, ev_base, worker) }, gzip = settings.use_gzip, callback = http_template_put_callback, + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + timeout = settings.timeout, }) else push_kibana_template() @@ -383,7 +407,11 @@ local function initial_setup(cfg, ev_base, worker) ev_base = ev_base, config = cfg, method = 'head', - callback = http_template_exist_callback + callback = http_template_exist_callback, + no_ssl_verify = settings.no_ssl_verify, + user = settings.user, + password = settings.password, + timeout = settings.timeout, }) end -- 2.39.5