]> git.proxmox.com Git - proxmox-acme.git/blob - src/PVE/ACME/DNSChallenge.pm
632210e623c57d55f80b9aeda8fbaa312d9dc373
[proxmox-acme.git] / src / PVE / ACME / DNSChallenge.pm
1 package PVE::ACME::DNSChallenge;
2
3 use strict;
4 use warnings;
5
6 use Digest::SHA qw(sha256);
7 use PVE::Tools;
8
9 use PVE::ACME;
10
11 use base qw(PVE::ACME::Challenge);
12
13 my $ACME_PATH = '/usr/share/proxmox-acme/proxmox-acme';
14
15 sub supported_challenge_types {
16 return ["dns-01"];
17 }
18
19 sub type {
20 return 'dns';
21 }
22
23 # describe the data schema of the supported plugins, e.g.:
24 # 'dnsprovider' => {
25 # name => 'Full name of Plugin',
26 # fields => {
27 # 'FOO_API_KEY' => {
28 # description => "The API key",
29 # default => "none",
30 # optional => 1,
31 # type => 'string',
32 # },
33 # # ...
34 # },
35 # },
36 my $plugins = {
37 '1984hosting' => {},
38 'acmedns' => {
39 name => 'acme-dns',
40 fields => {
41 'ACMEDNS_UPDATE_URL' => {
42 description => 'The API update endpoint',
43 type => 'string',
44 },
45 'ACMEDNS_USERNAME' => {
46 description => 'The acme-dns user',
47 type => 'string',
48 },
49 'ACMEDNS_PASSWORD' => {
50 description => 'The acme-dns password',
51 type => 'string',
52 },
53 'ACMEDNS_SUBDOMAIN' => {
54 description => 'The subdomain you got from acme-dns registration',
55 type => 'string',
56 },
57 },
58 },
59 'acmeproxy' => {},
60 'active24' => {
61 name => 'Active24',
62 fields => {
63 'ACTIVE24_Token' => {
64 description => "The API key",
65 type => 'string',
66 },
67 },
68 },
69 'ad' => {
70 name => 'Alwaysdata',
71 fields => {
72 'AD_API_KEY' => {
73 description => "The API key",
74 type => 'string',
75 },
76 },
77 },
78 'ali' => {
79 name => 'Alibaba Cloud DNS',
80 fields => {
81 'Ali_API' => {
82 description => 'The API endpoint',
83 default => "https://alidns.aliyuncs.com/",
84 type => 'string',
85 optional => 1,
86 },
87 'Ali_Key' => {
88 description => 'The API Key',
89 type => 'string',
90 },
91 'Ali_Secret' => {
92 description => 'The API Secret',
93 type => 'string',
94 },
95 },
96 },
97 'anx' => {},
98 'arvan' => {},
99 'autodns' => {},
100 'aws' => {
101 name => 'Amazon Route53 (AWS)',
102 fields => {
103 'AWS_ACCESS_KEY_ID' => {
104 name => 'ACCESS_KEY_ID',
105 description => 'The AWS access-key ID',
106 type => 'string',
107 },
108 'AWS_SECRET_ACCESS_KEY' => {
109 name => 'SECRET_ACCESS_KEY',
110 description => 'The AWS access-key secret',
111 type => 'string',
112 },
113 },
114 },
115 'azure' => {},
116 'cf' => {
117 name => 'Cloudflare Managed DNS',
118 description => 'Either provide global account key and email, or CF API token and Account ID.',
119 fields => {
120 'CF_Key' => {
121 description => 'The Cloudflare Global API Key',
122 type => 'string',
123 },
124 'CF_Email' => {
125 description => 'The Cloudflare Account EMail-Address',
126 type => 'string',
127 },
128 'CF_Token' => {
129 description => 'The new Cloudflare API Token',
130 type => 'string',
131 },
132 'CF_Account_ID' => {
133 description => 'The new Cloudflare API Account ID',
134 type => 'string',
135 },
136 'CF_Zone_ID' => {
137 description => 'For Zone restricted API Token',
138 type => 'string',
139 },
140 },
141 },
142 'clouddns' => {},
143 'cloudns' => {},
144 'cn' => {},
145 'conoha' => {},
146 'constellix' => {},
147 'cx' => {},
148 'cyon' => {},
149 'da' => {},
150 'ddnss' => {},
151 'desec' => {},
152 'df' => {},
153 'dgon' => {
154 name => 'DigitalOcean DNS',
155 fields => {
156 'DO_API_KEY' => {
157 description => 'The DigitalOcean API Key',
158 type => 'string',
159 },
160 },
161 },
162 'dnsimple' => {},
163 'do' => {},
164 'doapi' => {},
165 'domeneshop' => {},
166 'dp' => {},
167 'dpi' => {},
168 'dreamhost' => {},
169 'duckdns' => {},
170 'durabledns' => {},
171 'dyn' => {},
172 'dynu' => {},
173 'dynv6' => {},
174 'easydns' => {},
175 'edgedns' => {},
176 'euserv' => {},
177 'exoscale' => {},
178 'freedns' => {},
179 'gandi_livedns' => {},
180 'gcloud' => {},
181 'gd' => {
182 name => 'GoDaddy',
183 fields => {
184 'GD_Key' => {
185 description => 'The GoDaddy API Key',
186 type => 'string',
187 },
188 'GD_Secret' => {
189 description => 'The GoDaddy API Secret',
190 type => 'string',
191 },
192 },
193 },
194 'gdnsdk' => {},
195 'he' => {},
196 'hetzner' => {},
197 'hexonet' => {},
198 'hostingde' => {},
199 'huaweicloud' => {},
200 'infoblox' => {},
201 'infomaniak' => {},
202 'internetbs' => {},
203 'inwx' => {
204 name => 'INWX',
205 fields => {
206 'INWX_User' => {
207 description => 'The INWX username',
208 type => 'string',
209 },
210 'INWX_Password' => {
211 description => 'The INWX password',
212 type => 'string',
213 },
214 },
215 },
216 'ispconfig' => {},
217 'jd' => {},
218 'joker' => {},
219 'kappernet' => {
220 name => 'kapper.net',
221 fields => {
222 'KAPPERNETDNS_Key' => {
223 description => 'Your kapper.net API key',
224 type => 'string',
225 },
226 'KAPPERNETDNS_Secret' => {
227 description => 'Your kapper.net API secret',
228 type => 'string',
229 },
230 },
231 },
232 'kas' => {},
233 'kinghost' => {},
234 'knot' => {},
235 'leaseweb' => {},
236 'lexicon' => {},
237 'linode' => {},
238 'linode_v4' => {},
239 'loopia' => {},
240 'lua' => {},
241 'maradns' => {},
242 'me' => {},
243 'miab' => {},
244 'misaka' => {},
245 'myapi' => {},
246 'mydevil' => {},
247 'mydnsjp' => {},
248 'namecheap' => {},
249 'namecom' => {},
250 'namesilo' => {},
251 'nederhost' => {},
252 'neodigit' => {},
253 'netcup' => {},
254 'netlify' => {},
255 'nic' => {},
256 'njalla' => {},
257 'nm' => {},
258 'nsd' => {},
259 'nsone' => {},
260 'nsupdate' => {},
261 'nw' => {},
262 'one' => {},
263 'online' => {},
264 'openprovider' => {},
265 'openstack' => {},
266 'opnsense' => {},
267 'ovh' => {
268 name => 'OVH',
269 fields => {
270 'OVH_END_POINT' => {
271 description => "The OVH endpoint",
272 default => "ovh-eu",
273 optional => 1,
274 type => 'string',
275 },
276 'OVH_AK' => {
277 description => "The application key.",
278 type => 'string',
279 },
280 'OVH_AS' => {
281 description => "The application secret.",
282 type => 'string',
283 },
284 'OVH_CK' => {
285 description => "The consumer key.",
286 optional => 1,
287 type => 'string',
288 },
289 },
290 },
291 'pdns' => {
292 name => 'PowerDNS server',
293 fields => {
294 'PDNS_Url' => {
295 description => "The PowerDNS API endpoint.",
296 type => 'string',
297 },
298 'PDNS_ServerId'=> {
299 type => 'string',
300 },
301 'PDNS_Token'=> {
302 type => 'string',
303 },
304 'PDNS_Ttl'=> {
305 type => 'integer',
306 },
307 },
308 },
309 'pleskxml' => {},
310 'pointhq' => {},
311 'rackspace' => {},
312 'rcode0' => {},
313 'regru' => {},
314 'schlundtech' => {},
315 'selectel' => {},
316 'servercow' => {},
317 'tele3' => {},
318 'transip' => {},
319 'ultra' => {},
320 'unoeuro' => {},
321 'variomedia' => {},
322 'vscale' => {},
323 'vultr' => {},
324 'world4you' => {},
325 'yandex' => {},
326 'zilore' => {},
327 'zone' => {},
328 'zonomi' => {},
329 };
330
331 sub get_supported_plugins {
332 return $plugins;
333 }
334
335 sub properties {
336 return {
337 api => {
338 description => "API plugin name",
339 type => 'string',
340 enum => [sort keys %$plugins],
341 },
342 data => {
343 type => 'string',
344 description => 'DNS plugin data. (base64 encoded)',
345 },
346 'validation-delay' => {
347 type => 'integer',
348 description => 'Extra delay in seconds to wait before requesting validation.'
349 .' Allows to cope with a long TTL of DNS records.',
350 # low default, but our bet is that the acme-challenge domain isn't
351 # cached at all, so it hopefully shouldn't run into TTL issues
352 default => 30,
353 optional => 1,
354 minimum => 0,
355 maximum => 2 * 24 * 60 * 60,
356 }
357 };
358 }
359
360 sub options {
361 return {
362 api => {},
363 data => { optional => 1 },
364 nodes => { optional => 1 },
365 disable => { optional => 1 },
366 'validation-delay' => { optional => 1 },
367 };
368 }
369
370 my $proxmox_acme_command = sub {
371 my ($self, $acme, $auth, $data, $action) = @_;
372
373 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin});
374
375 my $alias = $data->{alias};
376 my $domain = $auth->{identifier}->{value};
377
378 my $challenge = $self->extract_challenge($auth->{challenges});
379 my $key_auth = $acme->key_authorization($challenge->{token});
380
381 my $txtvalue = PVE::ACME::encode(sha256($key_auth));
382 my $dnsplugin = $data->{plugin}->{api};
383 my $plugin_conf_string = $data->{plugin}->{data};
384
385 # for security reasons, we execute the command as nobody
386 # we can't verify that the code of the DNSPlugins are harmless.
387 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
388
389 # The order of the parameters passed to proxmox-acme is important
390 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
391 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
392 if ($alias) {
393 push @$cmd, $alias;
394 } else {
395 push @$cmd, $domain;
396 }
397 my $input = "$txtvalue\n";
398 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
399
400 PVE::Tools::run_command($cmd, input => $input);
401
402 $data->{url} = $challenge->{url};
403
404 return $domain;
405 };
406
407 sub setup {
408 my ($self, $acme, $auth, $data) = @_;
409
410 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
411 print "Add TXT record: _acme-challenge.$domain\n";
412
413 my $delay = $data->{plugin}->{'validation-delay'} // 30;
414 if ($delay > 0) {
415 print "Sleeping $delay seconds to wait for TXT record propagation\n";
416 sleep($delay); # don't care for EINTR
417 }
418 }
419
420 sub teardown {
421 my ($self, $acme, $auth, $data) = @_;
422
423 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
424 print "Remove TXT record: _acme-challenge.$domain\n";
425 }
426
427 1;