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',
221 name
=> 'kapper.net',
223 'KAPPERNETDNS_Key' => {
224 description
=> 'Your kapper.net API key',
227 'KAPPERNETDNS_Secret' => {
228 description
=> 'Your kapper.net API secret',
265 'openprovider' => {},
272 description
=> "The OVH endpoint",
278 description
=> "The application key.",
282 description
=> "The application secret.",
286 description
=> "The consumer key.",
293 name
=> 'PowerDNS server',
296 description
=> "The PowerDNS API endpoint.",
335 sub get_supported_plugins
{
342 description
=> "API plugin name",
344 enum
=> [sort keys %$plugins],
348 description
=> 'DNS plugin data. (base64 encoded)',
350 'validation-delay' => {
352 description
=> 'Extra delay in seconds to wait before requesting validation.'
353 .' Allows to cope with a long TTL of DNS records.',
354 # low default, but our bet is that the acme-challenge domain isn't
355 # cached at all, so it hopefully shouldn't run into TTL issues
359 maximum
=> 2 * 24 * 60 * 60,
367 data
=> { optional
=> 1 },
368 nodes
=> { optional
=> 1 },
369 disable
=> { optional
=> 1 },
370 'validation-delay' => { optional
=> 1 },
374 my $proxmox_acme_command = sub {
375 my ($self, $acme, $auth, $data, $action) = @_;
377 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
379 my $alias = $data->{alias
};
380 my $domain = $auth->{identifier
}->{value
};
382 my $challenge = $self->extract_challenge($auth->{challenges
});
383 my $key_auth = $acme->key_authorization($challenge->{token
});
385 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
386 my $dnsplugin = $data->{plugin
}->{api
};
387 my $plugin_conf_string = $data->{plugin
}->{data
};
389 # for security reasons, we execute the command as nobody
390 # we can't verify that the code of the DNSPlugins are harmless.
391 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
393 # The order of the parameters passed to proxmox-acme is important
394 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
395 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
401 my $input = "$txtvalue\n";
402 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
404 PVE
::Tools
::run_command
($cmd, input
=> $input);
406 $data->{url
} = $challenge->{url
};
412 my ($self, $acme, $auth, $data) = @_;
414 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
415 print "Add TXT record: _acme-challenge.$domain\n";
417 my $delay = $data->{plugin
}->{'validation-delay'} // 30;
419 print "Sleeping $delay seconds to wait for TXT record propagation\n";
420 sleep($delay); # don't care for EINTR
425 my ($self, $acme, $auth, $data) = @_;
427 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
428 print "Remove TXT record: _acme-challenge.$domain\n";