mirror of
https://github.com/coder/coder.git
synced 2026-06-03 21:18:24 +00:00
08e17a07fc
### Breaking Change (changelog note): > User connections to workspaces, and the opening of workspace apps or ports will no longer create entries in the audit log. Those events will now be included in the 'Connection Log'. Please see the 'Connection Log' page in the dashboard, and the Connection Log [documentation](https://coder.com/docs/admin/monitoring/connection-logs) for details. Those with permission to view the Audit Log will also be able to view the Connection Log. The new Connection Log has the same licensing restrictions as the Audit Log, and requires a Premium Coder deployment. ### Context This is the first PR of a few for moving connection events out of the audit log, and into a new database table and web UI page called the 'Connection Log'. This PR: - Creates the new table - Adds and tests queries for inserting and reading, including reading with an RBAC filter. - Implements the corresponding RBAC changes, such that anyone who can view the audit log can read from the table - Implements, under the enterprise package, a `ConnectionLogger` abstraction to replace the `Auditor` abstraction for these logs. (No-op'd in AGPL, like the `Auditor`) - Routes SSH connection and Workspace App events into the new `ConnectionLogger` - Updates all existing tests to check the values of the `ConnectionLogger` instead of the `Auditor`. Future PRs: - Add filtering to the query - Add an enterprise endpoint to query the new table - Write a query to delete old events from the audit log, call it from dbpurge. - Implement a table in the Web UI for viewing connection logs. > [!NOTE] > The PRs in this stack obviously won't be (completely) atomic. Whilst they'll each pass CI, the stack is designed to be merged all at once. I'm splitting them up for the sake of those reviewing, and so changes can be reviewed as early as possible. Despite this, it's really hard to make this PR any smaller than it already is. I'll be keeping it in draft until it's actually ready to merge.
54 lines
1.5 KiB
SQL
54 lines
1.5 KiB
SQL
INSERT INTO connection_logs (
|
|
id,
|
|
connect_time,
|
|
organization_id,
|
|
workspace_owner_id,
|
|
workspace_id,
|
|
workspace_name,
|
|
agent_name,
|
|
type,
|
|
code,
|
|
ip,
|
|
user_agent,
|
|
user_id,
|
|
slug_or_port,
|
|
connection_id,
|
|
disconnect_time,
|
|
disconnect_reason
|
|
) VALUES (
|
|
'00000000-0000-0000-0000-000000000001', -- log id
|
|
'2023-10-01 12:00:00+00', -- start time
|
|
'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', -- organization id
|
|
'a0061a8e-7db7-4585-838c-3116a003dd21', -- workspace owner id
|
|
'3a9a1feb-e89d-457c-9d53-ac751b198ebe', -- workspace id
|
|
'Test Workspace', -- workspace name
|
|
'test-agent', -- agent name
|
|
'ssh', -- type
|
|
0, -- code
|
|
'127.0.0.1', -- ip
|
|
NULL, -- user agent
|
|
NULL, -- user id
|
|
NULL, -- slug or port
|
|
'00000000-0000-0000-0000-000000000003', -- connection id
|
|
'2023-10-01 12:00:10+00', -- close time
|
|
'server shut down' -- reason
|
|
),
|
|
(
|
|
'00000000-0000-0000-0000-000000000002', -- log id
|
|
'2023-10-01 12:05:00+00', -- start time
|
|
'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', -- organization id
|
|
'a0061a8e-7db7-4585-838c-3116a003dd21', -- workspace owner id
|
|
'3a9a1feb-e89d-457c-9d53-ac751b198ebe', -- workspace id
|
|
'Test Workspace', -- workspace name
|
|
'test-agent', -- agent name
|
|
'workspace_app', -- type
|
|
200, -- code
|
|
'127.0.0.1',
|
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
|
|
'a0061a8e-7db7-4585-838c-3116a003dd21', -- user id
|
|
'code-server', -- slug or port
|
|
NULL, -- connection id (request ID)
|
|
NULL, -- close time
|
|
NULL -- reason
|
|
);
|