mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 08:41:19 -08:00
cmd/tailscale/cli: handle kubeconfig stat errors
kubeconfigPath dereferences FileInfo for non-ENOENT stat errors even though os.Stat returns nil FileInfo. Preserve the failing list entry so checkKubeconfigWritable reports the existing access error instead of panicking. Updates #11604 Signed-off-by: Bonobo <[email protected]>
This commit is contained in:
1 parent
290aad71cc
commit
8052bb2c53
2 files changed
+19
-4
No files matched your search
@@ -56,7 +56,14 @@ func kubeconfigPath() string {
|
||||
if kubeconfig := os.Getenv("KUBECONFIG"); kubeconfig != "" {
|
||||
var out string
|
||||
for _, out = range filepath.SplitList(kubeconfig) {
|
||||
if info, err := os.Stat(out); !os.IsNotExist(err) && !info.IsDir() {
|
||||
info, err := os.Stat(out)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !info.IsDir() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,10 +304,18 @@ func TestCheckKubeconfigWritable(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("directory mode permissions are not enforced the same way on Windows")
|
||||
}
|
||||
if os.Getuid() == 0 {
|
||||
t.Skip("root bypasses directory permission checks")
|
||||
}
|
||||
dir := t.TempDir()
|
||||
loop := filepath.Join(dir, "loop")
|
||||
if err := os.Symlink(filepath.Base(loop), loop); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("KUBECONFIG", loop)
|
||||
if got := kubeconfigPath(); got != loop {
|
||||
t.Errorf("kubeconfigPath() = %q, want %q", got, loop)
|
||||
}
|
||||
if os.Getuid() == 0 {
|
||||
return // root bypasses the remaining file permission check
|
||||
}
|
||||
sub := filepath.Join(dir, "ro")
|
||||
if err := os.Mkdir(sub, 0500); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in new issue
Block a user