Content-Length: 404603 | pFad | https://github.com/coder/coder-desktop-macos/pull/203

6B chore: run coder connect networking from launchdaemon by ethanndickson · Pull Request #203 · coder/coder-desktop-macos · GitHub
Skip to content

chore: run coder connect networking from launchdaemon #203

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

Open
wants to merge 2 commits into
base: ethan/mandatory-helper
Choose a base branch
from

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jul 23, 2025

Continues to address #201.

This PR reworks all XPC connections, such that the networking code runs within the privileged helper, instead of the network extension.

The XPC interfaces are described in XPC.swift, and roughly follow this sequence diagram:
(One difference is that we don't posix spawn the tunnel in this PR)

sequenceDiagram
    note left of App: User requests to start VPN:
    App->>+NetExt: Start VPN
    NetExt->>+PrivHelper: Request start VPN with TUN FD
    note right of PrivHelper: Privileged helper downloads and verifies binary.
    PrivHelper->>Tunnel: posix_spawn child process with FDs
    PrivHelper->>+Tunnel: Send proto start request
    Tunnel-->>-PrivHelper: Send proto start response
    PrivHelper->>+NetExt: Request for network config change
    NetExt-->>-PrivHelper: Response for network config change
    PrivHelper-->>-NetExt: Start VPN respons
    NetExt-->>-App: VPN started
    App->>PrivHelper: Request peer state
    PrivHelper->>Tunnel: Request peer state
    Tunnel-->>PrivHelper: Peer state response
    PrivHelper-->>App: Peer state response

    note left of App: Tunnel updates (bypass NetExt):
    Tunnel->>PrivHelper: Tunnel update proto message
    PrivHelper->>App: Tunnel update proto message

    note left of App: User requests to stop VPN:
    App->>+NetExt: Stop VPN
    NetExt->>+PrivHelper: Request stop VPN
    PrivHelper->>+Tunnel: Request stop VPN
    Tunnel-->>-PrivHelper: Stop VPN response
    note right of Tunnel: Tunnel binary exits
    PrivHelper-->>-NetExt: Stop VPN response
    NetExt-->>-App: VPN stopped

Loading

Of note is that the network extension starts and stops the daemon running within the privileged helper.
This is to support starting and stopping the VPN from the toggle in System Settings, and to ensure the "Connecting" and "Disconnecting" phase of the system VPN is indicative of the time the VPN is actually setting itself up and tearing itself down.

To accomplish this, the privileged helper listens on two different service names. One is connected to by the app, the other the network extension. (Once an XPC listener is connected to, communication is bidirectional)

Copy link
Member Author

ethanndickson commented Jul 23, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@ethanndickson ethanndickson self-assigned this Jul 23, 2025
@ethanndickson ethanndickson changed the base branch from main to graphite-base/203 July 24, 2025 07:06
@ethanndickson ethanndickson force-pushed the ethan/networking-in-launchdaemon branch from 49d5c99 to 72071e5 Compare July 24, 2025 07:06
@ethanndickson ethanndickson changed the base branch from graphite-base/203 to ethan/mandatory-helper July 24, 2025 07:07
@ethanndickson ethanndickson force-pushed the ethan/networking-in-launchdaemon branch from 72071e5 to c7dbde8 Compare July 24, 2025 09:07
@ethanndickson ethanndickson force-pushed the ethan/networking-in-launchdaemon branch from c7dbde8 to ef8832a Compare July 28, 2025 07:50
@ethanndickson ethanndickson force-pushed the ethan/mandatory-helper branch from 1737580 to 16c716d Compare July 28, 2025 07:50
Comment on lines 66 to 77
guard let proxy = conn.remoteObjectProxyWithErrorHandler({ err in
self.logger.error("failed to connect to HelperXPC \(err.localizedDescription, privacy: .public)")
continuation.resume(throwing: err)
}) as? HelperAppXPCInterface else {
self.logger.error("failed to get proxy for HelperXPC")
continuation.resume(throwing: XPCError.wrongProxyType)
return
}
proxy.ping {
self.logger.info("Connected to Helper over XPC")
continuation.resume()
}
Copy link
Member Author

@ethanndickson ethanndickson Jul 30, 2025

Choose a reason for hiding this comment

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

Important to note that I've refactored all the XPC connections to use this pattern. With this, you're guaranteed that either the the XPC reply will be run (proxy.ping { reply } in this case) or the [...]WithErrorHandler callback.

Comment on lines +14 to +15
// /var/root/Downloads
private let dest = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)
Copy link
Member Author

@ethanndickson ethanndickson Jul 30, 2025

Choose a reason for hiding this comment

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

Temporary. I've put it in /var/root/Library/Application\ Support/com.coder.Coder-Desktop/ as part of the PR that downloads the slim binary.

@ethanndickson ethanndickson marked this pull request as ready for review July 30, 2025 13:09
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

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

The XPC code seems a lot nicer but the type names and directions of the XPC types are hard to understand

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.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/coder/coder-desktop-macos/pull/203

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy