Skip to content

Commit 8e79ace

Browse files
Add Tailscale Serve support for WSL gateways (#967)
* Add Tailscale Serve support for WSL gateways * Validate Tailscale Serve proxy target * Install Tailscale from signed Noble repository * Make Tailscale identity auth opt-in * Harden Tailscale gateway setup * Refine Tailscale gateway authorization * Add Tailscale setup regression coverage * Scope Tailscale recovery to managed gateways --------- Co-authored-by: Scott Hanselman <[email protected]>
1 parent 6b9e814 commit 8e79ace

25 files changed

Lines changed: 1939 additions & 29 deletions

‎docs/WSL_GATEWAY_ADMIN.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ wsl.exe -d OpenClawGateway --user openclaw -- bash -lc "ls -ld /home/openclaw/.o
9494

9595
Do not run `systemctl --user` as `root`; that checks root's user service manager, not the gateway's service.
9696

97+
## Inspect an optional Tailscale Serve endpoint
98+
99+
When the setup review enabled **Tailnet access with Tailscale Serve**, the generated distro runs its own Tailscale daemon. The Windows Companion intentionally uses the generated `wss://<node>.<tailnet>.ts.net` endpoint; it does not silently fall back to localhost.
100+
101+
Windows must also have Tailscale installed and signed in to the same tailnet. These checks do not print credentials:
102+
103+
```powershell
104+
# Windows Companion side: confirm this PC is connected to Tailscale.
105+
& "$env:ProgramFiles\Tailscale\tailscale.exe" status --json
106+
107+
# WSL side: confirm the daemon is connected and has a MagicDNS name.
108+
wsl.exe -d OpenClawGateway --user root -- tailscale status --json
109+
110+
# Confirm Serve routes tailnet HTTPS to the loopback OpenClaw gateway port.
111+
# Tailscale lifecycle and Serve are intentionally owned by root, not openclaw.
112+
wsl.exe -d OpenClawGateway --user root -- /usr/bin/tailscale serve status --json
113+
114+
# Funnel is unsupported. This must show no public route.
115+
wsl.exe -d OpenClawGateway --user root -- /usr/bin/tailscale funnel status --json
116+
117+
# Check the OpenClaw gateway itself; it remains loopback-bound inside WSL.
118+
wsl.exe -d OpenClawGateway --user openclaw -- bash -lc "systemctl --user status openclaw-gateway.service --no-pager || true"
119+
```
120+
121+
The generated WSL distro is Ubuntu 24.04 (noble). Tailscale Serve setup requires that exact generated distro and rejects another `BaseDistro` before replacing an existing gateway. Setup installs Tailscale from its signed stable APT repository rather than executing the mutable `install.sh` bootstrap script as root.
122+
123+
Tailscale Serve preserves Companion token and device authentication by default (`gateway.auth.allowTailscale=false`). Setup runs `tailscale up`, Serve, reset, logout, and daemon management as root; the `openclaw` account is never made a Tailscale operator. Tailscale's LocalAPI permits read-only operations, such as identity lookup, to local unprivileged clients while reserving mutation for root or an explicitly configured operator. In the setup review, **Trust Tailscale identities for gateway authentication** is an explicit opt-in; when enabled, verified Tailscale identity headers and tailnet ACLs become part of the gateway access-control boundary. Token and device credentials remain available for Companion pairing and compatibility. Do not enable Funnel for this generated gateway: this workflow supports private tailnet Serve only.
124+
97125
## Use root instead of sudo
98126

99127
There is no interactive sudo password prompt. Open a root shell only when you intentionally need to inspect or change protected files:

‎src/OpenClaw.SetupEngine.UI/Pages/CapabilitiesPage.xaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@
109109
<TextBlock Grid.Column="2" Text="~200 MB" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorTertiaryBrush}" FontFamily="Cascadia Mono, Consolas" VerticalAlignment="Center" />
110110
</Grid>
111111
</Border>
112+
<Border Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1" CornerRadius="4" Padding="14,12">
113+
<StackPanel Spacing="8">
114+
<Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="14">
115+
<FontIcon Grid.Column="0" Glyph="&#xE701;" FontSize="18" VerticalAlignment="Center" />
116+
<StackPanel Grid.Column="1" Spacing="2">
117+
<TextBlock Text="Tailnet access with Tailscale Serve" Style="{StaticResource BodyStrongTextBlockStyle}" />
118+
<TextBlock TextWrapping="Wrap" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="Publish this private gateway as HTTPS/WSS to your Tailscale tailnet. Windows Tailscale must already be signed in; setup root owns Serve." />
119+
</StackPanel>
120+
<ToggleSwitch x:Name="TailscaleToggle" Grid.Column="2" OnContent="" OffContent="" Toggled="TailscaleToggle_Toggled" VerticalAlignment="Center" />
121+
</Grid>
122+
<StackPanel x:Name="TailscaleOptions" Visibility="Collapsed" Spacing="6" Margin="32,0,0,0">
123+
<TextBlock x:Name="TailscaleStatusText" Text="Check Windows Tailscale before continuing." Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" TextWrapping="Wrap" />
124+
<RadioButtons x:Name="TailscaleAuthModeSelector" SelectedIndex="0" SelectionChanged="TailscaleAuthMode_SelectionChanged">
125+
<x:String>Sign in in browser</x:String>
126+
<x:String>Use one-off auth key</x:String>
127+
</RadioButtons>
128+
<PasswordBox x:Name="TailscaleAuthKeyBox" Visibility="Collapsed" PlaceholderText="Tailscale auth key (not saved)" />
129+
<ToggleSwitch x:Name="TailscaleTrustAuthToggle" Header="Trust Tailscale identities for gateway authentication" OnContent="Enabled" OffContent="Disabled" Toggled="TailscaleTrustAuthToggle_Toggled" />
130+
<TextBlock TextWrapping="Wrap" Style="{StaticResource CaptionTextBlockStyle}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="Off by default. Enable only when your Tailscale ACLs should be part of the gateway access-control boundary; OpenClaw receives only a restricted identity lookup, not Tailscale operator control." />
131+
</StackPanel>
132+
</StackPanel>
133+
</Border>
112134
<Border Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1" CornerRadius="4" Padding="14,12">
113135
<Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="14">
114136
<FontIcon Grid.Column="0" Glyph="&#xE896;" FontSize="18" VerticalAlignment="Center" />

‎src/OpenClaw.SetupEngine.UI/Pages/CapabilitiesPage.xaml.cs‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.UI.Xaml.Navigation;
66
using OpenClaw.Shared;
77
using OpenClaw.SetupEngine.UI;
8+
using System.Diagnostics;
89

910
namespace OpenClaw.SetupEngine.UI.Pages;
1011

@@ -81,6 +82,10 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
8182
if (_setupWindow is not null)
8283
_setupWindow.Activated += SetupWindow_Activated;
8384
ApplySetupReviewSummary(_config);
85+
TailscaleToggle.IsOn = _config.Tailscale.Enabled;
86+
TailscaleTrustAuthToggle.IsOn = _config.Tailscale.TrustTailscaleAuth;
87+
TailscaleAuthModeSelector.SelectedIndex = _config.Tailscale.AuthMode == TailscaleAuthMode.AuthKey ? 1 : 0;
88+
UpdateTailscaleOptions();
8489
GoToStep(1);
8590
}
8691

@@ -201,6 +206,14 @@ private void WriteCapabilities()
201206
}
202207
}
203208
config.Settings.ApplyCapabilities(caps);
209+
config.Tailscale.Enabled = TailscaleToggle.IsOn == true;
210+
config.Tailscale.TrustTailscaleAuth = TailscaleTrustAuthToggle.IsOn == true;
211+
config.Tailscale.AuthMode = TailscaleAuthModeSelector.SelectedIndex == 1
212+
? TailscaleAuthMode.AuthKey
213+
: TailscaleAuthMode.Browser;
214+
config.Tailscale.AuthKey = config.Tailscale.AuthMode == TailscaleAuthMode.AuthKey
215+
? TailscaleAuthKeyBox.Password
216+
: null;
204217
}
205218

206219
private void ApplySetupReviewSummary(SetupConfig config)
@@ -218,6 +231,93 @@ private void ApplySetupReviewSummary(SetupConfig config)
218231
ExactCommandsText.Text = summary.ExactCommands;
219232
}
220233

234+
private void TailscaleToggle_Toggled(object sender, RoutedEventArgs e)
235+
{
236+
UpdateTailscaleOptions();
237+
if (_config is not null)
238+
{
239+
_config.Tailscale.Enabled = TailscaleToggle.IsOn == true;
240+
ApplySetupReviewSummary(_config);
241+
}
242+
}
243+
244+
private void TailscaleAuthMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
245+
{
246+
TailscaleAuthKeyBox.Visibility = TailscaleAuthModeSelector.SelectedIndex == 1
247+
? Visibility.Visible
248+
: Visibility.Collapsed;
249+
}
250+
251+
private void TailscaleTrustAuthToggle_Toggled(object sender, RoutedEventArgs e)
252+
{
253+
if (_config is null)
254+
return;
255+
256+
_config.Tailscale.TrustTailscaleAuth = TailscaleTrustAuthToggle.IsOn == true;
257+
ApplySetupReviewSummary(_config);
258+
}
259+
260+
private void UpdateTailscaleOptions()
261+
{
262+
var enabled = TailscaleToggle.IsOn == true;
263+
TailscaleOptions.Visibility = enabled ? Visibility.Visible : Visibility.Collapsed;
264+
TailscaleAuthKeyBox.Visibility = enabled && TailscaleAuthModeSelector.SelectedIndex == 1
265+
? Visibility.Visible
266+
: Visibility.Collapsed;
267+
if (enabled)
268+
_ = RefreshWindowsTailscaleStatusAsync();
269+
}
270+
271+
private async Task RefreshWindowsTailscaleStatusAsync()
272+
{
273+
TailscaleStatusText.Text = "Checking Windows Tailscale…";
274+
try
275+
{
276+
var path = PreflightWindowsTailscaleStep.ResolveWindowsTailscaleCliPath();
277+
var result = await Task.Run(() =>
278+
{
279+
var psi = new ProcessStartInfo(path, "status --json")
280+
{
281+
RedirectStandardOutput = true,
282+
RedirectStandardError = true,
283+
UseShellExecute = false,
284+
CreateNoWindow = true,
285+
};
286+
using var process = Process.Start(psi);
287+
if (process is null) return (ExitCode: -1, Output: string.Empty);
288+
var output = process.StandardOutput.ReadToEnd();
289+
process.WaitForExit(5000);
290+
return (ExitCode: process.ExitCode, Output: output);
291+
});
292+
string? dnsName = null;
293+
string? tailnetDnsSuffix = null;
294+
if (result.ExitCode == 0 &&
295+
TailscaleSetupPolicy.TryParseStatus(result.Output, out var status) &&
296+
status.IsRunning)
297+
{
298+
dnsName = status.DnsName;
299+
tailnetDnsSuffix = TailscaleSetupPolicy.GetTailnetDnsSuffix(dnsName);
300+
}
301+
TailscaleStatusText.Text = tailnetDnsSuffix is not null
302+
? $"Windows Tailscale connected as {dnsName}."
303+
: "Windows Tailscale must be installed and signed in before setup can continue.";
304+
if (_config is not null && TailscaleToggle.IsOn == true)
305+
{
306+
_config.Tailscale.TailnetDnsSuffix = tailnetDnsSuffix;
307+
ApplySetupReviewSummary(_config);
308+
}
309+
}
310+
catch
311+
{
312+
TailscaleStatusText.Text = "Windows Tailscale must be installed and signed in before setup can continue.";
313+
if (_config is not null && TailscaleToggle.IsOn == true)
314+
{
315+
_config.Tailscale.TailnetDnsSuffix = null;
316+
ApplySetupReviewSummary(_config);
317+
}
318+
}
319+
}
320+
221321
private string ProfileSummary()
222322
{
223323
if (MatchesProfile(ProfileReadOnly)) return "Read-only";

‎src/OpenClaw.SetupEngine.UI/Pages/ProgressPage.xaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
<ScrollViewer x:Name="InstallContent" Grid.Row="1" VerticalScrollBarVisibility="Auto">
2525
<StackPanel Padding="48,12,48,16" Spacing="16" VerticalAlignment="Top">
2626

27+
<InfoBar x:Name="TailscaleAuthorizationPanel" Visibility="Collapsed" IsOpen="True" IsClosable="False"
28+
Severity="Informational" Title="Authorize Tailscale">
29+
<StackPanel Spacing="4">
30+
<TextBlock x:Name="TailscaleAuthorizationText" TextWrapping="Wrap" />
31+
<HyperlinkButton x:Name="TailscaleAuthorizationLink" Content="Open Tailscale authorization"
32+
HorizontalAlignment="Left" Click="TailscaleAuthorization_Click" />
33+
</StackPanel>
34+
</InfoBar>
35+
2736
<StackPanel x:Name="StepsPanel" Spacing="2" />
2837

2938
<Expander IsExpanded="False"

‎src/OpenClaw.SetupEngine.UI/Pages/ProgressPage.xaml.cs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ public sealed partial class ProgressPage : Page
2828
private bool _pipelineFinished;
2929
private string _dataDir = null!;
3030
private string _localDataDir = null!;
31+
private Uri? _tailscaleAuthorizationUri;
3132
private const int MaxLogLines = 200;
3233

3334
internal bool IsPipelineRunning => _runCts != null && !_pipelineFinished;
3435

3536
// Map pipeline step IDs to display groups (N:1)
3637
private static readonly (string GroupId, string DisplayName, string[] StepIds)[] StepGroups =
3738
[
38-
("preflight", "Check system", ["preflight-os", "preflight-wsl"]),
39+
("preflight", "Check system", ["preflight-os", "preflight-wsl", "preflight-windows-tailscale"]),
3940
("cleanup", "Removing existing gateway", ["cleanup-distro", "cleanup-gateway"]),
4041
("port", "Checking gateway port", ["preflight-port"]),
4142
("wsl-create", "Installing clean WSL gateway", ["wsl-create"]),
4243
("wsl-configure", "Configuring instance", ["wsl-configure", "validate-wsl-lockdown"]),
4344
("install-cli", "Installing OpenClaw", ["install-cli"]),
45+
("tailscale-auth", "Connecting Tailscale", ["install-tailscale", "authorize-tailscale"]),
4446
("configure", "Preparing gateway", ["configure-gateway", "install-service"]),
4547
("start", "Starting gateway", ["start-gateway", "mint-token"]),
48+
("tailscale-serve", "Publishing on Tailscale", ["finalize-tailscale-serve"]),
4649
("pairing", "Pairing device", ["pair-operator", "pair-node", "verify-e2e"]),
4750
("finish", "Finishing setup", ["run-wizard", "start-keepalive"]),
4851
];
@@ -153,6 +156,7 @@ private async Task StartPipelineAsync()
153156
cts.Token,
154157
_dataDir,
155158
_localDataDir);
159+
ctx.ExternalAuthorizationPresenter = new ProgressAuthorizationPresenter(DispatcherQueue, ShowTailscaleAuthorization);
156160

157161
var steps = BuildSteps(config);
158162
_pipeline = new SetupPipeline(steps);
@@ -294,6 +298,20 @@ private void OpenLog_Click(object sender, RoutedEventArgs e)
294298
LogFileLauncher.RevealInExplorer(_config?.LogPath);
295299
}
296300

301+
private void ShowTailscaleAuthorization(ExternalAuthorizationRequest request)
302+
{
303+
_tailscaleAuthorizationUri = request.AuthorizationUri;
304+
TailscaleAuthorizationText.Text = request.Message;
305+
TailscaleAuthorizationPanel.Visibility = Visibility.Visible;
306+
_ = global::Windows.System.Launcher.LaunchUriAsync(request.AuthorizationUri);
307+
}
308+
309+
private void TailscaleAuthorization_Click(object sender, RoutedEventArgs e)
310+
{
311+
if (_tailscaleAuthorizationUri is not null)
312+
_ = global::Windows.System.Launcher.LaunchUriAsync(_tailscaleAuthorizationUri);
313+
}
314+
297315
// Swap the install UI for a "Gateway installed" milestone with an explicit
298316
// onboard CTA. The gateway keeps running (WSL keepalive), so the wizard
299317
// connects when the user chooses to continue.
@@ -320,6 +338,19 @@ private static List<SetupStep> BuildSteps(SetupConfig config)
320338
.ToList();
321339
}
322340

341+
internal sealed class ProgressAuthorizationPresenter(
342+
DispatcherQueue dispatcherQueue,
343+
Action<ExternalAuthorizationRequest> present) : IExternalAuthorizationPresenter
344+
{
345+
public Task PresentAsync(ExternalAuthorizationRequest request, CancellationToken cancellationToken)
346+
{
347+
cancellationToken.ThrowIfCancellationRequested();
348+
if (!dispatcherQueue.TryEnqueue(() => present(request)))
349+
throw new InvalidOperationException("Setup UI closed before the Tailscale authorization link could be shown.");
350+
return Task.CompletedTask;
351+
}
352+
}
353+
323354
// ─── Step Row UI Element ───
324355

325356
internal enum StepStatus { Idle, Running, Done, Failed }

‎src/OpenClaw.SetupEngine/Program.cs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public static class Program
1616
"--local-data-dir",
1717
"--distro-name",
1818
"--gateway-port",
19+
"--tailscale-auth",
20+
"--tailscale-hostname",
1921
"--autostart-name",
2022
"--startup-task-name",
2123
]);
@@ -30,6 +32,8 @@ public static class Program
3032
"--uninstall",
3133
"--confirm-destructive",
3234
"--preserve-logs",
35+
"--tailscale",
36+
"--tailscale-trust-auth",
3337
]);
3438

3539
public static async Task<int> Main(string[] args)
@@ -58,6 +62,10 @@ public static async Task<int> Main(string[] args)
5862
var localDataDir = parsedArguments.GetValue("--local-data-dir");
5963
var distroName = parsedArguments.GetValue("--distro-name");
6064
var gatewayPortText = parsedArguments.GetValue("--gateway-port");
65+
var tailscale = parsedArguments.HasFlag("--tailscale");
66+
var tailscaleTrustAuth = parsedArguments.HasFlag("--tailscale-trust-auth");
67+
var tailscaleAuth = parsedArguments.GetValue("--tailscale-auth");
68+
var tailscaleHostname = parsedArguments.GetValue("--tailscale-hostname");
6169
var autoStartName = parsedArguments.GetValue("--autostart-name") ?? "OpenClawTray";
6270
var startupTaskName = parsedArguments.GetValue("--startup-task-name") ?? WindowsStartupTaskRegistration.TaskName;
6371

@@ -106,6 +114,24 @@ public static async Task<int> Main(string[] args)
106114
config.GatewayPort = gatewayPort;
107115
config.GatewayUrl = null;
108116
}
117+
if (tailscale)
118+
config.Tailscale.Enabled = true;
119+
if (tailscaleTrustAuth)
120+
{
121+
config.Tailscale.Enabled = true;
122+
config.Tailscale.TrustTailscaleAuth = true;
123+
}
124+
if (!string.IsNullOrWhiteSpace(tailscaleAuth))
125+
{
126+
if (!TailscaleConfig.TryParseAuthMode(tailscaleAuth, out var authMode))
127+
{
128+
Console.Error.WriteLine($"ERROR: Invalid --tailscale-auth value '{tailscaleAuth}'. Use browser or auth-key.");
129+
return 2;
130+
}
131+
config.Tailscale.AuthMode = authMode;
132+
}
133+
if (!string.IsNullOrWhiteSpace(tailscaleHostname))
134+
config.Tailscale.Hostname = tailscaleHostname;
109135
GatewayLkgVersion.ApplyToConfig(config);
110136
if (headless) config.Headless = true;
111137
if (rollback) config.RollbackOnFailure = true;
@@ -115,6 +141,12 @@ public static async Task<int> Main(string[] args)
115141
if (dryRun) config.DryRun = true;
116142
if (confirmDestructive) config.ConfirmDestructive = true;
117143

144+
if (TailscaleSetupPolicy.ValidateConfig(config) is { } tailscaleConfigError)
145+
{
146+
Console.Error.WriteLine($"ERROR: {tailscaleConfigError}");
147+
return 2;
148+
}
149+
118150
// Default log path if not specified
119151
var logLabel = uninstall ? "uninstall" : "setup";
120152
config.LogPath ??= Path.Combine(
@@ -176,7 +208,8 @@ public static async Task<int> Main(string[] args)
176208
commands,
177209
cts.Token,
178210
dataDir,
179-
localDataDir);
211+
localDataDir,
212+
new ConsoleExternalAuthorizationPresenter());
180213

181214
// Build step pipeline
182215
List<SetupStep> steps;

0 commit comments

Comments
 (0)