Skip to content

Commit 5bef350

Browse files
committed
Add TAILSCALE_API_URL environment variable support: update Docker Compose, backend configuration, and README to include optional API URL for Tailscale integration, enhancing flexibility for users with region-specific endpoints. #4
1 parent 9e10790 commit 5bef350

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ OAuth provides better security through automatic token refresh and fine-grained
7171
2. Your organization name is displayed in the Organization section (used by the Tailscale API)
7272
3. Use this exact organization name for the `TAILSCALE_TAILNET` variable
7373

74+
#### API URL (Optional)
75+
For most users, the default API URL works fine. However, some users may need to use region-specific endpoints:
76+
- Default: `https://api.tailscale.com`
77+
- US-specific: `https://api.us.tailscale.com`
78+
79+
Set `TAILSCALE_API_URL=https://api.us.tailscale.com` if you need the US-specific endpoint.
80+
7481
### Environment Variables
7582

7683
| Variable | Description | Required | Default |
7784
|----------|-------------|----------|---------|
7885
| `TAILSCALE_TAILNET` | Your organization name | Yes | - |
86+
| `TAILSCALE_API_URL` | Tailscale API endpoint URL | No | `https://api.tailscale.com` |
7987
| **OAuth Method** |
8088
| `TAILSCALE_OAUTH_CLIENT_ID` | OAuth client ID | Yes* | - |
8189
| `TAILSCALE_OAUTH_CLIENT_SECRET` | OAuth client secret | Yes* | - |

backend/internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
type Config struct {
1212
TailscaleAPIKey string
1313
TailscaleTailnet string
14+
TailscaleAPIURL string
1415
TailscaleOAuthClientID string
1516
TailscaleOAuthClientSecret string
1617
TailscaleOAuthScopes []string
@@ -23,6 +24,7 @@ func Load() *Config {
2324
return &Config{
2425
TailscaleAPIKey: os.Getenv("TAILSCALE_API_KEY"),
2526
TailscaleTailnet: os.Getenv("TAILSCALE_TAILNET"),
27+
TailscaleAPIURL: getEnvWithDefault("TAILSCALE_API_URL", "https://api.tailscale.com"),
2628
TailscaleOAuthClientID: os.Getenv("TAILSCALE_OAUTH_CLIENT_ID"),
2729
TailscaleOAuthClientSecret: os.Getenv("TAILSCALE_OAUTH_CLIENT_SECRET"),
2830
TailscaleOAuthScopes: parseScopes(os.Getenv("TAILSCALE_OAUTH_SCOPES")),

backend/internal/services/tailscale.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type TailscaleService struct {
1717
apiKey string
1818
oauthConfig *clientcredentials.Config
1919
tailnet string
20+
baseURL string
2021
client *http.Client
2122
useOAuth bool
2223
}
@@ -67,6 +68,7 @@ type NetworkLogsResponse struct {
6768
func NewTailscaleService(cfg *config.Config) *TailscaleService {
6869
ts := &TailscaleService{
6970
tailnet: cfg.TailscaleTailnet,
71+
baseURL: cfg.TailscaleAPIURL,
7072
}
7173

7274
// Prioritize OAuth if configured, fallback to API key
@@ -75,7 +77,7 @@ func NewTailscaleService(cfg *config.Config) *TailscaleService {
7577
ClientID: cfg.TailscaleOAuthClientID,
7678
ClientSecret: cfg.TailscaleOAuthClientSecret,
7779
Scopes: cfg.TailscaleOAuthScopes,
78-
TokenURL: "https://api.tailscale.com/api/v2/oauth/token",
80+
TokenURL: cfg.TailscaleAPIURL + "/api/v2/oauth/token",
7981
}
8082
ts.client = ts.oauthConfig.Client(context.Background())
8183
ts.client.Timeout = 2 * time.Minute
@@ -93,7 +95,7 @@ func NewTailscaleService(cfg *config.Config) *TailscaleService {
9395

9496
// makeRequest makes an authenticated request to the Tailscale API
9597
func (ts *TailscaleService) makeRequest(endpoint string) ([]byte, error) {
96-
url := fmt.Sprintf("https://api.tailscale.com/api/v2%s", endpoint)
98+
url := fmt.Sprintf("%s/api/v2%s", ts.baseURL, endpoint)
9799

98100
req, err := http.NewRequest("GET", url, nil)
99101
if err != nil {

backend/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func main() {
7676

7777
log.Printf("Starting TSFlow server on port %s", port)
7878
log.Printf("Tailnet: %s", cfg.TailscaleTailnet)
79+
log.Printf("API URL: %s", cfg.TailscaleAPIURL)
7980
log.Printf("Environment: %s", cfg.Environment)
8081

8182
// Log authentication method being used

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
environment:
77
- TAILSCALE_API_KEY=${TAILSCALE_API_KEY}
88
- TAILSCALE_TAILNET=${TAILSCALE_TAILNET}
9+
- TAILSCALE_API_URL=${TAILSCALE_API_URL}
910
- TAILSCALE_OAUTH_CLIENT_ID=${TAILSCALE_OAUTH_CLIENT_ID}
1011
- TAILSCALE_OAUTH_CLIENT_SECRET=${TAILSCALE_OAUTH_CLIENT_SECRET}
1112
- TAILSCALE_OAUTH_SCOPES=${TAILSCALE_OAUTH_SCOPES}

k8s/secret.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type: Opaque
66
stringData:
77
TAILSCALE_API_KEY: ${TAILSCALE_API_KEY}
88
TAILSCALE_TAILNET: ${TAILSCALE_TAILNET}
9+
TAILSCALE_API_URL: ${TAILSCALE_API_URL}
910
TAILSCALE_OAUTH_CLIENT_ID: ${TAILSCALE_OAUTH_CLIENT_ID}
1011
TAILSCALE_OAUTH_CLIENT_SECRET: ${TAILSCALE_OAUTH_CLIENT_SECRET}
1112
TAILSCALE_OAUTH_SCOPES: ${TAILSCALE_OAUTH_SCOPES}

0 commit comments

Comments
 (0)