libstore/openStore: fix stores with IPv6 addresses #4319
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
nixStable
(2.3.7 to be precise) it's possible to connect to storesusing an IPv6 address:
This is also useful for
nixops(1)
where you could specify an IPv6address in
deployment.targetHost
.However, this behavior is broken on
nixUnstable
and fails with thefollowing error:
This happened because
openStore
fromlibstore
uses theparseURL
function from
libfetchers
which expects a valid URL as defined inRFC2732. However, this is unsupported by
ssh(1)
:This patch now allows both ways of specifying a store (
root@2001:db8::1
) andalso
root@[2001:db8::1]
since the latter one is useful to pass queryparameters 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 theform
2001:db8::1
and also[2001:db8::1]
.In
libstore
, a new function namedextractConnStr
ensures that aproper URL is passed to e.g.
ssh(1)
:If a URL looks like either
[2001:db8::1]
orroot@[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.
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:
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.