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