Skip to content

Commit ca9a2d9

Browse files
authored
tsidp-server.go: read ENV vars using Go (#123)
Signed-off-by: Rodrigo Schio <r@schio.dev>
1 parent 9dfe889 commit ca9a2d9

3 files changed

Lines changed: 20 additions & 69 deletions

File tree

Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ RUN addgroup -g 1001 -S app && \
3838
# Copy the binary from builder
3939
COPY --from=builder /app/tsidp-server /tsidp-server
4040

41-
# Copy the entrypoint script
42-
COPY scripts/docker/run.sh /run.sh
43-
RUN chmod +x /run.sh
44-
4541
USER app:app
4642

47-
# Run the binary through the entrypoint script
48-
ENTRYPOINT ["/run.sh"]
43+
ENTRYPOINT ["/tsidp-server"]

scripts/docker/run.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

tsidp-server.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package main
88

99
import (
1010
"bytes"
11+
"cmp"
1112
"context"
1213
"crypto/tls"
1314
"errors"
@@ -35,20 +36,20 @@ import (
3536

3637
// Command line flags
3738
var (
38-
flagPort = flag.Int("port", 443, "port to listen on")
39-
flagLocalPort = flag.Int("local-port", -1, "allow requests from localhost")
40-
flagUseLocalTailscaled = flag.Bool("use-local-tailscaled", false, "use local tailscaled instead of tsnet")
41-
flagFunnel = flag.Bool("funnel", false, "use Tailscale Funnel to make tsidp available on the public internet")
42-
flagHostname = flag.String("hostname", "idp", "tsnet hostname to use instead of idp")
43-
flagDir = flag.String("dir", "", "tsnet state directory; a default one will be created if not provided")
44-
flagEnableSTS = flag.Bool("enable-sts", false, "enable OIDC STS token exchange support")
39+
flagPort = flag.Int("port", envIntOr("TSIDP_PORT", 443), "port to listen on")
40+
flagLocalPort = flag.Int("local-port", envIntOr("TSIDP_LOCAL_PORT", -1), "allow requests from localhost")
41+
flagUseLocalTailscaled = flag.Bool("use-local-tailscaled", envknob.Bool("TSIDP_USE_LOCAL_TAILSCALED"), "use local tailscaled instead of tsnet")
42+
flagFunnel = flag.Bool("funnel", envknob.Bool("TSIDP_USE_FUNNEL"), "use Tailscale Funnel to make tsidp available on the public internet")
43+
flagHostname = flag.String("hostname", cmp.Or(envknob.String("TS_HOSTNAME"), "idp"), "tsnet hostname to use instead of idp")
44+
flagDir = flag.String("dir", envknob.String("TS_STATE_DIR"), "tsnet state directory; a default one will be created if not provided")
45+
flagEnableSTS = flag.Bool("enable-sts", envknob.Bool("TSIDP_ENABLE_STS"), "enable OIDC STS token exchange support")
4546

4647
// application logging levels
47-
flagLogLevel = flag.String("log", "info", "log levels: debug, info, warn, error")
48+
flagLogLevel = flag.String("log", cmp.Or(envknob.String("TSIDP_LOG"), "info"), "log levels: debug, info, warn, error")
4849

4950
// extended debugging information
50-
flagDebugAllRequests = flag.Bool("debug-all-requests", false, "capture and print all HTTP requests and responses")
51-
flagDebugTSNet = flag.Bool("debug-tsnet", false, "enable tsnet.Server logging")
51+
flagDebugAllRequests = flag.Bool("debug-all-requests", envknob.Bool("TSIDP_DEBUG_ALL_REQUESTS"), "capture and print all HTTP requests and responses")
52+
flagDebugTSNet = flag.Bool("debug-tsnet", envknob.Bool("TSIDP_DEBUG_TSNET"), "enable tsnet.Server logging")
5253
)
5354

5455
// main initializes and starts the tsidp server
@@ -338,3 +339,11 @@ func (rw *responseWrapper) Write(b []byte) (int, error) {
338339
// Write to the original response writer
339340
return rw.ResponseWriter.Write(b)
340341
}
342+
343+
func envIntOr(envVar string, implicitValue int) int {
344+
val, ok := envknob.LookupInt(envVar)
345+
if !ok {
346+
return implicitValue
347+
}
348+
return val
349+
}

0 commit comments

Comments
 (0)