Skip to content

Add DNS provider for Abion #2112

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
80 changes: 40 additions & 40 deletions README.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions cmd/zz_gen_cmd_dnshelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions docs/content/dns/zz_gen_abion.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/data/zz_cli_help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ To display the documentation for a specific DNS provider, run:
$ lego dnshelp -c code

Supported DNS providers:
acme-dns, active24, alidns, allinkl, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
abion, acme-dns, active24, alidns, allinkl, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi

More information: https://go-acme.github.io/lego/dns
"""
209 changes: 209 additions & 0 deletions providers/dns/abion/abion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// Package abion implements a DNS provider for solving the DNS-01 challenge using Abion.
package abion

import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/go-acme/lego/v4/challenge"
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/platform/config/env"
"github.com/go-acme/lego/v4/providers/dns/abion/internal"
)

// Environment variables names.
const (
envNamespace = "ABION_"

EnvAPIKey = envNamespace + "API_KEY"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
)

var _ challenge.ProviderTimeout = (*DNSProvider)(nil)

// Config is used to configure the creation of the DNSProvider.
type Config struct {
APIKey string
PropagationTimeout time.Duration
PollingInterval time.Duration
TTL int
HTTPClient *http.Client
}

// NewDefaultConfig returns a default configuration for the DNSProvider.
func NewDefaultConfig() *Config {
return &Config{
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
},
}
}

// DNSProvider implements the challenge.Provider interface.
type DNSProvider struct {
config *Config
client *internal.Client
}

// NewDNSProvider returns a DNSProvider instance configured for Abion.
// Credentials must be passed in the environment variable: ABION_API_KEY.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIKey)
if err != nil {
return nil, fmt.Errorf("abion: %w", err)
}

config := NewDefaultConfig()
config.APIKey = values[EnvAPIKey]

return NewDNSProviderConfig(config)
}

// NewDNSProviderConfig return a DNSProvider instance configured for Abion.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("abion: the configuration of the DNS provider is nil")
}

if config.APIKey == "" {
return nil, errors.New("abion: credentials missing")
}

client := internal.NewClient(config.APIKey)

if config.HTTPClient != nil {
client.HTTPClient = config.HTTPClient
}

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

// Timeout returns the timeout and interval to use when checking for DNS propagation.
// Adjusting here to cope with spikes in propagation times.
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}

// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, _, keyAuth string) error {
ctx := context.Background()
info := dns01.GetChallengeInfo(domain, keyAuth)

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

subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
if err != nil {
return fmt.Errorf("abion: %w", err)
}

zones, err := d.client.GetZone(ctx, dns01.UnFqdn(authZone))
if err != nil {
return fmt.Errorf("abion: get zone %w", err)
}

var data []internal.Record
if sub, ok := zones.Data.Attributes.Records[subDomain]; ok {
if records, exist := sub["TXT"]; exist {
data = append(data, records...)
}
}

data = append(data, internal.Record{
TTL: d.config.TTL,
Data: info.Value,
Comments: "lego",
})

patch := internal.ZoneRequest{
Data: internal.Zone{
Type: "zone",
ID: dns01.UnFqdn(authZone),
Attributes: internal.Attributes{
Records: map[string]map[string][]internal.Record{
subDomain: {"TXT": data},
},
},
},
}

_, err = d.client.UpdateZone(ctx, dns01.UnFqdn(authZone), patch)
if err != nil {
return fmt.Errorf("abion: update zone %w", err)
}

return nil
}

// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()
info := dns01.GetChallengeInfo(domain, keyAuth)

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

subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
if err != nil {
return fmt.Errorf("abion: %w", err)
}

zones, err := d.client.GetZone(ctx, dns01.UnFqdn(authZone))
if err != nil {
return fmt.Errorf("abion: get zone %w", err)
}

var data []internal.Record
if sub, ok := zones.Data.Attributes.Records[subDomain]; ok {
if records, exist := sub["TXT"]; exist {
for _, record := range records {
if record.Data != info.Value {
data = append(data, record)
}
}
}
}

payload := map[string][]internal.Record{}
if len(data) == 0 {
payload["TXT"] = nil
} else {
payload["TXT"] = data
}

patch := internal.ZoneRequest{
Data: internal.Zone{
Type: "zone",
ID: dns01.UnFqdn(authZone),
Attributes: internal.Attributes{
Records: map[string]map[string][]internal.Record{
subDomain: payload,
},
},
},
}

_, err = d.client.UpdateZone(ctx, dns01.UnFqdn(authZone), patch)
if err != nil {
return fmt.Errorf("abion: update zone %w", err)
}

return nil
}
22 changes: 22 additions & 0 deletions providers/dns/abion/abion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Name = "Abion"
Description = ''''''
URL = "https://abion.com"
Code = "abion"
Since = "v4.23.0"

Example = '''
ABION_API_KEY="xxxxxxxxxxxx" \
lego --email [email protected] --dns abion -d '*.example.com' -d example.com run
'''

[Configuration]
[Configuration.Credentials]
ABION_API_KEY = "API key"
[Configuration.Additional]
ABION_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
ABION_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
ABION_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
ABION_HTTP_TIMEOUT = "API request timeout in seconds (Default: 10)"

[Links]
API = "https://demo.abion.com/pmapi-doc/openapi-ui/index.html"
Loading
Loading