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",
42 description
=> "The API key",
51 description
=> "The API key",
57 name
=> 'Alibaba Cloud DNS',
60 description
=> 'The API endpoint',
61 default => "https://alidns.aliyuncs.com/",
66 description
=> 'The API Key',
70 description
=> 'The API Secret',
79 name
=> 'Amazon Route53 (AWS)',
81 'AWS_ACCESS_KEY_ID' => {
82 name
=> 'ACCESS_KEY_ID',
83 description
=> 'The AWS access-key ID',
86 'AWS_SECRET_ACCESS_KEY' => {
87 name
=> 'SECRET_ACCESS_KEY',
88 description
=> 'The AWS access-key secret',
95 name
=> 'Cloudflare Managed DNS',
96 description
=> 'Either provide global account key and email, or CF API token and Account ID.',
99 description
=> 'The Cloudflare Global API Key',
103 description
=> 'The Cloudflare Account EMail-Address',
107 description
=> 'The new Cloudflare API Token',
111 description
=> 'The new Cloudflare API Account ID',
115 description
=> 'For Zone restricted API Token',
132 name
=> 'DigitalOcean DNS',
135 description
=> 'The DigitalOcean API Key',
157 'gandi_livedns' => {},
163 description
=> 'The GoDaddy API Key',
167 description
=> 'The GoDaddy API Secret',
185 description
=> 'The INWX username',
189 description
=> 'The INWX password',
230 'openprovider' => {},
237 description
=> "The OVH endpoint",
243 description
=> "The application key.",
247 description
=> "The application secret.",
251 description
=> "The consumer key.",
258 name
=> 'PowerDNS server',
261 description
=> "The PowerDNS API endpoint.",
297 sub get_supported_plugins
{
304 description
=> "API plugin name",
306 enum
=> [sort keys %$plugins],
310 description
=> 'DNS plugin data. (base64 encoded)',
312 'validation-delay' => {
314 description
=> 'Extra delay in seconds to wait before requesting validation.'
315 .' Allows to cope with a long TTL of DNS records.',
316 # low default, but our bet is that the acme-challenge domain isn't
317 # cached at all, so it hopefully shouldn't run into TTL issues
321 maximum
=> 2 * 24 * 60 * 60,
329 data
=> { optional
=> 1 },
330 nodes
=> { optional
=> 1 },
331 disable
=> { optional
=> 1 },
332 'validation-delay' => { optional
=> 1 },
336 my $proxmox_acme_command = sub {
337 my ($self, $acme, $auth, $data, $action) = @_;
339 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
341 my $alias = $data->{alias
};
342 my $domain = $auth->{identifier
}->{value
};
344 my $challenge = $self->extract_challenge($auth->{challenges
});
345 my $key_auth = $acme->key_authorization($challenge->{token
});
347 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
348 my $dnsplugin = $data->{plugin
}->{api
};
349 my $plugin_conf_string = $data->{plugin
}->{data
};
351 # for security reasons, we execute the command as nobody
352 # we can't verify that the code of the DNSPlugins are harmless.
353 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
355 # The order of the parameters passed to proxmox-acme is important
356 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
357 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
363 my $input = "$txtvalue\n";
364 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
366 PVE
::Tools
::run_command
($cmd, input
=> $input);
368 $data->{url
} = $challenge->{url
};
374 my ($self, $acme, $auth, $data) = @_;
376 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
377 print "Add TXT record: _acme-challenge.$domain\n";
379 my $delay = $data->{plugin
}->{'validation-delay'} // 30;
381 print "Sleeping $delay seconds to wait for TXT record propagation\n";
382 sleep($delay); # don't care for EINTR
387 my ($self, $acme, $auth, $data) = @_;
389 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
390 print "Remove TXT record: _acme-challenge.$domain\n";