mirror of
https://github.com/vxcontrol/soldr-modules.git
synced 2026-07-18 18:44:30 -04:00
auditd: implement audit configuration watcher
This commit is contained in:
@@ -16,24 +16,13 @@ if not pm then
|
||||
return "success"
|
||||
end
|
||||
|
||||
local function setup_audit()
|
||||
local ok, err = audit.setup(pm, {
|
||||
audit.file_auditd_service_override,
|
||||
audit.file_auditd_conf,
|
||||
audit.file_audit_rules,
|
||||
})
|
||||
if not ok then __log.error(err) end
|
||||
end
|
||||
|
||||
local check_interval_sec
|
||||
local last_check = 0
|
||||
local watcher = require("watcher").new()
|
||||
|
||||
local function update_config()
|
||||
local c = cjson.decode(__config.get_current_config())
|
||||
check_interval_sec = c.check_interval_sec
|
||||
audit.file_auditd_conf:set(c.auditd_conf)
|
||||
audit.file_audit_rules:set(c.audit_rules)
|
||||
last_check = 0
|
||||
watcher:reset(c.check_interval)
|
||||
end
|
||||
update_config()
|
||||
|
||||
@@ -44,12 +33,12 @@ __api.add_cbs{
|
||||
end,
|
||||
}
|
||||
|
||||
while not __api.is_close() do
|
||||
local now = os.time()
|
||||
if now - last_check > check_interval_sec then
|
||||
last_check = now
|
||||
setup_audit()
|
||||
end
|
||||
__api.await(1000)
|
||||
end
|
||||
watcher:run(function()
|
||||
local ok, err = audit.setup(pm, {
|
||||
audit.file_auditd_service_override,
|
||||
audit.file_auditd_conf,
|
||||
audit.file_audit_rules,
|
||||
})
|
||||
if not ok then __log.error(err) end
|
||||
end)
|
||||
return "success"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
local Watcher = {}; Watcher.__index = Watcher
|
||||
|
||||
--:: seconds? -> Watcher
|
||||
function Watcher.new(interval)
|
||||
return setmetatable({
|
||||
_interval = interval or 0,
|
||||
}, Watcher)
|
||||
end
|
||||
|
||||
--:: seconds? -> ()
|
||||
function Watcher:reset(interval)
|
||||
self._last_run = 0
|
||||
self._interval = interval or self._interval
|
||||
end
|
||||
|
||||
function Watcher:run(f)
|
||||
self._last_run = 0
|
||||
self._interval = self._interval or 1
|
||||
|
||||
while not __api.is_close() do
|
||||
local now = os.time()
|
||||
if now - self._last_run >= self._interval then
|
||||
self._last_run = now
|
||||
f()
|
||||
end
|
||||
__api.await(1000)
|
||||
end
|
||||
end
|
||||
|
||||
return Watcher
|
||||
@@ -23,7 +23,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"check_interval_sec": {
|
||||
"check_interval": {
|
||||
"rules": {},
|
||||
"type": "integer",
|
||||
"ui": {
|
||||
@@ -35,7 +35,7 @@
|
||||
"required": [
|
||||
"audit_rules",
|
||||
"auditd_conf",
|
||||
"check_interval_sec"
|
||||
"check_interval"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"audit_rules": "# Managed by SOLDR(auditd)\n-D",
|
||||
"auditd_conf": "# Managed by SOLDR(auditd)",
|
||||
"check_interval_sec": 600
|
||||
"check_interval": 600
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"audit_rules": "# Managed by SOLDR(auditd)\n-D",
|
||||
"auditd_conf": "# Managed by SOLDR(auditd)",
|
||||
"check_interval_sec": 600
|
||||
"check_interval": 600
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
"description": "/etc/audit/auditd.conf"
|
||||
}
|
||||
},
|
||||
"check_interval_sec": {
|
||||
"check_interval": {
|
||||
"en": {
|
||||
"title": "Check interval, seconds",
|
||||
"description": "Module is checking audit configuration every given interval of time"
|
||||
|
||||
Reference in New Issue
Block a user