Logging and audit trails in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When systems record logs or audit trails, the time it takes to write and process these records matters. We want to understand how this time changes as more events happen.
How does the work grow as the number of logged events increases?
Analyze the time complexity of the following code snippet.
function writeAuditTrail(events) {
for (let i = 0; i < events.length; i++) {
logEvent(events[i]);
}
}
function logEvent(event) {
// Write event details to log storage
saveToLog(event);
}
This code writes each event from a list into a log one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each event in the list.
- How many times: Once for every event in the input list.
As the number of events grows, the time to write all logs grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 log writes |
| 100 | 100 log writes |
| 1000 | 1000 log writes |
Pattern observation: Doubling the events doubles the work needed.
Time Complexity: O(n)
This means the time to write logs grows directly with the number of events.
[X] Wrong: "Logging a batch of events takes the same time no matter how many events there are."
[OK] Correct: Each event must be recorded separately, so more events mean more work and more time.
Understanding how logging scales helps you design systems that handle many events smoothly. This skill shows you can think about system performance clearly.
"What if we batch multiple events into one log write? How would the time complexity change?"
Practice
Solution
Step 1: Understand the role of logging
Logging is used to keep a record of system and user activities.Step 2: Identify the correct purpose
Logging helps in reviewing actions for security and troubleshooting.Final Answer:
To record important system and user actions for review -> Option BQuick Check:
Logging = Record actions [OK]
- Confusing logging with access control
- Thinking logging speeds up processing
- Assuming logging deletes files
rsyslog?Solution
Step 1: Review rsyslog syntax basics
In rsyslog, the format is: selector action, e.g., '*.info /var/log/messages'.Step 2: Identify the correct syntax
*.info /var/log/messages matches the correct syntax without extra characters.Final Answer:
*.info /var/log/messages -> Option DQuick Check:
rsyslog syntax = selector + space + file path [OK]
- Adding semicolon at end of line
- Using > instead of space for file path
- Appending extra characters like * after file path
2024-06-01 10:15:30 user1 LOGIN SUCCESS
2024-06-01 10:16:05 user2 LOGIN FAILURE
2024-06-01 10:17:00 user1 LOGOUT
What event happened at 10:16:05?
Solution
Step 1: Read the log entry at 10:16:05
The log shows 'user2 LOGIN FAILURE' at that time.Step 2: Interpret the event
This means user2 tried to log in but failed.Final Answer:
User2 failed to log in -> Option AQuick Check:
LOGIN FAILURE = failed login [OK]
- Mixing user1 and user2 events
- Confusing LOGIN SUCCESS with FAILURE
- Ignoring timestamps
Solution
Step 1: Check auditd service status
If auditd is not running, no audit logs will be created.Step 2: Rule out other options
Log file size or system clock issues do not stop logging; admin rights do not prevent logs.Final Answer:
auditd service is not running -> Option AQuick Check:
auditd must run to log events [OK]
- Assuming large log files stop logging
- Blaming system clock for missing logs
- Thinking admin rights block logging
Solution
Step 1: Understand audit trail requirements
We need logs for login/logout only for admin group users.Step 2: Choose filtering method
Configuring audit rules to watch auth logs and filter by group targets only admin users.Step 3: Evaluate other options
System-wide logging is too broad; manual checks are inefficient; disabling logging for others may miss events.Final Answer:
Configure audit rules to watch /var/log/auth.log and filter by admin group users -> Option CQuick Check:
Audit rules + filtering = targeted logs [OK]
- Logging all users wastes resources
- Relying on manual checks is error-prone
- Disabling logs risks missing important events
