《Distributed Programming With Ruby》读书笔记二 Security and ID Conversion (Part1.1-2)

    • Security
      • Although DRb provide some security, they fall short of a full, comprehensive solution. This can make DRb less than desirable in a lot of real world situations. However, in situations where security is a lesser concern,such as prototyping and intranet application.
      • Safe mode to disable all eval() related calls
        • First, we retrieve a new remote object from the server. Then we undefine the instance_eval method on that remote object. Because of how DRb works, as we learned earlier, when a method does not exist on the local copy of the remote object, the method is invoked on the server side. So in the last line, when we call the instance_eval method and tell it to evaluate String "`rm -rf *`", we are telling the remote server to forcibly, and recursively, remove all files on the server.
        • It’s best to run your “server” code with a safe mode of at least 1: $SAFE = 1. This disables eval() and related calls on strings passed across the wire. Now, if you were to run our malicious client again, you would get the following error:
          • SecurityError: Insecure operation - instance_eval
        • comment:如何设置safe mode? check netxt part(ACL)
      • Access Control Lists(ACLs)
        • Only deny 192.168.1.7
          • acl = ACL.new(%w{deny 192.168.1.7})
      • DRb over SSL(Secure Sockets Layer)
      • In its simplest form SSL works like this: The client makes an SSL request to the server. The server says, “Here is my public key. Use it to encrypt your request, and I, the server,will use my private key to decode it.”
      • There is an example on how do lock down our "Hello World" application to accept only trusted connections of SSL of this part. Details should check books.

             

      • ID Conversion
        • The method of looking up an object in the ObjectSpace using the reference ID is called ID conversion.
        • DRb ships with three built-in ID converters: DRb::DRbId-Conv, DRb::TimerIdConv, and DRb::GWIdConv. It is also possible to build your own ID converter.
        • Built-in ID Converters
          • We only look at DRb::DRbIdConv and DRb::TimerIdConv. The general consensus on the DRb::GWIdConv converter is that it is extremely complicated to set up, prone to failure,and quite slow.
          • DRb::DRbIdConv
          • DRb::DRbIdConv is the default ID converter when dealing with DRb.The default ID converter, DRb::DRbId-Conv, simply uses the object_id for the object to determine its reference. That reference ID is then used to look up the object in the ObjectSpace and then invoke the requested message.
            • example:
            • server
            • client
            • output
              • client
              • server
            • As we can see, the object_id on the server printout matches the @ref instance variable on the DRbObject we received from the server. This is the default.
          • DRb::TimerIdConv
          • The default ID converter, DRb::DRbIdConv, has one downside. If you‘re not careful,referenced objects on the server can become garbage-collected and are no longer available when the client tries to reference them.
          • The only difference between DRb::TimerIdConv and DRb::DRbIdConv is that DRb::TimerIdConv tells the server to keep its objects alive for a certain amount of time after they were last accessed. The default length for this keepalive is 600 seconds,or 10 minutes.
            • server
          • A better approach to solve the garbage-collection problem lies in your architecture.Don’t take an object from the server and hold onto it in the client for any longer than you absolutely need to. Retrieve the object from the server, use it, and then get rid of it. If you want to make sure you have access to that same referenced object minutes, hours, or days later, you should consider writing your own custom ID converter that stores your objects in something other than the ObjectSpace.
        • Building Your Own ID Converter
        • Why would we want to do that? Perhaps we want to have some sort of signature in the ID so that we can tell by looking at it where it originated. Perhaps we are using a database as our object store on the server, and we want to use the primary key for the database row as the ID. Or perhaps we just want to be different.
          • Example: append HW: to the object_id for our objects so that we know that those objects came from the HelloWorldServer
          • change server code like:
          • client will output:
        • Using Multiple ID Converters
        • when you install a converter using the DRb.install_id_conv method, you tell DRb that all services in that Ruby VM are now to use that particular ID converter.
        • if you want to use multiple ID converters,the start_service method takes a third parameter, a Hash of configuration parameters. One parameter in the list of available parameters is :idconv, which tells DRb to use a particular ID converter for that service.
          • modify server code to:
          • client
          • output
时间: 2024-11-07 07:46:44

《Distributed Programming With Ruby》读书笔记二 Security and ID Conversion (Part1.1-2)的相关文章

《Distributed Programming With Ruby》读书笔记一Drb:Hellowold and Pass by Reference

<Distributed Programming With Ruby>Mark Bates Preface: The author was using Java and RMI(remote method invocation) as distributed interface in 2001. To solve performence problems, he found DRb. "I was already impressed with Ruby for being a ter

《Programming in Lua 3》读书笔记(二十二)

日期:2014.8.6 PartⅣ The C API 26 Extending Your Application 使用Lua很重要的一点是用来做配置语言.配合主语言做一些功能的配置. 26.1 The Basics 有的时候程序需要配置一些功能信息,很多时候可能有许多别的方法比用lua做配置要更简单:如使用环境变量或者读取文件,读取文件涉及到文件的解析.如果使用Lua进行配置的话,相当于用lua文件替代了要读取的如csv.txt文件等. 使用Lua进行配置的时候,就需要使用Lua API去控制

《Programming in Lua 3》读书笔记(二十一)

日期:2014.8.1 PartⅣ The C API 25 An Overview of the C API Lua是一种嵌入式语言.这就意味着Lua不是单独存在的,而是可以通过一系列的标准库将lua的特性嵌入至其他应用模块中. Lua以Lua interpreter(lua的解释器?)来解决了其不是独立程序,我们直到现在却又能独立使用Lua的问题.这个解释器是一个小型的程序(不超过500行代码),使用lua的标准库来实现独立解释程序,这个程序将处理与用户的交互等操作交给lua的标准库,这些库

《Programming Hive》读书笔记(一)Hadoop和hive环境搭建

<Programming Hive>读书笔记(一)Hadoop和Hive环境搭建 先把基本的技术和工具学好,才能更高效地思考和工作. Chapter 1.Introduction 简介 Chapter 2.Getting Started 环境配置 Hadoop版本会更新,以官方安装教程为准 http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html#Standalone_O

代码的未来读书笔记&lt;二&gt;

代码的未来读书笔记<二> 3.1语言的设计 对Ruby JavaScript Java Go 从服务端客户端以及静态动态这2个角度进行了对比. 这四种语言由于不同的设计方针,产生了不同的设计风格. Header 客户端 服务端 动态 Html5 Ruby 静态 Java Go 静态动态 静态:无需实际运行,仅根据程序代码就能确定结果. 动态:只有到了运行时才能确定结果.不过无论任何程序,或多或少都包含的动态的特性. 动态运行模式 运行中的程序能识别自身,并对自身进行操作.对程序自身进行操作的编

《卓有成效的程序员》----读书笔记二

六大方面对比Launchy和TypeAndRun(TAR) 对于快速启动工具,很多人都有自己的偏好,多次听到朋友介绍Launchy的好,虽然自己一直在使用着TAR,还是克制不住对于好软件的渴求,下载Launchy进行试用.很多软件都是有一个试用期的,也许新的软件确实不错,但是你习惯了以前使用的那个软件.今天就比较客观的将Launchy和TAR进行一下对比,从界面.上手速度到功能.自定义,以及软件的稳定性.占用资源进行详细的比较. [界面美观]Launchy:毫无疑问这是它的强项.1.0正式版自带

《R实战》读书笔记二

第一章 R简介 本章概要 1安装R 2理解R语言 3运行R程序 本章所介绍的内容概括如下. 一个典型的数据分析步骤如图1所示. 图1:典型数据分析步骤 简而言之,现今的数据分析要求我们从多种数据源中获取数据.数据合并.标注.清洗和分析,并且把分析的结果进行展示,形成报告或者系统,辅助决策.R能够满足现今数据分析的要求. 为什么用R? R是一个适合统计分析和绘图的环境与语言.它是开源.免费的,获得世界范围社区支持.统计分析和绘图工具已经很多了,例如:SPSS,SAS,Excel,Stata和Min

《学会提问》读书笔记二

<学会提问>读书笔记二 因为书中的小点知识和思考太多,我从这篇笔记开始就只记我害怕会遗忘的知识,思考过程就不提及了. 弱势批判性思维和强势批判性思维 弱势批判性思维的目的是用批判性思维来反驳.抵制那些和你意见不同的论述最终就是为了看到那些与你主张不一致的人服服帖帖的甘心认输,但是这样就意味着,你对于是否接近真理和发扬美德漠不关心,实际上也摧毁了批判性思维潜在的人性的一面和不断发展进步的特征.而且我认为,弱势批判性思维的出发点是自私的,他们盲目地认为自己的观点就是正确的,用批判性思维来批判其他人

《大型网站技术架构》读书笔记二:大型网站架构模式

一.分层 最常见的架构模式,将系统在横向维度上切分成几个部分,每个部分单一职责.网站一般分为三个层次:应用层.服务层和数据层,其具体结构如下图所示: 通过分层,一个庞大系统切分成不同部分,便于分工合作和维护. 但是,分层架构也有一些挑战:①必须合理规划层次边界和接口:②禁止跨层次的调用及逆向调用. 二.分割 分割是在纵向方面对软件进行切分->将不同的功能和服务分割开来,包装成高内聚低耦合的模块单元,有助于软件开发和维护,还便于不同模块的分布式部署,提高网站的并发处理能力和功能扩展能力. 三.分布