Skip to content

Commit

Permalink
Populate system cert pool if root cert not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mabojars committed Aug 2, 2024
1 parent 5c0d4f3 commit 2d35126
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cloud/scope/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scope

import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -61,8 +63,23 @@ func CreateLinodeClient(config ClientConfig, opts ...Option) (LinodeClient, erro
timeout = config.Timeout
}

// Use system cert pool if root CA cert was not provided explicitly for this client.
// Works around linodego not using system certs if LINODE_CA is provided,
// which affects all clients spawned via linodego.NewClient
tlsConfig := &tls.Config{MinVersion: tls.VersionTLS12}
if config.RootCertificatePath == "" {
systemCertPool, err := x509.SystemCertPool()
if err != nil {
return nil, err

Check warning on line 73 in cloud/scope/common.go

View check run for this annotation

Codecov / codecov/patch

cloud/scope/common.go#L73

Added line #L73 was not covered by tests
}
tlsConfig.RootCAs = systemCertPool
}

httpClient := &http.Client{
Timeout: timeout,
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
}

newClient := linodego.NewClient(httpClient)
Expand Down

0 comments on commit 2d35126

Please sign in to comment.