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