Skip to content

Commit 2d1f6f1

Browse files
authored
cmd/k8s-operator: require namespace config (tailscale#14648)
Most users should not run into this because it's set in the helm chart and the deploy manifest, but if namespace is not set we get confusing authz errors because the kube client tries to fetch some namespaced resources as though they're cluster-scoped and reports permission denied. Try to detect namespace from the default projected volume, and otherwise fatal. Fixes #cleanup Change-Id: I64b34191e440b61204b9ad30bbfa117abbbe09c3 Signed-off-by: Tom Proctor <[email protected]>
1 parent 00bd906 commit 2d1f6f1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/k8s-operator/operator.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ func main() {
8888
zlog := kzap.NewRaw(opts...).Sugar()
8989
logf.SetLogger(zapr.NewLogger(zlog.Desugar()))
9090

91+
if tsNamespace == "" {
92+
const namespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
93+
b, err := os.ReadFile(namespaceFile)
94+
if err != nil {
95+
zlog.Fatalf("Could not get operator namespace from OPERATOR_NAMESPACE environment variable or default projected volume: %v", err)
96+
}
97+
tsNamespace = strings.TrimSpace(string(b))
98+
}
99+
91100
// The operator can run either as a plain operator or it can
92101
// additionally act as api-server proxy
93102
// https://tailscale.com/kb/1236/kubernetes-operator/?q=kubernetes#accessing-the-kubernetes-control-plane-using-an-api-server-proxy.

0 commit comments

Comments
 (0)