Skip to content

Commit 9606802

Browse files
maxfelsher-cgihsbt
authored andcommitted
Do not hard-code permissions for new gem directories during bundle install
This hard-coding was overriding umask and setgid settings, making it very difficult to manage gem installations through a shared group. In addition, it differs from the behavior of `gem install`. The hard-coding was originally added in 79386f4 as part of an unrelated reimplementation of `Bundler::RubyGemsGemInstaller#install`, but it looks like the logic on the corresponding line of `Gem::Installer#install` might have been misinterpreted, as that line only sets the `mode` argument if `options[:dir_mode]` is set.
1 parent d9cfcd8 commit 9606802

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

bundler/lib/bundler/rubygems_gem_installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def install
2020
strict_rm_rf spec.extension_dir
2121

2222
SharedHelpers.filesystem_access(gem_dir, :create) do
23-
FileUtils.mkdir_p gem_dir, mode: 0o755
23+
FileUtils.mkdir_p gem_dir
2424
end
2525

2626
SharedHelpers.filesystem_access(gem_dir, :write) do

spec/commands/install_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,37 @@ def run
13061306
end
13071307
end
13081308

1309+
describe "when using umask 002 and setgid bit", :permissions do
1310+
let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") }
1311+
let(:foo_path) { gems_path.join("foo-1.0.0") }
1312+
1313+
before do
1314+
build_repo4 do
1315+
build_gem "foo", "1.0.0" do |s|
1316+
s.write "CHANGELOG.md", "foo"
1317+
end
1318+
end
1319+
1320+
gemfile <<-G
1321+
source "https://gem.repo4"
1322+
gem 'foo'
1323+
G
1324+
1325+
FileUtils.mkdir_p(gems_path)
1326+
FileUtils.chmod("g+s", gems_path)
1327+
end
1328+
1329+
it "should create the gem directory with proper permissions" do
1330+
with_umask(0o002) do
1331+
bundle_config "path vendor"
1332+
bundle :install
1333+
expect(out).to include("Bundle complete!")
1334+
expect(err).to be_empty
1335+
expect(File.stat(foo_path).mode & 0o7777).to eq(0o2775)
1336+
end
1337+
end
1338+
end
1339+
13091340
describe "parallel make" do
13101341
before do
13111342
unless Gem::Installer.private_method_defined?(:build_jobs)

0 commit comments

Comments
 (0)