Skip to content

Commit ddc9b3d

Browse files
committed
Support host specific keys
Signed-off-by: Connor Kelly <connor.r.kelly@gmail.com>
1 parent 9eeac15 commit ddc9b3d

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

Caddyfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
order tailscale_auth after basicauth
3+
tailscale {
4+
auth_key "tskey-auth-"
5+
6+
caddy {
7+
auth_key "tskey-auth-caddy"
8+
}
9+
}
310
}
411

512
:80 {

module.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func getServer(_, addr string) (*tsnetServerDestructor, error) {
107107

108108
if host != "" {
109109
s.AuthKey = getAuthKey(host)
110-
log.Println("auth_key", s.AuthKey)
111110

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

136135
func getAuthKey(host string) string {
136+
hostAuthKey, loaded := app.LoadOrStore(host, "")
137+
if loaded {
138+
return hostAuthKey.(TSServer).AuthKey
139+
}
140+
137141
storedAuthKey, loaded := app.LoadOrStore(authUsageKey, "")
138142
if loaded {
139143
return storedAuthKey.(string)

module_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ func Test_GetAuthKey(t *testing.T) {
3535
host: testHost,
3636
},
3737
"host key from environment": {
38-
want: testHostKey,
39-
host: testHost,
38+
want: testHostKey,
39+
skipApp: true,
40+
host: testHost,
4041
},
4142
}
4243
for name, tt := range tests {

0 commit comments

Comments
 (0)