Ruby:找不到临时目录

前端之家收集整理的这篇文章主要介绍了Ruby:找不到临时目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的Passenger Rails应用程序中出现了大约500个错误.查看日志时,乘客无法访问/ tmp目录.我已经验证它存在并且具有对root的RW访问权限,然后尝试了www-data.这里发生了什么?
2014-01-14 16:01:16.6573 20624/7fa7c8806700 Pool2/SmartSpawner.h:301 ]: Preloader for /var/www/socialrest_homepage started on PID 20686,listening on unix:/tmp/passenger.1.0.20618/generation-0/backends/preloader.20686
App 20704 stdout: 
[Tue Jan 14 16:01:17 2014] [error] [client 168.215.171.129] Premature end of script headers: 
App 20686 stderr: /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tmpdir.rb:34:in `tmpdir': could not find a temporary directory (ArgumentError)
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/utils/tmpio.rb:17:in `new'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/utils/tee_input.rb:99:in `initialize'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/rack/thread_handler_extension.rb:55:in `new'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/rack/thread_handler_extension.rb:55:in `process_request'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
App 20686 stderr:   from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/lib/phusion_passenger/request_handler.rb:440:in `block (3 levels) in start_threads'
[ 2014-01-14 16:01:21.0163 20624/7fa7cb242700 Pool2/Pool.h:776 ]: Process (pid=20704,group=/var/www/socialrest_homepage#default) no longer exists! Detaching it from the pool.
App 20720 stdout:

这是我当前的/ tmp和config / environment.rb所有权:

drwxrwxrwx   5 root root 4.0K Jan 14 16:01 tmp

-rwxr-xr-x  1 root root  196 Jan 13 20:06 environment.rb

解决方法

堆栈跟踪最重要的部分是错误消息:
could not find a temporary directory (ArgumentError)

当你告诉Ruby> = 2.0创建一个临时文件时,它会查找一个可以安全地创建文件的目录.在任何人可以替换文件的目录中创建临时文件将是一个很大(和常见)的安全漏洞!

你有两个可能性:

>通过将其中一个环境变量TMPDIR或TMP或TEMP设置为安全目录,告诉ruby可以安全地创建临时文件的位置.
>修复ruby尝试使用的目录的权限. Ruby尝试使用的目录:systempdir(“/ tmp”)和当前目录

如果目录不是可写入的,或者设置了粘滞位,Ruby会认为目录是安全的. (不要将粘性位(t)与seteuid / setgid位混淆!)

因此,您可以将工作目录设置为不可写入或执行以下操作,而不是设置TMPDIR:

chmod +t /tmp

chmod的手册页解释了粘滞位的使用:

[It] prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory,and is commonly found on world-writable directories like /tmp.

以下是没有粘性位的情况:https://security.stackexchange.com/questions/9115/can-you-describe-a-real-life-scenario-of-exploiting-sticky-bits/108666#108666

另见:https://blog.diacode.com/fixing-temporary-dir-problems-with-ruby-2

猜你在找的Ruby相关文章