Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit loading X509 key pair in EOS HTTP Client if the scheme is not https #4870

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/eos-http-client-tls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Only load X509 on https

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).

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.


https://github.com/cs3org/reva/pull/4870
27 changes: 18 additions & 9 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -147,26 +148,34 @@ func NewEOSHTTPClient(opt *HTTPOptions) (*EOSHTTPClient, error) {
}

opt.init()
cert, err := tls.LoadX509KeyPair(opt.ClientCertFile, opt.ClientKeyFile)
baseUrl, err := url.Parse(opt.BaseURL)
if err != nil {
return nil, err
return nil, errors.New("Failed to parse BaseURL")
}

// TODO: the error reporting of http.transport is insufficient
// we may want to check manually at least the existence of the certfiles
// The point is that also the error reporting of the context that calls this function
// is weak
t := &http.Transport{
TLSClientConfig: &tls.Config{
Certificates: []tls.Certificate{cert},
},
MaxIdleConns: opt.MaxIdleConns,
MaxConnsPerHost: opt.MaxConnsPerHost,
MaxIdleConnsPerHost: opt.MaxIdleConnsPerHost,
IdleConnTimeout: time.Duration(opt.IdleConnTimeout) * time.Second,
DisableCompression: true,
}

if baseUrl.Scheme == "https" {
cert, err := tls.LoadX509KeyPair(opt.ClientCertFile, opt.ClientKeyFile)
if err != nil {
return nil, err
}
t.TLSClientConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
}

// TODO: the error reporting of http.transport is insufficient
// we may want to check manually at least the existence of the certfiles
// The point is that also the error reporting of the context that calls this function
// is weak

cl := &http.Client{
Transport: t,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
Loading