Skip to content

Conversation

@atpons
Copy link

@atpons atpons commented Feb 18, 2025

What was the end-user or developer problem that led to this PR?

When using private gem registries (like GitHub Packages), users need to provide authentication credentials.

This PR implements the credential helper mechanism proposed in rubygems/rfcs#59, which allows users to securely retrieve authentication credentials from external processes.

What is your fix for the problem, implemented in this PR?

  • Added credential-helper setting that specifies path to helper program
    • Helper is executed to obtain credentials in username:password format
  • Support fallbacks to existing credential configuration if helper fails

Here's an example of using it with GitHub Packages with GitHub CLI:

$ bundle config --local credential.helper.rubygems.pkg.github.com "/usr/local/bin/github-cred-helper.sh"

Additionally, It is also possible to place an executable file named bundler-credential-github.

Make sure the following tasks are checked

@welcome
Copy link

welcome bot commented Feb 18, 2025

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@atpons atpons force-pushed the add-credential-helper branch from ac0d913 to 0e48def Compare February 18, 2025 14:30
@atpons atpons marked this pull request as ready for review February 18, 2025 14:32
return unless helper_path

begin
output = `#{helper_path}`.strip
Copy link
Contributor

Choose a reason for hiding this comment

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

@segiddins do you see any security issues with calling out this? Value is coming from bundle config.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a preference that we use the same pattern as https://git-scm.com/docs/gitcredentials#_configuration_options. Additionally, we should be using IO.popen for the subprocess

Copy link
Author

Choose a reason for hiding this comment

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

@simi @segiddins 0e48def...be95a01

Taking security concerns into consideration, I have modified the code to use IO.popen.

Additionally, similar to Git, I have implemented function a that automatically recognizes executables named bundler-credential-{helper-name} for automatically discovering helpers.

@deivid-rodriguez
Copy link
Contributor

Planning to dive into this and the RFC soon. I normally use ENV variables to avoid saving credentials to disk, but it seems nice to support something more built in!

@bootjp
Copy link

bootjp commented Apr 18, 2025

This Pull Request is very useful for my current issue. I want to use a private gem for both local development and on CI (GitHub Actions), but I’m having trouble managing the credentials.

@simi @segiddins If the issues pointed out in the review are resolved, can this Pull Request be merged?

@atpons: Do you still have the motivation to merge this Pull Request? If not, I can continue with the implementation.

@atpons
Copy link
Author

atpons commented Apr 18, 2025

Sorry,I haven't been able to work on it because I was busy, but I will continue with the implementation.
I'm also hoping it will be merged.

Copy link
Contributor

@martinemde martinemde left a comment

Choose a reason for hiding this comment

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

Love it. Can't wait to use this.

Thanks for your work. Just one small nitpick for readability and then I'll defer to @segiddins to finalize the requested git inspired change.

@atpons
Copy link
Author

atpons commented May 17, 2025

Sorry, I've fixed some specs for change to using IO.popen 🙏

Copy link
Contributor

@segiddins segiddins left a comment

Choose a reason for hiding this comment

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

With checking for exit status of the credential helper

"bundler-credential-#{command[0]}"
end

output = Bundler.with_unbundled_env { IO.popen(command, &:read) }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - lets check $? after IO.popen

Copy link
Author

Choose a reason for hiding this comment

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

thanks, db1e5ab fixed checking Process.last_status (use $? difficult to write specs)

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.

6 participants