Skip to content

Commit d0f8ba0

Browse files
committed
Wire up setting to StartRequest, PR comments
1 parent a13f952 commit d0f8ba0

File tree

8 files changed

+26
-42
lines changed

8 files changed

+26
-42
lines changed

App/Models/Settings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CoderConnectSettings : ISettings<CoderConnectSettings>
3737
/// <summary>
3838
/// When this is true Coder Connect will not attempt to protect against Tailscale loopback issues.
3939
/// </summary>
40-
public bool DisableTailscaleLoopProtection { get; set; }
40+
public bool EnableCorporateVpnSupport { get; set; }
4141

4242
/// <summary>
4343
/// CoderConnect current settings version. Increment this when the settings schema changes.
@@ -52,20 +52,20 @@ public CoderConnectSettings()
5252

5353
ConnectOnLaunch = false;
5454

55-
DisableTailscaleLoopProtection = false;
55+
EnableCorporateVpnSupport = false;
5656
}
5757

58-
public CoderConnectSettings(int? version, bool connectOnLaunch, bool disableTailscaleLoopProtection)
58+
public CoderConnectSettings(int? version, bool connectOnLaunch, bool enableCorporateVpnSupport)
5959
{
6060
Version = version ?? VERSION;
6161

6262
ConnectOnLaunch = connectOnLaunch;
6363

64-
DisableTailscaleLoopProtection = disableTailscaleLoopProtection;
64+
EnableCorporateVpnSupport = enableCorporateVpnSupport;
6565
}
6666

6767
public CoderConnectSettings Clone()
6868
{
69-
return new CoderConnectSettings(Version, ConnectOnLaunch, DisableTailscaleLoopProtection);
69+
return new CoderConnectSettings(Version, ConnectOnLaunch, EnableCorporateVpnSupport);
7070
}
7171
}

App/Services/CredentialManager.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ private async Task<CredentialModel> LoadCredentialsInner(CancellationToken ct)
223223
};
224224
}
225225

226-
// Grab the lock again so we can update the state.
227-
using (await _opLock.LockAsync(ct))
226+
// Grab the lock again so we can update the state. Don't use the CT
227+
// here as it may have already been canceled.
228+
using (await _opLock.LockAsync(TimeSpan.FromSeconds(5), CancellationToken.None))
228229
{
229230
// Prevent new LoadCredentials calls from returning this task.
230231
if (_loadCts != null)
@@ -242,11 +243,8 @@ private async Task<CredentialModel> LoadCredentialsInner(CancellationToken ct)
242243
if (latestCreds is not null) return latestCreds;
243244
}
244245

245-
// If there aren't any latest credentials after a cancellation, we
246-
// most likely timed out and should throw.
247-
ct.ThrowIfCancellationRequested();
248-
249246
UpdateState(model);
247+
ct.ThrowIfCancellationRequested();
250248
return model;
251249
}
252250
}

App/Services/RpcController.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ public async Task StartVpn(CancellationToken ct = default)
158158
using var _ = await AcquireOperationLockNowAsync();
159159
AssertRpcConnected();
160160

161-
var coderConnectSettings = await _settingsManager.Read();
162-
var disableTailscaleLoopProtection = coderConnectSettings.DisableTailscaleLoopProtection;
163-
Debug.WriteLine(
164-
$"Starting VPN with DisableTailscaleLoopProtection={disableTailscaleLoopProtection}");
165-
161+
var coderConnectSettings = await _settingsManager.Read(ct);
166162
var credentials = _credentialManager.GetCachedCredentials();
167163
if (credentials.State != CredentialState.Valid)
168164
throw new RpcOperationException(
@@ -182,6 +178,7 @@ public async Task StartVpn(CancellationToken ct = default)
182178
{
183179
CoderUrl = credentials.CoderUrl?.ToString(),
184180
ApiToken = credentials.ApiToken,
181+
TunnelUseSoftNetIsolation = coderConnectSettings.EnableCorporateVpnSupport,
185182
},
186183
}, ct);
187184
}

App/ViewModels/SettingsViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public SettingsViewModel(ILogger<SettingsViewModel> logger, ISettingsManager<Cod
3434
_connectSettings = settingsManager.Read().GetAwaiter().GetResult();
3535
StartOnLogin = startupManager.IsEnabled();
3636
ConnectOnLaunch = _connectSettings.ConnectOnLaunch;
37-
DisableTailscaleLoopProtection = _connectSettings.DisableTailscaleLoopProtection;
37+
DisableTailscaleLoopProtection = _connectSettings.EnableCorporateVpnSupport;
3838

3939
// Various policies can disable the "Start on login" option.
4040
// We disable the option in the UI if the policy is set.
@@ -53,7 +53,7 @@ partial void OnDisableTailscaleLoopProtectionChanged(bool oldValue, bool newValu
5353
return;
5454
try
5555
{
56-
_connectSettings.DisableTailscaleLoopProtection = DisableTailscaleLoopProtection;
56+
_connectSettings.EnableCorporateVpnSupport = DisableTailscaleLoopProtection;
5757
_connectSettingsManager.Write(_connectSettings);
5858
}
5959
catch (Exception ex)

App/Views/Pages/SettingsMainPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
>
4545
<ToggleSwitch IsOn="{x:Bind ViewModel.ConnectOnLaunch, Mode=TwoWay}" />
4646
</controls:SettingsCard>
47-
<controls:SettingsCard Description="This setting controls whether Coder Connect should bypass VPN loop preventation mechanism. Turn this ON only when dealing with a Coder deployment behind a corporate VPN."
48-
Header="Disable corporate VPN loop protection"
49-
HeaderIcon="{ui:FontIcon Glyph=&#xE8AF;}"
47+
<controls:SettingsCard Description="This setting loosens some VPN loop protection checks in Coder Connect, allowing traffic to flow to a Coder deployment behind a corporate VPN. We only recommend enabling this option if Coder Connect doesn't work with your Coder deployment behind a corporate VPN."
48+
Header="Enable support for corporate VPNs"
49+
HeaderIcon="{ui:FontIcon Glyph=&#xE705;}"
5050
>
5151
<ToggleSwitch IsOn="{x:Bind ViewModel.DisableTailscaleLoopProtection, Mode=TwoWay}" />
5252
</controls:SettingsCard>

App/Views/SettingsWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
xmlns:winuiex="using:WinUIEx"
1010
mc:Ignorable="d"
1111
Title="Coder Settings"
12-
Width="600" Height="450"
13-
MinWidth="600" MinHeight="450">
12+
Width="600" Height="500"
13+
MinWidth="600" MinHeight="500">
1414

1515
<Window.SystemBackdrop>
1616
<MicaBackdrop/>

App/Views/TrayWindow.xaml.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
using Coder.Desktop.App.Views.Pages;
66
using CommunityToolkit.Mvvm.Input;
77
using Microsoft.UI;
8-
using Microsoft.UI.Input;
98
using Microsoft.UI.Windowing;
109
using Microsoft.UI.Xaml;
1110
using Microsoft.UI.Xaml.Controls;
12-
using Microsoft.UI.Xaml.Documents;
1311
using Microsoft.UI.Xaml.Media.Animation;
1412
using System;
1513
using System.Collections.Generic;
@@ -19,6 +17,7 @@
1917
using Windows.Graphics;
2018
using Windows.System;
2119
using Windows.UI.Core;
20+
using Microsoft.UI.Input;
2221
using WinRT.Interop;
2322
using WindowActivatedEventArgs = Microsoft.UI.Xaml.WindowActivatedEventArgs;
2423

@@ -41,7 +40,6 @@ public sealed partial class TrayWindow : Window
4140

4241
private readonly IRpcController _rpcController;
4342
private readonly ICredentialManager _credentialManager;
44-
private readonly ISyncSessionController _syncSessionController;
4543
private readonly IUpdateController _updateController;
4644
private readonly IUserNotifier _userNotifier;
4745
private readonly TrayWindowLoadingPage _loadingPage;
@@ -51,15 +49,13 @@ public sealed partial class TrayWindow : Window
5149

5250
public TrayWindow(
5351
IRpcController rpcController, ICredentialManager credentialManager,
54-
ISyncSessionController syncSessionController, IUpdateController updateController,
55-
IUserNotifier userNotifier,
52+
IUpdateController updateController, IUserNotifier userNotifier,
5653
TrayWindowLoadingPage loadingPage,
5754
TrayWindowDisconnectedPage disconnectedPage, TrayWindowLoginRequiredPage loginRequiredPage,
5855
TrayWindowMainPage mainPage)
5956
{
6057
_rpcController = rpcController;
6158
_credentialManager = credentialManager;
62-
_syncSessionController = syncSessionController;
6359
_updateController = updateController;
6460
_userNotifier = userNotifier;
6561
_loadingPage = loadingPage;
@@ -74,9 +70,7 @@ public TrayWindow(
7470

7571
_rpcController.StateChanged += RpcController_StateChanged;
7672
_credentialManager.CredentialsChanged += CredentialManager_CredentialsChanged;
77-
_syncSessionController.StateChanged += SyncSessionController_StateChanged;
78-
SetPageByState(_rpcController.GetState(), _credentialManager.GetCachedCredentials(),
79-
_syncSessionController.GetState());
73+
SetPageByState(_rpcController.GetState(), _credentialManager.GetCachedCredentials());
8074

8175
// Setting these directly in the .xaml doesn't seem to work for whatever reason.
8276
TrayIcon.OpenCommand = Tray_OpenCommand;
@@ -127,8 +121,7 @@ public TrayWindow(
127121
};
128122
}
129123

130-
private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel,
131-
SyncSessionControllerStateModel syncSessionModel)
124+
private void SetPageByState(RpcModel rpcModel, CredentialModel credentialModel)
132125
{
133126
if (credentialModel.State == CredentialState.Unknown)
134127
{
@@ -201,18 +194,13 @@ private void MaybeNotifyUser(RpcModel rpcModel)
201194

202195
private void RpcController_StateChanged(object? _, RpcModel model)
203196
{
204-
SetPageByState(model, _credentialManager.GetCachedCredentials(), _syncSessionController.GetState());
197+
SetPageByState(model, _credentialManager.GetCachedCredentials());
205198
MaybeNotifyUser(model);
206199
}
207200

208201
private void CredentialManager_CredentialsChanged(object? _, CredentialModel model)
209202
{
210-
SetPageByState(_rpcController.GetState(), model, _syncSessionController.GetState());
211-
}
212-
213-
private void SyncSessionController_StateChanged(object? _, SyncSessionControllerStateModel model)
214-
{
215-
SetPageByState(_rpcController.GetState(), _credentialManager.GetCachedCredentials(), model);
203+
SetPageByState(_rpcController.GetState(), model);
216204
}
217205

218206
// Sadly this is necessary because Window.Content.SizeChanged doesn't

Vpn.Proto/vpn.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ message ServiceMessage {
6262
StartResponse start = 2;
6363
StopResponse stop = 3;
6464
Status status = 4; // either in reply to a StatusRequest or broadcasted
65-
StartProgress start_progress = 5; // broadcasted during startup
65+
StartProgress start_progress = 5; // broadcasted during startup (used exclusively by Windows)
6666
}
6767
}
6868

@@ -214,6 +214,7 @@ message NetworkSettingsResponse {
214214
// StartResponse.
215215
message StartRequest {
216216
int32 tunnel_file_descriptor = 1;
217+
bool tunnel_use_soft_net_isolation = 8;
217218
string coder_url = 2;
218219
string api_token = 3;
219220
// Additional HTTP headers added to all requests

0 commit comments

Comments
 (0)