Skip to content

Commit 36187ba

Browse files
committed
Make Tailscale identity auth opt-in
1 parent 2e2ea2b commit 36187ba

11 files changed

Lines changed: 74 additions & 7 deletions

File tree

‎docs/WSL_GATEWAY_ADMIN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ wsl.exe -d OpenClawGateway --user openclaw -- bash -lc "systemctl --user status
116116

117117
The generated WSL distro is Ubuntu 24.04 (noble). Setup installs Tailscale from its signed stable APT repository rather than executing the mutable `install.sh` bootstrap script as root.
118118

119-
The setup trusts Tailscale identity headers for this tailnet-only gateway (`gateway.auth.allowTailscale=true`). Tailnet ACLs therefore control who may reach this authentication path; 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.
119+
Tailscale Serve preserves Companion token and device authentication by default (`gateway.auth.allowTailscale=false`). 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.
120120

121121
## Use root instead of sudo
122122

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
<x:String>Use one-off auth key</x:String>
127127
</RadioButtons>
128128
<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." />
129131
</StackPanel>
130132
</StackPanel>
131133
</Border>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
8383
_setupWindow.Activated += SetupWindow_Activated;
8484
ApplySetupReviewSummary(_config);
8585
TailscaleToggle.IsOn = _config.Tailscale.Enabled;
86+
TailscaleTrustAuthToggle.IsOn = _config.Tailscale.TrustTailscaleAuth;
8687
TailscaleAuthModeSelector.SelectedIndex = _config.Tailscale.AuthMode == TailscaleAuthMode.AuthKey ? 1 : 0;
8788
UpdateTailscaleOptions();
8889
GoToStep(1);
@@ -206,6 +207,7 @@ private void WriteCapabilities()
206207
}
207208
config.Settings.ApplyCapabilities(caps);
208209
config.Tailscale.Enabled = TailscaleToggle.IsOn == true;
210+
config.Tailscale.TrustTailscaleAuth = TailscaleTrustAuthToggle.IsOn == true;
209211
config.Tailscale.AuthMode = TailscaleAuthModeSelector.SelectedIndex == 1
210212
? TailscaleAuthMode.AuthKey
211213
: TailscaleAuthMode.Browser;
@@ -246,6 +248,15 @@ private void TailscaleAuthMode_SelectionChanged(object sender, SelectionChangedE
246248
: Visibility.Collapsed;
247249
}
248250

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+
249260
private void UpdateTailscaleOptions()
250261
{
251262
var enabled = TailscaleToggle.IsOn == true;

‎src/OpenClaw.SetupEngine/Program.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static async Task<int> Main(string[] args)
2828
var distroName = GetArg(args, "--distro-name");
2929
var gatewayPortText = GetArg(args, "--gateway-port");
3030
var tailscale = HasFlag(args, "--tailscale");
31+
var tailscaleTrustAuth = HasFlag(args, "--tailscale-trust-auth");
3132
var tailscaleAuth = GetArg(args, "--tailscale-auth");
3233
var tailscaleHostname = GetArg(args, "--tailscale-hostname");
3334
var autoStartName = GetArg(args, "--autostart-name") ?? "OpenClawTray";
@@ -72,6 +73,11 @@ public static async Task<int> Main(string[] args)
7273
}
7374
if (tailscale)
7475
config.Tailscale.Enabled = true;
76+
if (tailscaleTrustAuth)
77+
{
78+
config.Tailscale.Enabled = true;
79+
config.Tailscale.TrustTailscaleAuth = true;
80+
}
7581
if (!string.IsNullOrWhiteSpace(tailscaleAuth))
7682
{
7783
if (!TailscaleConfig.TryParseAuthMode(tailscaleAuth, out var authMode))

‎src/OpenClaw.SetupEngine/SetupContext.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public static SetupConfig FromEnvironment(SetupConfig? baseConfig = null)
5858
config.LogPath = logPath;
5959
if (Environment.GetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE") is "1" or "true")
6060
config.Tailscale.Enabled = true;
61+
if (Environment.GetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE_TRUST_AUTH") is "1" or "true")
62+
{
63+
config.Tailscale.Enabled = true;
64+
config.Tailscale.TrustTailscaleAuth = true;
65+
}
6166
if (Environment.GetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE_AUTH") is { Length: > 0 } authMode &&
6267
TailscaleConfig.TryParseAuthMode(authMode, out var parsedAuthMode))
6368
config.Tailscale.AuthMode = parsedAuthMode;
@@ -320,6 +325,12 @@ public enum TailscaleAuthMode
320325
public sealed class TailscaleConfig
321326
{
322327
public bool Enabled { get; set; }
328+
/// <summary>
329+
/// Allows verified Tailscale identity headers to participate in gateway
330+
/// authentication. Disabled by default so Serve does not expand the
331+
/// gateway's authorization boundary without an explicit choice.
332+
/// </summary>
333+
public bool TrustTailscaleAuth { get; set; }
323334
public TailscaleAuthMode AuthMode { get; set; } = TailscaleAuthMode.Browser;
324335
public string? Hostname { get; set; }
325336
public int AuthTimeoutSeconds { get; set; } = 300;

‎src/OpenClaw.SetupEngine/SetupReviewSummary.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public static SetupReviewSummary Build(SetupConfig config, string? dataDir = nul
3333
? $"wss://{config.Tailscale.EffectiveHostname}.<tailnet>.ts.net"
3434
: $"wss://{config.Tailscale.EffectiveHostname}.{tailnetDnsSuffix}";
3535
var gatewayDescription = tailscaleEnabled
36-
? "Tailscale Serve enabled — the gateway stays loopback-only, trusts tailnet identity authentication, and Companion connects over private HTTPS/WSS."
36+
? config.Tailscale.TrustTailscaleAuth
37+
? "Tailscale Serve enabled — the gateway stays loopback-only, trusts tailnet identity authentication, and Companion connects over private HTTPS/WSS."
38+
: "Tailscale Serve enabled — the gateway stays loopback-only, requires existing Companion token or device authentication, and connects over private HTTPS/WSS."
3739
: isLanBind
3840
? "LAN bind enabled — reachable from this PC and your local network according to Windows firewall/routing."
3941
: "Loopback only — not reachable from your network or the internet.";

‎src/OpenClaw.SetupEngine/SetupSteps.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,11 +1410,12 @@ openclaw config set gateway.nodes.allowCommands {escapedAllowedCommands}
14101410

14111411
if (tailscale?.Enabled == true)
14121412
{
1413-
configCommands += """
1413+
var trustTailscaleAuth = tailscale.TrustTailscaleAuth ? "true" : "false";
1414+
configCommands += $"""
14141415
14151416
openclaw config set gateway.tailscale.mode serve
14161417
openclaw config set gateway.tailscale.resetOnExit false
1417-
openclaw config set gateway.auth.allowTailscale true
1418+
openclaw config set gateway.auth.allowTailscale {trustTailscaleAuth}
14181419
""";
14191420
}
14201421

‎src/OpenClaw.SetupEngine/default-config.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
// Optional tailnet-only HTTPS/WSS endpoint for the generated WSL gateway.
4242
"Tailscale": {
4343
"Enabled": false,
44+
// Opt in only when tailnet identity and ACLs should participate in gateway authentication.
45+
"TrustTailscaleAuth": false,
4446
"AuthMode": "Browser",
4547
"Hostname": null,
4648
"AuthTimeoutSeconds": 300

‎tests/OpenClaw.SetupEngine.Tests/SetupConfigTests.cs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void Defaults_AreReasonable()
3838
Assert.Null(config.WindowsNodeContext.WorkspacePath);
3939
Assert.Equal(180, config.WindowsNodeContext.TimeoutSeconds);
4040
Assert.False(config.Tailscale.Enabled);
41+
Assert.False(config.Tailscale.TrustTailscaleAuth);
4142
Assert.Equal(TailscaleAuthMode.Browser, config.Tailscale.AuthMode);
4243
Assert.Equal(300, config.Tailscale.AuthTimeoutSeconds);
4344
}
@@ -148,22 +149,27 @@ public void FromEnvironment_OverridesDefaults()
148149
var prevDistro = Environment.GetEnvironmentVariable("OPENCLAW_SETUP_DISTRO");
149150
var prevPort = Environment.GetEnvironmentVariable("OPENCLAW_SETUP_PORT");
150151
var prevHeadless = Environment.GetEnvironmentVariable("OPENCLAW_SETUP_HEADLESS");
152+
var prevTrustTailscaleAuth = Environment.GetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE_TRUST_AUTH");
151153
try
152154
{
153155
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_DISTRO", "EnvDistro");
154156
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_PORT", "9876");
155157
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_HEADLESS", "true");
158+
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE_TRUST_AUTH", "true");
156159

157160
var config = SetupConfig.FromEnvironment();
158161
Assert.Equal("EnvDistro", config.DistroName);
159162
Assert.Equal(9876, config.GatewayPort);
160163
Assert.True(config.Headless);
164+
Assert.True(config.Tailscale.Enabled);
165+
Assert.True(config.Tailscale.TrustTailscaleAuth);
161166
}
162167
finally
163168
{
164169
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_DISTRO", prevDistro);
165170
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_PORT", prevPort);
166171
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_HEADLESS", prevHeadless);
172+
Environment.SetEnvironmentVariable("OPENCLAW_SETUP_TAILSCALE_TRUST_AUTH", prevTrustTailscaleAuth);
167173
}
168174
}
169175

@@ -337,10 +343,23 @@ public void SetupReviewSummary_UsesDiscoveredTailnetSuffix()
337343

338344
Assert.Equal("wss://openclaw-test.example.ts.net", summary.GatewayEndpoint);
339345
Assert.DoesNotContain("<tailnet>", summary.GatewayEndpoint);
340-
Assert.Contains("trusts tailnet identity authentication", summary.GatewayDescription);
346+
Assert.Contains("requires existing Companion token or device authentication", summary.GatewayDescription);
341347
Assert.Equal("OpenClawGateway · wss://openclaw-test.example.ts.net", summary.CompletionGatewaySummary);
342348
}
343349

350+
[Fact]
351+
public void SetupReviewSummary_StatesWhenTailscaleAuthIsTrusted()
352+
{
353+
var config = new SetupConfig
354+
{
355+
Tailscale = new TailscaleConfig { Enabled = true, TrustTailscaleAuth = true }
356+
};
357+
358+
var summary = SetupReviewSummaryBuilder.Build(config);
359+
360+
Assert.Contains("trusts tailnet identity authentication", summary.GatewayDescription);
361+
}
362+
344363
[Fact]
345364
public void SetupConfig_UsesBundledDefaultConfig_IsRuntimeOnly()
346365
{

‎tests/OpenClaw.SetupEngine.Tests/SetupStepsTests.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ public void ConfigureGateway_EnablesDevicePairPluginForLoopbackGateway()
999999
}
10001000

10011001
[Fact]
1002-
public void ConfigureGateway_TailscaleUsesNativeServeAndDefersPublicUrlUntilEndpointKnown()
1002+
public void ConfigureGateway_TailscaleUsesNativeServeAndKeepsTailscaleAuthOptIn()
10031003
{
10041004
var commands = ConfigureGatewayStep.BuildConfigCommands(
10051005
new GatewayConfig { Bind = "loopback" },
@@ -1009,10 +1009,22 @@ public void ConfigureGateway_TailscaleUsesNativeServeAndDefersPublicUrlUntilEndp
10091009

10101010
Assert.Contains("openclaw config set gateway.tailscale.mode serve", commands);
10111011
Assert.Contains("openclaw config set gateway.tailscale.resetOnExit false", commands);
1012-
Assert.Contains("openclaw config set gateway.auth.allowTailscale true", commands);
1012+
Assert.Contains("openclaw config set gateway.auth.allowTailscale false", commands);
10131013
Assert.DoesNotContain("http://127.0.0.1:18789", commands);
10141014
}
10151015

1016+
[Fact]
1017+
public void ConfigureGateway_EnablesTailscaleIdentityAuthOnlyWhenRequested()
1018+
{
1019+
var commands = ConfigureGatewayStep.BuildConfigCommands(
1020+
new GatewayConfig { Bind = "loopback" },
1021+
18789,
1022+
"'[]'",
1023+
new TailscaleConfig { Enabled = true, TrustTailscaleAuth = true });
1024+
1025+
Assert.Contains("openclaw config set gateway.auth.allowTailscale true", commands);
1026+
}
1027+
10161028
[Fact]
10171029
public void TailscalePolicy_ParsesAuthorizationUrlsAndOnlyAcceptsGatewayServeProxy()
10181030
{

0 commit comments

Comments
 (0)