8000 tailscale: add more parameters and firewall zone config by asvow · Pull Request #26407 · openwrt/packages · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tailscale: add more parameters and firewall zone config #26407

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 1 commit into
base: master
Choose a base branch
from

Conversation

asvow
Copy link
@asvow asvow commented Apr 28, 2025

Maintainer: me / @mochaaP @SuperSandro2000 @ja-pa @oskarirauta
Compile tested: 24.10.1 & Snapshot
Run tested: x86-64
Description:

Based on the official documentation, introduce support for most tailscale up parameters and OpenWrt firewall zone configuration to simplify and improve the Tailscale configuration. Meanwhile, provide the corresponding luci-app-tailscale (openwrt/luci#7735).

Add:

  • --accept-routes
  • --hostname
  • --accept-dns
  • --advertise-exit-node
  • --exit-node
  • --exit-node-allow-lan-access
  • --advertise-routes
  • --snat-subnet-routes
  • --login-server
  • --authkey
  • other extra flags for enabling settings upon the initiation of Tailscale
  • Set OpenWrt firewall zone for tailscale

Reference:

  1. https://openwrt.org/docs/guide-user/services/vpn/tailscale/start
  2. https://tailscale.com/kb/1241/tailscale-up
  3. https://tailscale.com/kb/1214/site-to-site

asvow added a commit to asvow/luci that referenced this pull request Apr 28, 2025
setting.js: adjust it to match the tailscale package (openwrt/packages#26407)
config/tailscale: drop
init.d/tailscale: drop

Signed-off-by: asvow <asvows@gmail.com>
@GeorgeSapkin
Copy link
Contributor

Please check contributing guidelines wrt commit author and signoff, and submissions guidelines wrt commit message formatting.

When modifying a package without updating the underlying software, you're expected to bump the PKG_RELEASE.

Copy link
Contributor
@GeorgeSapkin GeorgeSapkin left a comment

Choose a reason for hiding this comment

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

You should definitely comment some code or break it up into smaller functions.

@asvow asvow force-pushed the pr/20250428-tailscale branch from 832e218 to 68326d7 Compare April 28, 2025 13:36
@asvow asvow requested a review from GeorgeSapkin April 29, 2025 06:13
@asvow asvow requested a review from GeorgeSapkin April 30, 2025 12:25
@asvow asvow force-pushed the pr/20250428-tailscale branch from 9ffbb4e to 0c49a 6D4E 06 Compare May 2, 2025 01:13
@asvow asvow changed the title tailscale: improve and simplify config tailscale: add more parameters and firewall zone config May 2, 2025
@asvow asvow force-pushed the pr/20250428-tailscale branch from 0c49a06 to 6e468a2 Compare May 2, 2025 01:19
@asvow asvow requested a review from GeorgeSapkin May 2, 2025 01:40
Copy link
Contributor
@GeorgeSapkin GeorgeSapkin left a comment

Choose a reason for hiding this comment

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

I'm still not convinced about the utility of the subshell. What happens if something inside of it fails? How would the user know? It seems like the service will continue running, but in some kind of an undefined state, i.e. some bits will be semi-configured. Perhaps, you should stop the service and cleanup? And what happens if you run the code inside the subshell without it?

@asvow
Copy link
Author
asvow commented May 3, 2025

I'm still not convinced about the utility of the subshell. What happens if something inside of it fails? How would the user know? It seems like the service will continue running, but in some kind of an undefined state, i.e. some bits will be semi-configured. Perhaps, you should stop the service and cleanup? And what happens if you run the code inside the subshell without it?

I'm certain this subshell is necessary and must use & to run in the background as an asynchronous task that continues functioning normally even after the parent process completes and exits. Without the & symbol, the configurations inside won't take effect as expected, since commands like ifconfig | grep 'tailscale', tailscale ip -4, and tailscale status --json within the subshell need to retrieve their intended outputs after the parent process has exited. Regarding your previous concern about how users would know (about errors), I will add relevant error prompts and implement configuration rollback procedures.

Copy link
Contributor
@GeorgeSapkin GeorgeSapkin left a comment

Choose a reason for hiding this comment

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

What's bothering me about the whole subshell thing, is that it's circumventing the normal procd process management, and seemingly running the config section nowhere and logging to nowhere, i.e. after the service is started, since you're not awaiting its completion. I understand how procd works and you explanation why you're doing this but it doesn't make this code any more elegant.

What you could do instead is have a config helper script, that would run using the standard procd_open_instance. That way you could do whatever you want inside, without worrying about the side-effects of an async subshell.

Also, all the current exit code checks [ $? -ne 0 ] are checking the exit status of the most recently executed command, so if any previous command fails they won't be triggered. A contrived example of the scenario:

true
false
true
[ $? -ne 0 ] && echo failed

@mochaaP
Copy link
Contributor
mochaaP commented May 4, 2025
  1. Perhaps we can ask upstream about configuring options (those from tailscale set) using environment variables from tailscaled.
  2. In my opinion, many of the configuration logic of "waiting on something" or "cleanup" could be done via a callback on ubus. @bradfitz will Tailscale upstream willing to add a build tag for OpenWrt?

@asvow asvow requested a review from GeorgeSapkin May 5, 2025 14:08
@asvow
Copy link
Author
asvow commented May 5, 2025

What's bothering me about the whole subshell thing, is that it's circumventing the normal procd process management, and seemingly running the config section nowhere and logging to nowhere, i.e. after the service is started, since you're not awaiting its completion. I understand how procd works and you explanation why you're doing this but it doesn't make this code any more elegant.

What you could do instead is have a config helper script, that would run using the standard procd_open_instance. That way you could do whatever you want inside, without worrying about the side-effects of an async subshell.

Also, all the current exit code checks [ $? -ne 0 ] are checking the exit status of the most recently executed command, so if any previous command fails they won't be triggered. A contrived example of the scenario:

true
false
true
[ $? -ne 0 ] && echo failed

I get your point – subshell usage has been removed and the code refactored, then committed. Note that this commit used my GitHub anonymous email; please ignore it for now. I'll correct this when squashing all changes into a single commit to finalize the commit history.
Also, I'm sorry for making changes after requesting a review. I discovered a bug caused by the case statement's logic of exiting after the first match. To fix it would require adding a loop statement, which I think would complicate the code. Therefore, I revert to the previous implementation to keep the code simple.

@asvow asvow force-pushed the pr/20250428-tailscale branch from 80ca696 to 0932b41 Compare May 6, 2025 12:09
This implements:
* Add support for main Tailscale parameters, including:
  - accept-routes
  - hostname
  - accept-dns
  - advertise-exit-node
  - exit-node
  - advertise-routes
  - snat-subnet-routes
  - subnet-routes
  - login-server
  - authkey
* Other parameters not mentioned above also support configuration by setting flags.
* Firewall zone configuration integration.

Ref:
  - https://tailscale.com/kb/1241/tailscale-up
  - https://openwrt.org/docs/guide-user/services/vpn/tailscale/start

Signed-off-by: Geoffrey Hall <asvows@gmail.com>
@asvow asvow force-pushed the pr/20250428-tailscale branch from 4a757b6 to b1069ac Compare May 12, 2025 05:35
@asvow
Copy link
Author
asvow commented May 12, 2025

@hnyman I thoroughly checked the build log and confirmed the error was due to the missing /etc/hotplug.d/iface path. Already fixed by patching the Makefile with the following changes:

diff --git a/net/tailscale/Makefile b/net/tailscale/Makefile
index be6502fe4..2cfc1d970 100644
--- a/net/tailscale/Makefile
+++ b/net/tailscale/Makefile
@@ -56,7 +56,7 @@ define Package/tailscale/conffiles
 endef
 
 define Package/tailscale/install
-	$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config
+	$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config $(1)/etc/hotplug.d/iface
 	$(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/tailscaled $(1)/usr/sbin
 	$(LN) tailscaled $(1)/usr/sbin/tailscale
 	$(INSTALL_BIN) ./files//tailscale.init $(1)/etc/init.d/tailscale
-- 

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.

4 participants
0