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

Bump netaddr gem for CVE-2019-17383 #2369

Closed
wants to merge 3 commits into from
Closed

Conversation

FlorianNachtigall
Copy link
Contributor

@FlorianNachtigall FlorianNachtigall commented Apr 1, 2022

tldr

netaddr 1.5.0 is vulnerable. Upgrading to netaddr v2 required a lot of changes (see d40d9b7). Let's discuss if this is reasonable and we should finalize the PR or whether other options should be considered (see #Alternatives).

What is this change about?

The currently used version of netaddr is vulnerable:

This change updates the gem to the latest version with no known vulnerabilities. bundle update netaddr was used to ensure indirect dependencies are updated as well.

Breaking changes netaddr v1 -> v2

netaddr was completely rewritten from v1 to v2 and the interface changed significantly. Most importantly, NetAddr::CIDR was removed and replaced with NetAddr::IPv4Net & NetAddr::IPv6Net and NetAddr::IPv4 & NetAddr::IPv6, which provide similar functionality.

Our approach

Due to the broad usage of NetAddr::CIDR in the code base the PR introduces many changes, however, we tried to rebuild the old functionality with the new API as much as possible to keep the complexity manageable. We created a wrapper for NetAddr::IPv{4,6}Net -> IpUtil::CIDR and NetAddr::IPv{4,6} -> IpUtil::CIDRIP respectively to maintain the old behavior and differentiate the IP version in one central place.

All netaddr v2 changes have now been incorporated and all bosh-director unit tests are green. Some smaller todos (indicated by TODO NETADDR) and refactorings are still open.
Yet, before we finalize the PR, let's discuss if bumping netaddr to v2 is reasonable considering the size of the change or whether other options should be considered (see #Alternatives).

Open issues with netaddr v2

Alternatives

  • The potential fix for CVE-2019-17383 was backported to 1.5.3, however, the version has not yet been released on rubygems.org. We could ask for it to be made available.
  • Adopting Ruby's default IPAddr gem which provides similar functionality and is potentially better maintained.

What tests have you run against this PR?

  • bosh-director unit tests (all succeeding besides two unrelated NATS cert tests which fail due to changed OpenSSL error messages)

How should this change be described in bosh release notes?

  • upgrade netaddr gem to 2.0.5

Does this PR introduce a breaking change?

  • no

Tag your pair, your PM, and/or team!

@friegger @cloudfoundry/cf-bosh-europe

@@ -255,7 +255,7 @@ module Bosh::Director::DeploymentPlan

expect(existing_plans[0].reservation.network.name).to eq('my-network-2')
expect(existing_plans[0].reservation.instance_model).to eq(instance_model)
expect(ip_to_netaddr(existing_plans[0].reservation.ip)).to eq('192.168.1.2')
expect(ip_to_netaddr(existing_plans[0].reservation.ip).to_s).to eq('192.168.1.2')
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using the format_ip method in all these expects with ip_to_netaddr(..).to_s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I changed all of them.

raise NetworkReservedIpOutOfRange,
"Reserved IP '#{format_ip(ip)}' is out of " \
"Reserved IP '#{format_ip(ip_obj)}' is out of " \
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use the raw ip from json here. Otherwise an exception could raise for. {"ip" : {...}} and you don't get the expected exception.
"Reserved IP '#{ip}' is out of "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

each_ip iterates over the json and supplies the integer representation of each ip. To have a human-readable error message the ip has to be converted back to its string representation. Therefore, either format_ip(ip) or CIDRIP.parse(ip).to_s are required.

@FlorianNachtigall FlorianNachtigall force-pushed the bump-gems branch 6 times, most recently from 56acdd8 to 44f1975 Compare April 6, 2022 14:37
@FlorianNachtigall FlorianNachtigall changed the title Bump json & netaddr gem Bump netaddr gem Apr 7, 2022
@FlorianNachtigall FlorianNachtigall changed the title Bump netaddr gem Bump netaddr gem for CVE-2019-17383 Apr 7, 2022
@FlorianNachtigall FlorianNachtigall marked this pull request as ready for review April 7, 2022 14:45
@rkoster rkoster requested review from a team, jpalermo and bgandon and removed request for a team April 14, 2022 15:14
Copy link
Contributor

@rkoster rkoster left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a few TODO's that should be removed/addressed

expect(subnet.netmask).to eq('ffff:ffff:ffff:ffff:0000:0000:0000:0000')
expect(subnet.gateway).to eq('fdab:d85c:118d:8a46:0000:0000:0000:0001')
expect(subnet.range.network.to_s).to eq('fdab:d85c:118d:8a46::')
# subnet.range.ip.size == 2**64 # TODO NETADDR: bug? / what was tested here?
Copy link
Contributor

Choose a reason for hiding this comment

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

That CIDR Prefix is parsed into a range size. Should probably be updated to network.prefix_len

@rkoster
Copy link
Contributor

rkoster commented Apr 20, 2022

I do like the idea of moving to IPAddr, but since most of the work for bumping netaddr seems to have been done already, I would try and get this merged first.

@jpalermo
Copy link
Member

I'm not opposed to merging it, but I feel like it would be easier if we just move to IPAddr. Either change is probably going to have some rough patches and pipeline breakages. Feels like less work to just fix things once, rather than bumping the netaddr gem, fixing things, then replacing netaddr and fixing things again.

I was looking over the use cases and it seems like IPAddr should work for everything we're using netaddr for. This way we have one fewer external dependency too.

I'm happy to work on an IPAddr PR, but also happy to defer to the folks who put this PR together if they want to do the work.

Again, also happy to merge it and work on IPAddr later if that's what the consensus is.

@bgandon bgandon removed their request for review April 21, 2022 06:26
@bgandon bgandon removed their assignment Apr 21, 2022
@FlorianNachtigall
Copy link
Contributor Author

Thanks for the feedback. I'm happy with any approach. Though, the work already put into bumping netaddr shouldn't influence the decision and if we believe IPAddr is the better way forward, I have no hard feelings about discarding all changes.

@friegger
Copy link
Contributor

Also asked for a netaddr 1.5.3 RubyGems release: dspinhirne/netaddr-rb#29

@FlorianNachtigall
Copy link
Contributor Author

In terms of fixing the CVE quickly, what are your thoughts on bumping to netaddr 1.5.3 until we have migrated to IPAddr?
(blocked by dspinhirne/netaddr-rb#29)

@rkoster
Copy link
Contributor

rkoster commented Apr 21, 2022

We could also install netaddr 1.5.3 from github (we also do this for eventmachine here), and then migrate to IPAddr.

FlorianNachtigall added a commit that referenced this pull request May 5, 2022
Consume netaddr release from github since it hasn't been published on
rubygems yet. For more context see:
- dspinhirne/netaddr-rb#29
- #2369

Co-authored-by: Shilpa Chandrashekara <[email protected]>
FlorianNachtigall added a commit that referenced this pull request May 5, 2022
Consume netaddr release from github since it hasn't been published on
rubygems yet. For more context see:
- dspinhirne/netaddr-rb#29
- #2369

Co-authored-by: Shilpa Chandrashekara <[email protected]>
@FlorianNachtigall
Copy link
Contributor Author

Closing in favor of #2373

cunnie pushed a commit that referenced this pull request Jun 29, 2022
Consume netaddr release from github since it hasn't been published on
rubygems yet. For more context see:
- dspinhirne/netaddr-rb#29
- #2369

Co-authored-by: Shilpa Chandrashekara <[email protected]>
@aramprice aramprice deleted the bump-gems branch November 22, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

6 participants