Skip to content

Commit

Permalink
designate: allow manually overwriting DNS zone (#2204)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
jan-di and ldez authored Jul 18, 2024
1 parent 321cea5 commit 04864ff
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln(` - "DESIGNATE_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "DESIGNATE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "DESIGNATE_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "DESIGNATE_ZONE_NAME": The zone name to use in the OpenStack Project to manage TXT records.`)
ew.writeln(` - "OS_PROJECT_ID": Project ID`)
ew.writeln(` - "OS_TENANT_NAME": Tenant name (deprecated see OS_PROJECT_NAME and OS_PROJECT_ID)`)

Expand Down
1 change: 1 addition & 0 deletions docs/content/dns/zz_gen_designate.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
| `DESIGNATE_POLLING_INTERVAL` | Time between DNS propagation check |
| `DESIGNATE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `DESIGNATE_TTL` | The TTL of the TXT record used for the DNS challenge |
| `DESIGNATE_ZONE_NAME` | The zone name to use in the OpenStack Project to manage TXT records. |
| `OS_PROJECT_ID` | Project ID |
| `OS_TENANT_NAME` | Tenant name (deprecated see OS_PROJECT_NAME and OS_PROJECT_ID) |

Expand Down
28 changes: 22 additions & 6 deletions providers/dns/designate/designate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"

EnvZoneName = envNamespace + "ZONE_NAME"

envNamespaceClient = "OS_"

EnvAuthURL = envNamespaceClient + "AUTH_URL"
Expand Down Expand Up @@ -127,12 +129,12 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
zone, err := getAuthZone(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("designate: could not find zone for domain %q: %w", domain, err)
return fmt.Errorf("designate: %w", err)
}

zoneID, err := d.getZoneID(authZone)
zoneID, err := d.getZoneID(zone)
if err != nil {
return fmt.Errorf("designate: couldn't get zone ID in Present: %w", err)
}
Expand Down Expand Up @@ -167,12 +169,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
zone, err := getAuthZone(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("designate: could not find zone for domain %q: %w", domain, err)
return fmt.Errorf("designate: %w", err)
}

zoneID, err := d.getZoneID(authZone)
zoneID, err := d.getZoneID(zone)
if err != nil {
return fmt.Errorf("designate: couldn't get zone ID in CleanUp: %w", err)
}
Expand Down Expand Up @@ -273,3 +275,17 @@ func (d *DNSProvider) getRecord(zoneID, wanted string) (*recordsets.RecordSet, e

return nil, nil
}

func getAuthZone(fqdn string) (string, error) {
authZone := env.GetOrFile(EnvZoneName)
if authZone != "" {
return authZone, nil
}

authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return "", fmt.Errorf("could not find zone: %w", err)
}

return authZone, nil
}
1 change: 1 addition & 0 deletions providers/dns/designate/designate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Public cloud providers with support for Designate:
[Configuration.Additional]
OS_PROJECT_ID = "Project ID"
OS_TENANT_NAME = "Tenant name (deprecated see OS_PROJECT_NAME and OS_PROJECT_ID)"
DESIGNATE_ZONE_NAME = "The zone name to use in the OpenStack Project to manage TXT records."
DESIGNATE_POLLING_INTERVAL = "Time between DNS propagation check"
DESIGNATE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
DESIGNATE_TTL = "The TTL of the TXT record used for the DNS challenge"
Expand Down

0 comments on commit 04864ff

Please sign in to comment.