Skip to content

Refactor ParsePortSpec to handle IPv6 addresses, and improve validation#213

Merged
AkihiroSuda merged 4 commits into
rootless-containers:masterfrom
thaJeztah:portspec_ipv6
Feb 15, 2021
Merged

Refactor ParsePortSpec to handle IPv6 addresses, and improve validation#213
AkihiroSuda merged 4 commits into
rootless-containers:masterfrom
thaJeztah:portspec_ipv6

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Feb 11, 2021

Copy link
Copy Markdown
Contributor

Refactor of portutil, related to moby/moby#41908 and #207

Refactor ParsePortSpec to handle IPv6 addresses

The PortSpec uses colons a delimiter between parts. If an IPv6 address is used, this leads to the colons in the IP-address to be handled as delimiter.

Commit 1d78bed (#207) also added support for "ChildIP" to the portspec format, which (adding to the above) made parsing the format even more ambiguous.

This patch rewrites ParsePortSpec to handle IPv6 addresses, but requires those addresses to be wrapped by square brackes.

ValidatePortSpec: accept sctp as valid proto

There was an inconsistency between ParsePortSpec and ValidatePortSpec; ParsePortSpec accepted "sctp" as a valid proto, whereas ValidatePortSpec did not.

This patch re-uses the validateProto() function to validate.

ValidatePortSpec: validate ChildIP (if set)

The function already validated ParentIP, but did not validate ChildIP; also added a minimal test

Use net.JoinHostPort() to join IP-addresses with port

This makes sure the IPv6 addresses are wrapped with square brackets (e.g., [::1]:8080)

The PortSpec uses colons a delimiter between parts. If an IPv6
address is used, this leads to the colons in the IP-address to
be handled as delimiter.

Commit 1d78bed also added support
for "ChildIP" to the portspec format, which (adding to the above)
made parsing the format even more ambiguous.

This patch rewrites ParsePortSpec to handle IPv6 addresses, but
requires those addresses to be wrapped by square brackes.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
There was an inconsistency between ParsePortSpec and ValidatePortSpec;
ParsePortSpec accepted "sctp" as a valid proto, whereas ValidatePortSpec
did not.

This patch re-uses the `validateProto()` function to validate.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
The function already validated ParentIP, but did not validate ChildIP;
also added a minimal test

Signed-off-by: Sebastiaan van Stijn <[email protected]>
This makes sure the IPv6 addresses are wrapped with square brackets
(e.g., [::1]:8080)

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@AkihiroSuda

Copy link
Copy Markdown
Member

Thanks!

@thaJeztah

Copy link
Copy Markdown
Contributor Author

Testing it on the moby PR to see if there's things missing still, but I think remaining failures are not in this code (will have to check though)

@thaJeztah

Copy link
Copy Markdown
Contributor Author

Moved out of draft; tried this branch separate from the libnetwork changes, and rootless CI on moby passes with this; moby/moby#42021

Well can look into the failures with the libnetwork update separately

Comment thread pkg/port/socat/socat.go
"socat",
fmt.Sprintf("%s-LISTEN:%d,bind=%s,reuseaddr,fork,rcvbuf=65536,sndbuf=65536", proto, spec.ParentPort, ipStr),
fmt.Sprintf(`EXEC:"%s",nofork`,
fmt.Sprintf("nsenter -U -n --preserve-credentials -t %d socat STDIN %s4:%s", childPID, proto, hp)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this sprintf is nested, but not new in this PR 🤷‍♂️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I was also looking at that; at first thought there was a reason, but didn't see any either. Should've changed it while I was modifying the code; let me do a follow-up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants