fix CVE-2019-11244: kubectl --http-cache=<world-accessible dir> creates world-writeable cached schema files

Kubernetes-commit: f228ae3364729caed59087e23c42868454bc3ff4
This commit is contained in:
Yucheng Wu
2019-05-14 14:49:38 +08:00
committed by Kubernetes Publisher
parent e10a9b6eaa
commit 790a4f6363
4 changed files with 84 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ package disk
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
@@ -96,6 +97,32 @@ func TestNewCachedDiscoveryClient_TTL(t *testing.T) {
assert.Equal(c.groupCalls, 2)
}
func TestNewCachedDiscoveryClient_PathPerm(t *testing.T) {
assert := assert.New(t)
d, err := ioutil.TempDir("", "")
assert.NoError(err)
os.RemoveAll(d)
defer os.RemoveAll(d)
c := fakeDiscoveryClient{}
cdc := newCachedDiscoveryClient(&c, d, 1*time.Nanosecond)
cdc.ServerGroups()
err = filepath.Walk(d, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
assert.Equal(os.FileMode(0750), info.Mode().Perm())
} else {
assert.Equal(os.FileMode(0660), info.Mode().Perm())
}
return nil
})
assert.NoError(err)
}
type fakeDiscoveryClient struct {
groupCalls int
resourceCalls int