fix(snownet): compare preshared_key on connection upsert - #9999
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
thomaseizinger
marked this pull request as draft
July 25, 2025 06:21
Member
Author
Ha! I just checked the Elixir source code and we actually do generate a new one for each flow. The code comments say that this must be ignored for existing connections. However, if the connection setup protocol does not succeed, we are screwed. This in fact means that even without a portal deploy, anytime the connection setup gets interrupted through a WebSocket disconnect, this can happen. |
jamilbk
approved these changes
Jul 25, 2025
thomaseizinger
marked this pull request as ready for review
July 25, 2025 13:34
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Jul 25, 2025
Whenever a client requests a connection to gateway, we need to generate a preshared key that will be used for the underlying WireGuard tunnel. When the connection setup broke or otherwise was lost, _after_ the gateway the received the authorize_flow call, but _before_ the client could receive the response (and initiate a tunnel), we would have to wait until an ICE timeout occurred in order to reset state on the gateway. This is because the psk was not used to determine if this was a _new_ flow authorization. So the old authorization would be matched, and the client would never be able to connect, since its tunnel was using the new psk, and the gateway the old. To fix this, we generate a secure random 32-byte `psk_base` on each client and gateway. When a client wishes to connect to a gateway, we compute the WireGuard preshared key as an HMAC over these two inputs. This fixes the issue by ensuring that subsequent flow authorization requests from a particular client to a particular gateway will yield the same psk. Related: #9999 Related: firezone/infra#99
thomaseizinger
enabled auto-merge
July 25, 2025 21:13
Member
Author
|
Ready for prime time! 🚀 🚀 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By chance, I've discovered in a CI failure that we won't be able to handshake a new session if the
preshared_keychanges. This makes a lot of sense. Thepreshared_keyneeds to be the same on both ends as it is a shared secret that gets mixed into the Noise handshake.In following sequence of events, we would thus previously run into a "failed to decrypt handshake packet" scenario:
preshared_keyto a new secret. Restarting the portal also cuts all WebSockets and therefore, the Gateways response never arrives.preshared_key!How exactly (3) happens doesn't matter. There are probably other conditions as to where the WebSocket connections get cut and we cannot complete our connection handshake.