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

Default strategy prevents proxied gems upgrades #370

Closed
fauno opened this issue Mar 19, 2022 · 11 comments
Closed

Default strategy prevents proxied gems upgrades #370

fauno opened this issue Mar 19, 2022 · 11 comments

Comments

@fauno
Copy link

fauno commented Mar 19, 2022

I recently upgraded our geminabox instance from 1.2.0 to 1.4.1 and discovered the strategy change made on 54f7343 because bundle audit was telling me to upgrade to rails >= 6.4.1.7, but our repo only had up to 6.1.4.6.

I understand the previous strategy makes geminabox more secure, but it also prevents proxy instances to get upstream upgrades, specially if they were upgrading from a pre 1.3.0 geminabox version like us.

@fauno fauno changed the title Default strategy prevents gem upgrades Default strategy prevents proxied gems upgrades Mar 19, 2022
@fauno
Copy link
Author

fauno commented Mar 19, 2022

I'm discussing a proposal with my coworkers :)

@conathan
Copy link

From #345 (comment), they mentioned that you can get similar to the old behavior by using: Geminabox.rubygems_proxy_merge_strategy = :combine_local_and_remote_gem_versions

@catdevnull
Copy link

@conathan This would revert to the old (insecure) strategy :/

@fauno
Copy link
Author

fauno commented Mar 24, 2022

Since in our case we want to keep the proxy+local cache strategy, we think a better strategy would be to actually keep track of which gems are local. It would work like this:

  • Gems pushed with gem inabox ... are considered local;
  • Gems pulled but never pushed are considered remote;
  • Geminabox never proxies a local gem;

This way:

  • Proxy+cache keeps updating remote gems;
  • Local gems are never confused with remote gems;
  • If you fork a gem but keep the same name, once you push it, it starts taking precedence over remote versions;

If you think this is a good idea, we can work on a pull request :)

@conathan
Copy link

In our case, we are only using it as a cacheing mirror (and our actual setup is with adding the patch at #353, and using Geminabox.rubygems_proxy_merge_strategy = :remote_gems_take_precedence_over_local_gems.

  • No local gems, other then what geminabox has cached

(Should probably mention, personally unaware of security implications of combine_local_and_remote_gem_versions, but haven't been trying to use the same geminabox instance for local and remote gems [we use one geminabox for our local gems [default merge strategy], another for rubygems [remote_gems_take_precidence], and a 3rd for cincgems [remote_gems_take_precidence]).

But felt like mentioning the 353 pull request was getting off topic for what was mentioned here, so opted to mention the combine_local_and_remote_gem_versions instead (which is currently in the codebase)

  • Speaking of, a gotcha we ran into, was this patch 404's on the info links when using the combined merge strategy, where we switched to remote_gems_take precidence (makes sense looking at the patch). But in this case remote gems on merge strategy matched our setup nicely

@github-actions
Copy link

github-actions bot commented Jul 5, 2022

Could you update this issue?

@seandilda
Copy link

@conathan This would revert to the old (insecure) strategy :/

The old version is only insecure if you're using the same instance as a caching proxy AND adding local gems. I think the true fix is that geminabox should stop supporting the combined usage. It should have to choose between :local_gem_server mode or :caching_proxy mode. The security issues come when you try to support both at once.

@tnir tnir pinned this issue Jul 5, 2022
@skaes
Copy link
Contributor

skaes commented Jul 13, 2022

The security issues come when you try to support both at once.

Security problems are still there, even if you have separate gem servers, because you would have to make sure every Gemfile in your company specifies for each in-house gem the correct server to pull from. This becomes increasingly tedious if you start building gems the depend on other gems. Last time I looked, bundler did not allow to specify gem server priorities.

@seandilda @fauno please check out the pending PR #435. It reduces the problem of preventing gem upgrades to the situation where you have uploaded a version of a public gem to your server that differs from all the publicly available gems.

@fauno
Copy link
Author

fauno commented Jul 13, 2022

@seandilda @fauno please check out the pending PR #435. It reduces the problem of preventing gem upgrades to the situation where you have uploaded a version of a public gem to your server that differs from all the publicly available gems.

hi! thanks! you're refering to a8ff740 right? at first i thought it wouldn't work for us because we push binary gems (using gem-compiler) from source-only gems available on rubygems (and sometimes patched versions, but mostly binary gems without changes). but i see you try to check if it exists remotely, and since they won't, the upload would be allowed, correct?

@skaes
Copy link
Contributor

skaes commented Jul 13, 2022

but i see you try to check if it exists remotely, and since they won't, the upload would be allowed, correct?

I would assume that for binary gems the SHA256 sum of the file content differs from all versions on rubygems.

So I guess the answer is no.

BTW, from a security point of view this is no different than uploading a version increment of a pure Ruby gem.

We are running a standalone server at the moment. The most basic strategy we use is to temporarily add rubgygems.org
as a bundler source, run bundle update and then sync our local gem cache with our server (we use a simple shell script using curl for that).

@github-actions
Copy link

Could you update this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

5 participants