1 package PVE
::ACME
::DNSChallenge
;
6 use Digest
::SHA
qw(sha256);
9 use base
qw(PVE::ACME::Challenge);
11 my $ACME_PATH = '/usr/share/proxmox-acme/proxmox-acme';
13 sub supported_challenge_types
{
21 # describe the data schema of the supported plugins, e.g.:
23 # name => 'Full name of Plugin',
26 # description => "The API key",
41 description
=> "The API key",
50 description
=> "The API key",
56 name
=> 'Alibaba Cloud DNS',
59 description
=> 'The API endpoint',
60 default => "https://alidns.aliyuncs.com/",
65 description
=> 'The API Key',
69 description
=> 'The API Secret',
76 name
=> 'Amazon Route53 (AWS)',
78 'AWS_ACCESS_KEY_ID' => {
79 name
=> 'ACCESS_KEY_ID',
80 description
=> 'The AWS access-key ID',
83 'AWS_SECRET_ACCESS_KEY' => {
84 name
=> 'SECRET_ACCESS_KEY',
85 description
=> 'The AWS access-key secret',
92 name
=> 'Cloudflare Managed DNS',
93 description
=> 'Either provide global account key and email, or CF API token and Account ID.',
96 description
=> 'The Cloudflare Global API Key',
100 description
=> 'The Cloudflare Account EMail-Address',
104 description
=> 'The new Cloudflare API Token',
108 description
=> 'The new Cloudflare API Account ID',
112 description
=> 'For Zone restricted API Token',
129 name
=> 'DigitalOcean DNS',
132 description
=> 'The DigitalOcean API Key',
153 'gandi_livedns' => {},
159 description
=> 'The GoDaddy API Key',
163 description
=> 'The GoDaddy API Secret',
178 description
=> 'The INWX username',
182 description
=> 'The INWX password',
218 'openprovider' => {},
224 description
=> "The OVH endpoint",
230 description
=> "The application key.",
234 description
=> "The application secret.",
238 description
=> "The consumer key.",
245 name
=> 'PowerDNS server',
248 description
=> "The PowerDNS API endpoint.",
282 sub get_supported_plugins
{
289 description
=> "API plugin name",
291 enum
=> [sort keys %$plugins],
295 description
=> 'DNS plugin data. (base64 encoded)',
297 'validation-delay' => {
299 description
=> 'Extra delay in seconds to wait before requesting validation.'
300 .' Allows to cope with a long TTL of DNS records.',
301 # low default, but our bet is that the acme-challenge domain isn't
302 # cached at all, so it hopefully shouldn't run into TTL issues
306 maximum
=> 2 * 24 * 60 * 60,
314 data
=> { optional
=> 1 },
315 nodes
=> { optional
=> 1 },
316 disable
=> { optional
=> 1 },
317 'validation-delay' => { optional
=> 1 },
321 my $proxmox_acme_command = sub {
322 my ($self, $acme, $auth, $data, $action) = @_;
324 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
326 my $alias = $data->{alias
};
327 my $domain = $auth->{identifier
}->{value
};
329 my $challenge = $self->extract_challenge($auth->{challenges
});
330 my $key_auth = $acme->key_authorization($challenge->{token
});
332 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
333 my $dnsplugin = $data->{plugin
}->{api
};
334 my $plugin_conf_string = $data->{plugin
}->{data
};
336 # for security reasons, we execute the command as nobody
337 # we can't verify that the code of the DNSPlugins are harmless.
338 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
340 # The order of the parameters passed to proxmox-acme is important
341 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
342 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
348 my $input = "$txtvalue\n";
349 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
351 PVE
::Tools
::run_command
($cmd, input
=> $input);
353 $data->{url
} = $challenge->{url
};
359 my ($self, $acme, $auth, $data) = @_;
361 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
362 print "Add TXT record: _acme-challenge.$domain\n";
364 my $delay = $data->{plugin
}->{'validation-delay'} // 30;
366 print "Sleeping $delay seconds to wait for TXT record propagation\n";
367 sleep($delay); # don't care for EINTR
372 my ($self, $acme, $auth, $data) = @_;
374 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
375 print "Remove TXT record: _acme-challenge.$domain\n";