cmd/containerboot: provide extra args to 'tailscale set'

Introduces a new TS_SET_EXTRA_ARGS that can be used to
provide additonal args to 'tailscale set'.

Updates tailscale/tailscale#10708

Signed-off-by: Irbe Krumina <irbe@tailscale.com>
This commit is contained in:
Irbe Krumina 2024-01-04 14:56:28 +00:00
parent 3a9450bc06
commit 62d99715a4
2 changed files with 13 additions and 3 deletions

View File

@ -25,6 +25,10 @@
// destination defined by a MagicDNS name.
// - TS_TAILSCALED_EXTRA_ARGS: extra arguments to 'tailscaled'.
// - TS_EXTRA_ARGS: extra arguments to 'tailscale up'.
// - TS_SET_EXTRA_ARGS: extra arguments to 'tailscale set'.'tailscale set' is
// run on subsequent container restarts if TS_AUTH_ONCE is set to true. It
// gets passed values of TS_ACCEPT_DNS, TS_SOCKET, TS_ROUTES, TS_HOSTNAME
// and TS_SET_EXTRA_ARGS.
// - TS_USERSPACE: run with userspace networking (the default)
// instead of kernel networking.
// - TS_STATE_DIR: the directory in which to store tailscaled
@ -111,6 +115,7 @@ func main() {
TailnetTargetFQDN: defaultEnv("TS_TAILNET_TARGET_FQDN", ""),
DaemonExtraArgs: defaultEnv("TS_TAILSCALED_EXTRA_ARGS", ""),
ExtraArgs: defaultEnv("TS_EXTRA_ARGS", ""),
SetExtraArgs: defaultEnv("TS_SET_EXTRA_ARGS", ""),
InKubernetes: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
UserspaceMode: defaultBool("TS_USERSPACE", true),
StateDir: defaultEnv("TS_STATE_DIR", ""),
@ -695,6 +700,9 @@ func tailscaleSet(ctx context.Context, cfg *settings) error {
if cfg.Hostname != "" {
args = append(args, "--hostname="+cfg.Hostname)
}
if cfg.SetExtraArgs != "" {
args = append(args, strings.Fields(cfg.SetExtraArgs)...)
}
log.Printf("Running 'tailscale set'")
cmd := exec.CommandContext(ctx, "tailscale", args...)
cmd.Stdout = os.Stdout
@ -877,6 +885,7 @@ type settings struct {
ServeConfigPath string
DaemonExtraArgs string
ExtraArgs string
SetExtraArgs string
InKubernetes bool
UserspaceMode bool
StateDir string

View File

@ -350,8 +350,9 @@ func TestContainerBoot(t *testing.T) {
{
Name: "authkey_once",
Env: map[string]string{
"TS_AUTHKEY": "tskey-key",
"TS_AUTH_ONCE": "true",
"TS_AUTHKEY": "tskey-key",
"TS_AUTH_ONCE": "true",
"TS_SET_EXTRA_ARGS": "--advertise-exit-node=true --advertise-app-connector=true",
},
Phases: []phase{
{
@ -370,7 +371,7 @@ func TestContainerBoot(t *testing.T) {
{
Notify: runningNotify,
WantCmds: []string{
"/usr/bin/tailscale --socket=/tmp/tailscaled.sock set --accept-dns=false",
"/usr/bin/tailscale --socket=/tmp/tailscaled.sock set --accept-dns=false --advertise-exit-node=true --advertise-app-connector=true",
},
},
},