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

fix(apple): sync tunnel configuration after saving #4338

Merged
merged 1 commit into from
Mar 27, 2024
Merged

Conversation

jamilbk
Copy link
Member

@jamilbk jamilbk commented Mar 27, 2024

Fixes #4321
Fixes #4339

Copy link

vercel bot commented Mar 27, 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 Mar 27, 2024 4:51pm

@@ -123,10 +123,7 @@ public final class TunnelStore: ObservableObject {
func createManager() async throws {
let protocolConfiguration = NETunnelProviderProtocol()
let manager = NETunnelProviderManager()
let providerConfiguration =
protocolConfiguration.providerConfiguration
as? [String: String]
Copy link
Member Author

@jamilbk jamilbk Mar 27, 2024

Choose a reason for hiding this comment

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

This was the a bug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it trying to read something that wasn't there?

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 by default it's an empty dict [] which can be cast to [String: String], causing the conditional to evaluate true.

Copy link

github-actions bot commented Mar 27, 2024

Terraform Cloud Plan Output

Plan: 9 to add, 8 to change, 0 to destroy.

Terraform Cloud Plan

Copy link

github-actions bot commented Mar 27, 2024

Performance Test Results

TCP

Test Name Received/s Sent/s Retransmits
direct-tcp-client2server 221.8 MiB (-2%) 223.3 MiB (-2%) 229 (+51%)
direct-tcp-server2client 224.6 MiB (+1%) 226.2 MiB (+1%) 84 (-69%)
relayed-tcp-client2server 144.6 MiB (-2%) 145.3 MiB (-3%) 198 (+43%)
relayed-tcp-server2client 153.5 MiB (-1%) 153.9 MiB (-1%) 162 (-4%)

UDP

Test Name Total/s Jitter Lost
direct-udp-client2server 50.0 MiB (-0%) 0.06ms (+72%) 0.00% (NaN%)
direct-udp-server2client 50.0 MiB (+0%) 0.01ms (-47%) 0.00% (NaN%)
relayed-udp-client2server 50.0 MiB (-0%) 0.08ms (-8%) 0.00% (NaN%)
relayed-udp-server2client 50.0 MiB (+0%) 0.04ms (-25%) 0.00% (NaN%)

Copy link
Member Author

@jamilbk jamilbk left a comment

Choose a reason for hiding this comment

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

This TunnelStore class is full of code smells still, but at least it's commented. Baby steps.

@@ -26,12 +26,12 @@ public final class SettingsViewModel: ObservableObject {
public init(tunnelStore: TunnelStore, logger: AppLogger) {
self.tunnelStore = tunnelStore
self.logger = logger
settings = Settings.defaultValue
self.settings = tunnelStore.settings
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes another exposed race condition that we hit more often now because we connect faster and don't switch between states unless we need to.

}

func loadSettings() {
func setupObservers() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to match the convention elsewhere

func loadSettings() {
model.loadSettings()
func reloadSettings() {
model.settings = model.tunnelStore.settings
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why this was rebinding settings each time... maybe a memory leak

import Foundation

#if os(iOS)
import UIKit.UIDevice
#endif

public class DeviceMetadata {
// If firezone-id hasn't ever been written, the app is considered
// to be launched for the first time.
public static func firstTime() -> Bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to DeviceMetadata since it doesn't really belong in TunnelStore

@@ -20,7 +20,7 @@ public enum KeychainError: Error {
public actor Keychain {
private let label = "Firezone token"
private let description = "Firezone access token used to authenticate the client."
private let service = "dev.firezone.firezone"
private let service = Bundle.main.bundleIdentifier!
Copy link
Member Author

Choose a reason for hiding this comment

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

This is updated just so that debug testing and release testing don't clobber each other's Keychain items.

Comment on lines +30 to +36
static func fromProviderConfiguration(providerConfiguration: [String: Any]?) -> Settings {
if let providerConfiguration = providerConfiguration as? [String: String] {
return Settings(
authBaseURL: providerConfiguration[TunnelStoreKeys.authBaseURL]
?? Settings.defaultValue.authBaseURL,
apiURL: providerConfiguration[TunnelStoreKeys.apiURL] ?? Settings.defaultValue.apiURL,
apiURL: providerConfiguration[TunnelStoreKeys.apiURL]
?? Settings.defaultValue.apiURL,
Copy link
Member Author

Choose a reason for hiding this comment

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

Cleanup

Copy link
Collaborator

@ReactorScram ReactorScram left a comment

Choose a reason for hiding this comment

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

I don't understand most of it and I just skimmed through it

@@ -27,12 +27,13 @@ struct Settings: Equatable {
}

// Convert provider configuration (which may have empty fields if it was tampered with) to Settings
static func fromProviderConfiguration(providerConfiguration: [String: String]?) -> Settings {
if let providerConfiguration = providerConfiguration {
static func fromProviderConfiguration(providerConfiguration: [String: Any]?) -> Settings {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did this change to Any?

Copy link
Member Author

Choose a reason for hiding this comment

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

We take on the responsibility of casting in here instead of making the caller do it

// loadAllFromPreferences() returns list of tunnel configurations we created. Since our bundle ID
// can change (by us), find the one that's current and ignore the others.
// loadAllFromPreferences() returns list of tunnel configurations created by our bundle ID.
// Since our bundle ID can change (by us), find the one that's current and ignore the others.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It can't change at runtime, right? This is talking about the ID changing after an update is installed?

The App Store doesn't use the bundle as a package ID? Is such a thing possible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, this can't change at runtime. It's inexorably linked to other things in the App Store listing, so it wouldn't be easy to change.

One scenario we may want to change it though is if we build a different Network Extension for some reason (different transport, DNS proxy, content filter, etc) and want to include both or update this one's name.

@@ -123,10 +123,7 @@ public final class TunnelStore: ObservableObject {
func createManager() async throws {
let protocolConfiguration = NETunnelProviderProtocol()
let manager = NETunnelProviderManager()
let providerConfiguration =
protocolConfiguration.providerConfiguration
as? [String: String]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it trying to read something that wasn't there?

Comment on lines +226 to +227
// Network Extensions don't have a 2-way binding up to the GUI process,
// so we need to periodically ask the tunnel process for them.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, you mentioned that, now I remember.

Base automatically changed from fix/macos-12-keychain-group to main March 27, 2024 16:30
@jamilbk jamilbk enabled auto-merge March 27, 2024 16:51
@jamilbk jamilbk added this pull request to the merge queue Mar 27, 2024
Merged via the queue into main with commit 2e35fe8 Mar 27, 2024
155 checks passed
@jamilbk jamilbk deleted the fix/tunnel-config branch March 27, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants