]> git.proxmox.com Git - proxmox-acme.git/blame - src/PVE/ACME/DNSChallenge.pm
dns challenge: add world4you schema
[proxmox-acme.git] / src / PVE / ACME / DNSChallenge.pm
CommitLineData
98b96d9e
WL
1package PVE::ACME::DNSChallenge;
2
3use strict;
4use warnings;
5
6use Digest::SHA qw(sha256);
7use PVE::Tools;
8
c617455e
WB
9use PVE::ACME;
10
98b96d9e
WL
11use base qw(PVE::ACME::Challenge);
12
13my $ACME_PATH = '/usr/share/proxmox-acme/proxmox-acme';
14
15sub supported_challenge_types {
122626b3 16 return ["dns-01"];
98b96d9e
WL
17}
18
19sub type {
20 return 'dns';
21}
22
aa7b91cb
TL
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# },
6f5be4aa 36my $plugins = {
da7c723f 37 '1984hosting' => {},
dfc8695d
TL
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 },
6f5be4aa 59 'acmeproxy' => {},
aa7b91cb
TL
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 },
da7c723f
TL
97 'anx' => {},
98 'arvan' => {},
0663394d
TL
99 'aurora' => {
100 name => 'AuroraDNS',
101 fields => {
102 'AURORA_Key' => {
103 description => 'The API Key',
104 type => 'string',
105 },
106 'AURORA_Secret' => {
107 description => 'The API Secret',
108 type => 'string',
109 },
110 },
111 },
6f5be4aa 112 'autodns' => {},
aa7b91cb
TL
113 'aws' => {
114 name => 'Amazon Route53 (AWS)',
115 fields => {
116 'AWS_ACCESS_KEY_ID' => {
117 name => 'ACCESS_KEY_ID',
118 description => 'The AWS access-key ID',
119 type => 'string',
120 },
121 'AWS_SECRET_ACCESS_KEY' => {
122 name => 'SECRET_ACCESS_KEY',
123 description => 'The AWS access-key secret',
124 type => 'string',
125 },
126 },
127 },
6f5be4aa 128 'azure' => {},
aa7b91cb
TL
129 'cf' => {
130 name => 'Cloudflare Managed DNS',
131 description => 'Either provide global account key and email, or CF API token and Account ID.',
132 fields => {
133 'CF_Key' => {
134 description => 'The Cloudflare Global API Key',
135 type => 'string',
136 },
137 'CF_Email' => {
138 description => 'The Cloudflare Account EMail-Address',
139 type => 'string',
140 },
141 'CF_Token' => {
142 description => 'The new Cloudflare API Token',
143 type => 'string',
144 },
145 'CF_Account_ID' => {
146 description => 'The new Cloudflare API Account ID',
147 type => 'string',
148 },
149 'CF_Zone_ID' => {
150 description => 'For Zone restricted API Token',
151 type => 'string',
152 },
153 },
154 },
6f5be4aa
DC
155 'clouddns' => {},
156 'cloudns' => {},
157 'cn' => {},
158 'conoha' => {},
159 'constellix' => {},
160 'cx' => {},
161 'cyon' => {},
162 'da' => {},
163 'ddnss' => {},
164 'desec' => {},
ec59606a 165 'df' => {},
231ed7c0
TL
166 'dgon' => {
167 name => 'DigitalOcean DNS',
168 fields => {
169 'DO_API_KEY' => {
170 description => 'The DigitalOcean API Key',
171 type => 'string',
172 },
173 },
174 },
6f5be4aa
DC
175 'dnsimple' => {},
176 'do' => {},
177 'doapi' => {},
178 'domeneshop' => {},
179 'dp' => {},
180 'dpi' => {},
181 'dreamhost' => {},
182 'duckdns' => {},
183 'durabledns' => {},
184 'dyn' => {},
185 'dynu' => {},
186 'dynv6' => {},
187 'easydns' => {},
da7c723f 188 'edgedns' => {},
6f5be4aa
DC
189 'euserv' => {},
190 'exoscale' => {},
191 'freedns' => {},
192 'gandi_livedns' => {},
193 'gcloud' => {},
aa7b91cb
TL
194 'gd' => {
195 name => 'GoDaddy',
196 fields => {
197 'GD_Key' => {
198 description => 'The GoDaddy API Key',
199 type => 'string',
200 },
201 'GD_Secret' => {
202 description => 'The GoDaddy API Secret',
203 type => 'string',
204 },
205 },
206 },
6f5be4aa
DC
207 'gdnsdk' => {},
208 'he' => {},
da7c723f 209 'hetzner' => {},
6f5be4aa
DC
210 'hexonet' => {},
211 'hostingde' => {},
da7c723f 212 'huaweicloud' => {},
6f5be4aa 213 'infoblox' => {},
da7c723f 214 'infomaniak' => {},
6f5be4aa 215 'internetbs' => {},
956b5190
TL
216 'inwx' => {
217 name => 'INWX',
218 fields => {
219 'INWX_User' => {
220 description => 'The INWX username',
221 type => 'string',
222 },
223 'INWX_Password' => {
224 description => 'The INWX password',
225 type => 'string',
226 },
227 },
228 },
21e6ed30 229 'ionos' => {},
6f5be4aa
DC
230 'ispconfig' => {},
231 'jd' => {},
da7c723f 232 'joker' => {},
dfc8695d
TL
233 'kappernet' => {
234 name => 'kapper.net',
235 fields => {
236 'KAPPERNETDNS_Key' => {
237 description => 'Your kapper.net API key',
238 type => 'string',
239 },
240 'KAPPERNETDNS_Secret' => {
241 description => 'Your kapper.net API secret',
242 type => 'string',
243 },
244 },
245 },
6f5be4aa
DC
246 'kas' => {},
247 'kinghost' => {},
248 'knot' => {},
249 'leaseweb' => {},
250 'lexicon' => {},
251 'linode' => {},
252 'linode_v4' => {},
253 'loopia' => {},
254 'lua' => {},
255 'maradns' => {},
256 'me' => {},
257 'miab' => {},
258 'misaka' => {},
259 'myapi' => {},
260 'mydevil' => {},
261 'mydnsjp' => {},
262 'namecheap' => {},
263 'namecom' => {},
264 'namesilo' => {},
265 'nederhost' => {},
266 'neodigit' => {},
267 'netcup' => {},
da7c723f 268 'netlify' => {},
6f5be4aa 269 'nic' => {},
da7c723f
TL
270 'njalla' => {},
271 'nm' => {},
6f5be4aa
DC
272 'nsd' => {},
273 'nsone' => {},
274 'nsupdate' => {},
275 'nw' => {},
276 'one' => {},
277 'online' => {},
278 'openprovider' => {},
da7c723f 279 'openstack' => {},
6f5be4aa
DC
280 'opnsense' => {},
281 'ovh' => {
dfd2aa27
TL
282 name => 'OVH',
283 fields => {
284 'OVH_END_POINT' => {
285 description => "The OVH endpoint",
286 default => "ovh-eu",
287 optional => 1,
288 type => 'string',
289 },
290 'OVH_AK' => {
291 description => "The application key.",
292 type => 'string',
293 },
294 'OVH_AS' => {
295 description => "The application secret.",
296 type => 'string',
297 },
298 'OVH_CK' => {
299 description => "The consumer key.",
300 optional => 1,
301 type => 'string',
302 },
69ce6537 303 },
6f5be4aa
DC
304 },
305 'pdns' => {
dfd2aa27
TL
306 name => 'PowerDNS server',
307 fields => {
308 'PDNS_Url' => {
309 description => "The PowerDNS API endpoint.",
310 type => 'string',
311 },
312 'PDNS_ServerId'=> {
313 type => 'string',
314 },
315 'PDNS_Token'=> {
316 type => 'string',
317 },
318 'PDNS_Ttl'=> {
319 type => 'integer',
320 },
6f5be4aa
DC
321 },
322 },
323 'pleskxml' => {},
324 'pointhq' => {},
0663394d
TL
325 'porkbun' => {
326 name => 'Porkbun',
327 fields => {
328 'PORKBUN_API_KEY' => {
329 description => 'The API Key',
330 type => 'string',
331 },
332 'PORKBUN_SECRET_API_KEY' => {
333 description => 'The API Secret',
334 type => 'string',
335 },
336 },
337 },
21e6ed30 338 'rackcorp' => {},
6f5be4aa
DC
339 'rackspace' => {},
340 'rcode0' => {},
341 'regru' => {},
21e6ed30 342 'scaleway' => {},
6f5be4aa
DC
343 'schlundtech' => {},
344 'selectel' => {},
345 'servercow' => {},
21e6ed30 346 'simply' => {},
6f5be4aa 347 'tele3' => {},
da7c723f 348 'transip' => {},
6f5be4aa
DC
349 'ultra' => {},
350 'unoeuro' => {},
351 'variomedia' => {},
352 'vscale' => {},
353 'vultr' => {},
da91f536
LS
354 'world4you' => {
355 name => 'World4You',
356 fields => {
357 'WORLD4YOU_USERNAME' => {
358 description => "The World4You customer id or package id",
359 type => 'string',
360 },
361 'WORLD4YOU_PASSWORD' => {
362 description => "The World4You password",
363 type => 'string',
364 },
365 },
366 },
0663394d 367 'websupport' => {},
6f5be4aa
DC
368 'yandex' => {},
369 'zilore' => {},
370 'zone' => {},
371 'zonomi' => {},
372};
373
e3924936 374sub get_supported_plugins {
6f5be4aa 375 return $plugins;
e3924936 376}
98b96d9e
WL
377
378sub properties {
379 return {
380 api => {
381 description => "API plugin name",
382 type => 'string',
6f5be4aa 383 enum => [sort keys %$plugins],
98b96d9e
WL
384 },
385 data => {
386 type => 'string',
6372e898 387 description => 'DNS plugin data. (base64 encoded)',
98b96d9e 388 },
4317ba99
TL
389 'validation-delay' => {
390 type => 'integer',
391 description => 'Extra delay in seconds to wait before requesting validation.'
392 .' Allows to cope with a long TTL of DNS records.',
393 # low default, but our bet is that the acme-challenge domain isn't
394 # cached at all, so it hopefully shouldn't run into TTL issues
395 default => 30,
396 optional => 1,
397 minimum => 0,
398 maximum => 2 * 24 * 60 * 60,
399 }
98b96d9e
WL
400 };
401}
402
403sub options {
404 return {
405 api => {},
13b63882 406 data => { optional => 1 },
98b96d9e
WL
407 nodes => { optional => 1 },
408 disable => { optional => 1 },
4317ba99 409 'validation-delay' => { optional => 1 },
98b96d9e
WL
410 };
411}
412
f00829fd
FG
413my $proxmox_acme_command = sub {
414 my ($self, $acme, $auth, $data, $action) = @_;
98b96d9e
WL
415
416 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin});
f00829fd
FG
417
418 my $alias = $data->{alias};
419 my $domain = $auth->{identifier}->{value};
420
421 my $challenge = $self->extract_challenge($auth->{challenges});
422 my $key_auth = $acme->key_authorization($challenge->{token});
423
424 my $txtvalue = PVE::ACME::encode(sha256($key_auth));
98b96d9e
WL
425 my $dnsplugin = $data->{plugin}->{api};
426 my $plugin_conf_string = $data->{plugin}->{data};
427
428 # for security reasons, we execute the command as nobody
429 # we can't verify that the code of the DNSPlugins are harmless.
f0ed0733 430 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
98b96d9e 431
f00829fd
FG
432 # The order of the parameters passed to proxmox-acme is important
433 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
434 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
435 if ($alias) {
436 push @$cmd, $alias;
437 } else {
438 push @$cmd, $domain;
439 }
13bc64ea
FG
440 my $input = "$txtvalue\n";
441 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
f00829fd 442
13bc64ea 443 PVE::Tools::run_command($cmd, input => $input);
f00829fd
FG
444
445 $data->{url} = $challenge->{url};
446
447 return $domain;
448};
449
450sub setup {
451 my ($self, $acme, $auth, $data) = @_;
452
453 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
98b96d9e 454 print "Add TXT record: _acme-challenge.$domain\n";
4317ba99 455
1192b595 456 my $delay = $data->{plugin}->{'validation-delay'} // 30;
4317ba99
TL
457 if ($delay > 0) {
458 print "Sleeping $delay seconds to wait for TXT record propagation\n";
459 sleep($delay); # don't care for EINTR
460 }
98b96d9e
WL
461}
462
98b96d9e 463sub teardown {
f00829fd 464 my ($self, $acme, $auth, $data) = @_;
98b96d9e 465
f00829fd 466 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
98b96d9e
WL
467 print "Remove TXT record: _acme-challenge.$domain\n";
468}
469
4701;