mirror of
https://github.com/kubernetes/client-go.git
synced 2026-06-16 23:05:32 +00:00
Compare commits
1 Commits
kubernetes
...
kubernetes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0722d92a7 |
58
Godeps/Godeps.json
generated
58
Godeps/Godeps.json
generated
@@ -256,119 +256,119 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/admissionregistration/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/admissionregistration/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/apps/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/apps/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/apps/v1beta2",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/authentication/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/authentication/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/authorization/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/authorization/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/autoscaling/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/autoscaling/v2beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/batch/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/batch/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/batch/v2alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/certificates/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/core/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/events/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/extensions/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/imagepolicy/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/networking/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/policy/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/rbac/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/rbac/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/rbac/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/scheduling/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/settings/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/storage/v1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/storage/v1alpha1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api/storage/v1beta1",
|
||||
"Rev": "12444147eb1150aa5c80d2aae532cbc5b7be73d0"
|
||||
"Rev": "6c0bbc3e58fab96285be9b6ed41b12b58c737a96"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
|
||||
|
||||
@@ -98,20 +98,18 @@ func NewRESTMapper(groupResources []*APIGroupResources, versionInterfaces meta.V
|
||||
scope = meta.RESTScopeRoot
|
||||
}
|
||||
|
||||
// if we have a slash, then this is a subresource and we shouldn't create mappings for those.
|
||||
if strings.Contains(resource.Name, "/") {
|
||||
// this is for legacy resources and servers which don't list singular forms. For those we must still guess.
|
||||
if len(resource.SingularName) == 0 {
|
||||
versionMapper.Add(gv.WithKind(resource.Kind), scope)
|
||||
// TODO this is producing unsafe guesses that don't actually work, but it matches previous behavior
|
||||
versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope)
|
||||
continue
|
||||
}
|
||||
|
||||
plural := gv.WithResource(resource.Name)
|
||||
singular := gv.WithResource(resource.SingularName)
|
||||
// this is for legacy resources and servers which don't list singular forms. For those we must still guess.
|
||||
if len(resource.SingularName) == 0 {
|
||||
_, singular = meta.UnsafeGuessKindToResource(gv.WithKind(resource.Kind))
|
||||
}
|
||||
|
||||
versionMapper.AddSpecific(gv.WithKind(strings.ToLower(resource.Kind)), plural, singular, scope)
|
||||
versionMapper.AddSpecific(gv.WithKind(resource.Kind), plural, singular, scope)
|
||||
versionMapper.AddSpecific(gv.WithKind(strings.ToLower(resource.Kind)), plural, singular, scope)
|
||||
// TODO this is producing unsafe guesses that don't actually work, but it matches previous behavior
|
||||
versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package transport
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -130,7 +129,7 @@ func SetAuthProxyHeaders(req *http.Request, username string, groups []string, ex
|
||||
}
|
||||
for key, values := range extra {
|
||||
for _, value := range values {
|
||||
req.Header.Add("X-Remote-Extra-"+headerKeyEscape(key), value)
|
||||
req.Header.Add("X-Remote-Extra-"+key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +246,7 @@ func (rt *impersonatingRoundTripper) RoundTrip(req *http.Request) (*http.Respons
|
||||
}
|
||||
for k, vv := range rt.impersonate.Extra {
|
||||
for _, v := range vv {
|
||||
req.Header.Add(ImpersonateUserExtraHeaderPrefix+headerKeyEscape(k), v)
|
||||
req.Header.Add(ImpersonateUserExtraHeaderPrefix+k, v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,110 +422,3 @@ func (rt *debuggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
|
||||
func (rt *debuggingRoundTripper) WrappedRoundTripper() http.RoundTripper {
|
||||
return rt.delegatedRoundTripper
|
||||
}
|
||||
|
||||
func legalHeaderByte(b byte) bool {
|
||||
return int(b) < len(legalHeaderKeyBytes) && legalHeaderKeyBytes[b]
|
||||
}
|
||||
|
||||
func shouldEscape(b byte) bool {
|
||||
// url.PathUnescape() returns an error if any '%' is not followed by two
|
||||
// hexadecimal digits, so we'll intentionally encode it.
|
||||
return !legalHeaderByte(b) || b == '%'
|
||||
}
|
||||
|
||||
func headerKeyEscape(key string) string {
|
||||
var buf bytes.Buffer
|
||||
for i := 0; i < len(key); i++ {
|
||||
b := key[i]
|
||||
if shouldEscape(b) {
|
||||
// %-encode bytes that should be escaped:
|
||||
// https://tools.ietf.org/html/rfc3986#section-2.1
|
||||
fmt.Fprintf(&buf, "%%%02X", b)
|
||||
continue
|
||||
}
|
||||
buf.WriteByte(b)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// legalHeaderKeyBytes was copied from net/http/lex.go's isTokenTable.
|
||||
// See https://httpwg.github.io/specs/rfc7230.html#rule.token.separators
|
||||
var legalHeaderKeyBytes = [127]bool{
|
||||
'%': true,
|
||||
'!': true,
|
||||
'#': true,
|
||||
'$': true,
|
||||
'&': true,
|
||||
'\'': true,
|
||||
'*': true,
|
||||
'+': true,
|
||||
'-': true,
|
||||
'.': true,
|
||||
'0': true,
|
||||
'1': true,
|
||||
'2': true,
|
||||
'3': true,
|
||||
'4': true,
|
||||
'5': true,
|
||||
'6': true,
|
||||
'7': true,
|
||||
'8': true,
|
||||
'9': true,
|
||||
'A': true,
|
||||
'B': true,
|
||||
'C': true,
|
||||
'D': true,
|
||||
'E': true,
|
||||
'F': true,
|
||||
'G': true,
|
||||
'H': true,
|
||||
'I': true,
|
||||
'J': true,
|
||||
'K': true,
|
||||
'L': true,
|
||||
'M': true,
|
||||
'N': true,
|
||||
'O': true,
|
||||
'P': true,
|
||||
'Q': true,
|
||||
'R': true,
|
||||
'S': true,
|
||||
'T': true,
|
||||
'U': true,
|
||||
'W': true,
|
||||
'V': true,
|
||||
'X': true,
|
||||
'Y': true,
|
||||
'Z': true,
|
||||
'^': true,
|
||||
'_': true,
|
||||
'`': true,
|
||||
'a': true,
|
||||
'b': true,
|
||||
'c': true,
|
||||
'd': true,
|
||||
'e': true,
|
||||
'f': true,
|
||||
'g': true,
|
||||
'h': true,
|
||||
'i': true,
|
||||
'j': true,
|
||||
'k': true,
|
||||
'l': true,
|
||||
'm': true,
|
||||
'n': true,
|
||||
'o': true,
|
||||
'p': true,
|
||||
'q': true,
|
||||
'r': true,
|
||||
's': true,
|
||||
't': true,
|
||||
'u': true,
|
||||
'v': true,
|
||||
'w': true,
|
||||
'x': true,
|
||||
'y': true,
|
||||
'z': true,
|
||||
'|': true,
|
||||
'~': true,
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package transport
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -126,32 +125,6 @@ func TestImpersonationRoundTripper(t *testing.T) {
|
||||
ImpersonateUserExtraHeaderPrefix + "Second": {"B", "b"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "escape handling",
|
||||
impersonationConfig: ImpersonationConfig{
|
||||
UserName: "user",
|
||||
Extra: map[string][]string{
|
||||
"test.example.com/thing.thing": {"A", "a"},
|
||||
},
|
||||
},
|
||||
expected: map[string][]string{
|
||||
ImpersonateUserHeader: {"user"},
|
||||
ImpersonateUserExtraHeaderPrefix + `Test.example.com%2fthing.thing`: {"A", "a"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "double escape handling",
|
||||
impersonationConfig: ImpersonationConfig{
|
||||
UserName: "user",
|
||||
Extra: map[string][]string{
|
||||
"test.example.com/thing.thing%20another.thing": {"A", "a"},
|
||||
},
|
||||
},
|
||||
expected: map[string][]string{
|
||||
ImpersonateUserHeader: {"user"},
|
||||
ImpersonateUserExtraHeaderPrefix + `Test.example.com%2fthing.thing%2520another.thing`: {"A", "a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
@@ -186,10 +159,9 @@ func TestImpersonationRoundTripper(t *testing.T) {
|
||||
|
||||
func TestAuthProxyRoundTripper(t *testing.T) {
|
||||
for n, tc := range map[string]struct {
|
||||
username string
|
||||
groups []string
|
||||
extra map[string][]string
|
||||
expectedExtra map[string][]string
|
||||
username string
|
||||
groups []string
|
||||
extra map[string][]string
|
||||
}{
|
||||
"allfields": {
|
||||
username: "user",
|
||||
@@ -198,34 +170,6 @@ func TestAuthProxyRoundTripper(t *testing.T) {
|
||||
"one": {"alpha", "bravo"},
|
||||
"two": {"charlie", "delta"},
|
||||
},
|
||||
expectedExtra: map[string][]string{
|
||||
"one": {"alpha", "bravo"},
|
||||
"two": {"charlie", "delta"},
|
||||
},
|
||||
},
|
||||
"escaped extra": {
|
||||
username: "user",
|
||||
groups: []string{"groupA", "groupB"},
|
||||
extra: map[string][]string{
|
||||
"one": {"alpha", "bravo"},
|
||||
"example.com/two": {"charlie", "delta"},
|
||||
},
|
||||
expectedExtra: map[string][]string{
|
||||
"one": {"alpha", "bravo"},
|
||||
"example.com%2ftwo": {"charlie", "delta"},
|
||||
},
|
||||
},
|
||||
"double escaped extra": {
|
||||
username: "user",
|
||||
groups: []string{"groupA", "groupB"},
|
||||
extra: map[string][]string{
|
||||
"one": {"alpha", "bravo"},
|
||||
"example.com/two%20three": {"charlie", "delta"},
|
||||
},
|
||||
expectedExtra: map[string][]string{
|
||||
"one": {"alpha", "bravo"},
|
||||
"example.com%2ftwo%2520three": {"charlie", "delta"},
|
||||
},
|
||||
},
|
||||
} {
|
||||
rt := &testRoundTripper{}
|
||||
@@ -266,64 +210,9 @@ func TestAuthProxyRoundTripper(t *testing.T) {
|
||||
actualExtra[extraKey] = append(actualExtra[key], values...)
|
||||
}
|
||||
}
|
||||
if e, a := tc.expectedExtra, actualExtra; !reflect.DeepEqual(e, a) {
|
||||
if e, a := tc.extra, actualExtra; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%s expected %v, got %v", n, e, a)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestHeaderEscapeRoundTrip tests to see if foo == url.PathUnescape(headerEscape(foo))
|
||||
// This behavior is important for client -> API server transmission of extra values.
|
||||
func TestHeaderEscapeRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := []struct {
|
||||
name string
|
||||
key string
|
||||
}{
|
||||
{
|
||||
name: "alpha",
|
||||
key: "alphabetical",
|
||||
},
|
||||
{
|
||||
name: "alphanumeric",
|
||||
key: "alph4num3r1c",
|
||||
},
|
||||
{
|
||||
name: "percent encoded",
|
||||
key: "percent%20encoded",
|
||||
},
|
||||
{
|
||||
name: "almost percent encoded",
|
||||
key: "almost%zzpercent%xxencoded",
|
||||
},
|
||||
{
|
||||
name: "illegal char & percent encoding",
|
||||
key: "example.com/percent%20encoded",
|
||||
},
|
||||
{
|
||||
name: "weird unicode stuff",
|
||||
key: "example.com/ᛒᚥᛏᛖᚥᚢとロビン",
|
||||
},
|
||||
{
|
||||
name: "header legal chars",
|
||||
key: "abc123!#$+.-_*\\^`~|'",
|
||||
},
|
||||
{
|
||||
name: "legal path, illegal header",
|
||||
key: "@=:",
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
escaped := headerKeyEscape(tc.key)
|
||||
unescaped, err := url.PathUnescape(escaped)
|
||||
if err != nil {
|
||||
t.Fatalf("url.PathUnescape(%q) returned error: %v", escaped, err)
|
||||
}
|
||||
if tc.key != unescaped {
|
||||
t.Errorf("url.PathUnescape(headerKeyEscape(%q)) returned %q, wanted %q", tc.key, unescaped, tc.key)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user