Skip to content

Commit

Permalink
MB-50530: Allow for disable of time based audit rotation
Browse files Browse the repository at this point in the history
Given that it is possible to disable size based audit
rotation it should also be possible to disable time
based.

Change-Id: I8492df61e4583fa55bd7e9993e7cf14ebe2c6b69
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/169230
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: James H <james.harrison@couchbase.com>
  • Loading branch information
trondn committed Jan 24, 2022
1 parent 7661617 commit 977fbc4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions auditd/src/auditconfig.cc
Expand Up @@ -107,8 +107,8 @@ size_t AuditConfig::get_rotate_size() const {
}

void AuditConfig::set_rotate_interval(uint32_t interval) {
if (interval > max_file_rotation_time ||
interval < min_file_rotation_time) {
if (interval != 0 && (interval > max_file_rotation_time ||
interval < min_file_rotation_time)) {
std::stringstream ss;
ss << "AuditConfig::set_rotate_interval(): Rotation interval "
<< interval << " is outside the legal range ["
Expand Down
10 changes: 6 additions & 4 deletions auditd/src/auditfile.cc
Expand Up @@ -67,10 +67,12 @@ uint32_t AuditFile::get_seconds_to_rotation() const {
}

bool AuditFile::time_to_rotate_log() const {
cb_assert(open_time != 0);
time_t now = auditd_time();
if (difftime(now, open_time) > rotate_interval) {
return true;
if (rotate_interval) {
cb_assert(open_time != 0);
time_t now = auditd_time();
if (difftime(now, open_time) > rotate_interval) {
return true;
}
}

if (max_log_size && (current_size > max_log_size)) {
Expand Down
6 changes: 6 additions & 0 deletions auditd/tests/auditconfig_test.cc
Expand Up @@ -161,6 +161,12 @@ TEST_F(AuditConfigTest, TestNoRotateInterval) {
EXPECT_THROW(config.initialize_config(json), nlohmann::json::exception);
}

TEST_F(AuditConfigTest, TestDisableRotateInterval) {
json["rotate_interval"] = 0;
config.initialize_config(json);
EXPECT_EQ(0, config.get_rotate_interval());
}

TEST_F(AuditConfigTest, TestRotateIntervalSetGet) {
AuditConfig defaultvalue;
const uint32_t min_file_rotation_time = defaultvalue.get_min_file_rotation_time();
Expand Down
21 changes: 21 additions & 0 deletions auditd/tests/auditfile_test.cc
Expand Up @@ -123,6 +123,27 @@ TEST_F(AuditFileTest, TestTimeRotate) {
EXPECT_EQ(10, files.size());
}

/// Verify that it is possible to disable time based rotation
TEST_F(AuditFileTest, TestTimeRotateDisabled) {
config.set_rotate_interval(0);
config.set_rotate_size(0);

AuditFile auditfile("testing");
auditfile.reconfigure(config);
event["log_path"] = "fooo";

// Generate a few events while traveling in time
for (int ii = 0; ii < 10; ++ii) {
auditfile.ensure_open();
auditfile.write_event_to_disk(event);
cb_timeofday_timetravel(config.get_min_file_rotation_time() + 1);
}
auditfile.close();

auto files = findFilesWithPrefix(testdir + "/testing");
EXPECT_EQ(1, files.size());
}

/**
* Test that the we'll rotate to the next file as the content
* of the file gets bigger.
Expand Down

0 comments on commit 977fbc4

Please sign in to comment.