@@ -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)
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