3 nbdkit-curl-plugin - nbdkit curl plugin (HTTP, FTP and other protocols)
7 nbdkit -r curl [url=]http://example.com/disk.img
11 C<nbdkit-curl-plugin> is a plugin for L<nbdkit(1)> which turns content
12 served over HTTP, FTP, and more, into a Network Block Device. It uses
13 a library called libcurl (also known as cURL) to read data from URLs.
14 The exact list of protocols that libcurl can handle depends on how it
15 was compiled, but most versions will handle HTTP, HTTPS, FTP, FTPS and
16 more (see: S<C<curl -V>>).
18 B<Note:> This plugin supports writes. However for HTTP, you may not
19 want nbdkit to issue PUT requests to the remote server (which probably
20 doesn't understand them). To force nbdkit to use a readonly
21 connection, pass the I<-r> flag. Using the I<-r> flag also enables
22 NBD multi-conn, which usually performs much better (if the client
25 Although this plugin can access SFTP (ie. SSH) servers, it is much
26 better to use L<nbdkit-ssh-plugin(1)>. This plugin can be used to
27 access C<file:///> URLs, but you should use L<nbdkit-file-plugin(1)>
32 nbdkit -r curl http://example.com/disk.img
34 serves the remote disk image as NBD on TCP port 10809 (to control
35 ports and protocols used to serve NBD see L<nbdkit(1)>).
41 =item B<cainfo=>FILENAME
45 Configure CA bundle for libcurl. See L<CURLOPT_CAINFO(3)> for details.
47 Pass empty string in order to not use the default certificate store
48 that libcurl is compiled with.
54 Set CA certificates directory location for libcurl. See
55 L<CURLOPT_CAPATH(3)> for more information.
57 =item B<connections=>N
59 Open up to C<N> curl connections to the web server. The default is 4.
60 Curl connections are shared between all NBD clients, so you may wish
61 to increase this if you expect many simultaneous NBD clients (or a
62 single client using many multi-conn connections).
64 See L</NBD CONNECTIONS AND CURL HANDLES> below.
66 =item B<cookie=>COOKIE
68 =item B<cookie=+>FILENAME
76 Set a cookie in the request header when connecting to the remote
81 cookie='vmware_soap_session="52a01262-bf93-ccce-d379-8dabb3e55560"'
83 This option can be used at most once. It only works for HTTP and
84 HTTPS transports. To set multiple cookies you must concatenate them
87 cookie='name1=content1; name2=content2'
89 See L<CURLOPT_COOKIE(3)> for more information about this. The format
90 is quite strict and must consist of C<key=value>, each cookie
91 separated by exactly S<C<"; ">> (semicolon and space).
93 If the cookie is used for authentication then passing it on the
94 command line is not secure on shared machines. Use the alternate
95 C<+FILENAME> syntax to pass it in a file, C<-> to read the cookie
96 interactively, or C<-FD> to read it from a file descriptor.
102 Enable cookie processing (eg. when following redirects), starting with
103 an empty list of cookies. This is equivalent to calling
104 L<CURLOPT_COOKIEFILE(3)> with an empty string.
106 =item B<cookiefile=>FILENAME
110 Enable cookie processing (eg. when following redirects), prepopulating
111 cookies from the given file. The file can contain cookies in any
112 format supported by curl, see L<CURLOPT_COOKIEFILE(3)>. Cookies sent
113 by the server are not saved when nbdkit exits.
115 =item B<cookiejar=>FILENAME
119 Enable cookie processing (eg. when following redirects), prepopulating
120 cookies from the given file, and writing server cookies back to the
121 file when the NBD handle is closed. The file can contain cookies in
122 any format supported by curl, see L<CURLOPT_COOKIEJAR(3)>.
124 There is some advice on the internet telling you to set this to
125 F</dev/null>, but you B<should not> do this because it can corrupt
126 F</dev/null>. If you don't want a cookiejar, omit this option. If
127 you want to enable cookie processing without updating a permanent
128 cookiejar, use the C<cookiefile=> option instead.
130 =item B<cookie-script=>SCRIPT
132 =item B<cookie-script-renew=>SECS
134 (nbdkit E<ge> 1.22, not Windows)
136 Run C<SCRIPT> (a command or shell script fragment) to generate the
137 HTTP/HTTPS cookies. C<cookie-script> cannot be used with C<cookie>.
138 See L</HEADER AND COOKIE SCRIPTS> below.
140 =item B<followlocation=false>
144 Do not follow redirects from the server. The default is true (follow
147 You can follow redirects but avoid redirecting to a less secure
148 protocol (eg. HTTPS redirecting to FTP) by using the C<protocols>
151 =item B<header=>HEADER
155 For HTTP/HTTPS, send a custom header, or remove a header that curl has
156 added. To add a custom header:
158 header='X-My-Name: John Doe'
160 To remove a header that curl has added, add the header followed by a
165 To add a custom header that has no value, you have to use a semicolon
166 instead of colon. This adds an C<X-Empty:> header with no value:
170 See L<CURLOPT_HTTPHEADER(3)>. You can use this option multiple times
171 in order to add several headers. Note this sends the header in all
172 requests, even when following a redirect, which can cause headers
173 (eg. containing sensitive authorization information) to be sent to
174 hosts other than the one originally requested.
176 =item B<header-script=>SCRIPT
178 =item B<header-script-renew=>SECS
180 (nbdkit E<ge> 1.22, not Windows)
182 Run C<SCRIPT> (a command or shell script fragment) to generate the
183 HTTP/HTTPS headers. C<header-script> cannot be used with C<header>.
184 See L</HEADER AND COOKIE SCRIPTS> below.
186 =item B<password=>PASSWORD
188 Set the password to use when connecting to the remote server.
190 Note that passing this on the command line is not secure on shared
195 Ask for the password (interactively) when nbdkit starts up.
197 =item B<password=+>FILENAME
199 Read the password from the named file. This is a secure method
200 to supply a password, as long as you set the permissions on the file
203 =item B<password=->FD
205 Read the password from file descriptor number C<FD>, inherited from
206 the parent process when nbdkit starts up. This is also a secure
207 method to supply a password.
209 =item B<protocols=>PROTO,PROTO,...
213 Limit the protocols that are allowed in the URL. Use this option for
214 extra security if the URL comes from an untrusted source and you want
215 to avoid security isues in the more obscure protocols that curl
216 supports. (See qemu CVE-2013-0249 for an example of a security bug
217 introduced by allowing unrestricted protocols).
219 For example if you only intend HTTP and HTTPS URLs to be used, then
220 add this parameter: C<protocols=http,https>
222 This restriction also applies if the plugin follows a redirect to
223 another protocol (eg. you start with an C<https://> URL which the
224 server redirects to C<ftp://>). To prevent redirects altogether see
225 the C<followlocation> parameter.
227 The value of this parameter is a comma-separated list of protocols,
228 for example C<protocols=https>, or C<protocols=http,https>, or
229 C<protocols=file,ftp,gopher>. For a list of known protocols, see the
230 libcurl manual (L<CURLOPT_PROTOCOLS_STR(3)>).
232 The default is to allow any protocol.
238 Set the proxy. See L<CURLOPT_PROXY(3)>.
240 =item B<proxy-password=>PASSWORD
242 =item B<proxy-password=->
244 =item B<proxy-password=+>FILENAME
246 =item B<proxy-password=->FD
248 =item B<proxy-user=>USERNAME
252 Set the proxy username and password.
254 =item B<sslverify=false>
256 Don't verify the SSL certificate of the remote host.
258 =item B<ssl-cipher-list=>CIPHER[:CIPHER...]
260 =item B<ssl-version=tlsv1>
262 =item B<ssl-version=sslv2>
264 =item B<ssl-version=sslv3>
266 =item B<ssl-version=tlsv1.0>
268 =item B<ssl-version=tlsv1.1>
270 =item B<ssl-version=tlsv1.2>
272 =item B<ssl-version=tlsv1.3>
274 Set the SSL ciphers and TLS version. For further information see
275 L<CURLOPT_SSL_CIPHER_LIST(3)> and L<CURLOPT_SSLVERSION(3)>.
277 =item B<tcp-keepalive=true>
281 Enable TCP keepalives.
283 =item B<tcp-nodelay=false>
287 Enable Nagle’s algorithm. Small writes on the network socket will not
288 be sent immediately but will be held in a local buffer and coalesced
289 if possible. This is more efficient for the network but can cause
292 The default (in libcurl E<ge> 7.50.2) is that Nagle’s algorithm is
293 disabled for better latency at the expense of network efficiency.
295 See L<CURLOPT_TCP_NODELAY(3)>.
297 =item B<timeout=>SECS
299 Set the timeout for requests.
303 Use the default libcurl timeout for requests.
305 =item B<tls13-ciphers=>CIPHER[:CIPHER...]
307 Select TLSv1.3 ciphers available. See L<CURLOPT_TLS13_CIPHERS(3)> and
308 L<https://curl.se/docs/ssl-ciphers.html>
310 =item B<unix-socket-path=>PATH
314 Instead of using a TCP connection, connect to the server over the
315 named Unix domain socket. See L<CURLOPT_UNIX_SOCKET_PATH(3)>.
319 The URL of the remote disk image. This is passed to libcurl directly
320 via L<CURLOPT_URL(3)>.
322 This parameter is required.
324 C<url=> is a magic config key and may be omitted in most cases.
325 See L<nbdkit(1)/Magic parameters>.
327 =item B<user=>USERNAME
329 Set the username to use when connecting to the remote server. This
330 may also be set in the URL (eg. C<http://foo@example.com/disk.img>)
332 =item B<user-agent=>USER-AGENT
336 Send user-agent header when using HTTP or HTTPS. The default is no
341 =head1 NBD CONNECTIONS AND CURL HANDLES
343 nbdkit E<le> 1.32 used a simple model where a new NBD connection would
344 create a new libcurl handle. In practice this meant there was a
345 1-to-1 relationship between NBD connections and HTTP connections to
346 the remote web server (assuming http: or https: URL).
348 nbdkit E<ge> 1.34 changed to using a fixed pool of libcurl handles
349 shared across all NBD connections. You can control the maximum number
350 of curl handles in the pool with the C<connections> parameter (default
351 4). Note that if there are more than 4 NBD connections, they will
352 share the 4 web server connections, unless you adjust C<connections>.
354 =head1 HEADER AND COOKIE SCRIPTS
356 While the C<header> and C<cookie> parameters can be used to specify
357 static headers and cookies which are used in every HTTP/HTTPS request,
358 the alternate C<header-script> and C<cookie-script> parameters can be
359 used to run an external script or program to generate headers and/or
360 cookies. This is particularly useful to access services which require
361 an authorization token. In addition the C<header-script-renew> and
362 C<cookie-script-renew> parameters allow you to renew the authorization
363 token by rerunning the script periodically.
365 C<header-script> is incompatible with C<header>, and C<cookie-script>
366 is incompatible with C<cookie>.
370 The header script should print zero or more HTTP headers, each line of
371 output in the same format as the C<header> parameter. The headers
372 printed by the script are passed to L<CURLOPT_HTTPHEADER(3)>.
374 In the following example, an imaginary web service requires
375 authentication using a token fetched from a separate login server.
376 The token expires after 60 seconds, so we also tell the plugin that it
377 must renew the token (by re-running the script) if more than 50
378 seconds have elapsed since the last request:
380 nbdkit curl https://service.example.com/disk.img \
382 printf "Authorization: Bearer "
383 curl -s -X POST https://auth.example.com/login |
386 header-script-renew=50
390 The cookie script should print a single line in the same format as the
391 C<cookie> parameter. This is passed to L<CURLOPT_COOKIE(3)>.
393 =head2 Header and cookie script shell variables
395 Within the C<header-script> and C<cookie-script> the following shell
396 variables are available:
402 The number of times that the script has been called. The first time
403 the script is called this contains C<0>.
407 The URL as passed to the plugin.
411 =head2 Example: VMware ESXi cookies
413 VMware ESXi’s web server can expose both VMDK and raw format disk
414 images, but requires you to log in using HTTP Basic Authentication.
415 While you can use the C<user> and C<password> parameters to send HTTP
416 Basic Authentication headers in every request, tests have shown that
417 it is faster to accept the cookie which the server returns and send
418 that instead. (It is not clear why it is faster, but one theory is
419 that VMware has to do a more expensive username and password check
422 The web server can be accessed as below. Since the cookie expires
423 after a certain period of time, we use C<cookie-script-renew>, and
424 because the server uses a self-signed certificate we must use
425 I<--insecure> and C<sslverify=false>.
427 SERVER=esx.example.com
431 URL="https://$SERVER/folder/$GUEST/$GUEST-flat.vmdk?dcPath=$DCPATH&dsName=$DS"
435 curl --head -s --insecure -u root:password "$url" |
436 sed -ne "{ s/^Set-Cookie: \([^;]*\);.*/\1/ip }"
438 cookie-script-renew=500 \
441 =head2 Example: Docker Hub authorization tokens
443 Accessing objects like container layers from Docker Hub requires that
444 you first fetch an authorization token, even for anonymous access.
445 These tokens expire after about 5 minutes (300 seconds) so must be
446 periodically renewed.
448 You will need this authorization script (F</tmp/auth.sh>):
452 curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$IMAGE:pull" |
455 You will also need this script to get the blobSum of the layer
456 (F</tmp/blobsum.sh>):
461 curl -s -X GET -H "Authorization: Bearer $TOKEN" \
462 "https://registry-1.docker.io/v2/$IMAGE/manifests/latest" |
463 jq -r '.fsLayers[0].blobSum'
465 Both scripts must be executable, and both can be run on their own to
466 check they are working. To run nbdkit:
469 BLOBSUM=`/tmp/blobsum.sh`
470 URL="https://registry-1.docker.io/v2/$IMAGE/blobs/$BLOBSUM"
473 header-script=' printf "Authorization: Bearer "; /tmp/auth.sh ' \
474 header-script-renew=200 \
477 Note that this exposes a tar file over NBD. See also
478 L<nbdkit-tar-filter(1)>.
484 =item B<-D curl.scripts=1>
486 This prints out the headers and cookies generated by the
487 C<header-script> and C<cookie-script> options, which can be useful
488 when debugging these scripts.
490 =item B<-D curl.verbose=1>
492 This enables very verbose curl debugging. See L<CURLOPT_VERBOSE(3)>.
493 This is mainly useful if you suspect there is a bug inside libcurl
502 =item F<$plugindir/nbdkit-curl-plugin.so>
506 Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
512 C<nbdkit-curl-plugin> first appeared in nbdkit 1.2.
518 L<CURLOPT_CAINFO(3)>,
519 L<CURLOPT_CAPATH(3)>,
520 L<CURLOPT_COOKIE(3)>,
521 L<CURLOPT_COOKIEFILE(3)>,
522 L<CURLOPT_COOKIEJAR(3)>,
523 L<CURLOPT_FOLLOWLOCATION(3)>,
524 L<CURLOPT_HTTPHEADER(3)>,
526 L<CURLOPT_SSL_CIPHER_LIST(3)>,
527 L<CURLOPT_SSLVERSION(3)>,
528 L<CURLOPT_TCP_KEEPALIVE(3)>,
529 L<CURLOPT_TCP_NODELAY(3)>,
530 L<CURLOPT_TLS13_CIPHERS(3)>,
532 L<CURLOPT_UNIX_SOCKET_PATH(3)>,
533 L<CURLOPT_USERAGENT(3)>,
534 L<CURLOPT_VERBOSE(3)>,
536 L<nbdkit-extentlist-filter(1)>,
537 L<nbdkit-file-plugin(1)>,
538 L<nbdkit-retry-filter(1)>,
539 L<nbdkit-retry-request-filter(1)>,
540 L<nbdkit-ssh-plugin(1)>,
541 L<nbdkit-torrent-plugin(1)>,
543 L<http://curl.haxx.se>,
544 L<https://curl.se/docs/ssl-ciphers.html>
550 Parts derived from Alexander Graf's "QEMU Block driver for CURL images".
554 Copyright (C) 2014-2020 Red Hat Inc.