Skip to content

Commit

Permalink
Merge pull request etcd-io#17066 from ivanvc/disable-forwarding-redir…
Browse files Browse the repository at this point in the history
…ects-for-peer-http-connection

server: disable redirects in peer communication
  • Loading branch information
ahrtr authored Dec 5, 2023
2 parents b89a451 + 8578e07 commit d8f0771
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 12 additions & 1 deletion server/etcdserver/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func getClusterFromRemotePeers(lg *zap.Logger, urls []string, timeout time.Durat
cc := &http.Client{
Transport: rt,
Timeout: timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
for _, u := range urls {
addr := u + "/members"
Expand Down Expand Up @@ -289,7 +292,12 @@ func getVersion(lg *zap.Logger, m *membership.Member, rt http.RoundTripper, time
}

func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.RoundTripper) ([]*membership.Member, error) {
cc := &http.Client{Transport: peerRt}
cc := &http.Client{
Transport: peerRt,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
// TODO: refactor member http handler code
// cannot import etcdhttp, so manually construct url
requestUrl := url + "/members/promote/" + fmt.Sprintf("%d", id)
Expand Down Expand Up @@ -362,6 +370,9 @@ func getDowngradeEnabled(lg *zap.Logger, m *membership.Member, rt http.RoundTrip
cc := &http.Client{
Transport: rt,
Timeout: timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
var (
err error
Expand Down
7 changes: 6 additions & 1 deletion server/etcdserver/corrupt.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ func (s *EtcdServer) getPeerHashKVs(rev int64) []*peerHashKVResp {

lg := s.Logger()

cc := &http.Client{Transport: s.peerRt}
cc := &http.Client{
Transport: s.peerRt,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
var resps []*peerHashKVResp
for _, p := range peers {
if len(p.eps) == 0 {
Expand Down
14 changes: 12 additions & 2 deletions server/lease/leasehttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundT
return -1, err
}

cc := &http.Client{Transport: rt}
cc := &http.Client{
Transport: rt,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(lreq))
if err != nil {
return -1, err
Expand Down Expand Up @@ -210,7 +215,12 @@ func TimeToLiveHTTP(ctx context.Context, id lease.LeaseID, keys bool, url string

req = req.WithContext(ctx)

cc := &http.Client{Transport: rt}
cc := &http.Client{
Transport: rt,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
var b []byte
// buffer errc channel so that errc don't block inside the go routinue
resp, err := cc.Do(req)
Expand Down

0 comments on commit d8f0771

Please sign in to comment.