mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
v2http: use guest access in non-TLS mode
Fix https://github.com/coreos/etcd/issues/6075.
This commit is contained in:
parent
b722bedf8a
commit
a31283cf51
@ -116,10 +116,11 @@ func hasKeyPrefixAccess(sec auth.Store, r *http.Request, key string, recursive,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var user *auth.User
|
var user *auth.User
|
||||||
if r.Header.Get("Authorization") == "" && clientCertAuthEnabled {
|
if r.Header.Get("Authorization") == "" {
|
||||||
user = userFromClientCertificate(sec, r)
|
if clientCertAuthEnabled {
|
||||||
|
user = userFromClientCertificate(sec, r)
|
||||||
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
plog.Warningf("auth: no authorization provided, checking guest access")
|
|
||||||
return hasGuestAccess(sec, r, key)
|
return hasGuestAccess(sec, r, key)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -717,6 +717,36 @@ func TestPrefixAccess(t *testing.T) {
|
|||||||
hasKeyPrefixAccess: false,
|
hasKeyPrefixAccess: false,
|
||||||
hasRecursiveAccess: 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 {
|
for i, tt := range table {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user