Skip to content

Commit

Permalink
Add custom CA file to openstack cloud provider config
Browse files Browse the repository at this point in the history
In cases where insecure OpenStack endpoint is to be used
(e.g., when testing), gophercloud will fail to connect
to such endpoints. This patch adds support for custom CA
file configuration option, which, when provided, will
make gophercloud validate OpenStack endpoint against
certificate(s) read from file specified in that option.
  • Loading branch information
Karol Stepniewski authored and kars7e committed Feb 13, 2017
1 parent 91a5856 commit 7b5f58f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cloudprovider/providers/openstack/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ go_library(
"//vendor:gopkg.in/gcfg.v1",
"//vendor:k8s.io/apimachinery/pkg/api/resource",
"//vendor:k8s.io/apimachinery/pkg/types",
"//vendor:k8s.io/apimachinery/pkg/util/net",
"//vendor:k8s.io/client-go/util/cert",
],
)

Expand Down
14 changes: 14 additions & 0 deletions pkg/cloudprovider/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package openstack

import (
"crypto/tls"
"errors"
"fmt"
"io"
Expand All @@ -37,6 +38,8 @@ import (

"github.com/golang/glog"
"k8s.io/apimachinery/pkg/types"
netutil "k8s.io/apimachinery/pkg/util/net"
certutil "k8s.io/client-go/util/cert"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/cloudprovider"
)
Expand Down Expand Up @@ -118,6 +121,7 @@ type Config struct {
DomainId string `gcfg:"domain-id"`
DomainName string `gcfg:"domain-name"`
Region string
CAFile string `gcfg:"ca-file"`
}
LoadBalancer LoadBalancerOpts
BlockStorage BlockStorageOpts
Expand Down Expand Up @@ -205,6 +209,16 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
if err != nil {
return nil, err
}
if cfg.Global.CAFile != "" {
roots, err := certutil.NewPool(cfg.Global.CAFile)
if err != nil {
return nil, err
}
config := &tls.Config{}
config.RootCAs = roots
provider.HTTPClient.Transport = netutil.SetOldTransportDefaults(&http.Transport{TLSClientConfig: config})

}
if cfg.Global.TrustId != "" {
authOptionsExt := trust.AuthOptionsExt{
TrustID: cfg.Global.TrustId,
Expand Down

0 comments on commit 7b5f58f

Please sign in to comment.