<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kondo Uchio</title>
    <description>The latest articles on DEV Community by Kondo Uchio (@udzura).</description>
    <link>https://dev.to/udzura</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F41403%2F4b861ad6-086d-4c14-8c3f-bc862413d15c.jpeg</url>
      <title>DEV Community: Kondo Uchio</title>
      <link>https://dev.to/udzura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/udzura"/>
    <language>en</language>
    <item>
      <title>RubyKaigi Teaser: Ruby on the Edge</title>
      <dc:creator>Kondo Uchio</dc:creator>
      <pubDate>Mon, 23 Mar 2026 14:29:24 +0000</pubDate>
      <link>https://dev.to/udzura/rubykaigi-teaser-ruby-on-the-edge-o7a</link>
      <guid>https://dev.to/udzura/rubykaigi-teaser-ruby-on-the-edge-o7a</guid>
      <description>&lt;p&gt;Are you interested in lightweight web development on the edge? Platforms like &lt;a href="https://workers.cloudflare.com/" rel="noopener noreferrer"&gt;Cloudflare Workers&lt;/a&gt; and &lt;a href="https://www.fastly.com/jp/products/edge-compute" rel="noopener noreferrer"&gt;Fastly Compute&lt;/a&gt; have been gaining tremendous popularity.&lt;/p&gt;

&lt;p&gt;However, edge development in Ruby still faces significant challenges. One of the biggest issues, I believe, is file size. &lt;a href="https://github.com/ruby/ruby.wasm" rel="noopener noreferrer"&gt;ruby.wasm&lt;/a&gt; is an incredible piece of work, but since it packs a fully-featured Ruby into Wasm, the generated artifact is simply too large for edge use cases.&lt;br&gt;
Do you really need that much overhead just to do "a little something"?&lt;/p&gt;

&lt;p&gt;My new framework, &lt;a href="https://github.com/mrubyedge/uzumibi" rel="noopener noreferrer"&gt;&lt;strong&gt;Uzumibi&lt;/strong&gt;&lt;/a&gt; (a Japanese name, like "Hono" — it means &lt;em&gt;live embers buried under ash&lt;/em&gt;), breaks through that wall.&lt;/p&gt;

&lt;p&gt;Here's a very basic example of Uzumibi code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Uzumibi&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Router&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"content-type"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"x-powered-by"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;RUBY_ENGINE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;RUBY_VERSION&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"It works!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="vg"&gt;$APP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  The Evolution of mruby/edge
&lt;/h2&gt;

&lt;p&gt;Let me give you a bit of background. At RubyKaigi 2024, I gave a talk about &lt;strong&gt;mruby/edge&lt;/strong&gt;, a lightweight, Wasm-friendly implementation of mruby written in Rust.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://rubykaigi.org/2024/presentations/udzura.html" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frubykaigi.org%2F2024%2Fimages%2Fogp-2e830974.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://rubykaigi.org/2024/presentations/udzura.html" rel="noopener noreferrer" class="c-link"&gt;
            
An mruby for WebAssembly - RubyKaigi 2024

          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            RubyKaigi 2024, #rubykaigi
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frubykaigi.org%2F2024%2Fimages%2Ffavicon-a9c87a8f.png"&gt;
          rubykaigi.org
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;




&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://udzura.jp/slides/2024/rubykaigi/" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;udzura.jp&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;At the time, it was barely more than an implementation that could run a Fibonacci function — calling it a PoC would have been generous. The idea of running a Wasm file based on mruby/edge on the edge felt like a pipe dream.&lt;/p&gt;

&lt;p&gt;Two years later, mruby/edge has evolved dramatically. It now covers &lt;strong&gt;over 80%&lt;/strong&gt; of the instructions implemented by the mruby 3.4 VM. We prioritized the most critical instructions and got them working. We've also completed standard library implementations, using mruby/c 3.x as a benchmark, focusing on the most "Ruby-like" features. Documentation is available in COVERAGE.md on the &lt;a href="https://github.com/mrubyedge/mrubyedge/blob/v1.1.10/mrubyedge/COVERAGE.md" rel="noopener noreferrer"&gt;mruby/edge repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And of course, it still runs easily in the browser, so we've already prepared a &lt;strong&gt;Playground&lt;/strong&gt; for you. Please give it a try!&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://mrubyedge.github.io/playground/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmrubyedge.github.io%2Fplayground%2Fogp.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://mrubyedge.github.io/playground/" rel="noopener noreferrer" class="c-link"&gt;
            mruby/edge Playground
          &lt;/a&gt;
        &lt;/h2&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmrubyedge.github.io%2Fplayground%2Ffavicon.ico"&gt;
          mrubyedge.github.io
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;(The Playground uses &lt;a href="https://github.com/picoruby/mruby-compiler2" rel="noopener noreferrer"&gt;mruby-compiler2&lt;/a&gt;, created by my dear and respected friend hasumikin. mruby/edge doesn't have its own compiler yet.)&lt;/p&gt;

&lt;p&gt;The time has finally come. I've released &lt;strong&gt;Uzumibi&lt;/strong&gt;, a framework built on mruby/edge, and I'm actively developing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Firepower of Uzumibi
&lt;/h2&gt;

&lt;p&gt;Here are the key features of Uzumibi:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight artifacts.&lt;/strong&gt; A Cloudflare Workers app with realistic functionality weighs in at around &lt;strong&gt;1.2 MiB&lt;/strong&gt;, and compresses to &lt;strong&gt;under 400 KiB&lt;/strong&gt;. That's well within the free tier limits, and loads fast.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An intuitive, Sinatra-like routing DSL&lt;/strong&gt; that feels natural for Ruby developers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple project templates.&lt;/strong&gt; Currently supported: Cloudflare Workers, Fastly Compute, Fermyon Cloud (Spin), and as a bonus, Google Cloud Run(!). Let me know what other platforms you'd like to see supported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You can develop APIs entirely in the browser.&lt;/strong&gt; This is powered by Web (Service) Workers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: Complex features like external service integrations currently only work on Cloudflare Workers. Sorry about that!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With Uzumibi, you can deploy an application to the edge just by writing Ruby code (okay, you might need a little bit of configuration and some dashboard clicks). Uzumibi is a framework for stubborn Ruby developers (like me!) who find JavaScript and TypeScript just a little bit... not quite right.&lt;/p&gt;

&lt;p&gt;Uzumibi is brand new — there will be missing features and bugs. But that also means the possibilities are wide open. Come to RubyKaigi and hear about the potential of this newborn "new Ruby."&lt;/p&gt;

&lt;h2&gt;
  
  
  See You in Hakodate!
&lt;/h2&gt;

&lt;p&gt;My talk is scheduled at &lt;strong&gt;RubyKaigi 2026&lt;/strong&gt; in &lt;strong&gt;Hakodate, Hokkaido&lt;/strong&gt;. Check the official schedule for the exact date and time:&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://rubykaigi.org/2026/schedule/day2/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frubykaigi.org%2F2026%2Fimages%2Fogp-dd7976fa.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://rubykaigi.org/2026/schedule/day2/" rel="noopener noreferrer" class="c-link"&gt;
            
Schedule - RubyKaigi 2026

          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            RubyKaigi 2026, #rubykaigi
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Frubykaigi.org%2F2026%2Fimages%2Ffavicon-5b62728b.png"&gt;
          rubykaigi.org
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I'm going to have a talk on &lt;strong&gt;April 23&lt;/strong&gt;, the 2nd day of RubyKaigi!&lt;/p&gt;

&lt;p&gt;Can't wait? Great news for those who want to try it right away — I've published &lt;a href="https://mrubyedge.github.io/beginning-uzumibi/" rel="noopener noreferrer"&gt;&lt;strong&gt;"Beginning Uzumibi"&lt;/strong&gt;&lt;/a&gt; online. Give it a spin, and then come tell me your thoughts in person at Hakodate!&lt;/p&gt;

&lt;p&gt;(Online issues and pull requests are, of course, also very welcome!)&lt;/p&gt;

</description>
      <category>rubykaigi</category>
    </item>
    <item>
      <title>Trying seccomp via mruby</title>
      <dc:creator>Kondo Uchio</dc:creator>
      <pubDate>Thu, 16 Nov 2017 05:30:51 +0000</pubDate>
      <link>https://dev.to/udzura/trying-seccomp-via-mruby-6af</link>
      <guid>https://dev.to/udzura/trying-seccomp-via-mruby-6af</guid>
      <description>&lt;h2&gt;
  
  
  seccomp?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://man7.org/linux/man-pages/man2/seccomp.2.html" rel="noopener noreferrer"&gt;&lt;code&gt;seccomp(2)&lt;/code&gt;&lt;/a&gt; is a Linux system call that filters processes' syscall invocations. After Linux 3.5, they introduced "seccomp mode 2" that allow systems to filter syscalls by syscall numbers and their arguments.&lt;/p&gt;

&lt;p&gt;This is also one of basic containers features, e.g. &lt;a href="https://docs.docker.com/engine/security/seccomp/" rel="noopener noreferrer"&gt;Docker uses this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It uses BPF (Berkeley Packet Filter), which is also used in &lt;code&gt;libpcap&lt;/code&gt;, to filter syscalls as fast as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  mruby?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/mruby/mruby" rel="noopener noreferrer"&gt;mruby&lt;/a&gt; is one of the Ruby implementations (FYI mruby is created by Matz, as MRI is founded by Matz). It is designed to be embeddable into gadgets and to be lightweight than CRuby.&lt;/p&gt;

&lt;p&gt;As a side effect of embedding features, mruby has very clean and concise C API, so it is easy to write C bindings/systems programmings with it. It is similar to Lua language in many aspects.&lt;/p&gt;




&lt;p&gt;I am going to try to use seccomp basic features via &lt;a href="https://github.com/seccomp/libseccomp" rel="noopener noreferrer"&gt;libseccomp&lt;/a&gt;, writing mruby's gem(mrbgem) to bind libseccomp.&lt;/p&gt;

&lt;p&gt;Here is &lt;a href="https://github.com/haconiwa/mruby-seccomp" rel="noopener noreferrer"&gt;&lt;code&gt;mruby-seccomp&lt;/code&gt;&lt;/a&gt;. You can build a &lt;code&gt;mruby&lt;/code&gt; binary with seccomp access, by checking out this repo in some Linux and just hit &lt;code&gt;make&lt;/code&gt;(building mruby itself requires CRuby, bison and some libraries).&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic usage
&lt;/h2&gt;

&lt;p&gt;In C level, you can create seccomp context by &lt;code&gt;seccomp_init(3)&lt;/code&gt;, add filter rules by &lt;code&gt;seccomp_rule_add(3)&lt;/code&gt;, then load to current process by &lt;code&gt;seccomp_load(3)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A seccomp context has a default action:&lt;br&gt;
&lt;code&gt;:kill =&amp;gt; SCMP_ACT_KILL, :allow =&amp;gt; SCMP_ACT_ALLOW, :trap =&amp;gt; SCMP_ACT_TRAP, ...&lt;/code&gt; &lt;br&gt;
Then you can add custom filter actions with syscall and arguments specifications.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;:kill&lt;/code&gt; by default to make a whitelist, and use &lt;code&gt;:allow&lt;/code&gt; a blacklist.&lt;/p&gt;

&lt;p&gt;This is a blacklist that restricts &lt;code&gt;uname(2)&lt;/code&gt; calls. Build with &lt;a href="https://github.com/matsumotory/mruby-uname" rel="noopener noreferrer"&gt;mruby-uname&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;default: :allow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:uname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;
&lt;span class="no"&gt;Uname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nodename&lt;/span&gt; &lt;span class="c1"&gt;# Really calls `uname(2)` !&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./mruby/bin/mruby /tmp/test.rb 
&lt;span class="go"&gt;Bad system call
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Bad system call&lt;/code&gt; implies &lt;code&gt;SIGSYS&lt;/code&gt; - you even can trap this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combination with &lt;code&gt;fork()/exec()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Loaded seccomp's information will not be changed after &lt;code&gt;fork/clone and execve&lt;/code&gt;, as &lt;a href="https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt" rel="noopener noreferrer"&gt;a kernel document&lt;/a&gt; says.&lt;/p&gt;

&lt;p&gt;You can load a seccomp context just after &lt;code&gt;fork()&lt;/code&gt; and then do &lt;code&gt;execve()&lt;/code&gt;, to create a "sandbox" container - which restricts child processes to call specified syscalls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# fork from https://github.com/iij/mruby-process&lt;/span&gt;
&lt;span class="c1"&gt;# exec from https://github.com/haconiwa/mruby-exec&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;default: :allow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;kill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:mkdir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ARG&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ARG&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;pid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fork&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;

  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"==== It will be jailed. Please try to mkdir"&lt;/span&gt;
  &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="s2"&gt;"/bin/sh"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="nb"&gt;p&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitpid2&lt;/span&gt; &lt;span class="n"&gt;pid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./mruby/bin/mruby /tmp/jail.rb 
&lt;span class="go"&gt;==== It will be jailed. Please try to mkdir
&lt;/span&gt;&lt;span class="gp"&gt;sh-4.2$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; /tmp/test1234
&lt;span class="go"&gt;Bad system call
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is similar to &lt;a href="http://man7.org/linux/man-pages/man7/capabilities.7.html" rel="noopener noreferrer"&gt;Linux Capabilities&lt;/a&gt;, but seccomp has a finer granularity to control programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced features
&lt;/h2&gt;

&lt;p&gt;Using seccomp we can catch SIGSYS with the informations of what syscall is blocked(via struct &lt;code&gt;siginfo_t&lt;/code&gt;). mruby-seccomp supports this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;default: :allow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:uname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on_trap&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;syscall&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Trapped: syscall &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;Seccomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;syscall_to_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;syscall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; = #&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;syscall&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;

&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="c1"&gt;# Then hit `uname(2)`&lt;/span&gt;
  &lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"nodename: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;Uname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nodename&lt;/span&gt;
&lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Catch as error: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;message&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Trapping is OK"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./mruby/bin/mruby /tmp/trap.rb 
&lt;span class="gp"&gt;Trapped: syscall uname = #&lt;/span&gt;63
&lt;span class="go"&gt;Catch as error: uname failed
Trapping is OK
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: Signal handlers will be cleaned after &lt;code&gt;exec()&lt;/code&gt;. So exec()'ing to be bash and trapping &lt;code&gt;uname(1)&lt;/code&gt; hit is unsupported now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;seccomp&lt;/code&gt; can restrict a process and a process tree's syscall invocations. We can do an experiment using mruby, mruby-seccomp and some mrbgems about processes control.&lt;/p&gt;

&lt;p&gt;BTW seccomp is supported in Docker, LXC and &lt;a href="https://github.com/haconiwa/haconiwa#readme" rel="noopener noreferrer"&gt;Haconiwa&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Pull requests to &lt;a href="https://github.com/haconiwa/mruby-seccomp" rel="noopener noreferrer"&gt;mruby-seccomp&lt;/a&gt; is welcomed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Original Japanese article
&lt;/h2&gt;

&lt;p&gt;Original article written by me in Japanese:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://udzura.hatenablog.jp/entry/2016/11/18/160020" rel="noopener noreferrer"&gt;http://udzura.hatenablog.jp/entry/2016/11/18/160020&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>container</category>
      <category>docker</category>
      <category>seccomp</category>
      <category>mruby</category>
    </item>
    <item>
      <title>Writing a small bare-metal container</title>
      <dc:creator>Kondo Uchio</dc:creator>
      <pubDate>Wed, 15 Nov 2017 05:16:26 +0000</pubDate>
      <link>https://dev.to/udzura/writing-a-small-bare-metal-container-aof</link>
      <guid>https://dev.to/udzura/writing-a-small-bare-metal-container-aof</guid>
      <description>&lt;p&gt;First, run &lt;code&gt;debootstrap&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; /root/devto
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;debootstrap &lt;span class="nt"&gt;--variant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;minbase &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="go"&gt;    jessie \
    /root/devto \
    http://ftp.jp.debian.org/debian
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, prepare a small ruby script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# $ cat after-unshare.rb &lt;/span&gt;
&lt;span class="c1"&gt;#!/usr/bin/env ruby&lt;/span&gt;
&lt;span class="n"&gt;container_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;container_name&lt;/span&gt;
&lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt; &lt;span class="s2"&gt;"/sys/fs/cgroup/cpu/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="nb"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"skip"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt; &lt;span class="s2"&gt;"/sys/fs/cgroup/cpu/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/cpu.cfs_period_us"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"100000"&lt;/span&gt;
&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt; &lt;span class="s2"&gt;"/sys/fs/cgroup/cpu/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/cpu.cfs_quota_us"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="s2"&gt;"30000"&lt;/span&gt; &lt;span class="c1"&gt;# 30%&lt;/span&gt;
&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt; &lt;span class="s2"&gt;"/sys/fs/cgroup/cpu/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/tasks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="vg"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt;
&lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chroot&lt;/span&gt; &lt;span class="s2"&gt;"/root/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chdir&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;
&lt;span class="nb"&gt;system&lt;/span&gt; &lt;span class="s2"&gt;"mount --make-rprivate /"&lt;/span&gt;
&lt;span class="nb"&gt;system&lt;/span&gt; &lt;span class="s2"&gt;"mount -t proc proc /proc"&lt;/span&gt;
&lt;span class="nb"&gt;system&lt;/span&gt; &lt;span class="s2"&gt;"hostname &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;container_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.example.com"&lt;/span&gt;

&lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="s2"&gt;"bash -l"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After all, run this ruby script via &lt;code&gt;unshare(1)&lt;/code&gt; with options below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+x after-unshare.rb
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;unshare &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="go"&gt;    --fork \
    --pid \
    --mount \
    --uts \
    `pwd`/after-unshare.rb devto
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it!! You're got into the container!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;root@devto:/#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ps auxf
&lt;span class="go"&gt;USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.3  0.3  20288  3240 ?        S    05:13   0:00 bash -l
root         7  0.0  0.2  17496  2080 ?        R+   05:13   0:00 ps auxf
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>container</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
