1 package PVE
::ACME
::DNSChallenge
;
6 use Digest
::SHA
qw(sha256);
11 use base
qw(PVE::ACME::Challenge);
13 my $ACME_PATH = '/usr/share/proxmox-acme/proxmox-acme';
15 sub supported_challenge_types
{
23 # describe the data schema of the supported plugins, e.g.:
25 # name => 'Full name of Plugin',
28 # description => "The API key",
41 'ACMEDNS_UPDATE_URL' => {
42 description
=> 'The API update endpoint',
45 'ACMEDNS_USERNAME' => {
46 description
=> 'The acme-dns user',
49 'ACMEDNS_PASSWORD' => {
50 description
=> 'The acme-dns password',
53 'ACMEDNS_SUBDOMAIN' => {
54 description
=> 'The subdomain you got from acme-dns registration',
64 description
=> "The API key",
73 description
=> "The API key",
79 name
=> 'Alibaba Cloud DNS',
82 description
=> 'The API endpoint',
83 default => "https://alidns.aliyuncs.com/",
88 description
=> 'The API Key',
92 description
=> 'The API Secret',
101 name
=> 'Amazon Route53 (AWS)',
103 'AWS_ACCESS_KEY_ID' => {
104 name
=> 'ACCESS_KEY_ID',
105 description
=> 'The AWS access-key ID',
108 'AWS_SECRET_ACCESS_KEY' => {
109 name
=> 'SECRET_ACCESS_KEY',
110 description
=> 'The AWS access-key secret',
117 name
=> 'Cloudflare Managed DNS',
118 description
=> 'Either provide global account key and email, or CF API token and Account ID.',
121 description
=> 'The Cloudflare Global API Key',
125 description
=> 'The Cloudflare Account EMail-Address',
129 description
=> 'The new Cloudflare API Token',
133 description
=> 'The new Cloudflare API Account ID',
137 description
=> 'For Zone restricted API Token',
154 name
=> 'DigitalOcean DNS',
157 description
=> 'The DigitalOcean API Key',
179 'gandi_livedns' => {},
185 description
=> 'The GoDaddy API Key',
189 description
=> 'The GoDaddy API Secret',
207 description
=> 'The INWX username',
211 description
=> 'The INWX password',
220 name
=> 'kapper.net',
222 'KAPPERNETDNS_Key' => {
223 description
=> 'Your kapper.net API key',
226 'KAPPERNETDNS_Secret' => {
227 description
=> 'Your kapper.net API secret',
264 'openprovider' => {},
271 description
=> "The OVH endpoint",
277 description
=> "The application key.",
281 description
=> "The application secret.",
285 description
=> "The consumer key.",
292 name
=> 'PowerDNS server',
295 description
=> "The PowerDNS API endpoint.",
331 sub get_supported_plugins
{
338 description
=> "API plugin name",
340 enum
=> [sort keys %$plugins],
344 description
=> 'DNS plugin data. (base64 encoded)',
346 'validation-delay' => {
348 description
=> 'Extra delay in seconds to wait before requesting validation.'
349 .' Allows to cope with a long TTL of DNS records.',
350 # low default, but our bet is that the acme-challenge domain isn't
351 # cached at all, so it hopefully shouldn't run into TTL issues
355 maximum
=> 2 * 24 * 60 * 60,
363 data
=> { optional
=> 1 },
364 nodes
=> { optional
=> 1 },
365 disable
=> { optional
=> 1 },
366 'validation-delay' => { optional
=> 1 },
370 my $proxmox_acme_command = sub {
371 my ($self, $acme, $auth, $data, $action) = @_;
373 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
375 my $alias = $data->{alias
};
376 my $domain = $auth->{identifier
}->{value
};
378 my $challenge = $self->extract_challenge($auth->{challenges
});
379 my $key_auth = $acme->key_authorization($challenge->{token
});
381 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
382 my $dnsplugin = $data->{plugin
}->{api
};
383 my $plugin_conf_string = $data->{plugin
}->{data
};
385 # for security reasons, we execute the command as nobody
386 # we can't verify that the code of the DNSPlugins are harmless.
387 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
389 # The order of the parameters passed to proxmox-acme is important
390 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
391 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
397 my $input = "$txtvalue\n";
398 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
400 PVE
::Tools
::run_command
($cmd, input
=> $input);
402 $data->{url
} = $challenge->{url
};
408 my ($self, $acme, $auth, $data) = @_;
410 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
411 print "Add TXT record: _acme-challenge.$domain\n";
413 my $delay = $data->{plugin
}->{'validation-delay'} // 30;
415 print "Sleeping $delay seconds to wait for TXT record propagation\n";
416 sleep($delay); # don't care for EINTR
421 my ($self, $acme, $auth, $data) = @_;
423 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
424 print "Remove TXT record: _acme-challenge.$domain\n";