2025-07-09 09:21:56 +01:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
//go:build !plan9
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2025-07-22 14:46:38 +01:00
|
|
|
"tailscale.com/kube/kubetypes"
|
|
|
|
"tailscale.com/types/ptr"
|
2025-07-09 09:21:56 +01:00
|
|
|
)
|
|
|
|
|
2025-07-22 14:46:38 +01:00
|
|
|
func parseAPIProxyMode() *kubetypes.APIServerProxyMode {
|
2025-07-09 09:21:56 +01:00
|
|
|
haveAuthProxyEnv := os.Getenv("AUTH_PROXY") != ""
|
|
|
|
haveAPIProxyEnv := os.Getenv("APISERVER_PROXY") != ""
|
|
|
|
switch {
|
|
|
|
case haveAPIProxyEnv && haveAuthProxyEnv:
|
|
|
|
log.Fatal("AUTH_PROXY (deprecated) and APISERVER_PROXY are mutually exclusive, please unset AUTH_PROXY")
|
|
|
|
case haveAuthProxyEnv:
|
|
|
|
var authProxyEnv = defaultBool("AUTH_PROXY", false) // deprecated
|
|
|
|
if authProxyEnv {
|
2025-07-22 14:46:38 +01:00
|
|
|
return ptr.To(kubetypes.APIServerProxyModeAuth)
|
2025-07-09 09:21:56 +01:00
|
|
|
}
|
2025-07-22 14:46:38 +01:00
|
|
|
return nil
|
2025-07-09 09:21:56 +01:00
|
|
|
case haveAPIProxyEnv:
|
|
|
|
var apiProxyEnv = defaultEnv("APISERVER_PROXY", "") // true, false or "noauth"
|
|
|
|
switch apiProxyEnv {
|
|
|
|
case "true":
|
2025-07-22 14:46:38 +01:00
|
|
|
return ptr.To(kubetypes.APIServerProxyModeAuth)
|
2025-07-09 09:21:56 +01:00
|
|
|
case "false", "":
|
2025-07-22 14:46:38 +01:00
|
|
|
return nil
|
2025-07-09 09:21:56 +01:00
|
|
|
case "noauth":
|
2025-07-22 14:46:38 +01:00
|
|
|
return ptr.To(kubetypes.APIServerProxyModeNoAuth)
|
2025-07-09 09:21:56 +01:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unknown APISERVER_PROXY value %q", apiProxyEnv))
|
|
|
|
}
|
|
|
|
}
|
2025-07-22 14:46:38 +01:00
|
|
|
return nil
|
2025-07-09 09:21:56 +01:00
|
|
|
}
|