Skip to content

Commit aba5cb8

Browse files
authored
fix(docs): capture and export audit logs (coder#7991)
* hotfix(docs): Capturing/exporting audit logs We frequntly get questions about this! * fmt
1 parent 31bd2b0 commit aba5cb8

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/admin/audit-logs.md

+53
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,59 @@ The supported filters are:
4343
- `date_to` - The inclusive end date with format `YYYY-MM-DD`.
4444
- `build_reason` - To be used with `resource_type:workspace_build`, the [initiator](https://pkg.go.dev/github.com/coder/coder/codersdk#BuildReason) behind the build start or stop.
4545

46+
## Capturing/Exporting Audit Logs
47+
48+
In addition to the user interface, there are multiple ways to consume or query audit trails.
49+
50+
## REST API
51+
52+
Audit logs can be accessed through our REST API. You can find detailed information about this in our [endpoint documentation](../api/audit#get-audit-logs).
53+
54+
## Service Logs
55+
56+
Audit trails are also dispatched as service logs and can be captured and categorized using any log management tool such as [Splunk](https://splunk.com).
57+
58+
Example of a [JSON formatted](../cli/server#--log-json) audit log entry:
59+
60+
```json
61+
{
62+
"ts": "2023-06-13T03:45:37.294730279Z",
63+
"level": "INFO",
64+
"msg": "audit_log",
65+
"caller": "/home/runner/work/coder/coder/enterprise/audit/backends/slog.go:36",
66+
"func": "github.com/coder/coder/enterprise/audit/backends.slogBackend.Export",
67+
"logger_names": ["coderd"],
68+
"fields": {
69+
"ID": "033a9ffa-b54d-4c10-8ec3-2aaf9e6d741a",
70+
"Time": "2023-06-13T03:45:37.288506Z",
71+
"UserID": "6c405053-27e3-484a-9ad7-bcb64e7bfde6",
72+
"OrganizationID": "00000000-0000-0000-0000-000000000000",
73+
"Ip": "{IPNet:{IP:\u003cnil\u003e Mask:\u003cnil\u003e} Valid:false}",
74+
"UserAgent": "{String: Valid:false}",
75+
"ResourceType": "workspace_build",
76+
"ResourceID": "ca5647e0-ef50-4202-a246-717e04447380",
77+
"ResourceTarget": "",
78+
"Action": "start",
79+
"Diff": {},
80+
"StatusCode": 200,
81+
"AdditionalFields": {
82+
"workspace_name": "linux-container",
83+
"build_number": "9",
84+
"build_reason": "initiator",
85+
"workspace_owner": ""
86+
},
87+
"RequestID": "bb791ac3-f6ee-4da8-8ec2-f54e87013e93",
88+
"ResourceIcon": ""
89+
}
90+
}
91+
```
92+
93+
Example of a [human readable](../cli/server#--log-human) audit log entry:
94+
95+
```sh
96+
2023-06-13 03:43:29.233 [info] coderd: audit_log ID=95f7c392-da3e-480c-a579-8909f145fbe2 Time="2023-06-13T03:43:29.230422Z" UserID=6c405053-27e3-484a-9ad7-bcb64e7bfde6 OrganizationID=00000000-0000-0000-0000-000000000000 Ip=<nil> UserAgent=<nil> ResourceType=workspace_build ResourceID=988ae133-5b73-41e3-a55e-e1e9d3ef0b66 ResourceTarget="" Action=start Diff="{}" StatusCode=200 AdditionalFields="{\"workspace_name\":\"linux-container\",\"build_number\":\"7\",\"build_reason\":\"initiator\",\"workspace_owner\":\"\"}" RequestID=9682b1b5-7b9f-4bf2-9a39-9463f8e41cd6 ResourceIcon=""
97+
```
98+
4699
## Enabling this feature
47100

48101
This feature is only available with an enterprise license. [Learn more](../enterprise.md)

0 commit comments

Comments
 (0)