Hook cheat sheet: Ruby
How to add a vulnboxd runtime hook to a Ruby service by hand. Find your setup in the table, then follow its block.
- Without source access: only the compose file changes; redeploy. With source access: you change the code or Dockerfile and rebuild.
- Hub automation says how much the hub's proposals do for you. Fully: approve the proposal in the hub; the block is the fallback when it failed. With conditions: the same, when the conditions listed hold. Partly: the hub pushes the compose part, the rest is yours. Not at all: everything is by hand.
/usr/local/lib/vulnboxd/traceis the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at/opt/vbxtracein the container.- How to check that the hook works and undo it is at the end of the page.
- Runtime hooks explains what a hook does.
Ruby
| Setup | Use this when | Change | Hub automation |
|---|---|---|---|
| Ruby runtime hook (RUBYOPT) | Depends on rack, puma, unicorn, falcon, thin or 10 more (in Gemfile) | compose | fully |
| Ruby runtime hook (require in config.ru) | Depends on rack (in Gemfile) | source, rebuild | partly |
Without source access
Only the compose file changes: the image and the code stay as they are.
Ruby runtime hook (RUBYOPT)
- Use this when: Ruby service that depends on
rack,puma,unicorn,falcon,thinor 10 more (inGemfile). - Hub automation: fully. The hub proposes exactly this change and pushes it (one commit per container) once you approve it. Do it by hand only when the proposal failed, e.g. on an unusual compose file.
- Check and undo: hook mounted into the container
Mounts vulnboxd's hook directory read-only at /opt/vbxtrace and adds -r/opt/vbxtrace/ruby/vbxtrace.rb to RUBYOPT, so every Ruby process of the service reports which request started a child process, opened a connection or a file. Image and source stay untouched; set VBXTRACE=0 to switch it off.
Compose: merge into the service (app is its name) and redeploy:
services:
app:
volumes:
- /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
environment:
RUBYOPT: "-r/opt/vbxtrace/ruby/vbxtrace.rb" # already set? append, separated by a spaceExact detection rules
Package Y1 (Ruby hook), proposal Y1:compose, defined in hooks/ruby/y1/proposals/compose.toml.
- Image matches (regex):
^(docker\.io/)?(library/)?ruby:,^[^ ]*/ruby:,^(docker\.io/)?bitnami/ruby,^(docker\.io/)?phusion/passenger-(ruby|full),^(docker\.io/)?(library/)?rails: - Command matches (regex):
\bpuma\b,\bunicorn(_rails)?\b,\bfalcon\b,\bthin\b,\brackup\b,\brails\s+(s|server)\b,\bbundle\s+exec\b,\biodine\b,\bagoo\b,\bruby\b,\bhanami\s+server\b - Dependency on:
rack,puma,unicorn,falcon,thin,webrick,iodine,agoo,rails,railties,sinatra,roda,hanami,hanami-router,grape - Files:
Gemfile,Gemfile.lock,gems.rb,gems.locked,config.ru,*.gemspec,.ruby-version
With source access
These change the service's code or Dockerfile, then it is rebuilt.
Ruby runtime hook (require in config.ru)
- Use this when: Ruby service that depends on
rack(inGemfile). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Mounts vulnboxd's hook directory read-only at /opt/vbxtrace and loads the hook from the first line of config.ru. Use when RUBYOPT cannot be set for the service. The require is a no-op when the file is missing, so the service still starts without the mount.
1. Compose: merge into the service (app is its name) and redeploy:
services:
app:
volumes:
- /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro2. Source change, then rebuild:
- add the read-only mount of
/usr/local/lib/vulnboxd/traceat/opt/vbxtraceto the service - add
require "/opt/vbxtrace/ruby/vbxtrace" if File.exist?("/opt/vbxtrace/ruby/vbxtrace.rb")as the first line ofconfig.ru
Example change on a sample service (hooks/ruby/y1/proposals/config-ru.diff):
--- a/<service>/config.ru
+++ b/<service>/config.ru
@@ -1,3 +1,4 @@
+require "/opt/vbxtrace/ruby/vbxtrace" if File.exist?("/opt/vbxtrace/ruby/vbxtrace.rb")
require_relative "config/environment"
run Rails.applicationExact detection rules
Package Y1 (Ruby hook), proposal Y1:config-ru, defined in hooks/ruby/y1/proposals/config-ru.toml.
- Dependency on:
rack - Files:
config.ru
Check that it works, and undo
Each block links the variant it needs.
Hook mounted into the container
Check: After the redeploy, this lists the processes that loaded the hook (empty: it is not loaded):
docker compose exec app sh -c 'grep -l vbxtrace /proc/[0-9]*/maps'The hub's Trace tab then shows links whose method starts with hook:.
Undo: Set VBXTRACE: "0" in the service's environment and restart it, or revert the commit (the hub's proposal screen has a revert per container). Remove the mount of /opt/vbxtrace only together with what loads from it: a runtime told to preload a missing file may refuse to start.