-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): add support for verify-clients
- Loading branch information
1 parent
daaa592
commit 69de0ef
Showing
4 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
#!/bin/bash | ||
|
||
# Initialize the command with the executable | ||
CMD="/app/derper" | ||
# Initialize the commands with the executables | ||
DERP_CMD="/app/derper" | ||
TSD_CMD="/app/tailscaled" | ||
TS_CMD="/app/tailscale up" | ||
|
||
# Generate derpmap | ||
jq -n --arg hostname "${DERP_HOSTNAME}" '{"Regions":{"900":{"RegionID":900,"Nodes":[{"Name":"900","HostName":$hostname}]}}}' > /app/derpmap.json | ||
|
||
# Loop through all environment variables | ||
for VAR in $(env); do | ||
# Check if the variable starts with DERP_ | ||
if [[ $VAR == DERP_* ]]; then | ||
# Extract the name and value | ||
VAR_NAME=$(echo "$VAR" | cut -d= -f1) | ||
VAR_VALUE=$(echo "$VAR" | cut -d= -f2-) | ||
# Check if the variable starts with DERP_, TSD_, or TS_ | ||
case "$VAR" in | ||
DERP_*|TSD_*|TS_*) | ||
# Extract the name and value | ||
VAR_NAME=$(echo "$VAR" | cut -d= -f1) | ||
VAR_VALUE=$(echo "$VAR" | cut -d= -f2-) | ||
|
||
# Convert the variable name to an argument name | ||
# Remove the prefix, replace underscores with dashes, and convert to lowercase | ||
ARG_NAME=$(echo "$VAR_NAME" | sed -E 's/^(DERP_|TSD_|TS_)//; s/_/-/g; y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/') | ||
|
||
# Append the argument to command based on argument name | ||
case "$VAR_NAME" in | ||
DERP_*) | ||
DERP_CMD="$DERP_CMD --$ARG_NAME=$VAR_VALUE" | ||
echo "Adding $ARG_NAME=$VAR_VALUE to DERP_CMD" | ||
;; | ||
TSD_*) | ||
TSD_CMD="$TSD_CMD --$ARG_NAME=$VAR_VALUE" | ||
echo "Adding $ARG_NAME=$VAR_VALUE to TSD_CMD" | ||
;; | ||
TS_*) | ||
TS_CMD="$TS_CMD --$ARG_NAME=$VAR_VALUE" | ||
# We don't want to log the auth key | ||
echo "Adding $ARG_NAME to TS_CMD" | ||
;; | ||
esac | ||
;; | ||
esac | ||
|
||
# Convert the variable name to lowercase and replace underscores with hyphens | ||
ARG_NAME=$(echo "$VAR_NAME" | sed 's/^DERP_//' | tr '[:upper:]' '[:lower:]' | tr '_' '-') | ||
|
||
# Append the argument to the command | ||
CMD="$CMD --$ARG_NAME=$VAR_VALUE" | ||
fi | ||
done | ||
|
||
# Execute the command | ||
exec $CMD | ||
# Start tailscaled and call tailscale up if we need to verify clients | ||
if [[ $DERP_VERIFY_CLIENTS == "true" ]]; then | ||
# Start and background tailscaled | ||
setsid $TSD_CMD > /dev/stdout 2> /dev/stderr & | ||
# Start and background tailscale up | ||
setsid $TS_CMD > /dev/stdout 2> /dev/stderr & | ||
fi | ||
|
||
# Execute the derper | ||
exec $DERP_CMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters