Skip to content

Commit e023cf5

Browse files
authored
Merge pull request #3663 from nickanderson/ENT-14134/master
ENT-14134: Improved documentation for audit logs
2 parents 10864e9 + 27d55f4 commit e023cf5

6 files changed

Lines changed: 138 additions & 7 deletions

File tree

content/api/enterprise-api-ref/audit-logs-api.markdown

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,20 @@ HTTP 200 OK
207207
"Authentication",
208208
]
209209
```
210+
211+
## Permissions
212+
213+
All Audit log API endpoints require the `audit-log.view` RBAC permission. This
214+
permission is granted to the `admin` role by default and can be assigned to
215+
other roles via the [Web RBAC API](/api/enterprise-api-ref/web-rbac/).
216+
217+
## Retention
218+
219+
Audit log entries are stored in the `audit_log` table of the `cfsettings`
220+
PostgreSQL database (see the
221+
[schema reference](/api/enterprise-api-ref/sql-schema/cfsettings/)) and are retained
222+
indefinitely. No automatic pruning is performed.
223+
224+
Operators are expected to apply their own retention policy. See
225+
[Audit log retention](/web-ui/hub_administration/audit-log-retention/)
226+
for inspection queries and pruning recipes.

content/api/enterprise-api-ref/sql-schema/cfsettings.markdown

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aliases:
77

88
Settings used by Mission Portal APIs, no reported data.
99

10-
## Table: audit_logs
10+
## Table: audit_log
1111

1212
Stores system logs about actions performed by users.
1313

@@ -17,15 +17,19 @@ Stores system logs about actions performed by users.
1717
The unique identifier of audit log event, generated from a sequence.
1818
- **time** _(timestamp without a time zone)_
1919
Time when an event happened.
20-
- **action** _(text)_
21-
What was done (e.g., updated, created, deleted, deployed).
22-
- **object_type** _(text)_
23-
Type of affected object (e.g., user, role, build project).
20+
- **actor** _(text, not null)_
21+
User who performed the action.
22+
- **action** _(audit_log_action enum, not null)_
23+
What was done.
24+
- **object_type** _(audit_log_object_type enum, not null)_
25+
Type of affected object.
2426
- **object_id** _(text)_
2527
Identifier of an affected object (e.g. user, role id, build project id), if applicable.
26-
- **details** _(json)_
28+
- **object_name** _(text)_
29+
Name of the affected object (e.g. user name, role name, settings name).
30+
- **details** _(jsonb)_
2731
More details in the free-json format.
28-
- **ip_address** _(boolean)_
32+
- **ip_address** _(inet)_
2933
IP address of the user who performed the action.
3034

3135
## Table: build_modules

content/web-ui/_index.markdown

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@ All Events can be searched and viewed from the Event Log page.
9292

9393
<img src="web-ui-mission-portal-api-view-whole-system-events-rbac.png" alt="Mission Portal - Events View whole system events RBAC page" width="380px">
9494

95+
### Audit log
96+
97+
The Audit log records administrative actions performed in Mission Portal — for
98+
example user, role, and settings changes, host and group edits, Build project
99+
changes, and federated reporting configuration. Each entry captures the actor,
100+
action, affected object, timestamp, and originating IP address.
101+
102+
The Audit log is distinct from the Event log: the Event log tracks
103+
_system events_ like host bootstraps and alert state changes, while the Audit
104+
log tracks _human actions_ against the administrative surface.
105+
106+
- Entries are queryable via the [Audit log API](/api/enterprise-api-ref/audit-logs-api/).
107+
- Viewing the Audit log requires the `audit-log.view` RBAC permission (granted to `admin` by default).
108+
- Entries are stored in the `audit_log` table of the `cfsettings` database and
109+
are retained indefinitely unless pruned. See
110+
[Audit log retention](/web-ui/hub_administration/audit-log-retention/) for
111+
guidance on inspecting and managing table growth.
112+
113+
![](images/audit-log.png)
114+
115+
The log can be filtered by date range, actor, object type, and object
116+
name to narrow down to specific activity.
117+
Each row links to a detail view showing the full activity record and any
118+
structured details captured for the action. For example, the configuration
119+
fields changed in a settings update or the values associated with a created
120+
object.
121+
122+
![](images/audit-log-entry.png)
123+
95124
### Newly bootstrapped hosts widget
96125

97126
The Newly bootstrapped hosts widget helps to visualize the number of hosts bootstrapped to CFEngine over time.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
layout: default
3+
title: Audit log retention
4+
aliases:
5+
- "/web-ui-hub_administration-audit-log-retention.html"
6+
---
7+
8+
The Mission Portal [Audit log API](/api/enterprise-api-ref/audit-logs-api/)
9+
records administrative actions (user, role, settings, host, group, Build
10+
project, and federated reporting changes) in the `audit_log` table of the
11+
`cfsettings` PostgreSQL database.
12+
13+
## Default retention
14+
15+
There is no automatic purging of audit log entries. Records are kept
16+
indefinitely until manually removed.
17+
18+
This is intentional for compliance use cases where a long, complete history is
19+
desirable, but it means the `audit_log` table will grow without bound on
20+
long-running hubs. Operators are expected to apply their own retention policy.
21+
22+
## Inspecting current size
23+
24+
To see how many entries you have and how old they are:
25+
26+
```console
27+
sudo -u cfpostgres /var/cfengine/bin/psql cfsettings -c \
28+
"SELECT count(*) AS rows,
29+
min(time) AS oldest,
30+
max(time) AS newest,
31+
pg_size_pretty(pg_total_relation_size('audit_log')) AS size
32+
FROM audit_log;"
33+
```
34+
35+
## Manually pruning old entries
36+
37+
To delete entries older than a chosen number of days, run as the `cfpostgres`
38+
user on the hub:
39+
40+
```console
41+
sudo -u cfpostgres /var/cfengine/bin/psql cfsettings -c \
42+
"DELETE FROM audit_log WHERE time < NOW() - INTERVAL '180 days';"
43+
```
44+
45+
The `idx_audit_log_timestamp` index ensures this is efficient even on large
46+
tables. Adjust the interval to match your retention policy (regulatory
47+
requirements often dictate 1, 3, or 7 years).
48+
49+
## Scheduling pruning with CFEngine policy
50+
51+
Deletion of old records can be accomplished via policy using a `commands` promise. For example:
52+
53+
```cf3
54+
bundle agent audit_log_retention
55+
# @brief Prune Mission Portal audit_log entries older than $(days) days
56+
{
57+
vars:
58+
"days" string => "365";
59+
60+
commands:
61+
policy_server::
62+
"$(sys.bindir)/psql"
63+
args => "cfsettings -c \"DELETE FROM audit_log WHERE time < NOW() - INTERVAL '$(days) day';\"",
64+
contain => in_shell_and_silent,
65+
action => if_elapsed_day,
66+
handle => "audit_log_retention_prune",
67+
comment => "Prune Mission Portal audit_log entries older than $(days) days";
68+
}
69+
```
70+
71+
## RBAC
72+
73+
Viewing the Audit log in Mission Portal or via the API requires the
74+
`audit-log.view` RBAC permission, granted to the `admin` role by default.
75+
76+
## See also
77+
78+
- [Audit log API](/api/enterprise-api-ref/audit-logs-api/) &mdash; query the log programmatically
79+
- [Database schema: `audit_log`](/api/enterprise-api-ref/sql-schema/cfsettings/) &mdash; column reference
80+
- [Event log](/web-ui/#event-log) &mdash; a separate, automatically-pruned log of host
81+
bootstraps, decommissions, and alert state changes
48 KB
Loading
70.9 KB
Loading

0 commit comments

Comments
 (0)