Skip to content

Commit

Permalink
Support host specific keys
Browse files Browse the repository at this point in the history
  • Loading branch information
clly committed Feb 12, 2024
1 parent 63a9c89 commit 5745e44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
order tailscale_auth after basicauth
tailscale {
auth_key "tskey-auth-"

caddy {
auth_key "tskey-auth-caddy"
}
}
}

:80 {
Expand Down
6 changes: 5 additions & 1 deletion module.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func getServer(_, addr string) (*tsnetServerDestructor, error) {

if host != "" {
s.AuthKey = getAuthKey(host)
log.Println("auth_key", s.AuthKey)

// Set config directory for tsnet. By default, tsnet will use the name of the
// running program, but we include the hostname as well so that a single
Expand All @@ -134,6 +133,11 @@ func getServer(_, addr string) (*tsnetServerDestructor, error) {
}

func getAuthKey(host string) string {
hostAuthKey, loaded := app.LoadOrStore(host, "")
if loaded {
return hostAuthKey.(TSServer).AuthKey
}

storedAuthKey, loaded := app.LoadOrStore(authUsageKey, "")
if loaded {
return storedAuthKey.(string)
Expand Down
5 changes: 3 additions & 2 deletions module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func Test_GetAuthKey(t *testing.T) {
host: testHost,
},
"host key from environment": {
want: testHostKey,
host: testHost,
want: testHostKey,
skipApp: true,
host: testHost,
},
}
for name, tt := range tests {
Expand Down

0 comments on commit 5745e44

Please sign in to comment.