Skip to content

Commit 91b29fb

Browse files
committed
Add support for TLS client auth
1 parent 38bf061 commit 91b29fb

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
110110
The first paragraph contains the authentication parameters for
111111
OpenStack's Identity v3 API. Optionally a `region_name` can be specified, but this is only
112-
required if there are multiple regions to choose from.
112+
required if there are multiple regions to choose from. You can also specify the `tls_client_certificate_path` and `tls_client_key_path` for creating a TLS client.
113113

114114
You can use the `fromEnv` special syntax for the `to.container`, `to.object_prefix`, and
115115
the Swift fields (options under the `swift` key).

pkg/objects/swift.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package objects
2121

2222
import (
23+
"crypto/tls"
2324
"fmt"
2425
"io"
2526
"net/http"
@@ -48,6 +49,8 @@ type SwiftLocation struct {
4849
ApplicationCredentialID secrets.FromEnv `yaml:"application_credential_id"`
4950
ApplicationCredentialName secrets.FromEnv `yaml:"application_credential_name"`
5051
ApplicationCredentialSecret secrets.FromEnv `yaml:"application_credential_secret"`
52+
TLSClientCertificatePath secrets.FromEnv `yaml:"tls_client_certificate_path"`
53+
TLSClientKeyPath secrets.FromEnv `yaml:"tls_client_key_path"`
5154
RegionName secrets.FromEnv `yaml:"region_name"`
5255
ContainerName secrets.FromEnv `yaml:"container"`
5356
ObjectNamePrefix secrets.FromEnv `yaml:"object_prefix"`
@@ -88,6 +91,15 @@ func (s *SwiftLocation) Validate(name string) []error {
8891
result = append(result, fmt.Errorf("missing value for %s.auth_url", name))
8992
}
9093

94+
if s.TLSClientCertificatePath != "" || s.TLSClientKeyPath != "" {
95+
if s.TLSClientCertificatePath == "" {
96+
result = append(result, fmt.Errorf("missing value for %s.tls_client_certificate_path", name))
97+
}
98+
if s.TLSClientKeyPath == "" {
99+
result = append(result, fmt.Errorf("missing value for %s.tls_client_key_path", name))
100+
}
101+
}
102+
91103
if s.ApplicationCredentialID != "" || s.ApplicationCredentialName != "" {
92104
//checking application credential requirements
93105
if s.ApplicationCredentialID == "" {
@@ -173,9 +185,22 @@ func (s *SwiftLocation) Connect(name string) error {
173185
return fmt.Errorf("cannot create OpenStack client: %s", err.Error())
174186
}
175187

188+
transport := &http.Transport{}
189+
if s.TLSClientCertificatePath != "" && s.TLSClientKeyPath != "" {
190+
cert, err := tls.LoadX509KeyPair(string(s.TLSClientCertificatePath), string(s.TLSClientKeyPath))
191+
if err != nil {
192+
return fmt.Errorf("failed to load x509 key pair: %s", err.Error())
193+
}
194+
transport.TLSClientConfig = &tls.Config{
195+
Certificates: []tls.Certificate{cert},
196+
MinVersion: tls.VersionTLS12,
197+
}
198+
provider.HTTPClient.Transport = transport
199+
}
200+
176201
if logg.ShowDebug {
177202
provider.HTTPClient.Transport = &client.RoundTripper{
178-
Rt: http.DefaultTransport,
203+
Rt: transport,
179204
Logger: &logger{Prefix: name},
180205
}
181206
}

0 commit comments

Comments
 (0)