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",
39 'ACMEDNS_UPDATE_URL' => {
40 description
=> 'The API update endpoint',
43 'ACMEDNS_USERNAME' => {
44 description
=> 'The acme-dns user',
47 'ACMEDNS_PASSWORD' => {
48 description
=> 'The acme-dns password',
51 'ACMEDNS_SUBDOMAIN' => {
52 description
=> 'The subdomain you got from acme-dns registration',
62 description
=> "The API key",
71 description
=> "The API key",
77 name
=> 'Alibaba Cloud DNS',
80 description
=> 'The API endpoint',
81 default => "https://alidns.aliyuncs.com/",
86 description
=> 'The API Key',
90 description
=> 'The API Secret',
99 name
=> 'Amazon Route53 (AWS)',
101 'AWS_ACCESS_KEY_ID' => {
102 name
=> 'ACCESS_KEY_ID',
103 description
=> 'The AWS access-key ID',
106 'AWS_SECRET_ACCESS_KEY' => {
107 name
=> 'SECRET_ACCESS_KEY',
108 description
=> 'The AWS access-key secret',
115 name
=> 'Cloudflare Managed DNS',
116 description
=> 'Either provide global account key and email, or CF API token and Account ID.',
119 description
=> 'The Cloudflare Global API Key',
123 description
=> 'The Cloudflare Account EMail-Address',
127 description
=> 'The new Cloudflare API Token',
131 description
=> 'The new Cloudflare API Account ID',
135 description
=> 'For Zone restricted API Token',
152 name
=> 'DigitalOcean DNS',
155 description
=> 'The DigitalOcean API Key',
177 'gandi_livedns' => {},
183 description
=> 'The GoDaddy API Key',
187 description
=> 'The GoDaddy API Secret',
205 description
=> 'The INWX username',
209 description
=> 'The INWX password',
218 name
=> 'kapper.net',
220 'KAPPERNETDNS_Key' => {
221 description
=> 'Your kapper.net API key',
224 'KAPPERNETDNS_Secret' => {
225 description
=> 'Your kapper.net API secret',
262 'openprovider' => {},
269 description
=> "The OVH endpoint",
275 description
=> "The application key.",
279 description
=> "The application secret.",
283 description
=> "The consumer key.",
290 name
=> 'PowerDNS server',
293 description
=> "The PowerDNS API endpoint.",
329 sub get_supported_plugins
{
336 description
=> "API plugin name",
338 enum
=> [sort keys %$plugins],
342 description
=> 'DNS plugin data. (base64 encoded)',
344 'validation-delay' => {
346 description
=> 'Extra delay in seconds to wait before requesting validation.'
347 .' Allows to cope with a long TTL of DNS records.',
348 # low default, but our bet is that the acme-challenge domain isn't
349 # cached at all, so it hopefully shouldn't run into TTL issues
353 maximum
=> 2 * 24 * 60 * 60,
361 data
=> { optional
=> 1 },
362 nodes
=> { optional
=> 1 },
363 disable
=> { optional
=> 1 },
364 'validation-delay' => { optional
=> 1 },
368 my $proxmox_acme_command = sub {
369 my ($self, $acme, $auth, $data, $action) = @_;
371 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
373 my $alias = $data->{alias
};
374 my $domain = $auth->{identifier
}->{value
};
376 my $challenge = $self->extract_challenge($auth->{challenges
});
377 my $key_auth = $acme->key_authorization($challenge->{token
});
379 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
380 my $dnsplugin = $data->{plugin
}->{api
};
381 my $plugin_conf_string = $data->{plugin
}->{data
};
383 # for security reasons, we execute the command as nobody
384 # we can't verify that the code of the DNSPlugins are harmless.
385 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
387 # The order of the parameters passed to proxmox-acme is important
388 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
389 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
395 my $input = "$txtvalue\n";
396 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
398 PVE
::Tools
::run_command
($cmd, input
=> $input);
400 $data->{url
} = $challenge->{url
};
406 my ($self, $acme, $auth, $data) = @_;
408 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
409 print "Add TXT record: _acme-challenge.$domain\n";
411 my $delay = $data->{plugin
}->{'validation-delay'} // 30;
413 print "Sleeping $delay seconds to wait for TXT record propagation\n";
414 sleep($delay); # don't care for EINTR
419 my ($self, $acme, $auth, $data) = @_;
421 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
422 print "Remove TXT record: _acme-challenge.$domain\n";