1. What exactly will your security model look like? I'm not even sure that
you have a clear vision yet so maybe before dealing with implementations it
might be more helpful to first make clear what will be allowed, what not and
how you want to separate areas of different capabilities.
A permission is an object with the method implies?( permission )
implies?( permission ) returns true iff self implies permission. For
instance:
TRUE == write_in_any_file.implies?( write_in_foo_txt ).
FALSE == write_in_any_file.implies?( format_hard_disk ).
Of course, TRUE == a.implies( a ).
When a protected operation is tried, the method am_i_allowed?(
permission ) is executed. This method returns FALSE if the "current
permissions" do not imply permission.
Each source code file will be asociated with a permission. The current
permission is the AND of the implies of the permissions of all the
files in the calling stack.
For instance.
Lets imagine:
a.rb: has format_hard_disk && write_in_any_file permissions (*).
b.rb: has write_in_any_file permission (*).
(*) assume that the ruby process is running as root for a moment.
And this is the (pseudo)code:
a.rb:
def foo()
format_hard_disk()
end
b.rb:
require "a"
require "securedruby"
configure_permissions()
foo()
When "ruby b.rb" is run. The following process happens:
1 - foo is defined.
2 - Secured ruby is loaded.
3 - permissions for the files are set.
4 - foo is started. (STACK: b.rb, a.rb)
4.1 - format_hard_disk is started (STACK: b.rb - a.rb - ???).
4.2 - check if b.rb permissions imply format_hard_disk. (pass)
4.3 - check if a.rb permissions imply format_hard_disk. (NO pass)
4.4 - throw security exception (formatting is NOT EXECUTED).
2. When 1 is answered this one might become more clear: what security you
need is not possible using threads with different $SAFE levels?
That one is easy. Run untrusted libs/servlets/scripts without
modification and be able to box them without requiring the client code
to be any different as it would be if it's trusted.
Regards and thank's for your time and attention,
Aureliano.
PS: just having this conversation with all of you is making clearer for
me the picture of what I want to do. Thank you very much.