Skip to content

fix: Randomly derive UUIDs from non-conformant session IDs#51571

Merged
codingllama merged 7 commits intomasterfrom
codingllama/pgbe-session-id
Jan 29, 2025
Merged

fix: Randomly derive UUIDs from non-conformant session IDs#51571
codingllama merged 7 commits intomasterfrom
codingllama/pgbe-session-id

Conversation

@codingllama
Copy link
Copy Markdown
Contributor

@codingllama codingllama commented Jan 28, 2025

Fix an issue where the Postgres event would drop App Access events due to it using a non-UUID session ID.

Instead of changing the App session ID this goes at the core of the problem, which is the Postgres events backend, and makes it resilient to all non-UUID session IDs.

Addressing the issue on App Access itself is possible, which would lower the bits of the App session ID (likely fine). The caveat is that it doesn't stop future mistakes, or addresses any other non-conformant session IDs that may already exist. Tackling the issue on Postgres increases the reliability of the events backend.

The session_id column is used to query events via SearchSessionEvents. SearchSessionEvents is hard-coded to a few event types, which already excludes App events. Nevertheless the PR tests querying events via its private counterpart, searchEvents. The session_id column is never read and returned as part of events, only written and used as a query filter.

Note that the transformation from "sessionID string" to "session_id UUID" is one-way. The original session ID is contained within the event itself and the column can be queried by transforming the original string, which seems adequate for the uses this sees today. If one wanted a direct column to the "unmodified" session_id this would need additional work, but that seems unnecessary for now. The PR is explicitly trying to avoid schema changes, so in this light the solution presented here is ideal.

UUIDs derived from non-standard session IDs use UUIDv5, instead of the usual UUIDv4 from uuid.Parse. That could be used to as a hint to distinguish them from the "original" UUIDs.

#46207

Changelog: Fixes issue where the Postgres backend would drop App Access events

@codingllama codingllama changed the title Randomly derive UUIDs from non-conformant session IDs fix: Randomly derive UUIDs from non-conformant session IDs Jan 28, 2025
@github-actions github-actions Bot added audit-log Issues related to Teleports Audit Log size/md labels Jan 28, 2025
@github-actions github-actions Bot requested a review from kopiczko January 28, 2025 21:25
Copy link
Copy Markdown
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

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

Wouldn't we rather do a migration (in the rdbms sense) to a different data type? As soon as we start deriving the session_id in a non-reversible way we won't have the option to do a migration in a quick-ish way, and we'd have to go through the whole events table to read the sid from the event data.

Comment thread lib/events/pgevents/pgevents_test.go Outdated
Comment thread lib/events/pgevents/pgevents_test.go Outdated
Comment thread lib/events/pgevents/pgevents.go Outdated
Comment thread lib/events/pgevents/pgevents.go Outdated
Copy link
Copy Markdown
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

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

I just realized that in a hypothetical future migration where we change data types we will only have to check the rows that have a UUIDv5 in them, which wouldn't be that bad, all things considered.

@codingllama codingllama force-pushed the codingllama/pgbe-session-id branch from 50a672b to a96f721 Compare January 29, 2025 13:14
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@espadolini, making this into a thread.

Wouldn't we rather do a migration (in the rdbms sense) to a different data type? As soon as we start deriving the session_id in a non-reversible way we won't have the option to do a migration in a quick-ish way, and we'd have to go through the whole events table to read the sid from the event data.

I'm wary of a system-driven alter table, in a table we potentially don't manage and whose size I can't determine. There's a lot that can go wrong in this kind of migration, starting with it just taking an unexpectedly long time.

We don't seem to ever read this value into the event, which makes the current approach possible.

I did consider adding a new "translation" table of sorts that records the {modified,original} UUIDs, so we could more easily recover the original (without unmarshaling the JSON data). We could pursue that, but I'm not it's necessary at this point.

I just realized that in a hypothetical future migration where we change data types we will only have to check the rows that have a UUIDv5 in them, which wouldn't be that bad, all things considered.

I suppose that's something. 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mentioned UUIDv5 on a8e632e.

@codingllama
Copy link
Copy Markdown
Contributor Author

Rebased onto master and pushed a few changes I thought I had pushed before (mainly comments). Apologies for the noise, PTAL.

@codingllama codingllama force-pushed the codingllama/pgbe-session-id branch from a96f721 to db14f87 Compare January 29, 2025 13:28
@codingllama
Copy link
Copy Markdown
Contributor Author

Friendly ping @kopiczko.

Comment thread lib/events/pgevents/pgevents_test.go Outdated
Comment thread lib/events/pgevents/pgevents_test.go
@codingllama
Copy link
Copy Markdown
Contributor Author

Thanks everyone!

@codingllama codingllama enabled auto-merge January 29, 2025 19:25
@codingllama codingllama added this pull request to the merge queue Jan 29, 2025
Merged via the queue into master with commit 533202f Jan 29, 2025
@codingllama codingllama deleted the codingllama/pgbe-session-id branch January 29, 2025 21:35
@public-teleport-github-review-bot
Copy link
Copy Markdown

@codingllama See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Create PR

codingllama added a commit that referenced this pull request Jan 30, 2025
* Tests event with non-UUID session ID

* Randomly derive UUIDs from non-conformant session IDs

* nit: Use "" instead of ``

* Link godoc references to Log.deriveSessionID

* Mention UUIDv5 for derived IDs

* Do not log the session ID

* Rename test helper, move truncateEvents out of it
codingllama added a commit that referenced this pull request Jan 30, 2025
* Tests event with non-UUID session ID

* Randomly derive UUIDs from non-conformant session IDs

* nit: Use "" instead of ``

* Link godoc references to Log.deriveSessionID

* Mention UUIDv5 for derived IDs

* Do not log the session ID

* Rename test helper, move truncateEvents out of it
github-merge-queue Bot pushed a commit that referenced this pull request Jan 30, 2025
…51645)

* Tests event with non-UUID session ID

* Randomly derive UUIDs from non-conformant session IDs

* nit: Use "" instead of ``

* Link godoc references to Log.deriveSessionID

* Mention UUIDv5 for derived IDs

* Do not log the session ID

* Rename test helper, move truncateEvents out of it
github-merge-queue Bot pushed a commit that referenced this pull request Jan 30, 2025
…51644)

* Tests event with non-UUID session ID

* Randomly derive UUIDs from non-conformant session IDs

* nit: Use "" instead of ``

* Link godoc references to Log.deriveSessionID

* Mention UUIDv5 for derived IDs

* Do not log the session ID

* Rename test helper, move truncateEvents out of it
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
…onal#51571)

* Tests event with non-UUID session ID

* Randomly derive UUIDs from non-conformant session IDs

* nit: Use "" instead of ``

* Link godoc references to Log.deriveSessionID

* Mention UUIDv5 for derived IDs

* Do not log the session ID

* Rename test helper, move truncateEvents out of it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-log Issues related to Teleports Audit Log backport/branch/v17 size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants