Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime/permissions): support IP CIDR ranges in net allowlist #11509

Closed
wants to merge 5 commits into from

Conversation

dsseng
Copy link
Contributor

@dsseng dsseng commented Jul 24, 2021

Fixes #9816

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
@CLAassistant
Copy link

CLAassistant commented Jul 24, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bartlomieju bartlomieju added this to the 1.13.0 milestone Jul 26, 2021
@bartlomieju
Copy link
Member

@lucacasonato requested not to land this one until he can review it. Removing milestone for now

@bartlomieju bartlomieju removed this from the 1.13.0 milestone Jul 29, 2021
@bnoordhuis
Copy link
Contributor

Can I suggest switching to Ipv4Network and Ipv6Network from the ipnetwork crate? It'll be easier to read and maintain than the regex approach.

It also supports IPv6 CIDRs like fc00::/7, something your PR doesn't currently handle.

@dsseng
Copy link
Contributor Author

dsseng commented Aug 6, 2021

Yes, currently I only did that for IPv4. ipnetwork looks really good and should make code clearer. If Deno team members are not against including this crate as a dependency (seems not installed), I will integrate it in place of regex.

@ry
Copy link
Member

ry commented Aug 6, 2021

@sh7dm the added dependency seems worth it

@dsseng
Copy link
Contributor Author

dsseng commented Aug 6, 2021

ipnet crate which is already being built with some Deno's dependencies should do the job as well: https://docs.rs/ipnet/2.3.1/ipnet/struct.Ipv4Net.html#examples-11.

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

I haven't reviewed implementation, but this would likely block full URL network allow list due to possible parsing ambiguity between CIDR ranges and URLs (is this concern warranted?).

With full URL network allow list I mean the following: --allow-net=https://api.github.com/meta would allow fetching https://api.github.com/meta, but not https://api.github.com/users/lucacasonato. Currently filtering is just per domain.

runtime/permissions.rs Outdated Show resolved Hide resolved
@dsseng
Copy link
Contributor Author

dsseng commented Aug 8, 2021

I haven't reviewed implementation, but this would likely block full URL network allow list due to possible parsing ambiguity between CIDR ranges and URLs (is this concern warranted?).

Can also be a trouble. Maybe we should either add some prefix or another CLI flag for CIDR?

@lucacasonato
Copy link
Member

Actually maybe it is not even ambiguous without square brackets:

The port should come after the CIDR range, so after the /. If the string does not contain /, then it is not a cidr range.

So should look like this:

ffff:ffff:ffff::/24:443
|-------1------||2||3-|

1: address
2: subnet size
3: port

If the subnet size is missing address must be enclosed in square brackets if it is IPv6. We already enforce this.

@dsseng
Copy link
Contributor Author

dsseng commented Aug 8, 2021

Yes, but what about URLs? How do we find out that ffff:ffff:ffff::/24 is CIDR allowing any connection to any IP starting with ffff:ffff:ffff... by mask of 24 bits or is allowing requesting HTTP path /24 from ffff:ffff:ffff:0:0:0:0:0? If we force users to use ffff:ffff:ffff::/24 for the first case and [ffff:ffff:ffff::]/24 this will be solved.

@ry ry added this to the 1.14.0 milestone Aug 13, 2021
@lucacasonato
Copy link
Member

@sh7dm IPv6 in URLs already requires that you wrap the address in square brackets: https://url.spec.whatwg.org/#valid-host-string

@lucacasonato lucacasonato self-assigned this Aug 24, 2021
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Overall, happy to get this feature. I have a few more asks though:

  • CIDR ranges are re-parsed on each permission check. CIDR ranges should be parsed once, and then stored in the NetDescriptor as a ipnet::IpNet (maybe turn NetDescriptor into an enum?).

  • Please also add a test that IPv6 CIDR where the IP address is surrounded by [ ] does not work.

@dsseng
Copy link
Contributor Author

dsseng commented Aug 25, 2021

Well, enum should be a great idea

@bartlomieju bartlomieju modified the milestones: 1.14.0, 1.15.0 Sep 13, 2021
@lucacasonato lucacasonato removed this from the 1.15.0 milestone Oct 11, 2021
@stale stale bot added the stale label Dec 14, 2021
@denoland denoland deleted a comment from stale bot Dec 14, 2021
@stale stale bot removed the stale label Dec 14, 2021
@bnoordhuis
Copy link
Contributor

@sh7dm Do you still want to move forward with this? Seems like a great feature to have.

@dsseng
Copy link
Contributor Author

dsseng commented Dec 14, 2021

Quite busy currently, sorry. No time for builds and proper testing. I do hope maintainers can help delivering this feature.

@bnoordhuis
Copy link
Contributor

That's too bad but thanks for your reply. Since this PR has merge conflicts, I'll go ahead and take the liberty of closing it.

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.

feature: support cidr blocks egress control with --allow-net
7 participants