Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regru: client certificate support #2050

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,8 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln(` - "REGRU_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "REGRU_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "REGRU_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "REGRU_TLS_CERT": authentication certificate`)
ew.writeln(` - "REGRU_TLS_KEY": authentication private key`)
ew.writeln(` - "REGRU_TTL": The TTL of the TXT record used for the DNS challenge`)

ew.writeln()
Expand Down
2 changes: 2 additions & 0 deletions docs/content/dns/zz_gen_regru.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
| `REGRU_HTTP_TIMEOUT` | API request timeout |
| `REGRU_POLLING_INTERVAL` | Time between DNS propagation check |
| `REGRU_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `REGRU_TLS_CERT` | authentication certificate |
| `REGRU_TLS_KEY` | authentication private key |
| `REGRU_TTL` | The TTL of the TXT record used for the DNS challenge |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
Expand Down
28 changes: 28 additions & 0 deletions providers/dns/regru/regru.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package regru

import (
"context"
"crypto/tls"
"errors"
"fmt"
"net/http"
Expand All @@ -19,6 +20,8 @@ const (

EnvUsername = envNamespace + "USERNAME"
EnvPassword = envNamespace + "PASSWORD"
EnvTLSCert = envNamespace + "TLS_CERT"
EnvTLSKey = envNamespace + "TLS_KEY"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
Expand All @@ -30,6 +33,8 @@ const (
type Config struct {
Username string
Password string
TLSCert string
TLSKey string

PropagationTimeout time.Duration
PollingInterval time.Duration
Expand Down Expand Up @@ -67,6 +72,8 @@ func NewDNSProvider() (*DNSProvider, error) {
config := NewDefaultConfig()
config.Username = values[EnvUsername]
config.Password = values[EnvPassword]
config.TLSCert = env.GetOrDefaultString(EnvTLSCert, "")
config.TLSKey = env.GetOrDefaultString(EnvTLSKey, "")

return NewDNSProviderConfig(config)
}
Expand All @@ -87,6 +94,27 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
client.HTTPClient = config.HTTPClient
}

if config.TLSCert != "" || config.TLSKey != "" {
if config.TLSCert == "" {
return nil, errors.New("regru: TLS certificate is missing")
}

if config.TLSKey == "" {
return nil, errors.New("regru: TLS key is missing")
}

tlsCert, err := tls.X509KeyPair([]byte(config.TLSCert), []byte(config.TLSKey))
if err != nil {
return nil, fmt.Errorf("regru: %w", err)
}

client.HTTPClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
Certificates: []tls.Certificate{tlsCert},
},
}
}

return &DNSProvider{config: config, client: client}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions providers/dns/regru/regru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ lego --email you@example.com --dns regru --domains my.example.org run
REGRU_USERNAME = "API username"
REGRU_PASSWORD = "API password"
[Configuration.Additional]
REGRU_TLS_CERT = "authentication certificate"
REGRU_TLS_KEY = "authentication private key"
REGRU_POLLING_INTERVAL = "Time between DNS propagation check"
REGRU_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
REGRU_TTL = "The TTL of the TXT record used for the DNS challenge"
Expand Down