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

Multiple DNS provider support #328

Closed
wants to merge 10 commits into from
Closed
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
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
## [0.1.0] - 2015-12-03
- Initial release

[0.3.1]: https://github.com/xenolf/lego/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/xenolf/lego/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/xenolf/lego/compare/v0.1.1...v0.2.0
[0.1.1]: https://github.com/xenolf/lego/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/xenolf/lego/tree/v0.1.0
[0.3.1]: https://github.com/ManuelGysin/lego/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/ManuelGysin/lego/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/ManuelGysin/lego/compare/v0.1.1...v0.2.0
[0.1.1]: https://github.com/ManuelGysin/lego/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/ManuelGysin/lego/tree/v0.1.0
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# lego
Let's Encrypt client and ACME library written in Go

[![GoDoc](https://godoc.org/github.com/xenolf/lego/acme?status.svg)](https://godoc.org/github.com/xenolf/lego/acme)
[![GoDoc](https://godoc.org/github.com/ManuelGysin/lego/acme?status.svg)](https://godoc.org/github.com/ManuelGysin/lego/acme)
[![Build Status](https://travis-ci.org/xenolf/lego.svg?branch=master)](https://travis-ci.org/xenolf/lego)
[![Dev Chat](https://img.shields.io/badge/dev%20chat-gitter-blue.svg?label=dev+chat)](https://gitter.im/xenolf/lego)

Expand All @@ -11,7 +11,7 @@ This is a work in progress. Please do *NOT* run this on a production server and
#### Installation
lego supports both binary installs and install from source.

To get the binary just download the latest release for your OS/Arch from [the release page](https://github.com/xenolf/lego/releases)
To get the binary just download the latest release for your OS/Arch from [the release page](https://github.com/ManuelGysin/lego/releases)
and put the binary somewhere convenient. lego does not assume anything about the location you run it from.

To install from source, just run
Expand All @@ -35,8 +35,8 @@ docker build -t lego .
- TLS with Server Name Indication (tls-sni-01)
- DNS (dns-01)
- SAN certificate support
- Comes with multiple optional [DNS providers](https://github.com/xenolf/lego/tree/master/providers/dns)
- [Custom challenge solvers](https://github.com/xenolf/lego/wiki/Writing-a-Challenge-Solver)
- Comes with multiple optional [DNS providers](https://github.com/ManuelGysin/lego/tree/master/providers/dns)
- [Custom challenge solvers](https://github.com/ManuelGysin/lego/wiki/Writing-a-Challenge-Solver)
- Certificate bundling
- OCSP helper function

Expand Down Expand Up @@ -106,7 +106,7 @@ GLOBAL OPTIONS:

##### CLI Example

Assumes the `lego` binary has permission to bind to ports 80 and 443. You can get a pre-built binary from the [releases](https://github.com/xenolf/lego/releases) page.
Assumes the `lego` binary has permission to bind to ports 80 and 443. You can get a pre-built binary from the [releases](https://github.com/ManuelGysin/lego/releases) page.
If your environment does not allow you to bind to these ports, please read [Port Usage](#port-usage).

Obtain a certificate:
Expand Down
2 changes: 1 addition & 1 deletion account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"path"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// Account represents a users local saved credentials
Expand Down
7 changes: 5 additions & 2 deletions acme/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ func (c *Client) SetChallengeProvider(challenge Challenge, p ChallengeProvider)
c.solvers[challenge] = &httpChallenge{jws: c.jws, validate: validate, provider: p}
case TLSSNI01:
c.solvers[challenge] = &tlsSNIChallenge{jws: c.jws, validate: validate, provider: p}
case DNS01:
c.solvers[challenge] = &dnsChallenge{jws: c.jws, validate: validate, provider: p}
default:
return fmt.Errorf("Unknown challenge %v", challenge)
}
return nil
}

func (c *Client) SetChallengeProviderDNS(challenge Challenge, p []ChallengeProvider) error {
c.solvers[challenge] = &dnsChallenge{jws: c.jws, validate: validate, providers: p}
return nil
}

// SetHTTPAddress specifies a custom interface:port to be used for HTTP based challenges.
// If this option is not used, the default port 80 and all interfaces will be used.
// To only specify a port and no interface use the ":port" notation.
Expand Down
51 changes: 38 additions & 13 deletions acme/dns_challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func DNS01Record(domain, keyAuth string) (fqdn string, value string, ttl int) {
type dnsChallenge struct {
jws *jws
validate validateFunc
provider ChallengeProvider
providers []ChallengeProvider
}

func (s *dnsChallenge) Solve(chlng challenge, domain string) error {
logf("[INFO][%s] acme: Trying to solve DNS-01", domain)

if s.provider == nil {
if s.providers == nil {
return errors.New("No DNS Provider configured")
}

Expand All @@ -85,14 +85,22 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error {
return err
}

err = s.provider.Present(domain, chlng.Token, keyAuth)
if err != nil {
return fmt.Errorf("Error presenting token: %s", err)
for _, v := range s.providers {
err = v.Present(domain, chlng.Token, keyAuth)

if err != nil {
return fmt.Errorf("Error presenting token: %s", err)
}
}

defer func() {
err := s.provider.CleanUp(domain, chlng.Token, keyAuth)
if err != nil {
log.Printf("Error cleaning up %s: %v ", domain, err)

for _, v := range s.providers {
err := v.CleanUp(domain, chlng.Token, keyAuth)

if err != nil {
log.Printf("Error cleaning up %s: %v ", domain, err)
}
}
}()

Expand All @@ -101,16 +109,33 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error {
logf("[INFO][%s] Checking DNS record propagation using %+v", domain, RecursiveNameservers)

var timeout, interval time.Duration
switch provider := s.provider.(type) {
case ChallengeProviderTimeout:
timeout, interval = provider.Timeout()
default:
timeout, interval = 60*time.Second, 2*time.Second

for _, v := range s.providers {
var tiou, inter time.Duration

switch provider := v.(type) {
case ChallengeProviderTimeout:
tiou, inter = provider.Timeout()
default:
tiou, inter = 60*time.Second, 2*time.Second
}

// Check if interval or timeout is greater, we take the highest number
if timeout < tiou {
timeout = tiou
}
if interval < inter {
interval = inter
}
}

timeout = 600*time.Second
interval = 600*time.Second

err = WaitFor(timeout, interval, func() (bool, error) {
return PreCheckDNS(fqdn, value)
})

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"text/tabwriter"

"github.com/urfave/cli"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// Logger is used to log errors; if nil, the default log.Logger is used.
Expand Down
24 changes: 16 additions & 8 deletions cli_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"time"

"github.com/urfave/cli"
"github.com/xenolf/lego/acme"
"github.com/xenolf/lego/providers/dns"
"github.com/xenolf/lego/providers/http/memcached"
"github.com/xenolf/lego/providers/http/webroot"
"github.com/ManuelGysin/lego/acme"
"github.com/ManuelGysin/lego/providers/dns"
"github.com/ManuelGysin/lego/providers/http/memcached"
"github.com/ManuelGysin/lego/providers/http/webroot"
)

func checkFolder(path string) error {
Expand Down Expand Up @@ -114,12 +114,20 @@ func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) {
}

if c.GlobalIsSet("dns") {
provider, err := dns.NewDNSChallengeProviderByName(c.GlobalString("dns"))
if err != nil {
logger().Fatal(err)
// Get providers
var providers []acme.ChallengeProvider

for _, v := range strings.Split(c.GlobalString("dns"), ",") {
provider, err := dns.NewDNSChallengeProviderByName(v)

if err != nil {
logger().Fatal(err)
}

providers = append(providers, provider)
}

client.SetChallengeProvider(acme.DNS01, provider)
client.SetChallengeProviderDNS(acme.DNS01, providers)

// --dns=foo indicates that the user specifically want to do a DNS challenge
// infer that the user also wants to exclude all other challenges
Expand Down
2 changes: 1 addition & 1 deletion configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/urfave/cli"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// Configuration type from CLI and config files.
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/auroradns/auroradns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/edeckers/auroradnsclient"
"github.com/edeckers/auroradnsclient/records"
"github.com/edeckers/auroradnsclient/zones"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
"os"
"sync"
)
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion providers/dns/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// CloudFlareAPIURL represents the API endpoint to call.
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/digitalocean/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// DNSProvider is an implementation of the acme.ChallengeProvider interface
Expand Down
42 changes: 21 additions & 21 deletions providers/dns/dns_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ package dns
import (
"fmt"

"github.com/xenolf/lego/acme"
"github.com/xenolf/lego/providers/dns/auroradns"
"github.com/xenolf/lego/providers/dns/azure"
"github.com/xenolf/lego/providers/dns/cloudflare"
"github.com/xenolf/lego/providers/dns/digitalocean"
"github.com/xenolf/lego/providers/dns/dnsimple"
"github.com/xenolf/lego/providers/dns/dnsmadeeasy"
"github.com/xenolf/lego/providers/dns/dnspod"
"github.com/xenolf/lego/providers/dns/dyn"
"github.com/xenolf/lego/providers/dns/exoscale"
"github.com/xenolf/lego/providers/dns/gandi"
"github.com/xenolf/lego/providers/dns/googlecloud"
"github.com/xenolf/lego/providers/dns/linode"
"github.com/xenolf/lego/providers/dns/namecheap"
"github.com/xenolf/lego/providers/dns/ns1"
"github.com/xenolf/lego/providers/dns/ovh"
"github.com/xenolf/lego/providers/dns/pdns"
"github.com/xenolf/lego/providers/dns/rackspace"
"github.com/xenolf/lego/providers/dns/rfc2136"
"github.com/xenolf/lego/providers/dns/route53"
"github.com/xenolf/lego/providers/dns/vultr"
"github.com/ManuelGysin/lego/acme"
"github.com/ManuelGysin/lego/providers/dns/auroradns"
"github.com/ManuelGysin/lego/providers/dns/azure"
"github.com/ManuelGysin/lego/providers/dns/cloudflare"
"github.com/ManuelGysin/lego/providers/dns/digitalocean"
"github.com/ManuelGysin/lego/providers/dns/dnsimple"
"github.com/ManuelGysin/lego/providers/dns/dnsmadeeasy"
"github.com/ManuelGysin/lego/providers/dns/dnspod"
"github.com/ManuelGysin/lego/providers/dns/dyn"
"github.com/ManuelGysin/lego/providers/dns/exoscale"
"github.com/ManuelGysin/lego/providers/dns/gandi"
"github.com/ManuelGysin/lego/providers/dns/googlecloud"
"github.com/ManuelGysin/lego/providers/dns/linode"
"github.com/ManuelGysin/lego/providers/dns/namecheap"
"github.com/ManuelGysin/lego/providers/dns/ns1"
"github.com/ManuelGysin/lego/providers/dns/ovh"
"github.com/ManuelGysin/lego/providers/dns/pdns"
"github.com/ManuelGysin/lego/providers/dns/rackspace"
"github.com/ManuelGysin/lego/providers/dns/rfc2136"
"github.com/ManuelGysin/lego/providers/dns/route53"
"github.com/ManuelGysin/lego/providers/dns/vultr"
)

func NewDNSChallengeProviderByName(name string) (acme.ChallengeProvider, error) {
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/dns_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xenolf/lego/providers/dns/exoscale"
"github.com/ManuelGysin/lego/providers/dns/exoscale"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/dnsimple/dnsimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/weppos/dnsimple-go/dnsimple"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// DNSProvider is an implementation of the acme.ChallengeProvider interface.
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/dnsmadeeasy/dnsmadeeasy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// DNSProvider is an implementation of the acme.ChallengeProvider interface that uses
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/dnspod/dnspod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/decker502/dnspod-go"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// DNSProvider is an implementation of the acme.ChallengeProvider interface.
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/dyn/dyn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strconv"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

var dynBaseURL = "https://api.dynect.net/REST"
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/exoscale/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"

"github.com/pyr/egoscale/src/egoscale"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// DNSProvider is an implementation of the acme.ChallengeProvider interface.
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/gandi/gandi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// Gandi API reference: http://doc.rpc.gandi.net/index.html
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/gandi/gandi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"testing"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

// stagingServer is the Let's Encrypt staging server used by the live test
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/googlecloud/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"time"

"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"

"golang.org/x/net/context"
"golang.org/x/oauth2/google"
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/linode/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/timewasted/linode/dns"
"github.com/xenolf/lego/acme"
"github.com/ManuelGysin/lego/acme"
)

const (
Expand Down
Loading