Never write credentials to lockfiles - #7560
Conversation
49cbb03 to
36a6063
Compare
36a6063 to
e8a3637
Compare
…edentials Never write credentials to lockfiles (cherry picked from commit 1e97357)
|
I'm still gathering information and getting a reproducible case, but I believe this change is causing problems during CI. The Where |
|
Thanks letting me know so quickly. I will try to figure out on Monday what's happening here and and make a patch release with a revert if needed. |
|
Thanks for your work on this source "https://<redacted>@gems.contribsys.com/" do
gem "sidekiq-pro", "~> 7.2"
end
|
|
That's exactly the feature implemented by this PR. Did it cause any issues or is it that you actually want credentials written to the lockfile? |
Oops, sorry! I actually just assumed that it would cause an issue. After actually testing it, I have none. So nvm! |
|
@technicalpickles Since we haven't got any more reports, I'm actually holding on the revert, but I'll wait till you find out more and investigate then. |
|
+1 on the issue of invalid assignment |
|
@technicalpickles Can you check if the lockfile is correct after |
|
Hey @deivid-rodriguez, our Gemfile.lock diff only contains removal of credentials and bundler version change. I spent a few minutes trying to reproduce this locally but couldn’t. The only difference between local and CI is that we use deployment mode. I’m going to give that a try next when I get a chance. |
|
@deivid-rodriguez I have reproduced the issue. Our application uses Karafka Pro, following the setup from @mensfeld in the Karafka docs: source 'https://USERNAME:PASSWORD@gems.karafka.io' do
gem 'karafka-license', 'LICENSE_ID'
endWe upgraded our Bundler version via When deploying to Heroku, we see: For now I will roll back to our previous Bundler version as a workaround. |
|
I noticed there is a backtick getting escaped to |
|
Oh your logs made me realize. Normally a lockfile generated with Bundle x.y.z will be bundled with Bundler x.y.z. Bundler has builtin behavior to ensure that. If that happens things work fine. However, Heroku is special and will forcefully use its own version (2.5.6 at the moment, apparently) and also does not provide any options to customize that. If Bundler older than 2.5.10 bundles a 2.5.10 lockfile that stripped credentials, and does that in "frozen mode", which Heroku also enables by default, then indeed things won't work. If you run |
|
Or if that's easier, set the |
See https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md FYI, a side effect of this update: After merging this PR, dependabot will strip credentials from the Gemfile.lock if there are any. E.g. for sidekiq-pro. This is because as of Bundler 2.5.10 gem credentials are never written to Gemfile.lock. See this PR: ruby/rubygems#7560 Our app is using Bundler 2.5.10+, so we're currently having to fight with dependabot because when we run `bundle install` the credentials get stripped and then when dependabot runs it puts them back in, since it's using an older version of Bundler.
That didn't work, because that variable only has an effect in Bundler 2.5.10 and later, and we're still given 2.5.6 by the Heroku buildpack, if I understand correctly. I think another workaround would be to explicitly set the credentials via |
Oh, too bad. That variable was present in 2.5.6 and I suggested it because I thought the reporter of #7185 suggested that it had the effect of preventing credentials to be added, but now I see it's actually the other way around (it forced credentials to be added when credentials were specified in configuration).
Yes, that'd be the preferred workaround, don't reference credentials directly in Gemfile either 👍. |
|
Hi 👋🏻 while I understand and support the idea of keeping credentials out of checked in lockfiles, it feels to me that changing the behavior and format of the lockfile is a major change. A contract breaking change. IMO, this kind of change should be warned about with deprecation warnings in a minor version first. Then in only in a major version, make this change. This change broke all Dependabot PRs with private gems using this pattern: # Gemfile
source "https:/USERNAME:PASSWORD@example.com" do
gem "private_gem"
endFor example, Sidekiq Enterprise. Can this change be urgently reverted please? 🖤 |
|
Hello. Thanks for the ping. This was supposed to change only a lockfile detail, but I was not expecting it to break anything other than that. I don't consider a somewhat surprising diff in a lockfile to be a breaking change. That said, it sounds like this has caused real problems, as reported in #7715. That's of course not ok. I will investigate that issue and decide what to do next. |
|
As a user, my thoughts: in #7715, they are running an older bundler vs a 2.5.11 generated lockfile. Like the dependabot related tickets, that's ultimately what I am noticing too -> anytime you use a 2.5.10+ bundler (whether locally or via a tool like dependabot), it writes out a syntax that doesn't work if you also use a lower-bundler for any reason (heroku, vendor'd, etc) In that sense, this is a breaking change, but I also think there's a bit of user (or tooling issues) - when you upgrade bundler in one spot, you should update in all. That's hard, I admit, if:
|
|
Thanks for the helpful feedback @broksonic21. I agree. I thought only issues were with Heroku and Dependabot, which in my opinion should eventually respect auto-switching. I also thought issues were only about constant lockfile churn from Dependabot/Heroku and local Bundler competing to add & remove credentials, and I expected those to be gone once both tools upgrade their internal version of Bundler. However, after thinking more about this today and looking at the new issue opened, I realize there are more cases where Bundler won't autoswitch (expectedly, or unexpectedly), and things can break in that case. Also I realize there are way more people putting credentials in their Gemfiles than I thought 😅. So I think we should restore a better default behavior that keeps credentials in lockfile if they are already there. Working on it! |
|
I created two PRs to alleviate these issues:
As a follow up change, I will add deprecation warnings when writing lockfiles with credentials, so that people can gradually remove credentials from them. |
What was the end-user or developer problem that led to this PR?
Bundler will sometimes write credentials to lockfiles, which is NOT very secure since, for example, they may get pushed to a public repo by mistake.
What is your fix for the problem, implemented in this PR?
Never write credentials to lockfiles.
Previously, if they were present, they'd be considered for lockfile expiration. I think it's fine to never consider them and never write them in the lockfile. If there are credentials present in the Gemfile (through ENV, for example), complete lockfile sources with those so that deployment mode (that only considers the lockfile) still works.
There was previously a setting to enable this behavior but I think it should be the default, so I removed the setting.
Fixes #1240.
Fixes #3234.
Closes #7185.
Make sure the following tasks are checked