From 6a800f480ec37c99ad848240d3535e3923b3309d Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Sat, 19 Jun 2021 10:10:39 +0200 Subject: [PATCH 1/8] providers/dns/azure: new env var AZURE_ZONE_NAME --- providers/dns/azure/azure.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/providers/dns/azure/azure.go b/providers/dns/azure/azure.go index 091b912f5d..23fd2adf91 100644 --- a/providers/dns/azure/azure.go +++ b/providers/dns/azure/azure.go @@ -33,6 +33,7 @@ const ( EnvTenantID = envNamespace + "TENANT_ID" EnvClientID = envNamespace + "CLIENT_ID" EnvClientSecret = envNamespace + "CLIENT_SECRET" + EnvZoneName = envNamespace + "ZONE_NAME" EnvTTL = envNamespace + "TTL" EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" @@ -169,9 +170,15 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { ctx := context.Background() fqdn, value := dns01.GetRecord(domain, keyAuth) - zone, err := d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) + var zone string + if env.GetOrFile(EnvZoneName) != "" { + zone = env.GetOrFile(EnvZoneName) + } else { + var err error + zone, err = d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) + } } rsc := dns.NewRecordSetsClientWithBaseURI(d.config.ResourceManagerEndpoint, d.config.SubscriptionID) @@ -224,9 +231,16 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { ctx := context.Background() fqdn, _ := dns01.GetRecord(domain, keyAuth) - zone, err := d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) + + var zone string + var err error + if env.GetOrFile(EnvZoneName) != "" { + zone = env.GetOrFile(EnvZoneName) + } else { + zone, err = d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) + } } relative := toRelativeRecord(fqdn, dns01.ToFqdn(zone)) From fda394cf135a0f5c0b5727767e63a88cb01006bd Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Sun, 20 Jun 2021 00:04:16 +0200 Subject: [PATCH 2/8] add documentation for AZURE_ZONE_NAME env variable --- cmd/zz_gen_cmd_dnshelp.go | 1 + docs/content/dns/zz_gen_azure.md | 1 + providers/dns/azure/azure.toml | 1 + 3 files changed, 3 insertions(+) diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index b198b926d3..da0403f3c4 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -236,6 +236,7 @@ func displayDNSHelp(name string) error { ew.writeln(` - "AZURE_POLLING_INTERVAL": Time between DNS propagation check`) ew.writeln(` - "AZURE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) ew.writeln(` - "AZURE_TTL": The TTL of the TXT record used for the DNS challenge`) + ew.writeln(` - "AZURE_ZONE_NAME": The name of the zone to use inside Azure DNS service (will skip query for SOA record from DNS)`) ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/azure`) diff --git a/docs/content/dns/zz_gen_azure.md b/docs/content/dns/zz_gen_azure.md index 4c4dcf7b43..1a86139ee6 100644 --- a/docs/content/dns/zz_gen_azure.md +++ b/docs/content/dns/zz_gen_azure.md @@ -49,6 +49,7 @@ More information [here](/lego/dns/#configuration-and-credentials). | `AZURE_POLLING_INTERVAL` | Time between DNS propagation check | | `AZURE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `AZURE_TTL` | The TTL of the TXT record used for the DNS challenge | +| `AZURE_ZONE_NAME` | The name of the zone to use inside Azure DNS service to add the MX record | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here](/lego/dns/#configuration-and-credentials). diff --git a/providers/dns/azure/azure.toml b/providers/dns/azure/azure.toml index c83361156e..d6359afd53 100644 --- a/providers/dns/azure/azure.toml +++ b/providers/dns/azure/azure.toml @@ -20,6 +20,7 @@ Example = '''''' AZURE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" AZURE_TTL = "The TTL of the TXT record used for the DNS challenge" AZURE_METADATA_ENDPOINT = "Metadata Service endpoint URL" + AZURE_ZONE_NAME = "Zone name to use inside Azure DNS service to add the TXT record in" [Links] API = "https://docs.microsoft.com/en-us/go/azure/" From a1355e0cd011fd135c04573a7ff76cf1e2c82216 Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Thu, 1 Jul 2021 21:42:39 +0200 Subject: [PATCH 3/8] Update zz_gen_azure.md typo: TXT record, not MX record for validation --- docs/content/dns/zz_gen_azure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/dns/zz_gen_azure.md b/docs/content/dns/zz_gen_azure.md index 1a86139ee6..12c4366eff 100644 --- a/docs/content/dns/zz_gen_azure.md +++ b/docs/content/dns/zz_gen_azure.md @@ -49,7 +49,7 @@ More information [here](/lego/dns/#configuration-and-credentials). | `AZURE_POLLING_INTERVAL` | Time between DNS propagation check | | `AZURE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `AZURE_TTL` | The TTL of the TXT record used for the DNS challenge | -| `AZURE_ZONE_NAME` | The name of the zone to use inside Azure DNS service to add the MX record | +| `AZURE_ZONE_NAME` | The name of the zone to use inside Azure DNS service to add the TXT record for validation | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here](/lego/dns/#configuration-and-credentials). From cf673f503816390cfaaf3b609cf58472460b500d Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Thu, 1 Jul 2021 21:51:06 +0200 Subject: [PATCH 4/8] azure: streamline generated doc with toml --- cmd/zz_gen_cmd_dnshelp.go | 2 +- docs/content/dns/zz_gen_azure.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index e4bfc8c7ef..56a3a4f90e 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -257,7 +257,7 @@ func displayDNSHelp(name string) error { ew.writeln(` - "AZURE_POLLING_INTERVAL": Time between DNS propagation check`) ew.writeln(` - "AZURE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) ew.writeln(` - "AZURE_TTL": The TTL of the TXT record used for the DNS challenge`) - ew.writeln(` - "AZURE_ZONE_NAME": The name of the zone to use inside Azure DNS service (will skip query for SOA record from DNS)`) + ew.writeln(` - "AZURE_ZONE_NAME": Zone name to use inside Azure DNS service to add the TXT record in`) ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/azure`) diff --git a/docs/content/dns/zz_gen_azure.md b/docs/content/dns/zz_gen_azure.md index 12c4366eff..be0cd67465 100644 --- a/docs/content/dns/zz_gen_azure.md +++ b/docs/content/dns/zz_gen_azure.md @@ -49,7 +49,7 @@ More information [here](/lego/dns/#configuration-and-credentials). | `AZURE_POLLING_INTERVAL` | Time between DNS propagation check | | `AZURE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `AZURE_TTL` | The TTL of the TXT record used for the DNS challenge | -| `AZURE_ZONE_NAME` | The name of the zone to use inside Azure DNS service to add the TXT record for validation | +| `AZURE_ZONE_NAME` | Zone name to use inside Azure DNS service to add the TXT record in | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here](/lego/dns/#configuration-and-credentials). From dbb80582cfc9cd5d8e2a4357b34527cd9279cb65 Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Fri, 16 Jul 2021 18:57:03 +0200 Subject: [PATCH 5/8] convert tab to spaces --- providers/dns/azure/azure.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/dns/azure/azure.toml b/providers/dns/azure/azure.toml index d6359afd53..ae5ef422fa 100644 --- a/providers/dns/azure/azure.toml +++ b/providers/dns/azure/azure.toml @@ -20,7 +20,7 @@ Example = '''''' AZURE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" AZURE_TTL = "The TTL of the TXT record used for the DNS challenge" AZURE_METADATA_ENDPOINT = "Metadata Service endpoint URL" - AZURE_ZONE_NAME = "Zone name to use inside Azure DNS service to add the TXT record in" + AZURE_ZONE_NAME = "Zone name to use inside Azure DNS service to add the TXT record in" [Links] API = "https://docs.microsoft.com/en-us/go/azure/" From 01783731582b0c73a11b1bc13b1868f6042f061c Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Fri, 16 Jul 2021 19:44:29 +0200 Subject: [PATCH 6/8] move zone name override into function getHostedZoneID --- providers/dns/azure/azure.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/providers/dns/azure/azure.go b/providers/dns/azure/azure.go index 23fd2adf91..61b8bb4de9 100644 --- a/providers/dns/azure/azure.go +++ b/providers/dns/azure/azure.go @@ -170,15 +170,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { ctx := context.Background() fqdn, value := dns01.GetRecord(domain, keyAuth) - var zone string - if env.GetOrFile(EnvZoneName) != "" { - zone = env.GetOrFile(EnvZoneName) - } else { - var err error - zone, err = d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) - } + zone, err := d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) } rsc := dns.NewRecordSetsClientWithBaseURI(d.config.ResourceManagerEndpoint, d.config.SubscriptionID) @@ -232,15 +226,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { fqdn, _ := dns01.GetRecord(domain, keyAuth) - var zone string - var err error - if env.GetOrFile(EnvZoneName) != "" { - zone = env.GetOrFile(EnvZoneName) - } else { - zone, err = d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) - } + zone, err := d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) } relative := toRelativeRecord(fqdn, dns01.ToFqdn(zone)) @@ -256,6 +244,10 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *DNSProvider) getHostedZoneID(ctx context.Context, fqdn string) (string, error) { + if env.GetOrFile(EnvZoneName) != "" { + return env.GetOrFile(EnvZoneName), nil + } + authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { return "", err From 8c8c4b46092674bdf838c61440a49199ebee9d09 Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Sat, 17 Jul 2021 12:03:57 +0200 Subject: [PATCH 7/8] cache result of GetOrFile Co-authored-by: Dominik Menke --- providers/dns/azure/azure.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/dns/azure/azure.go b/providers/dns/azure/azure.go index 61b8bb4de9..81258ae402 100644 --- a/providers/dns/azure/azure.go +++ b/providers/dns/azure/azure.go @@ -244,8 +244,8 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *DNSProvider) getHostedZoneID(ctx context.Context, fqdn string) (string, error) { - if env.GetOrFile(EnvZoneName) != "" { - return env.GetOrFile(EnvZoneName), nil + if zone := env.GetOrFile(EnvZoneName); zone != "" { + return zone, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) From 60b92da184f8d29be7d64b00537ef90430156d8e Mon Sep 17 00:00:00 2001 From: Christian Anton Date: Sat, 17 Jul 2021 12:07:07 +0200 Subject: [PATCH 8/8] fix spaces to tabs --- providers/dns/azure/azure.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/providers/dns/azure/azure.go b/providers/dns/azure/azure.go index 81258ae402..7289592f0f 100644 --- a/providers/dns/azure/azure.go +++ b/providers/dns/azure/azure.go @@ -170,9 +170,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { ctx := context.Background() fqdn, value := dns01.GetRecord(domain, keyAuth) - zone, err := d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) + zone, err := d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) } rsc := dns.NewRecordSetsClientWithBaseURI(d.config.ResourceManagerEndpoint, d.config.SubscriptionID) @@ -225,10 +225,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { ctx := context.Background() fqdn, _ := dns01.GetRecord(domain, keyAuth) - - zone, err := d.getHostedZoneID(ctx, fqdn) - if err != nil { - return fmt.Errorf("azure: %w", err) + zone, err := d.getHostedZoneID(ctx, fqdn) + if err != nil { + return fmt.Errorf("azure: %w", err) } relative := toRelativeRecord(fqdn, dns01.ToFqdn(zone)) @@ -245,7 +244,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *DNSProvider) getHostedZoneID(ctx context.Context, fqdn string) (string, error) { if zone := env.GetOrFile(EnvZoneName); zone != "" { - return zone, nil + return zone, nil } authZone, err := dns01.FindZoneByFqdn(fqdn)