Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Don't fallback to tempdir when required directories exist. #6550

Merged
merged 1 commit into from
Jun 12, 2018

Conversation

brodock
Copy link
Contributor

@brodock brodock commented May 23, 2018

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

When running Omnibus packaged software with updated bundler, a warning is displayed because the home folder is not owned by the user:

`/var/opt/gitlab` is not writable.
Bundler will use `/tmp/bundler/home/root' as your home directory temporarily.

There are valid reasons why this is desired, and I don't have control over it. What I can do is create the required folders used by bundler and provide them with the right permissions.

See #6546

What was your diagnosis of the problem?

In practice instead of asking for permission on a higher level, if required folders are present and they have the right permissions, we shouldn't fallback to warning + temp directory, we should just use what is provided.

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

When home directory is not writable, but the required .gem and .bundle
are, we should use them instead of falling back to use tempdirs.

This creates a workaround for more restrictive setups using Omnibus
Docker or any hardened setup, to overcome the annoyances introduced by #4951.

Why did you choose this fix out of the possible options?

This allows for distributions, package maintainers, etc to provide an alternative while keeping their hardenings requirements.

When provided the required folders with the required ownership/permission, we should not bother by not having any write permissions on the $HOME directory.

@ghost
Copy link

ghost commented May 23, 2018

Thanks for opening a pull request and helping make Bundler better! Someone from the Bundler 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 Travis CI to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of Travis CI 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 #bundler channel on Slack.

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

lib/bundler.rb Outdated
@@ -159,12 +159,13 @@ def ruby_scope
def user_home
@user_home ||= begin
home = Bundler.rubygems.user_home
user_dirs = home ? %w[.bundle .gem].map {|path| File.join(home, path) } : []
Copy link
Member

Choose a reason for hiding this comment

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

why is .gem called out here? I could set my GEM_HOME to something other than ~/.gem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, I didn't think too much on the required folders. I think now we only need the .bundle.

@brodock brodock force-pushed the 6546-fix-home-permissions branch from 4159879 to 467d90a Compare May 25, 2018 14:27
@brodock
Copy link
Contributor Author

brodock commented May 25, 2018

@segiddins code now checks only .bundle directory

@brodock brodock force-pushed the 6546-fix-home-permissions branch from 467d90a to facf625 Compare May 25, 2018 20:49
@colby-swandale
Copy link
Member

Is the ‘.bundle’ folder not defined anywhere in SharedHelpers or in Bundler? I’m concerned about having a hard coded string.

@colby-swandale
Copy link
Member

Thanks for finding that out, we will have to refactor that out in the future.

lib/bundler.rb Outdated
@@ -159,12 +159,13 @@ def ruby_scope
def user_home
@user_home ||= begin
home = Bundler.rubygems.user_home
dotbundle = home ? File.join(home, ".bundle") : nil
Copy link
Member

Choose a reason for hiding this comment

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

This is super nitpicky but can we rename this to bundle_home. dotbundle doesn't really mean anything. 🙏

When home directory is not writable, but the required .bundle is,
we should use it instead of falling back to use tempdirs.

This creates a workaround for more restrictive setups using Omnibus
Docker or any hardened setup, to overcome the annoyances introduced by rubygems#4951.
@brodock
Copy link
Contributor Author

brodock commented Jun 12, 2018

@colby-swandale done :)

@colby-swandale colby-swandale added this to the 1.16.3 milestone Jun 12, 2018
@colby-swandale
Copy link
Member

Thanks! @bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit fb40210 has been approved by colby-swandale

@bundlerbot
Copy link
Collaborator

⌛ Testing commit fb40210 with merge 31b53cf...

bundlerbot added a commit that referenced this pull request Jun 12, 2018
…dale

Don't fallback to tempdir when required directories exist.

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

When running Omnibus packaged software with updated bundler, a warning is displayed because the home folder is not owned by the user:

```
`/var/opt/gitlab` is not writable.
Bundler will use `/tmp/bundler/home/root' as your home directory temporarily.
```

There are valid reasons why this is desired, and I don't have control over it. What I can do is create the required folders used by bundler and provide them with the right permissions.

See #6546

### What was your diagnosis of the problem?

In practice instead of asking for permission on a higher level, if required folders are present and they have the right permissions, we shouldn't fallback to warning + temp directory, we should just use what is provided.

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

When home directory is not writable, but the required .gem and .bundle
are, we should use them instead of falling back to use tempdirs.

This creates a workaround for more restrictive setups using Omnibus
Docker or any hardened setup, to overcome the annoyances introduced by #4951.

### Why did you choose this fix out of the possible options?

This allows for distributions, package maintainers, etc to provide an alternative while keeping their hardenings requirements.

When provided the required folders with the required ownership/permission, we should not bother by not having any write permissions on the `$HOME` directory.
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: colby-swandale
Pushing 31b53cf to master...

@bundlerbot bundlerbot merged commit fb40210 into rubygems:master Jun 12, 2018
colby-swandale pushed a commit that referenced this pull request Jul 10, 2018
…dale

Don't fallback to tempdir when required directories exist.

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

When running Omnibus packaged software with updated bundler, a warning is displayed because the home folder is not owned by the user:

```
`/var/opt/gitlab` is not writable.
Bundler will use `/tmp/bundler/home/root' as your home directory temporarily.
```

There are valid reasons why this is desired, and I don't have control over it. What I can do is create the required folders used by bundler and provide them with the right permissions.

See #6546

### What was your diagnosis of the problem?

In practice instead of asking for permission on a higher level, if required folders are present and they have the right permissions, we shouldn't fallback to warning + temp directory, we should just use what is provided.

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

When home directory is not writable, but the required .gem and .bundle
are, we should use them instead of falling back to use tempdirs.

This creates a workaround for more restrictive setups using Omnibus
Docker or any hardened setup, to overcome the annoyances introduced by #4951.

### Why did you choose this fix out of the possible options?

This allows for distributions, package maintainers, etc to provide an alternative while keeping their hardenings requirements.

When provided the required folders with the required ownership/permission, we should not bother by not having any write permissions on the `$HOME` directory.

(cherry picked from commit 31b53cf)
maxlazio pushed a commit to gitlabhq/omnibus-gitlab that referenced this pull request Oct 24, 2018
A few reasons for this change:

GitLab CE and Gitaly are now using bundler v1.16.6 to avoid
rubygems/bundler#6537.

1.16.3 also ships with rubygems/bundler#6550, so
we no longer need the patch for this.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants