]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add HTTP basic auth support to elastic and clickhouse plugins
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Jul 2018 10:14:54 +0000 (11:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Jul 2018 10:15:19 +0000 (11:15 +0100)
src/plugins/lua/clickhouse.lua
src/plugins/lua/elastic.lua

index 82762edfe5722ce7cf9f5f160902e44e44ff673c..913fedf20130817acc998154b58afb47223da245 100644 (file)
@@ -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)
index 3a80256d25293bd65c5f6849c1714aebe81d0cac..f43393fe04d90dcd721135e2d3c19f18aea61285 100644 (file)
@@ -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