Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
730bc968
Unverified
Commit
730bc968
authored
May 16, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77874 from yuchengwu/fix-CVE-2019-11244
fix CVE-2019-11244: `kubectl --http-cache=<world-accessible dir>` cre…
parents
d823fa23
f228ae33
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
2 deletions
+84
-2
cached_discovery.go
...8s.io/client-go/discovery/cached/disk/cached_discovery.go
+2
-2
cached_discovery_test.go
.../client-go/discovery/cached/disk/cached_discovery_test.go
+27
-0
round_tripper.go
...c/k8s.io/client-go/discovery/cached/disk/round_tripper.go
+3
-0
round_tripper_test.go
....io/client-go/discovery/cached/disk/round_tripper_test.go
+52
-0
No files found.
staging/src/k8s.io/client-go/discovery/cached/disk/cached_discovery.go
View file @
730bc968
...
@@ -172,7 +172,7 @@ func (d *CachedDiscoveryClient) getCachedFile(filename string) ([]byte, error) {
...
@@ -172,7 +172,7 @@ func (d *CachedDiscoveryClient) getCachedFile(filename string) ([]byte, error) {
}
}
func
(
d
*
CachedDiscoveryClient
)
writeCachedFile
(
filename
string
,
obj
runtime
.
Object
)
error
{
func
(
d
*
CachedDiscoveryClient
)
writeCachedFile
(
filename
string
,
obj
runtime
.
Object
)
error
{
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
filename
),
075
5
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
filename
),
075
0
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -191,7 +191,7 @@ func (d *CachedDiscoveryClient) writeCachedFile(filename string, obj runtime.Obj
...
@@ -191,7 +191,7 @@ func (d *CachedDiscoveryClient) writeCachedFile(filename string, obj runtime.Obj
return
err
return
err
}
}
err
=
os
.
Chmod
(
f
.
Name
(),
0
755
)
err
=
os
.
Chmod
(
f
.
Name
(),
0
660
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
staging/src/k8s.io/client-go/discovery/cached/disk/cached_discovery_test.go
View file @
730bc968
...
@@ -19,6 +19,7 @@ package disk
...
@@ -19,6 +19,7 @@ package disk
import
(
import
(
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"testing"
"testing"
"time"
"time"
...
@@ -96,6 +97,32 @@ func TestNewCachedDiscoveryClient_TTL(t *testing.T) {
...
@@ -96,6 +97,32 @@ func TestNewCachedDiscoveryClient_TTL(t *testing.T) {
assert
.
Equal
(
c
.
groupCalls
,
2
)
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
{
type
fakeDiscoveryClient
struct
{
groupCalls
int
groupCalls
int
resourceCalls
int
resourceCalls
int
...
...
staging/src/k8s.io/client-go/discovery/cached/disk/round_tripper.go
View file @
730bc968
...
@@ -18,6 +18,7 @@ package disk
...
@@ -18,6 +18,7 @@ package disk
import
(
import
(
"net/http"
"net/http"
"os"
"path/filepath"
"path/filepath"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache"
...
@@ -35,6 +36,8 @@ type cacheRoundTripper struct {
...
@@ -35,6 +36,8 @@ type cacheRoundTripper struct {
// corresponding requests.
// corresponding requests.
func
newCacheRoundTripper
(
cacheDir
string
,
rt
http
.
RoundTripper
)
http
.
RoundTripper
{
func
newCacheRoundTripper
(
cacheDir
string
,
rt
http
.
RoundTripper
)
http
.
RoundTripper
{
d
:=
diskv
.
New
(
diskv
.
Options
{
d
:=
diskv
.
New
(
diskv
.
Options
{
PathPerm
:
os
.
FileMode
(
0750
),
FilePerm
:
os
.
FileMode
(
0660
),
BasePath
:
cacheDir
,
BasePath
:
cacheDir
,
TempDir
:
filepath
.
Join
(
cacheDir
,
".diskv-temp"
),
TempDir
:
filepath
.
Join
(
cacheDir
,
".diskv-temp"
),
})
})
...
...
staging/src/k8s.io/client-go/discovery/cached/disk/round_tripper_test.go
View file @
730bc968
...
@@ -22,7 +22,10 @@ import (
...
@@ -22,7 +22,10 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"os"
"path/filepath"
"testing"
"testing"
"github.com/stretchr/testify/assert"
)
)
// copied from k8s.io/client-go/transport/round_trippers_test.go
// copied from k8s.io/client-go/transport/round_trippers_test.go
...
@@ -93,3 +96,52 @@ func TestCacheRoundTripper(t *testing.T) {
...
@@ -93,3 +96,52 @@ func TestCacheRoundTripper(t *testing.T) {
t
.
Errorf
(
"Invalid content read from cache %q"
,
string
(
content
))
t
.
Errorf
(
"Invalid content read from cache %q"
,
string
(
content
))
}
}
}
}
func
TestCacheRoundTripperPathPerm
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
rt
:=
&
testRoundTripper
{}
cacheDir
,
err
:=
ioutil
.
TempDir
(
""
,
"cache-rt"
)
os
.
RemoveAll
(
cacheDir
)
defer
os
.
RemoveAll
(
cacheDir
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cache
:=
newCacheRoundTripper
(
cacheDir
,
rt
)
// First call, caches the response
req
:=
&
http
.
Request
{
Method
:
http
.
MethodGet
,
URL
:
&
url
.
URL
{
Host
:
"localhost"
},
}
rt
.
Response
=
&
http
.
Response
{
Header
:
http
.
Header
{
"ETag"
:
[]
string
{
`"123456"`
}},
Body
:
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
(
"Content"
))),
StatusCode
:
http
.
StatusOK
,
}
resp
,
err
:=
cache
.
RoundTrip
(
req
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
content
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
content
)
!=
"Content"
{
t
.
Errorf
(
`Expected Body to be "Content", got %q`
,
string
(
content
))
}
err
=
filepath
.
Walk
(
cacheDir
,
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment