Skip to content

Commit a41ea23

Browse files
authored
Merge pull request #4870 from cs3org/fix/eoshttpclient-tls
Omit loading X509 key pair in EOS HTTP Client if the scheme is not https
2 parents 122da0b + 6c73add commit a41ea23

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Enhancement: Only load X509 on https
2+
3+
Currently, the EOS HTTP Client always tries to read an X509 key pair from the file system (by default, from /etc/grid-security/host{key,cert}.pem). This makes it harder to write unit tests, as these fail when this key pair is not on the file system (which is the case for the test pipeline as well).
4+
5+
This PR introduces a fix for this problem, by only loading the X509 key pair if the scheme of the EOS endpoint is https. Unit tests can then create a mock HTTP endpoint, which will not trigger the loading of the key pair.
6+
7+
8+
https://github.com/cs3org/reva/pull/4870

pkg/eosclient/eosgrpc/eoshttp.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"bytes"
2323
"context"
2424
"crypto/tls"
25+
"errors"
2526
"fmt"
2627
"io"
2728
"net/http"
@@ -147,26 +148,34 @@ func NewEOSHTTPClient(opt *HTTPOptions) (*EOSHTTPClient, error) {
147148
}
148149

149150
opt.init()
150-
cert, err := tls.LoadX509KeyPair(opt.ClientCertFile, opt.ClientKeyFile)
151+
baseUrl, err := url.Parse(opt.BaseURL)
151152
if err != nil {
152-
return nil, err
153+
return nil, errors.New("Failed to parse BaseURL")
153154
}
154155

155-
// TODO: the error reporting of http.transport is insufficient
156-
// we may want to check manually at least the existence of the certfiles
157-
// The point is that also the error reporting of the context that calls this function
158-
// is weak
159156
t := &http.Transport{
160-
TLSClientConfig: &tls.Config{
161-
Certificates: []tls.Certificate{cert},
162-
},
163157
MaxIdleConns: opt.MaxIdleConns,
164158
MaxConnsPerHost: opt.MaxConnsPerHost,
165159
MaxIdleConnsPerHost: opt.MaxIdleConnsPerHost,
166160
IdleConnTimeout: time.Duration(opt.IdleConnTimeout) * time.Second,
167161
DisableCompression: true,
168162
}
169163

164+
if baseUrl.Scheme == "https" {
165+
cert, err := tls.LoadX509KeyPair(opt.ClientCertFile, opt.ClientKeyFile)
166+
if err != nil {
167+
return nil, err
168+
}
169+
t.TLSClientConfig = &tls.Config{
170+
Certificates: []tls.Certificate{cert},
171+
}
172+
}
173+
174+
// TODO: the error reporting of http.transport is insufficient
175+
// we may want to check manually at least the existence of the certfiles
176+
// The point is that also the error reporting of the context that calls this function
177+
// is weak
178+
170179
cl := &http.Client{
171180
Transport: t,
172181
CheckRedirect: func(req *http.Request, via []*http.Request) error {

0 commit comments

Comments
 (0)