Skip to content
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

Set Tailscale hostname through environment variable. #18

Closed
wants to merge 1 commit into from

Conversation

kdevan
Copy link
Contributor

@kdevan kdevan commented Aug 11, 2023

This is a very simple PR that just allows changing the Tailscale hostname through an environment variable. You may want to pass on this if there's plans to allow for multiple hosts per TS node as described here.

My use case is using this with Fly.io which requires matching up the Fly app name with the Tailscale hostname. And since I do require multiple nodes, one for each secure Fly app, I need to be able to match those with multiple Tailscale hostnames. I also would like to be able to do multiple environments like stage and production.

For the logic to get the environment variable or use a fallback, I followed the way that it's done here with TS_AUTHKEY. The fallback is the hardcoded value that's here now. The environment variable name TS_HOSTNAME matches the one that the official Tailscale docker container uses. Then I just updated README.md to reflect this change.

@willnorris
Copy link
Member

rather than add more magic env variables, I'd rather actually use caddy's configuration support. You can add configuration options for transports like anything else (see for example the http transport). Additionally, caddy has support for using environment variables in your config using {$VARNAME} syntax. So you could easily imagine using environment variables to configure the tailscale hostname with a caddyfile something like:

   reverse_proxy http://myhost.tailnet.ts.net:80 {
      transport tailscale {
        hostname {$TS_HOSTNAME}
      }
    }

I thought we had an example of parsing a caddyfile in caddy-tailscale, but I guess not. There are caddy docs, as well as plenty of examples in caddy itself. If that's more than you're up for trying to do that's fine... I certainly don't mind adding support for this. It'd be good to get it in place anyway, since that would be the preferred method of configuring other parts of the module anyway.

@kdevan
Copy link
Contributor Author

kdevan commented Aug 11, 2023

This is great, I would not have thought to do it this way. I'm curious to learn more Golang as well as Caddy modules, so... perfect :) I'll give this a shot. Thank you for the feedback.

@ChibangLW ChibangLW mentioned this pull request Oct 15, 2023
@ChibangLW
Copy link
Contributor

@kdevan maybe have a look at #22. There you can see the syntax to use the transport config.

@kernelb00t
Copy link

Any updates on this issue ?

willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
This includes:
 - Move TailscaleAuth logic into auth.go
 - Move all TSApp logic into app.go (including caddyfile parsing)
 - Rename "server" to "node" throughout. This aligns better with
   Tailscale terminology, and is reflective of the fact that nodes can
   also just be used as proxy transports, in which case they are not
   acting as servers at all.
 - Generally prefer referring to a node's "name" than "host". While this
   name is still used as the default hostname for the node, I would
   expect that to change with a future iteration of #18.
 - add godocs throughout

Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 8, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 9, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 9, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 9, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 9, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
willnorris added a commit that referenced this pull request May 9, 2024
this overrides the name used to refer to the node in the caddy config,
and is mostly useful because it can include environment variables.

Closes #18

Co-authored-by: kdevan <kaidevan@gmail.com>
Signed-off-by: Will Norris <will@tailscale.com>
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.

None yet

4 participants