mruby gem using unshare/setns to control linux namespce
C Ruby Shell
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 76 commits ahead, 2 commits behind rhykw:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
misc
mrblib
sample
src
test
.clang-format
.gitignore
.travis.yml
.travis_build_config.rb
LICENSE
README.md
Rakefile
mrbgem.rake
mruby-linux-namespace.gem

README.md

mruby-linux-namespace Build Status

A mruby gem using unshare/setns/clone to control linux namespaces.

install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|

  # ... (snip) ...

  conf.gem :github => 'haconiwa/mruby-linux-namespace'
  # mruby-process, mruby-exec, mruby-process-sys are also useful
end

example

## Using mruby-process-sys
> Process::Sys.getuid
 => 500
> Process::Sys.getgid
 => 500

> Namespace.unshare(Namespace::CLONE_NEWUSER|Namespace::CLONE_NEWNET)
 => 0

> Process::Sys.getuid
 => 65534 ... unknown
> Process::Sys.getgid
 => 65534

> File.open('/proc/self/uid_map','wb+').write('0 500 1')
 => 7
> File.open('/proc/self/setgroups','w+').write('deny')
 => 4
> File.open('/proc/self/gid_map','wb+').write('0 500 1')
 => 7
>
 => nil
> Process::Sys.getuid
 => 0
> Process::Sys.getgid
 => 0
>

Available APIs

  • Namecpace.unshare(flag)
  • Namecpace.setns(flag, pid: pid or fd: fd)
  • Namecpace.clone(flag) { #do something... e.g. exec } - Note that clone(2) support is experimental/Recommended to exec() fast

Please see sample/*.rb or test/*.rb

License

under the MIT License: see LICENSE file