Skip to content

Commit 5007403

Browse files
authored
scripts/docker: Add run.sh entrypoint for docker image (#51)
This adds a run.sh as the default entry point for the docker image. The run script maps optional environment variables to the command line flags used by tsidp-server. This makes the tsidp container align with the config-by-env-vars convention in docker deployments. Signed-off-by: Benson Wong <[email protected]>
1 parent 615d4dc commit 5007403

File tree

3 files changed

+84
-19
lines changed

3 files changed

+84
-19
lines changed

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ RUN apk --no-cache add ca-certificates
3030
WORKDIR /app
3131

3232
# Copy the binary from builder
33-
COPY --from=builder /app/tsidp-server .
33+
COPY --from=builder /app/tsidp-server /tsidp-server
3434

35-
# Run the binary
36-
ENTRYPOINT ["./tsidp-server"]
35+
# Copy the entrypoint script
36+
COPY scripts/docker/run.sh /run.sh
37+
RUN chmod +x /run.sh
38+
39+
# Run the binary through the entrypoint script
40+
ENTRYPOINT ["/run.sh"]

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ docker build -t tsidp .
3737
docker run -d \
3838
--name tsidp \
3939
-p 443:443 \
40+
-v tsidp-data:/data \
41+
-e TS_STATE_DIR=/data \
4042
-e TS_AUTHKEY=YOUR_TAILSCALE_AUTHKEY \
41-
-e TSNET_FORCE_LOGIN=1
43+
-e TSNET_FORCE_LOGIN=1 \
4244
-e TAILSCALE_USE_WIP_CODE=1 \
43-
-v tsidp-data:/var/lib/tsidp \
44-
tsidp --hostname=idp --dir=/var/lib/tsidp
45+
-e TSIDP_ENABLE_STS=1 \
46+
-e TS_HOSTNAME=idp \
47+
tsidp
4548
```
4649

4750
Visit `https://idp.yourtailnet.ts.net` to confirm the service is running.
@@ -125,24 +128,39 @@ tsidp supports all of the endpoints required & suggested by the [MCP Authorizati
125128

126129
## tsidp Configuration Options
127130

128-
The `tsidp` server supports several command-line flags:
131+
The `tsidp` server is configured by several command-line flags:
129132

130-
- `--verbose`: Enable verbose logging
131-
- `--port`: Port to listen on (default: 443)
132-
- `--local-port`: Allow requests from localhost
133-
- `--use-local-tailscaled`: Use local tailscaled instead of tsnet
134-
- `--funnel`: Use Tailscale Funnel to make tsidp available on the public internet so it works with SaaS products
135-
- `--hostname`: tsnet hostname
136-
- `--dir`: tsnet state directory
137-
- `--enable-sts`: Enable OAuth token exchange using RFC 8693
138-
- `--enable-debug`: Enable debug printing of requests to the server
133+
- `-verbose`: Enable verbose logging
134+
- `-port`: Port to listen on (default: 443)
135+
- `-local-port`: Allow requests from localhost
136+
- `-use-local-tailscaled`: Use local tailscaled instead of tsnet
137+
- `-funnel`: Use Tailscale Funnel to make tsidp available on the public internet so it works with SaaS products
138+
- `-hostname`: tsnet hostname
139+
- `-dir`: tsnet state directory
140+
- `-enable-sts`: Enable OAuth token exchange using RFC 8693
141+
- `-enable-debug`: Enable debug printing of requests to the server
139142

140143
### Environment Variables
141144

145+
These are needed while tsidp is in development (< v1.0.0):
146+
147+
- `TAILSCALE_USE_WIP_CODE`: Enable work-in-progress code (default: "1", required)
142148
- `TS_AUTHKEY`: Your Tailscale authentication key (required)
143-
- `TS_HOSTNAME`: Hostname for the `tsidp` server (default: "idp", Docker only)
144-
- `TS_STATE_DIR`: State directory (default: "/var/lib/tsidp", Docker only)
145-
- `TAILSCALE_USE_WIP_CODE`: Enable work-in-progress code (default: "1")
149+
150+
The docker container accepts environment variables that are mapped to the command-line flags:
151+
152+
| Environment Variable | CLI flag |
153+
| ------------------------------- | -------------------------- |
154+
| `TS_HOSTNAME=<hostname>` | `-hostname <hostname>` |
155+
| `TS_STATE_DIR=<directory>` | `-dir <directory>` |
156+
| `TSIDP_USE_FUNNEL=1` | `-funnel` |
157+
| `TSIDP_PORT=<port>` | `-port <port>` |
158+
| `TSIDP_LOCAL_PORT=<local-port>` | `-local-port <local-port>` |
159+
| `TSIDP_ENABLE_STS=1` | `-enable-sts` |
160+
| `TSIDP_VERBOSE=1` | `-verbose` |
161+
| `TSIDP_ENABLE_DEBUG=1` | `-enable-debug` |
162+
163+
All environment variables are optional. When omitted the default value for the command-line flag will be used.
146164

147165
## Support
148166

scripts/docker/run.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
3+
# Build command arguments based on environment variables
4+
ARGS=""
5+
6+
if [ -n "$TS_STATE_DIR" ]; then
7+
ARGS="$ARGS -dir=$TS_STATE_DIR"
8+
fi
9+
10+
if [ -n "$TS_HOSTNAME" ]; then
11+
ARGS="$ARGS -hostname=$TS_HOSTNAME"
12+
fi
13+
14+
if [ -n "$TSIDP_USE_FUNNEL" ]; then
15+
ARGS="$ARGS -funnel"
16+
fi
17+
18+
if [ -n "$TSIDP_ENABLE_STS" ]; then
19+
ARGS="$ARGS -enable-sts"
20+
fi
21+
22+
if [ -n "$TSIDP_PORT" ]; then
23+
ARGS="$ARGS -port=$TSIDP_PORT"
24+
fi
25+
26+
if [ -n "$TSIDP_LOCAL_PORT" ]; then
27+
ARGS="$ARGS -local-port=$TSIDP_LOCAL_PORT"
28+
fi
29+
30+
#
31+
# These flags will eventually be replaced
32+
# with more specific logging flags.
33+
#
34+
if [ -n "$TSIDP_VERBOSE" ]; then
35+
ARGS="$ARGS -verbose"
36+
fi
37+
38+
if [ -n "$TSIDP_ENABLE_DEBUG" ]; then
39+
ARGS="$ARGS -enable-debug"
40+
fi
41+
42+
# Execute tsidp-server with the built arguments
43+
exec /tsidp-server $ARGS "$@"

0 commit comments

Comments
 (0)