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
ac8808b7
Unverified
Commit
ac8808b7
authored
Sep 24, 2017
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promote continuation token schema to v1
Change the filtering logic to require a leading path and clean that afterwards.
parent
da7124e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
16 deletions
+22
-16
BUILD
staging/src/k8s.io/apiserver/pkg/storage/etcd3/BUILD
+1
-0
store.go
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go
+11
-10
store_test.go
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go
+10
-6
No files found.
staging/src/k8s.io/apiserver/pkg/storage/etcd3/BUILD
View file @
ac8808b7
...
...
@@ -18,6 +18,7 @@ go_test(
"//vendor/github.com/coreos/etcd/clientv3:go_default_library",
"//vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes:go_default_library",
"//vendor/github.com/coreos/etcd/integration:go_default_library",
"//vendor/github.com/coreos/pkg/capnslog:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/testing:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go
View file @
ac8808b7
...
...
@@ -429,25 +429,26 @@ func decodeContinue(continueValue, keyPrefix string) (fromKey string, rv int64,
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: %v"
,
err
)
}
switch
c
.
APIVersion
{
case
"
v1alpha
1"
:
case
"
meta.k8s.io/v
1"
:
if
c
.
ResourceVersion
==
0
{
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: incorrect encoded start resourceVersion (version
v1alpha
1)"
)
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: incorrect encoded start resourceVersion (version
meta.k8s.io/v
1)"
)
}
if
len
(
c
.
StartKey
)
==
0
{
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: encoded start key empty (version
v1alpha
1)"
)
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: encoded start key empty (version
meta.k8s.io/v
1)"
)
}
// defend against path traversal attacks by clients - path.Clean will ensure that startKey cannot
// be at a higher level of the hierarchy, and so when we append the key prefix we will end up with
// continue start key that is fully qualified and cannot range over anything less specific than
// keyPrefix.
cleaned
:=
path
.
Clean
(
c
.
StartKey
)
if
cleaned
!=
c
.
StartKey
||
cleaned
==
"."
||
cleaned
==
"/"
{
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: %s"
,
cleaned
)
key
:=
c
.
StartKey
if
!
strings
.
HasPrefix
(
key
,
"/"
)
{
key
=
"/"
+
key
}
if
len
(
cleaned
)
==
0
{
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: encoded start key empty (version 0)"
)
cleaned
:=
path
.
Clean
(
key
)
if
cleaned
!=
key
{
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: %s"
,
c
.
StartKey
)
}
return
keyPrefix
+
cleaned
,
c
.
ResourceVersion
,
nil
return
keyPrefix
+
cleaned
[
1
:
]
,
c
.
ResourceVersion
,
nil
default
:
return
""
,
0
,
fmt
.
Errorf
(
"continue key is not valid: server does not recognize this encoded version %q"
,
c
.
APIVersion
)
}
...
...
@@ -459,7 +460,7 @@ func encodeContinue(key, keyPrefix string, resourceVersion int64) (string, error
if
nextKey
==
key
{
return
""
,
fmt
.
Errorf
(
"unable to encode next field: the key and key prefix do not match"
)
}
out
,
err
:=
json
.
Marshal
(
&
continueToken
{
APIVersion
:
"
v1alpha
1"
,
ResourceVersion
:
resourceVersion
,
StartKey
:
nextKey
})
out
,
err
:=
json
.
Marshal
(
&
continueToken
{
APIVersion
:
"
meta.k8s.io/v
1"
,
ResourceVersion
:
resourceVersion
,
StartKey
:
nextKey
})
if
err
!=
nil
{
return
""
,
err
}
...
...
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go
View file @
ac8808b7
...
...
@@ -29,7 +29,9 @@ import (
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/integration"
"github.com/coreos/pkg/capnslog"
"golang.org/x/net/context"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
apitesting
"k8s.io/apimachinery/pkg/api/testing"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -55,6 +57,8 @@ func init() {
metav1
.
AddToGroupVersion
(
scheme
,
metav1
.
SchemeGroupVersion
)
example
.
AddToScheme
(
scheme
)
examplev1
.
AddToScheme
(
scheme
)
capnslog
.
SetGlobalLogLevel
(
capnslog
.
CRITICAL
)
}
// prefixTransformer adds and verifies that all data has the correct prefix on its way in and out.
...
...
@@ -1205,16 +1209,16 @@ func Test_decodeContinue(t *testing.T) {
wantRv
int64
wantErr
bool
}{
{
name
:
"valid"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha1"
,
1
,
"key"
),
keyPrefix
:
"/test/"
},
wantRv
:
1
,
wantFromKey
:
"/test/key"
},
{
name
:
"valid"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"key"
),
keyPrefix
:
"/test/"
},
wantRv
:
1
,
wantFromKey
:
"/test/key"
},
{
name
:
"root path"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"/"
),
keyPrefix
:
"/test/"
},
wantRv
:
1
,
wantFromKey
:
"/test/"
},
{
name
:
"empty version"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
""
,
1
,
"key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"invalid version"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1"
,
1
,
"key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha"
,
1
,
"../key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - local"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha"
,
1
,
"./key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - double parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha"
,
1
,
"./../key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - after parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha"
,
1
,
"key/../.."
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - separator"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"v1alpha"
,
1
,
"/"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"../key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - local"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"./key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - double parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"./../key"
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
{
name
:
"path traversal - after parent"
,
args
:
args
{
continueValue
:
encodeContinueOrDie
(
"meta.k8s.io/v1"
,
1
,
"key/../.."
),
keyPrefix
:
"/test/"
},
wantErr
:
true
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
...
...
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