lix/src/libstore
Maximilian Bosch 93a8a005de
libstore/openStore: fix stores with IPv6 addresses
In `nixStable` (2.3.7 to be precise) it's possible to connect to stores
using an IPv6 address:

  nix ping-store --store ssh://root@2001:db8::1

This is also useful for `nixops(1)` where you could specify an IPv6
address in `deployment.targetHost`.

However, this behavior is broken on `nixUnstable` and fails with the
following error:

  $ nix store ping --store ssh://root@2001:db8::1
  don't know how to open Nix store 'ssh://root@2001:db8::1'

This happened because `openStore` from `libstore` uses the `parseURL`
function from `libfetchers` which expects a valid URL as defined in
RFC2732. However, this is unsupported by `ssh(1)`:

  $ nix store ping --store 'ssh://root@[2001:db8::1]'
  cannot connect to 'root@[2001:db8::1]'

This patch now allows both ways of specifying a store (`root@2001:db8::1`) and
also `root@[2001:db8::1]` since the latter one is useful to pass query
parameters to the remote store.

In order to achieve this, the following changes were made:

* The URL regex from `url-parts.hh` now allows an IPv6 address in the
  form `2001:db8::1` and also `[2001:db8::1]`.

* In `libstore`, a new function named `extractConnStr` ensures that a
  proper URL is passed to e.g. `ssh(1)`:

  * If a URL looks like either `[2001:db8::1]` or `root@[2001:db8::1]`,
    the brackets will be removed using a regex. No additional validation
    is done here as only strings parsed by `parseURL` are expected.

  * In any other case, the string will be left untouched.

* The rules above only apply for `LegacySSHStore` and `SSHStore` (a.k.a
  `ssh://` and `ssh-ng://`).

Unresolved questions:

* I'm not really sure whether we want to allow both variants of IPv6
  addresses in the URL parser. However it should be noted that both seem
  to be possible according to RFC2732:

  > This document incudes an update to the generic syntax for Uniform
  > Resource Identifiers defined in RFC 2396 [URL].  It defines a syntax
  > for IPv6 addresses and allows the use of "[" and "]" within a URI
  > explicitly for this reserved purpose.

* Currently, it's not supported to specify a port number behind the
  hostname, however it seems as this is not really supported by the URL
  parser. Hence, this is probably out of scope here.
2020-12-09 12:23:29 +01:00
..
build Re-query for the derivation outputs in the post-build-hook 2020-12-08 11:11:02 +01:00
builtins Fix build 2020-08-06 21:04:31 -05:00
binary-cache-store.cc Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
binary-cache-store.hh Return more info from BinaryCacheStore::addToStoreCommon 2020-09-23 14:40:41 +00:00
builtins.hh buildenv: Eliminate global variables, other cleanup 2020-03-24 14:06:47 +01:00
content-address.cc Style fixes 2020-09-22 11:40:19 +02:00
content-address.hh Add ContentAddressMethod and parse/render it 2020-09-17 20:21:04 +02:00
crypto.cc binary-cache-public-keys -> trusted-public-keys 2017-11-20 17:32:34 +01:00
crypto.hh Revert "Get rid of unicode quotes (#1140)" 2016-11-26 00:38:01 +01:00
daemon.cc Canonicalize binary caches with ‘/’ when one is missing 2020-12-04 22:17:19 -06:00
daemon.hh Add missing #pragma once 2020-10-06 10:40:07 +02:00
derivations.cc Make drv hash modulo memo table thread-safe 2020-11-19 16:50:06 +00:00
derivations.hh Make drv hash modulo memo table thread-safe 2020-11-19 16:50:06 +00:00
dummy-store.cc Shut up some clang warnings 2020-10-06 14:52:30 +02:00
export-import.cc nix::worker_proto -> worker_proto 2020-09-30 00:41:18 +00:00
filetransfer.cc Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
filetransfer.hh Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
fs-accessor.hh Shut up some warnings 2019-09-22 21:57:05 +02:00
gc.cc Handle amount of disk space saved by hard linking being negative 2020-10-12 16:06:38 +00:00
globals.cc Generalize extra-* settings 2020-10-29 18:17:39 +01:00
globals.hh Always default to cache.nixos.org even when different nix store dir 2020-12-06 23:04:42 -06:00
http-binary-cache-store.cc Remove static variable name clashes 2020-10-06 13:49:20 +02:00
legacy-ssh-store.cc Remove static variable name clashes 2020-10-06 13:49:20 +02:00
local-binary-cache-store.cc Remove static variable name clashes 2020-10-06 13:49:20 +02:00
local-fs-store.cc Split out local-fs-store.hh 2020-10-09 20:18:08 +00:00
local-fs-store.hh Split out local-fs-store.hh 2020-10-09 20:18:08 +00:00
local-store.cc Hide the sqlite statements declarations for the local store 2020-12-08 13:29:13 +01:00
local-store.hh Hide the sqlite statements declarations for the local store 2020-12-08 13:29:13 +01:00
local.mk Prepare for build/*.hh headers 2020-10-12 17:07:51 +00:00
lock.cc Trim lock.cc 2020-10-11 16:44:19 +00:00
lock.hh Trim lock.hh 2020-10-11 16:44:07 +00:00
machines.cc Make system-features a store setting 2020-08-12 18:13:00 +00:00
machines.hh Make system-features a store setting 2020-08-12 18:13:00 +00:00
misc.cc Move Callback into its own header 2020-09-21 18:42:21 +02:00
names.cc Don't include <regex> in header files 2020-09-21 18:22:45 +02:00
names.hh Don't include <regex> in header files 2020-09-21 18:22:45 +02:00
nar-accessor.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
nar-accessor.hh NarAccessor: Run in constant memory 2020-07-13 17:30:42 +02:00
nar-info-disk-cache.cc Minimize the usage of Hash::dummy 2020-08-06 18:31:48 +00:00
nar-info-disk-cache.hh Misc changes from the flakes branch 2020-03-24 14:34:47 +01:00
nar-info.cc Minimize the usage of Hash::dummy 2020-08-06 18:31:48 +00:00
nar-info.hh Minimize the usage of Hash::dummy 2020-08-06 18:31:48 +00:00
nix-store.pc.in pkg-config files: Use c++17 2019-03-14 14:11:12 +01:00
optimise-store.cc Factor out common showBytes() 2020-10-06 10:40:49 +02:00
parsed-derivations.cc Make system-features a store setting 2020-08-12 18:13:00 +00:00
parsed-derivations.hh Add missing #pragma once 2020-10-06 10:40:07 +02:00
path-info.hh LocalStore: Get rid of recursive_mutex 2020-11-03 14:45:24 +01:00
path.cc toStorePath(): Return a StorePath and the suffix 2020-07-13 16:25:48 +02:00
path.hh Merge remote-tracking branch 'origin/master' into substitute-other-storedir 2020-07-02 11:14:04 -04:00
pathlocks.cc convert some printError calls to logError 2020-05-03 08:01:25 -06:00
pathlocks.hh Use BSD instead of POSIX file locks 2019-08-02 18:39:16 +02:00
profiles.cc Split out local-fs-store.hh 2020-10-09 20:18:08 +00:00
profiles.hh createGeneration(): Take a StorePath 2020-09-03 11:06:56 +02:00
references.cc Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
references.hh Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
remote-fs-accessor.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
remote-fs-accessor.hh toStorePath(): Return a StorePath and the suffix 2020-07-13 16:25:48 +02:00
remote-store.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
remote-store.hh Split out uds-remote-store.{cc.hh} 2020-10-11 17:37:05 +00:00
s3-binary-cache-store.cc Fix compatibility with newer AWS SDKs 2020-12-04 19:36:09 +01:00
s3-binary-cache-store.hh Revert "Remove putBytes" 2020-08-04 15:56:10 +02:00
s3.hh DataTransfer -> FileTransfer 2020-04-08 22:26:57 +02:00
sandbox-defaults.sb sandbox: fix /bin/sh on catalina 2020-03-20 22:12:30 +01:00
sandbox-minimal.sb Always use the Darwin sandbox 2017-06-06 18:44:49 +02:00
sandbox-network.sb OS X sandbox: Improve builtin sandbox profile 2017-05-31 17:25:51 +02:00
schema.sql Mark content-addressed paths in the Nix database and in .narinfo 2016-08-10 18:05:35 +02:00
serve-protocol.hh Make adding paths via nix-store --serve run in constant memory 2018-08-03 21:21:16 +02:00
sqlite.cc Make the sql debug statements more useful 2020-11-17 10:05:45 +01:00
sqlite.hh Merge remote-tracking branch 'origin/master' into flakes 2020-06-17 10:26:52 +02:00
ssh-store.cc Remove static variable name clashes 2020-10-06 13:49:20 +02:00
ssh.cc Revert the enum struct change 2020-06-18 22:11:26 +00:00
ssh.hh SSHMaster: Bypass SSH when connecting to localhost 2018-08-03 21:20:38 +02:00
store-api.cc libstore/openStore: fix stores with IPv6 addresses 2020-12-09 12:23:29 +01:00
store-api.hh Merge pull request #4180 from Ma27/ssh-ng-substitute 2020-11-17 14:01:04 +01:00
uds-remote-store.cc Split out uds-remote-store.{cc.hh} 2020-10-11 17:37:05 +00:00
uds-remote-store.hh Split out uds-remote-store.{cc.hh} 2020-10-11 17:37:05 +00:00
worker-protocol.hh Allow substituting paths when building remotely using ssh-ng:// 2020-11-05 20:12:37 +01:00