Say your CI pipeline runs automated tests, builds the gem and pushes to Rubygems, it needs permissions to push to Rubygems.
So if an attacker compromises the API key used by that pipeline, they get the rights to push to Rubygems.
So if an attacker compromises the API key used by that pipeline, they get the rights to push to Rubygems.
It'd depend on the individual software library and of course as a consumer of many libraries you generally will have limited or no visibility of the practices of all your dependencies.
As a consumer of software libraries, have you ever looked into the security practices of the library author before choosing whether to use it or not?