Skip to content

Commit cab8e1f

Browse files
boilerldez
andauthored
regru: client certificate support (#2050)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent d51b5e4 commit cab8e1f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,8 @@ func displayDNSHelp(w io.Writer, name string) error {
21842184
ew.writeln(` - "REGRU_HTTP_TIMEOUT": API request timeout`)
21852185
ew.writeln(` - "REGRU_POLLING_INTERVAL": Time between DNS propagation check`)
21862186
ew.writeln(` - "REGRU_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
2187+
ew.writeln(` - "REGRU_TLS_CERT": authentication certificate`)
2188+
ew.writeln(` - "REGRU_TLS_KEY": authentication private key`)
21872189
ew.writeln(` - "REGRU_TTL": The TTL of the TXT record used for the DNS challenge`)
21882190

21892191
ew.writeln()

docs/content/dns/zz_gen_regru.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
5252
| `REGRU_HTTP_TIMEOUT` | API request timeout |
5353
| `REGRU_POLLING_INTERVAL` | Time between DNS propagation check |
5454
| `REGRU_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
55+
| `REGRU_TLS_CERT` | authentication certificate |
56+
| `REGRU_TLS_KEY` | authentication private key |
5557
| `REGRU_TTL` | The TTL of the TXT record used for the DNS challenge |
5658

5759
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.

providers/dns/regru/regru.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package regru
33

44
import (
55
"context"
6+
"crypto/tls"
67
"errors"
78
"fmt"
89
"net/http"
@@ -19,6 +20,8 @@ const (
1920

2021
EnvUsername = envNamespace + "USERNAME"
2122
EnvPassword = envNamespace + "PASSWORD"
23+
EnvTLSCert = envNamespace + "TLS_CERT"
24+
EnvTLSKey = envNamespace + "TLS_KEY"
2225

2326
EnvTTL = envNamespace + "TTL"
2427
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
@@ -30,6 +33,8 @@ const (
3033
type Config struct {
3134
Username string
3235
Password string
36+
TLSCert string
37+
TLSKey string
3338

3439
PropagationTimeout time.Duration
3540
PollingInterval time.Duration
@@ -67,6 +72,8 @@ func NewDNSProvider() (*DNSProvider, error) {
6772
config := NewDefaultConfig()
6873
config.Username = values[EnvUsername]
6974
config.Password = values[EnvPassword]
75+
config.TLSCert = env.GetOrDefaultString(EnvTLSCert, "")
76+
config.TLSKey = env.GetOrDefaultString(EnvTLSKey, "")
7077

7178
return NewDNSProviderConfig(config)
7279
}
@@ -87,6 +94,27 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
8794
client.HTTPClient = config.HTTPClient
8895
}
8996

97+
if config.TLSCert != "" || config.TLSKey != "" {
98+
if config.TLSCert == "" {
99+
return nil, errors.New("regru: TLS certificate is missing")
100+
}
101+
102+
if config.TLSKey == "" {
103+
return nil, errors.New("regru: TLS key is missing")
104+
}
105+
106+
tlsCert, err := tls.X509KeyPair([]byte(config.TLSCert), []byte(config.TLSKey))
107+
if err != nil {
108+
return nil, fmt.Errorf("regru: %w", err)
109+
}
110+
111+
client.HTTPClient.Transport = &http.Transport{
112+
TLSClientConfig: &tls.Config{
113+
Certificates: []tls.Certificate{tlsCert},
114+
},
115+
}
116+
}
117+
90118
return &DNSProvider{config: config, client: client}, nil
91119
}
92120

providers/dns/regru/regru.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ lego --email [email protected] --dns regru --domains my.example.org run
1515
REGRU_USERNAME = "API username"
1616
REGRU_PASSWORD = "API password"
1717
[Configuration.Additional]
18+
REGRU_TLS_CERT = "authentication certificate"
19+
REGRU_TLS_KEY = "authentication private key"
1820
REGRU_POLLING_INTERVAL = "Time between DNS propagation check"
1921
REGRU_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
2022
REGRU_TTL = "The TTL of the TXT record used for the DNS challenge"

0 commit comments

Comments
 (0)