- Add Groups field to User struct with JSON storage - Include GetGroups() and SetGroups() helper methods - Extract groups from OIDC claims in FromClaim() - Add database migration 202509161200 for groups column - Update config-example.yaml with groups scope - Add comprehensive documentation and testing
54 lines
2.0 KiB
Bash
Executable File
54 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Setup script for Headscale server
|
|
# Creates users and generates pre-auth keys for Tailscale clients
|
|
|
|
set -e
|
|
|
|
echo "Waiting for Headscale to be ready..."
|
|
sleep 5
|
|
|
|
# Create a user for our test environment
|
|
echo "Creating user 'testuser'..."
|
|
docker exec headscale-server headscale users create testuser || echo "User might already exist"
|
|
|
|
# Get the user ID (newer Headscale versions require user ID instead of username)
|
|
echo "Getting user ID..."
|
|
USER_ID=$(docker exec headscale-server headscale --output json users list | jq -r '.[] | select(.username=="testuser") | .id' 2>/dev/null)
|
|
|
|
if [ -z "$USER_ID" ]; then
|
|
echo "Failed to get user ID. Trying alternative method..."
|
|
USER_ID=1 # Default to 1 for first user
|
|
fi
|
|
|
|
echo "Using user ID: $USER_ID"
|
|
|
|
# Generate pre-auth keys for the clients using user ID
|
|
echo "Generating pre-auth keys..."
|
|
KEY1=$(docker exec headscale-server headscale --output json preauthkeys create --user $USER_ID --reusable --expiration 24h | jq -r '.key' 2>/dev/null || echo "")
|
|
KEY2=$(docker exec headscale-server headscale --output json preauthkeys create --user $USER_ID --reusable --expiration 24h | jq -r '.key' 2>/dev/null || echo "")
|
|
|
|
if [ -z "$KEY1" ] || [ -z "$KEY2" ]; then
|
|
echo "Failed to generate pre-auth keys automatically."
|
|
echo "You can create them manually with:"
|
|
echo " docker exec headscale-server headscale preauthkeys create --user $USER_ID --reusable --expiration 24h"
|
|
echo ""
|
|
echo "Then add them to the .env file:"
|
|
echo " TS_AUTHKEY_CLIENT1=<key1>"
|
|
echo " TS_AUTHKEY_CLIENT2=<key2>"
|
|
else
|
|
# Save the keys to .env file
|
|
cat > .env << EOF
|
|
# Headscale pre-auth keys for Tailscale clients
|
|
COMPOSE_PROJECT_NAME=headscale-dev
|
|
TS_AUTHKEY_CLIENT1=$KEY1
|
|
TS_AUTHKEY_CLIENT2=$KEY2
|
|
EOF
|
|
|
|
echo "Pre-auth keys saved to .env file:"
|
|
echo " Client1: $KEY1"
|
|
echo " Client2: $KEY2"
|
|
fi
|
|
|
|
echo ""
|
|
echo "Setup complete! You can now restart the clients with:"
|
|
echo " docker compose restart tailscale-client1 tailscale-client2" |