Skip to content

Commit 5acdf36

Browse files
committed
2 parents 64b8dcc + 81bb2ec commit 5acdf36

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Increase MaxIdleConnsPerHost in http.Transport
44
([GH-305])
5+
* Provide a way to specify client cert and key
6+
([GH-315])
57

68
## 2.7.0 (May 20, 2020)
79

gitlab/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type Config struct {
1616
BaseURL string
1717
Insecure bool
1818
CACertFile string
19+
ClientCert string
20+
ClientKey string
1921
}
2022

2123
// Client returns a *gitlab.Client to interact with the configured gitlab instance
@@ -40,6 +42,15 @@ func (c *Config) Client() (interface{}, error) {
4042
tlsConfig.InsecureSkipVerify = true
4143
}
4244

45+
// add client cert and key to connection
46+
if c.ClientCert != "" && c.ClientKey != "" {
47+
clientPair, err := tls.LoadX509KeyPair(c.ClientCert, c.ClientKey)
48+
if err != nil {
49+
return nil, err
50+
}
51+
tlsConfig.Certificates = []tls.Certificate{clientPair}
52+
}
53+
4354
t := http.DefaultTransport.(*http.Transport).Clone()
4455
t.TLSClientConfig = tlsConfig
4556
t.MaxIdleConnsPerHost = 100

gitlab/provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func Provider() terraform.ResourceProvider {
3939
Default: false,
4040
Description: descriptions["insecure"],
4141
},
42+
"client_cert": {
43+
Type: schema.TypeString,
44+
Optional: true,
45+
Default: "",
46+
Description: descriptions["client_cert"],
47+
},
48+
"client_key": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Default: "",
52+
Description: descriptions["client_key"],
53+
},
4254
},
4355

4456
DataSourcesMap: map[string]*schema.Resource{
@@ -90,6 +102,10 @@ func init() {
90102
"cacert_file": "A file containing the ca certificate to use in case ssl certificate is not from a standard chain",
91103

92104
"insecure": "Disable SSL verification of API calls",
105+
106+
"client_cert": "File path to client certificate when GitLab instance is behind company proxy. File must contain PEM encoded data.",
107+
108+
"client_key": "File path to client key when GitLab instance is behind company proxy. File must contain PEM encoded data.",
93109
}
94110
}
95111

@@ -99,6 +115,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
99115
BaseURL: d.Get("base_url").(string),
100116
CACertFile: d.Get("cacert_file").(string),
101117
Insecure: d.Get("insecure").(bool),
118+
ClientCert: d.Get("client_cert").(string),
119+
ClientKey: d.Get("client_key").(string),
102120
}
103121

104122
return config.Client()

website/docs/index.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ The following arguments are supported in the `provider` block:
7878

7979
* `insecure` - (Optional; boolean, defaults to false) When set to true this disables SSL verification of the connection to the
8080
GitLab instance.
81+
82+
* `client_cert` - (Optional) File path to client certificate when GitLab instance is behind company proxy. File must contain PEM encoded data.
83+
84+
* `client_key` - (Optional) File path to client key when GitLab instance is behind company proxy. File must contain PEM encoded data. Required when `client_cert` is set.

0 commit comments

Comments
 (0)