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',
206 'openprovider' => {},
212 description
=> "The OVH endpoint",
218 description
=> "The application key.",
222 description
=> "The application secret.",
226 description
=> "The consumer key.",
233 name
=> 'PowerDNS server',
236 description
=> "The PowerDNS API endpoint.",
270 sub get_supported_plugins
{
277 description
=> "API plugin name",
279 enum
=> [sort keys %$plugins],
283 description
=> 'DNS plugin data. (base64 encoded)',
285 'validation-delay' => {
287 description
=> 'Extra delay in seconds to wait before requesting validation.'
288 .' Allows to cope with a long TTL of DNS records.',
289 # low default, but our bet is that the acme-challenge domain isn't
290 # cached at all, so it hopefully shouldn't run into TTL issues
294 maximum
=> 2 * 24 * 60 * 60,
302 data
=> { optional
=> 1 },
303 nodes
=> { optional
=> 1 },
304 disable
=> { optional
=> 1 },
305 'validation-delay' => { optional
=> 1 },
309 my $proxmox_acme_command = sub {
310 my ($self, $acme, $auth, $data, $action) = @_;
312 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
314 my $alias = $data->{alias
};
315 my $domain = $auth->{identifier
}->{value
};
317 my $challenge = $self->extract_challenge($auth->{challenges
});
318 my $key_auth = $acme->key_authorization($challenge->{token
});
320 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
321 my $dnsplugin = $data->{plugin
}->{api
};
322 my $plugin_conf_string = $data->{plugin
}->{data
};
324 # for security reasons, we execute the command as nobody
325 # we can't verify that the code of the DNSPlugins are harmless.
326 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
328 # The order of the parameters passed to proxmox-acme is important
329 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
330 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
336 my $input = "$txtvalue\n";
337 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
339 PVE
::Tools
::run_command
($cmd, input
=> $input);
341 $data->{url
} = $challenge->{url
};
347 my ($self, $acme, $auth, $data) = @_;
349 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
350 print "Add TXT record: _acme-challenge.$domain\n";
352 # FIXME: probe ourself for propagation of TXT record, while not 100%
353 # failsafe it's good enough of a heuristic to do away with fixed sleep
354 # intervalls - original acme.sh employs that heuristic too.
355 my $delay = $data->{'validation-delay'} // 30;
357 print "Sleeping $delay seconds to wait for TXT record propagation\n";
358 sleep($delay); # don't care for EINTR
363 my ($self, $acme, $auth, $data) = @_;
365 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
366 print "Remove TXT record: _acme-challenge.$domain\n";