Skip to content
Snippets Groups Projects
Commit fb1aace8 authored by Egor Ivkov's avatar Egor Ivkov Committed by Yaroslav Dynnikov
Browse files

feat: add integrity_violation audit log event

(cherry picked from commit 46dfe8c1)
parent 195ac023
No related branches found
No related tags found
No related merge requests found
use crate::traft::{LogicalClock, RaftSpaceAccess}; use crate::traft::LogicalClock;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use tarantool::{error::TarantoolError, log::SayLevel}; use tarantool::{error::TarantoolError, log::SayLevel};
......
...@@ -553,6 +553,22 @@ fn init_common( ...@@ -553,6 +553,22 @@ fn init_common(
tlog::set_core_logger_is_initialized(true); tlog::set_core_logger_is_initialized(true);
if let Err(e) = tarantool::set_cfg(cfg) { if let Err(e) = tarantool::set_cfg(cfg) {
let tnt_err = ::tarantool::error::TarantoolError::last();
let err_ty = tnt_err.error_type();
if err_ty == "XlogError" {
if let Some(config) = &config.instance.audit {
// Init log with stab values for raft_id and gen.
// We need to log the 'integrity_violation' event and
// there is nowhere to take raft state from at the moment.
audit::init(config, 0, 0);
crate::audit!(
message: "integrity violation detected",
title: "integrity_violation",
severity: High,
error: format!("{err_ty}: {}", tnt_err.message()),
)
}
}
tlog::set_core_logger_is_initialized(false); tlog::set_core_logger_is_initialized(false);
return Err(Error::other(format!("core initialization failed: {e}"))); return Err(Error::other(format!("core initialization failed: {e}")));
} }
......
...@@ -90,6 +90,31 @@ def test_startup(instance: Instance): ...@@ -90,6 +90,31 @@ def test_startup(instance: Instance):
assert event["initiator"] == "admin" assert event["initiator"] == "admin"
def test_integrity_violation(instance: Instance):
# Instance was up for some time
instance.start()
instance.terminate()
# Then data files were modified and instance restarted
snap_name = f"{instance.data_dir}/00000000000000000000.snap"
with open(snap_name, "w") as snap:
snap.write("abc")
# Instance should fail to start
instance.fail_to_start()
# Instance should detect integrity violation
events = list(AuditFile(instance.audit_flag_value).events())
event = take_until_title(iter(events), "integrity_violation")
assert event is not None
assert event["message"] == "integrity violation detected"
assert event["severity"] == "high"
assert (
event["error"]
== "XlogError: Unexpected end of file, run with 'force_recovery = true'"
)
def test_recover_database(instance: Instance): def test_recover_database(instance: Instance):
instance.start() instance.start()
instance.wait_online() instance.wait_online()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment