Skip to content

Commit e35953d

Browse files
author
angelbirth
committed
add flag 'ts-authkey-file' and env var TS_AUTHKEY_FILE for use with docker secrets
1 parent 335dc10 commit e35953d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

scripts/docker/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if [ -n "$TSIDP_LOCAL_PORT" ]; then
2727
ARGS="$ARGS -local-port=$TSIDP_LOCAL_PORT"
2828
fi
2929

30+
if [ -n "$TS_AUTHKEY_FILE" ]; then
31+
ARGS="$ARGS -ts-authkey-file=$TS_AUTHKEY_FILE"
32+
fi
33+
3034
# logging control
3135
if [ -n "$TSIDP_LOG" ]; then
3236
case "$TSIDP_LOG" in

tsidp-server.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020
"os"
2121
"os/signal"
22+
"path/filepath"
2223
"strings"
2324
"time"
2425

@@ -29,7 +30,6 @@ import (
2930
"tailscale.com/hostinfo"
3031
"tailscale.com/ipn"
3132
"tailscale.com/ipn/ipnstate"
32-
3333
"tailscale.com/tsnet"
3434
"tailscale.com/version"
3535
)
@@ -51,6 +51,8 @@ var (
5151
// extended debugging information
5252
flagDebugAllRequests = flag.Bool("debug-all-requests", false, "capture and print all HTTP requests and responses")
5353
flagDebugTSNet = flag.Bool("debug-tsnet", false, "enable tsnet.Server logging")
54+
55+
flagAuthKeyFile = flag.String("ts-authkey-file", "", "authkey file")
5456
)
5557

5658
// main initializes and starts the tsidp server
@@ -127,10 +129,28 @@ func main() {
127129
defer cleanup()
128130
} else {
129131
hostinfo.SetApp("tsidp")
132+
if *flagAuthKeyFile != "" {
133+
f, _ := filepath.Abs(*flagAuthKeyFile)
134+
file, err := os.Open(f)
135+
if err != nil {
136+
slog.Error("error opening auth key file", slog.Any("err", err))
137+
os.Exit(1)
138+
}
139+
authKeyBytes, err := io.ReadAll(file)
140+
if err != nil {
141+
slog.Error("error reading auth key file", slog.Any("err", err))
142+
os.Exit(1)
143+
}
144+
// reuse tsAuthKeyFile variable
145+
*flagAuthKeyFile = string(authKeyBytes)
146+
}
130147
ts := &tsnet.Server{
131148
Hostname: *flagHostname,
132149
Dir: *flagDir,
133150
}
151+
if *flagAuthKeyFile != "" {
152+
ts.AuthKey = *flagAuthKeyFile
153+
}
134154
if *flagDebugTSNet {
135155
ts.Logf = func(format string, args ...any) {
136156
cur := slog.SetLogLoggerLevel(slog.LevelDebug) // force debug if this option is on

0 commit comments

Comments
 (0)