LoginSignup
1
3

More than 5 years have passed since last update.

Ruby や Bundler の個人的メモ

Last updated at Posted at 2016-11-18

このページは Bundler の可愛さ(?)をお楽しみ頂くため邪魔にならない程度の差し障りのない会話をお楽しみいただくメモを晒すページです。

つまり俺得なだけで他に寄与しません!
Qiita に記事を書いている皆様には 99% 耳タコな話でしょう!

真面目な話をすると、主に日本語情報が少ないと感じたものや、これって補足したいなーって情報を忘れないためにメモするページ。

エラーメッセージメモ

Don't run Bundler as root...

$ sudo bundle install

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.

エラーの内容補足

言いたいことは何となくわかるが、逆に何となくしかわからなかったのでぐぐってみた。

Print warning when bundler is run by root · Issue #2936 · bundler/bundler
ruby - "Don't run bundler as root" - what is the exact difference made by using root? - Stack Overflow

Running sudo bundle install can cause huge and cascading problems for users trying to install gems on OS X into the system gems. We should print a warning and explain that Bundler will prompt for sudo if it's needed. We should also warn people that sudo bundle will break git gems, because they have to be writable by the user that Bundler runs as.

要するに「root で install するとシステムの gem ぶっ壊すかもしれないから注意メッセージ出そう」ってことらしい。
コメントでは OS X について言及しているようだが、別に Linux でも起きない話ではない。

対応方法

「じゃぁ root やめるわ」ってのが正しいんだろうけど、Rails などのリモートアクセスを許すサービスの実行権限をちゃんと分けているかが気になった。

例えばベタで書くとこんな感じのアプリケーションの実行環境があったとする。

# root がだめなので専用のユーザー権限作って対応するよ!
$ sudo -u rails git pull original-rails-app && cd original-rails-app
$ sudo -u rails bundle install

# supervisord で実行するも root じゃなくて rails ユーザーに設定済みだ!
$ sudo supervisorctl start original-rails-app

これだと万が一アプリケーションに任意のファイル書き込みを許すバグがあった場合に、バグの前提が酷すぎるという話は置いといて簡単に悪意のあるコードが埋め込まれてしまう。

要は supervisord で実行する際に nobody 等の別の権限のユーザーを使っていればいいのだけれど、まだまだ現役である CentOS-6系 EPEL にある supervisor.noarch-2.1-9.el6 では実行ユーザー権限の変更ができない。

結局のところ下記のどれかの対応が必要になる。

  • supervisord-3 を入れて nobody など安全なユーザー権限で実行する。
  • 諸事情で supervisord-3 を入れられない場合は supervisord を諦めて直接 unicorn を nobody などの安全なユーザー権限で実行する。
  • 諸事情で(略)supervisord じゃなくて upstart 使う。
  • SELinux 等の強制アクセス制御可能な仕組みを導入して書き換えを防ぐ。
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3