From 87498e02098529108619590ec0eb0d54665e0436 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 1 Aug 2016 11:10:18 -0700 Subject: [PATCH] v2http: use guest access in non-TLS mode Fix https://github.com/coreos/etcd/issues/6075. --- etcdserver/api/v2http/client_auth.go | 7 +++--- etcdserver/api/v2http/client_auth_test.go | 30 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/etcdserver/api/v2http/client_auth.go b/etcdserver/api/v2http/client_auth.go index 2b3278528..606e2e00b 100644 --- a/etcdserver/api/v2http/client_auth.go +++ b/etcdserver/api/v2http/client_auth.go @@ -116,10 +116,11 @@ func hasKeyPrefixAccess(sec auth.Store, r *http.Request, key string, recursive, } var user *auth.User - if r.Header.Get("Authorization") == "" && clientCertAuthEnabled { - user = userFromClientCertificate(sec, r) + if r.Header.Get("Authorization") == "" { + if clientCertAuthEnabled { + user = userFromClientCertificate(sec, r) + } if user == nil { - plog.Warningf("auth: no authorization provided, checking guest access") return hasGuestAccess(sec, r, key) } } else { diff --git a/etcdserver/api/v2http/client_auth_test.go b/etcdserver/api/v2http/client_auth_test.go index b5e32c487..261ce1689 100644 --- a/etcdserver/api/v2http/client_auth_test.go +++ b/etcdserver/api/v2http/client_auth_test.go @@ -717,6 +717,36 @@ func TestPrefixAccess(t *testing.T) { hasKeyPrefixAccess: false, hasRecursiveAccess: false, }, + { // guest access in non-TLS mode + key: "/foo", + req: (func() *http.Request { + return mustJSONRequest(t, "GET", "somepath", "") + })(), + store: &mockAuthStore{ + enabled: true, + users: map[string]*auth.User{ + "root": { + User: "root", + Password: goodPassword, + Roles: []string{"root"}, + }, + }, + roles: map[string]*auth.Role{ + "guest": { + Role: "guest", + Permissions: auth.Permissions{ + KV: auth.RWPermission{ + Read: []string{"/foo*"}, + Write: []string{"/foo*"}, + }, + }, + }, + }, + }, + hasRoot: false, + hasKeyPrefixAccess: true, + hasRecursiveAccess: true, + }, } for i, tt := range table {