auditd: implement audit configuration watcher

This commit is contained in:
Aleksey Nikitin
2023-02-05 15:02:09 +03:00
parent cd842fce75
commit 77048d99ce
6 changed files with 45 additions and 26 deletions
+10 -21
View File
@@ -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"
+30
View File
@@ -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
+2 -2
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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"