Skip to content

Commit

Permalink
Auth: add TLS client auth support (kubernetes#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus committed Sep 8, 2020
1 parent 21a8b17 commit 3bcfcbf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/using-manila-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Mandatory secrets for _trustee authentication:_ `os-trustID`, `os-trusteeID`, `o

Optionally, a custom certificate may be sourced via `os-certAuthorityPath` (path to a PEM file inside the plugin container). By default, the usual TLS verification is performed. To override this behavior and accept insecure certificates, set `os-TLSInsecure` to `true` (defaults to `false`).

For a client TLS authentication use both `os-clientCertPath` and `os-clientKeyPath` (paths to TLS keypair PEM files inside the plugin container).

### Topology-aware dynamic provisioning

Topology-aware dynamic provisioning makes it possible to reliably provision and use shares that are _not_ equally accessible from all compute nodes due to storage topology constraints.
Expand Down
4 changes: 4 additions & 0 deletions docs/using-openstack-cloud-controller-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ The options in `Global` section are used for openstack-cloud-controller-manager
Required. Keystone service URL, e.g. http://128.110.154.166/identity
* `ca-file`
Optional. CA certificate bundle file for communication with Keystone service, this is required when using the https protocol in the Keystone service URL.
* `cert-file`
Optional. Client certificate path used for the client TLS authentication.
* `key-file`
Optional. Client private key path used for the client TLS authentication.
* `username`
Keystone user name. If you are using [Keystone application credential](https://docs.openstack.org/keystone/latest/user/application_credentials.html), this option is not required.
* `password`
Expand Down
27 changes: 22 additions & 5 deletions pkg/cloudprovider/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,26 @@ type OpenStack struct {
}

type AuthOpts struct {
AuthURL string `gcfg:"auth-url" mapstructure:"auth-url" name:"os-authURL" dependsOn:"os-password|os-trustID|os-applicationCredentialSecret"`
AuthURL string `gcfg:"auth-url" mapstructure:"auth-url" name:"os-authURL" dependsOn:"os-password|os-trustID|os-applicationCredentialSecret|os-clientCertPath"`
UserID string `gcfg:"user-id" mapstructure:"user-id" name:"os-userID" value:"optional" dependsOn:"os-password"`
Username string `name:"os-userName" value:"optional" dependsOn:"os-password"`
Password string `name:"os-password" value:"optional" dependsOn:"os-domainID|os-domainName,os-projectID|os-projectName,os-userID|os-userName"`
TenantID string `gcfg:"tenant-id" mapstructure:"project-id" name:"os-projectID" value:"optional" dependsOn:"os-password"`
TenantName string `gcfg:"tenant-name" mapstructure:"project-name" name:"os-projectName" value:"optional" dependsOn:"os-password"`
TenantID string `gcfg:"tenant-id" mapstructure:"project-id" name:"os-projectID" value:"optional" dependsOn:"os-password|os-clientCertPath"`
TenantName string `gcfg:"tenant-name" mapstructure:"project-name" name:"os-projectName" value:"optional" dependsOn:"os-password|os-clientCertPath"`
TrustID string `gcfg:"trust-id" mapstructure:"trust-id" name:"os-trustID" value:"optional"`
DomainID string `gcfg:"domain-id" mapstructure:"domain-id" name:"os-domainID" value:"optional" dependsOn:"os-password"`
DomainName string `gcfg:"domain-name" mapstructure:"domain-name" name:"os-domainName" value:"optional" dependsOn:"os-password"`
DomainID string `gcfg:"domain-id" mapstructure:"domain-id" name:"os-domainID" value:"optional" dependsOn:"os-password|os-clientCertPath"`
DomainName string `gcfg:"domain-name" mapstructure:"domain-name" name:"os-domainName" value:"optional" dependsOn:"os-password|os-clientCertPath"`
TenantDomainID string `gcfg:"tenant-domain-id" mapstructure:"project-domain-id" name:"os-projectDomainID" value:"optional"`
TenantDomainName string `gcfg:"tenant-domain-name" mapstructure:"project-domain-name" name:"os-projectDomainName" value:"optional"`
UserDomainID string `gcfg:"user-domain-id" mapstructure:"user-domain-id" name:"os-userDomainID" value:"optional"`
UserDomainName string `gcfg:"user-domain-name" mapstructure:"user-domain-name" name:"os-userDomainName" value:"optional"`
Region string `name:"os-region"`
CAFile string `gcfg:"ca-file" mapstructure:"ca-file" name:"os-certAuthorityPath" value:"optional"`

// TLS client auth
CertFile string `gcfg:"cert-file" mapstructure:"cert-file" name:"os-clientCertPath" value:"optional" dependsOn:"os-clientKeyPath"`
KeyFile string `gcfg:"key-file" mapstructure:"key-file" name:"os-clientKeyPath" value:"optional" dependsOn:"os-clientCertPath"`

// Manila only options
TLSInsecure string `name:"os-TLSInsecure" value:"optional" matches:"^true|false$"`
// backward compatibility with the manila-csi-plugin
Expand Down Expand Up @@ -245,6 +249,8 @@ func LogCfg(cfg Config) {
klog.V(5).Infof("UserDomainName: %s", cfg.Global.UserDomainName)
klog.V(5).Infof("Region: %s", cfg.Global.Region)
klog.V(5).Infof("CAFile: %s", cfg.Global.CAFile)
klog.V(5).Infof("CertFile: %s", cfg.Global.CertFile)
klog.V(5).Infof("KeyFile: %s", cfg.Global.KeyFile)
klog.V(5).Infof("UseClouds: %t", cfg.Global.UseClouds)
klog.V(5).Infof("CloudsFile: %s", cfg.Global.CloudsFile)
klog.V(5).Infof("Cloud: %s", cfg.Global.Cloud)
Expand Down Expand Up @@ -442,6 +448,8 @@ func ReadClouds(cfg *Config) error {
cfg.Global.UserDomainName = replaceEmpty(cfg.Global.UserDomainName, cloud.AuthInfo.UserDomainName)
cfg.Global.Region = replaceEmpty(cfg.Global.Region, cloud.RegionName)
cfg.Global.CAFile = replaceEmpty(cfg.Global.CAFile, cloud.CACertFile)
cfg.Global.CertFile = replaceEmpty(cfg.Global.CertFile, cloud.ClientCertFile)
cfg.Global.KeyFile = replaceEmpty(cfg.Global.KeyFile, cloud.ClientKeyFile)
cfg.Global.ApplicationCredentialID = replaceEmpty(cfg.Global.ApplicationCredentialID, cloud.AuthInfo.ApplicationCredentialID)
cfg.Global.ApplicationCredentialName = replaceEmpty(cfg.Global.ApplicationCredentialName, cloud.AuthInfo.ApplicationCredentialName)
cfg.Global.ApplicationCredentialSecret = replaceEmpty(cfg.Global.ApplicationCredentialSecret, cloud.AuthInfo.ApplicationCredentialSecret)
Expand Down Expand Up @@ -526,6 +534,15 @@ func NewOpenStackClient(cfg *AuthOpts, userAgent string, extraUserAgent ...strin
config.RootCAs = caPool
}

// configure TLS client auth
if cfg.CertFile != "" && cfg.KeyFile != "" {
cert, err := tls.LoadX509KeyPair(cfg.CertFile, cfg.KeyFile)
if err != nil {
return nil, fmt.Errorf("error loading TLS key pair: %s", err)
}
config.Certificates = []tls.Certificate{cert}
}

provider.HTTPClient.Transport = netutil.SetOldTransportDefaults(&http.Transport{TLSClientConfig: config})

if klog.V(6).Enabled() {
Expand Down

0 comments on commit 3bcfcbf

Please sign in to comment.