Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: route connection logs to new table #18340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jun 12, 2025

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 move N entries from the audit logs table to the connection logs table, 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.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ethanndickson ethanndickson requested a review from Copilot June 12, 2025 07:58
Copilot

This comment was marked as resolved.

@ethanndickson
Copy link
Member Author

Requesting a draft review just to confirm we're happy with the DB schema, the RBAC setup, and the overall direction.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I think this looks great in general, but the upsert part of the logic here doesn't fully make sense to me (see related comment). Could you elaborate on the intent?

return nil
}

func NewMock() *MockConnectionLogger {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This feels more like a "fake" than a "mock".

connection_logs
LEFT JOIN users ON
connection_logs.user_id = users.id
LEFT JOIN users as workspace_owner ON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LEFT JOIN users as workspace_owner ON
LEFT JOIN users AS workspace_owner ON

-- limit of 100 to prevent accidental excessively large queries.
COALESCE(NULLIF(@limit_opt :: int, 0), 100)
OFFSET
@offset_opt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Using limit/offset will get increasingly more slow as the table grows and you paginate further. First page will usually remain fast though.

Fine for now, though. Just raising awareness.

@github-actions github-actions bot added the stale This issue is like stale bread. label Jun 24, 2025
@ethanndickson ethanndickson removed the stale This issue is like stale bread. label Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants