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

use tailscale cert manager with tailscale-proxy command #57

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ default, all incoming headers are passed through unmodified.)
fs.Bool("change-host-header", false, "Set upstream Host header to address of upstream")
fs.Bool("insecure", false, "Disable TLS verification (WARNING: DISABLES SECURITY BY NOT VERIFYING SSL CERTIFICATES!)")
fs.Bool("internal-certs", false, "Use internal CA for issuing certs")
fs.Bool("debug", false, "Enable debug logging")
return fs
}(),
})
Expand All @@ -81,6 +82,7 @@ func cmdTailscaleProxy(fs caddycmd.Flags) (int, error) {
changeHost := fs.Bool("change-host-header")
insecure := fs.Bool("insecure")
internalCerts := fs.Bool("internal-certs")
debug := fs.Bool("debug")

httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort)
httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort)
Expand Down Expand Up @@ -205,6 +207,15 @@ func cmdTailscaleProxy(fs caddycmd.Flags) (int, error) {
},
}
appsRaw["tls"] = caddyconfig.JSON(tlsApp, nil)
} else if tsBind {
tlsApp := caddytls.TLS{
Automation: &caddytls.AutomationConfig{
Policies: []*caddytls.AutomationPolicy{{
ManagersRaw: []json.RawMessage{json.RawMessage(`{"via": "tailscale"}`)},
}},
},
}
appsRaw["tls"] = caddyconfig.JSON(tlsApp, nil)
}

var false bool
Expand All @@ -216,6 +227,17 @@ func cmdTailscaleProxy(fs caddycmd.Flags) (int, error) {
},
AppsRaw: appsRaw,
}
if debug {
Copy link
Contributor

@irbekrm irbekrm Jun 5, 2024

Choose a reason for hiding this comment

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

Question: is the caddy config generated here persisted across restarts? (If it is, then users would have no way to unset the debug flag except for by deleting the config)

Copy link
Member Author

Choose a reason for hiding this comment

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

no, this config is entirely in memory. It's not persisted anywhere.

In hindsight, I'm not actually sure how useful this tailscale-proxy subcommand really is compared to just creating a pretty simple caddyfile that does the same thing. It was something I added pretty on, mostly just to see if I could 🤷🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

would the proxy subcommand be useful for the Dockerfile? #14

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, possibly. If the Dockerfile just provided a caddy binary with the tailscale plugin compiled in, then you could use that to run the proxy. I'll go ahead and add that to the v1 milestone... seems worth doing.

cfg.Logging = &caddy.Logging{
Logs: map[string]*caddy.CustomLog{
"default": {
BaseLog: caddy.BaseLog{
Level: "DEBUG",
},
},
},
}
}

err = caddy.Run(cfg)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion examples/proxyauth.caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

{
order tailscale_auth after basicauth
auto_https off
tailscale {
ephemeral # create all nodes as ephemeral
}
Expand Down