Skip to content
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

docs(connlib): add more inline docs to connlib's state #5105

Merged
merged 7 commits into from
May 24, 2024

Conversation

thomaseizinger
Copy link
Member

This is a follow-up to #5035. I didn't end up renaming Tunnel, GatewayState or ClientState but I've added some comments with my understanding of what the state is we are tracking and tried to group the fields together in a logical way.

Copy link

vercel bot commented May 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
firezone ⬜️ Ignored (Inspect) Visit Preview May 24, 2024 0:15am

@github-actions github-actions bot added the kind/docs Improvements or updates to documentation label May 23, 2024
Copy link

github-actions bot commented May 23, 2024

Terraform Cloud Plan Output

Plan: 16 to add, 15 to change, 2 to destroy.

Terraform Cloud Plan

Copy link

github-actions bot commented May 23, 2024

Performance Test Results

TCP

Test Name Received/s Sent/s Retransmits
direct-tcp-client2server 240.4 MiB (+1%) 242.2 MiB (+1%) 127 (-51%)
direct-tcp-server2client 240.6 MiB (-1%) 242.4 MiB (-1%) 230 (-14%)
relayed-tcp-client2server 217.7 MiB (-3%) 218.7 MiB (-3%) 218 (-10%)
relayed-tcp-server2client 236.3 MiB (-2%) 237.0 MiB (-2%) 369 (-12%)

UDP

Test Name Total/s Jitter Lost
direct-udp-client2server 500.0 MiB (+0%) 0.03ms (-10%) 47.10% (-4%)
direct-udp-server2client 500.0 MiB (-0%) 0.02ms (-29%) 21.17% (-6%)
relayed-udp-client2server 499.8 MiB (-0%) 0.02ms (-23%) 55.55% (-2%)
relayed-udp-server2client 500.0 MiB (+0%) 0.01ms (-84%) 39.65% (-14%)

rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
@@ -281,37 +281,61 @@ fn send_dns_answer(
}
}

/// A SANS-IO implementation of a client's functionality.
///
/// Internally, this composes a [`snownet::ClientNode`] with firezone's policy engine around resources.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I did cargo doc --no-deps --open -p firezone-tunnel and this link didn't show up?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess because snownet is not in the workspace

Copy link
Member Author

Choose a reason for hiding this comment

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

You need to build the docs for the entire rust/ directory. Then the links work.

rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
///
/// We assign one internal IP per externally resolved IP.
dns_resources_internal_ips: HashMap<DnsResource, HashSet<IpAddr>>,
/// DNS queries we can only answer once we have connected to the resource.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that connecting to the Resource or to the Gateway? It's the Gateway that resolves DNS, and the Resource doesn't do anything except accepting incoming connections after we've resolved it, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is for the special case where the configured upstream DNS server is a resource itself.

@conectado Can probably answer this.

Copy link
Collaborator

@conectado conectado May 24, 2024

Choose a reason for hiding this comment

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

These are for any DNS query that hasn't been answered by the gateway yet, we use this to create a response later on.

we don't really connect to a resource ever, but we have the gateway grant access to a resource, at that point it's resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I forgot to address this one. Will send another PR once it is merged.

ip_provider: IpProvider,
/// Maps from connlib-assigned IP of a DNS server back to the originally configured system DNS resolver.
dns_mapping: BiMap<IpAddr, DnsServer>,
/// When to next refresh DNS resources.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this do? Do we redo DNS resolving even while connected to a Resource? Or is this the DNS TTL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, let me dig into this.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the former. I clarified this in a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the only reason we don't use the TTL here is because we don't have it, we would need to use something like hickory on the gateway too to obtain it.

with the DNS refactor we are doing now this will go away anyways and refreshing will look really different with a whole new set of problems 😛

rust/connlib/tunnel/src/io.rs Outdated Show resolved Hide resolved
Comment on lines 48 to 51
/// [`Tunnel`] glues together connlib's [`Io`] component and the respective (pure) state of a client or gateway.
///
/// Most of connlib's functionality is implemented as a pure state machine in [`ClientState`] and [`GatewayState`].
/// The only job of [`Tunnel`] is to take input from the TUN [`Device`], [`Sockets`] or time and pass it to the respective state.
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 And the Portal connection via WebSocket / phoenix channel is not part of that pure state machine, right? It's also part of the Tunnel?

So for my goal of exercising the platform-specific I/O code of the Clients, even in Windows where a Portal can't be run, I could make a mock Tunnel implementation that uses the pure state machine but has fake I/O, similar to your prop tests, and then has a simulated portal?

Or is the WebSocket managed even higher, in ClientTunnel and GatewayTunnel wrappers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be part of the Tunnel. There is no reason why the Eventloops for gateways and client couldn't be in Tunnel (those manage the portal connection). Doing that is tracked in #3837.

But even once that is done, the connection to the portal is a side-effect and thus would likely be contained in Io or live at least next to it.

ClientState and GatewayState are already pure state machines so you can already run them on Windows without a portal or TUN device.

So for my goal of exercising the platform-specific I/O code of the Clients, even in Windows

Our proptests mock everything. IO, portal, TUN device. Our (linux) integration tests don't mock anything, they use a real portal, real TUN device and real sockets.

I don't think it makes much sense to mock only parts of this. If we want to test sockets and TUN device on Windows, and thus perform real network communication, we already have an abstraction layer that can cross OS boundaries: the network. I'd try to somehow connect to a real portal and real gateway from a Windows-VM. Like, can we run a Linux container in a Windows VM on GitHub actions and connect to that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, maybe we could. Github docs say the Windows runners have Docker installed.

But I haven't tried it because I don't want to spend all day fighting the CI again. Maybe if it was done in a side project so every run doesn't take 6 CPU-hours 🤔 And then integrated if it succeeds

It's just that, that's one more thing that has to be downloaded, installed, set up, another few gigabytes of junk to update. Testing everything end-to-end is great but I'd also just like to test the Windows to Windows Client integration sometimes.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just that, that's one more thing that has to be downloaded, installed, set up, another few gigabytes of junk to update. Testing everything end-to-end is great but I'd also just like to test the Windows to Windows Client integration sometimes.

Yeah that is definitely worthwhile testing. I've found this: actions/runner-images#2216 (comment)

Seems like we need a self-hosted Windows runner for that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Crud, yeah that was why I didn't try it before. Github doesn't do nested virtualization and Docker / WSL2 needs that to run Linux on Windows.

rust/connlib/tunnel/src/lib.rs Outdated Show resolved Hide resolved
thomaseizinger and others added 5 commits May 24, 2024 09:56
Copy link
Collaborator

@conectado conectado left a comment

Choose a reason for hiding this comment

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

Awesome, very nice to have proper docs

@thomaseizinger thomaseizinger dismissed ReactorScram’s stale review May 24, 2024 03:52

Addressed all comments.

@thomaseizinger thomaseizinger added this pull request to the merge queue May 24, 2024
Merged via the queue into main with commit bb8cc86 May 24, 2024
135 checks passed
@thomaseizinger thomaseizinger deleted the docs/tunnel branch May 24, 2024 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/docs Improvements or updates to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants