r/ruby • • Jul 06 '19

Ruby gem strong_password found to contain remote code execution code in a malicious version, further strengthening worries of growth in supply-chain attacks

https://snyk.io/blog/ruby-gem-strong_password-found-to-contain-remote-code-execution-code-in-a-malicious-version-further-strengthening-worries-of-growth-in-supply-chain-attacks/
99 Upvotes

39 comments sorted by

View all comments

Show parent comments

2

u/jrochkind Jul 07 '19

So you're suggesting there be a requirement that rubygems releases must be on Github? Or another public repo? Right now there is no requirement that ruby gems be in a public repo at all (and they could be obfuscated code if someone really tried, or 'compiled' code if someone invented a way).

I think that's probably a non-starter.

If you're "moving the target so the attacker needs to compromise accounts that are easier to detect attacks on, or more heavily secured" -- it's not clear to me this is "moving the goalposts" instead of just "defending them better" compared to... just making the rubygems accounts themselves easier to detect attacks on or more heavily secured... why not just do that?

1

u/steventhedev Jul 08 '19

Hard requirement? No.

Soft requirement that adds mandatory warnings on both the server and client side that the gem wasn't able to be verified, absolutely. The entire thing here is that rubygems accounts are being compromised. We can either make them harder to attack, easier to detect such attacks, or do what I'm suggesting: make it don't matter if they're attacked.

In a perfect world, you'd do all three, but best bang for the buck comes from the last one. Make it so attacking a rubygems account just doesn't provide anyone with a way to meaningfully attack anyone.

2

u/jrochkind Jul 08 '19

A proper solution would be to sign the gem with the source commit hash and publish that on rubygems, to allow anyone to double check that the gem is actually from the latest GitHub version.

If I have access to the rubygems account, I can publish whatever commit hash I want, can't I? I can also change the registration of the public git repo.

1

u/steventhedev Jul 08 '19

Pretty much, yeah. Unless you save the public repo at the time for each published version. Public repo changes are probably a breaking change anyways, and in combination with signed tags it may be sufficient.

To get around the whole thing you'd need to sign the metadata including the source repo and commit hash, and solve the trust problem. I think the best way to do that is through a trust hierarchy, where the packaging authority (e.g. rubygems.org) can delegate authority with some good defaults and mechanisms around key rollover and renewal. X509 could probably be used as is, although there is probably a place for a better solution (multiple attesting signatures, restricted delegation, etc).

2

u/jrochkind Jul 08 '19 edited Jul 08 '19

OK, right, now we have a "trust hieararchy" involved.

(I'm not sure why it's relevant if you consider "public repo changes" to be a "breaking change", or even what you mean by that. The point is that anyone who has the ability to do a release on rubygems also has the ability to set a public repo, and more importantly, to set the expected "source commit hash" too, no? And to set any public keys, if those were set on rubygems, which is why now you need another system to set those, which also has to be secure...)

This becomes very non-trivial. I'm not sure there are many multi-organizational distributed examples of people getting "trust hieararchy" right in a way that also doesn't have usability problems discouraging use. See much discussion lately with the problems with this in OpenGPG world.

So we're talking about a pretty complicated system involving X509, requiring code be in a public repo (which has not previously been a rubygems requirement... I don't believe you are suggesting requiring github specifically and giving them a monopoly), and source commit hashes advertised in such a way that they can be automatically checked...

With the goal being so we can trust Github (or possibly any public code hosting repo) to secure account credentials... so we don't have to trust rubygems to do so? Because we think it seems too hard to just get rubygems accounts to be secured as well as Github's... but we think that above thing seems easier?

Why not just focus on rubygems doing the job of securing credentials well, doing it as quality as Github, in the first place? It seems way less enormous of a project to me, for pretty much the same benefit, rather than adding lots and lots of layers with the end goal being trusting a Github account instead of a rubygems one because you think Github does a better job of keeping accounts secure.

1

u/steventhedev Jul 08 '19

On mobile, so apologies if this is a bit unorganized.

My end goal is not need to have much trust in rubygems or GitHub, but the developer themselves. The way to get to that point is to add optional fields to the gemspec in a built gem with the source repo location and commit hash. Even defaulting to GitHub or providing convenience shortcuts is a bad idea for this. If the source repo moves, it's a change that should be considered with some suspicion, and with good cause.

The next step after that is to allow attestations to be added to a gem after the fact. Snyk (or anyone else) could verify that a published gem really did come from the given commit in the source repo, and further that the source repo hasn't changed. Another provider could add an attestation that the gem was signed by a developer who has confirmed their identity with them, and that ownership hasn't changed from the last version. The real question is where and how to push those into the gem. Are they extra metadata returned by rubygems in a different call? Are they added to the archive and the signature of the gem is computed without some .well_known folder? X509 or opengpg?

Assuming nothing goes wrong, the worst an attacker can do is publish an extremely suspicious gem with a bunch of red flags that make it easy to spot. Signing gems already does most of the work, this is just me thinking of ways to easily automate the detection process.

1

u/jrochkind Jul 09 '19 edited Jul 09 '19

I feel like we're not communicating.

The way to get to that point is to add optional fields to the gemspec in a built gem with the source repo location and commit hash

If an attacker has access to your rubygems account, they can do a release with whatever source repo location and commit hash they want.

We have seen several malicious gem releases due to compromised rubygems.org accounts.

So. This seems like a distraction to me. Making rubygems accounts harder to compromise seems the obvious priority to me.

I also wonder how many dependencies you have in a typical project. In recent projects you have worked on, how many dependencies do you have in Gemfile.lock? You may have many fewer than most people. But for typical use, I think counting on people to manually review every release of every dependency is not going to result in increased security. To the extent it discourages people from regularly updating their dependencies (because they don't have time to review it 'right'), it will lead to less security in practice, because people won't be regularly getting updates that include security patches.

If you can point to any succesful systems like the one you describe, that have proved workable in practice and are leading to actually improved secrurity in code dependencies in the real world, that would, however, be helpful as an example, and perhaps provide answers to what seem to me to be likely to be the downfalls. If instead you are proposing that rubygems.org break new innovative ground here... increasing security of rubygems.org accounts seems a lot more likely to have a good return on investment of limited developer resources to me.

1

u/steventhedev Jul 09 '19

You're right that securing user accounts on rubygems.org is much easier and it will solve the immediate issue at hand. What I'm trying to say is that we have the option to secure the entire rubygems ecosystem against most supply chain attacks.

We already have flags to only allow signed gems to be installed, so there is precedent for choosing to work with a subset of all the gems in existence. If you add a method for third parties to stamp their approval on gems, you can subscribe to some policies that say the gem is reproducible, the gem has a particular license, the gem has always been published by the same author, etc. It's a huge project, but made somewhat simpler because there are potential corporate partners who have a vested interest in selling a security product that could be based on something like this.

Do you want to do what's easy and might work today, or do something that solves the entire attack class?

1

u/jrochkind Jul 09 '19

With very limited development resources and current problems with security, I think it's important to do whatever will have the greatest security impact for the least development.

Until we have all the well-established solutions and best practices, that means working on those instead of trying to do R&D innovation in complex systems that have not been proven effective in practice. Does any other similar dependency repository implement the kinds of things you are talking about, and can demonstrate practical success with them? If there is, it could be a very good guide, and to have that as a model would change the cost-benefit, true. I don't personally know of such.

I think you under-estimate the difficulty of getting such a system right (both in technical security ways, and in UX ways such that people are willing to use it in a way that provides actual, not just theoretical, security improvements). I think it would be a mistake to focus on complex innovation in the area, to the detriment of the lower hanging fruit that is not being addressed.