I have written an app in Ruby for my company and I was the only one
that had acess to read/execute it. I’ve hired someone to help me with
daily work and that includes having him execute a set of those Ruby
scripts.
Is it possible to allow him to only execute the code and not give read
permission? All boxes are running Linux.
Interpreted languages and shells (PHP, Python, Ruby, Perl, Bash, ZSH
etc…) all require read access to the script they are running, so they
can actually ‘read’ the commands they need to interpret. By default,
the ruby interpreter runs with the privileges of the user who executed
it. A possibility, although I have not tried it myself, would be to
setuid the ruby executable so that the interpreter always runs with
permission to read the script, even if the user does not have those
permissions.
Only complied binary’s can have only the executable bit set without
the read bit set, so another option you have, would be to put the ruby
file into a C char* and execute it using something like system(“ruby
-e ‘ruby_code’”). Of course you’d need to make sure strings are
properly escaped, and this might be too much work if the script is
constantly changing.
Other than that, I can’t think of any other ways around the problem. I
could be wrong though, and if anything I’ve said above is incorrect
I’m happy to be corrected.
I should also mention, that using setuid on the ruby executable could
open up security issues on the systems where you use this method, and
the script would need to be executed explicitly using ‘ruby
some_script’ as the users shell will not have read access to the
script to read any #!/usr/bin/ruby lines at the start of the script to
find which interpreter to use if executed using ./some_script.
The setuid idea seems nice to me. Yes, it might uncover some security
holes, but it still is much better than having the source code
exposed.
I’ve used setuid on the ruby executable and chmod 000 a test ruby
script. The user cannot read the file, but ruby can execute it, just
great. Problem is that dependencies are broken. It cannot locate
another script in the same directory. " require ‘lib’ " fails with a
file not found error.
I guess that’s not really a Ruby question, but I have an idea…
Sudo may be the best answer. Allow the user to sudo the Ruby app as
another user with read access to the script. You’ll want to read the
sudoers man page as you’ll need the no authentication option and other
tidbits. Then you can wrap up the sudo command (something like sudo -u
reading_user /path/to/app) with an alias or shell script that your
underling can call. There are still security concerns, but you have
more control than with the setuid option, I think.
It seems that using setuid removes ‘.’ from $LOAD_PATH. If you add
$LOAD_PATH.push(‘.’) it should solve the loading issue. As an aside,
you can minimise security issues by having a user other than root own
the ruby executable. Perhaps the same user who owns the code? but this
would probably cause issues with gems and permissions. There lots of
different approaches you could take from there, it all depends on what
you like. One nice feature I’ve noticed is that -e is not allowed when
running setuid which means a user can’t simply do ruby -e ‘puts
File.read(“test.rb”)’, Although, there is nothing to stop them putting
that code in a file and running it that way. Covering up that loop
hole I can’t help with.
If you can’t trust your worker, who can you trust?
If you can’t trust them, don’t give them the job.
you could write a tool in C to act as an intermediary.
Have it take whatever args you give to the Ruby script.
But allow the C tool to run under a uid used by the system, but allow
the user execute priveledges on the C tool.
The C tool then runs the Ruby script owned by the other uid and
passes the args to it, returning to the user any important results.
It’s convoluted but any solution is going to be, other than hiring
somebody you trust.
If you can’t trust your worker, who can you trust?
If you can’t trust them, don’t give them the job.
Yes, and going round the houses to hide the source doesn’t exactly
promote good harmony among the workforce either (it shrieks “I don’t
trust you!”). Just make sure the employment contract is solid.
I have written an app in Ruby for my company and I was the only one
that had acess to read/execute it. I’ve hired someone to help me with
daily work and that includes having him execute a set of those Ruby
scripts.
Is it possible to allow him to only execute the code and not give read
permission? All boxes are running Linux.
If you don’t want the source code to be visible you might consider a
couple levels of encryption and, maybe, hosting the actual “exe” on a
site that you control and have a loader exe grab it when it is needed.
For example, for Ruby program X, you could encrypt X with a key(also on
another server if you wish) and then make a loader that would decrypt it
on the fly and interpret the resulting code. You could add checksums,
etc. for the loader if you’re worried about someone hacking it so they
can then view the code.
Depending on what you’re doing with it, it could make more sense to have
a web interface to it and then you would only have to put it on a server
of your choosing and let them call it that way.
I have written an app in Ruby for my company and I was the only one
that had acess to read/execute it. I’ve hired someone to help me with
daily work and that includes having him execute a set of those Ruby
scripts.
Is it possible to allow him to only execute the code and not give read
permission? All boxes are running Linux.
i may have overlooked something but what is wrong with using chmod?
Ruby scripts are not ELF/Mach-O/PE/“whatever your system uses”
binaries. Your friend needs to be able to read the script to execute
it.
Well, the permissions settings need to include the UID of the process
that tries to use the script.
It is possible to make it a system level UID where users can run it
indirectly, but not open and read the file. But any admin can change
that, and a good admin would probably be very suspicious of it.
the best way will be to implement on ruby an encryption method. that
will
take a key stored on a secure place and use it to decode encrypted files
on
the flyIt might create some overload but it will be an interesting
project
to code. and I guess a lot of people hosting rails apps might be really
interested on this also.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.