Skip to content

Commit 45eade4

Browse files
authored
Merge pull request #14 from utilitywarehouse/ca-cert-err
Improve error handling in verifyConn
2 parents dbdcbee + c983a54 commit 45eade4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kube/client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kube
22

33
import (
4-
"errors"
54
"fmt"
65
"io"
76

@@ -16,8 +15,6 @@ import (
1615

1716
// in case of local kube config
1817
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
19-
20-
"github.com/utilitywarehouse/semaphore-wireguard/log"
2118
)
2219

2320
type certMan struct {
@@ -26,21 +23,24 @@ type certMan struct {
2623

2724
func (cm *certMan) verifyConn(cs tls.ConnectionState) error {
2825
resp, err := http.Get(cm.caURL)
26+
if err != nil {
27+
return fmt.Errorf("error getting remote CA from %s: %v", cm.caURL, err)
28+
}
2929
defer func() {
3030
io.Copy(ioutil.Discard, resp.Body)
3131
resp.Body.Close()
3232
}()
33-
if err != nil {
34-
log.Logger.Error(
35-
"error getting remote CA",
36-
"err", err)
37-
return err
33+
if resp.StatusCode != http.StatusOK {
34+
return fmt.Errorf("expected %d response from %s, got %d", http.StatusOK, cm.caURL, resp.StatusCode)
3835
}
3936
body, err := ioutil.ReadAll(resp.Body)
37+
if err != nil {
38+
return fmt.Errorf("error reading response body from %s: %v", cm.caURL, err)
39+
}
4040
roots := x509.NewCertPool()
4141
ok := roots.AppendCertsFromPEM(body)
4242
if !ok {
43-
return errors.New("failed to parse root certificate")
43+
return fmt.Errorf("failed to parse root certificate from %s", cm.caURL)
4444
}
4545
opts := x509.VerifyOptions{
4646
DNSName: cs.ServerName,

0 commit comments

Comments
 (0)