mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
v2http: set 'ClientCertAuthEnabled' in client.go
This commit is contained in:
parent
68ece954fb
commit
25aeeb35c3
@ -65,11 +65,12 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
|
|||||||
sec := auth.NewStore(server, timeout)
|
sec := auth.NewStore(server, timeout)
|
||||||
|
|
||||||
kh := &keysHandler{
|
kh := &keysHandler{
|
||||||
sec: sec,
|
sec: sec,
|
||||||
server: server,
|
server: server,
|
||||||
cluster: server.Cluster(),
|
cluster: server.Cluster(),
|
||||||
timer: server,
|
timer: server,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
|
clientCertAuthEnabled: server.Cfg.ClientCertAuthEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
sh := &statsHandler{
|
sh := &statsHandler{
|
||||||
@ -82,6 +83,7 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
|
|||||||
cluster: server.Cluster(),
|
cluster: server.Cluster(),
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
clock: clockwork.NewRealClock(),
|
clock: clockwork.NewRealClock(),
|
||||||
|
clientCertAuthEnabled: server.Cfg.ClientCertAuthEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
dmh := &deprecatedMachinesHandler{
|
dmh := &deprecatedMachinesHandler{
|
||||||
@ -89,8 +91,9 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
|
|||||||
}
|
}
|
||||||
|
|
||||||
sech := &authHandler{
|
sech := &authHandler{
|
||||||
sec: sec,
|
sec: sec,
|
||||||
cluster: server.Cluster(),
|
cluster: server.Cluster(),
|
||||||
|
clientCertAuthEnabled: server.Cfg.ClientCertAuthEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
@ -132,11 +135,12 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
|
|||||||
}
|
}
|
||||||
|
|
||||||
type keysHandler struct {
|
type keysHandler struct {
|
||||||
sec auth.Store
|
sec auth.Store
|
||||||
server etcdserver.Server
|
server etcdserver.Server
|
||||||
cluster api.Cluster
|
cluster api.Cluster
|
||||||
timer etcdserver.RaftTimer
|
timer etcdserver.RaftTimer
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
clientCertAuthEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -156,7 +160,7 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// The path must be valid at this point (we've parsed the request successfully).
|
// The path must be valid at this point (we've parsed the request successfully).
|
||||||
if !hasKeyPrefixAccess(h.sec, r, r.URL.Path[len(keysPrefix):], rr.Recursive) {
|
if !hasKeyPrefixAccess(h.sec, r, r.URL.Path[len(keysPrefix):], rr.Recursive, h.clientCertAuthEnabled) {
|
||||||
writeKeyNoAuth(w)
|
writeKeyNoAuth(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -199,18 +203,19 @@ func (h *deprecatedMachinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|||||||
}
|
}
|
||||||
|
|
||||||
type membersHandler struct {
|
type membersHandler struct {
|
||||||
sec auth.Store
|
sec auth.Store
|
||||||
server etcdserver.Server
|
server etcdserver.Server
|
||||||
cluster api.Cluster
|
cluster api.Cluster
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
clock clockwork.Clock
|
clock clockwork.Clock
|
||||||
|
clientCertAuthEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if !allowMethod(w, r.Method, "GET", "POST", "DELETE", "PUT") {
|
if !allowMethod(w, r.Method, "GET", "POST", "DELETE", "PUT") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !hasWriteRootAccess(h.sec, r) {
|
if !hasWriteRootAccess(h.sec, r, h.clientCertAuthEnabled) {
|
||||||
writeNoAuth(w, r)
|
writeNoAuth(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user