Skip to content

Hook cheat sheet: Scala Native ​

How to add a vulnboxd runtime hook to a Scala Native 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/trace is the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at /opt/vbxtrace in 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.

Scala Native ​

SetupUse this whenChangeHub automation
vulnboxd hook for Scala NativeDepends on sbt-scala-native or snunit (in its manifest)source, rebuildpartly

With source access ​

These change the service's code or Dockerfile, then it is rebuilt.

vulnboxd hook for Scala Native ​

  • Use this when: Scala Native service that depends on sbt-scala-native or snunit (in its manifest).
  • Hub automation: partly. The hub pushes the compose lines; the source change is yours.
  • Check and undo: hook mounted into the container

Vendors the @extern binding of vbxhook (the sbt plugin compiles the C sources) and adds request_begin/request_end around the service's request handling; thread-per-connection servers keep an exact request counter per connection.

1. Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro

2. Source change, then rebuild:

  1. copy /usr/local/lib/vulnboxd/trace/native/scala-native/src/main/scala/vbxtrace into <service>/src/main/scala/vbxtrace
  2. copy native/c/vbxhook.c, native/c/vbxhook.h and include/vbxtrace.h from the hook directory into <service>/src/main/resources/scala-native/
  3. around each request: val ctx = VBXTrace.begin(socket.getLocalPort, socket.getInetAddress.getHostAddress, socket.getPort, index) ... VBXTrace.end(ctx, status), with index counted per connection
  4. optional: report spawned processes (VBXTrace.spawned(ctx, p.pid())), outgoing connections (VBXTrace.connected) and opened files (VBXTrace.opened)
  5. glibc < 2.34 only: nativeConfig ~= (_.withLinkingOptions(_ :+ "-ldl"))
  6. mount the hook directory read-only at /opt/vbxtrace in the service's compose entry

Example change on a sample service (hooks/native/c4/proposals/scala-native.diff):

diff
# Example: a Scala Native server (thread per connection) after vendoring src/main/scala/vbxtrace and the
# C sources in src/main/resources/scala-native/.
--- a/src/main/scala/Server.scala
+++ b/src/main/scala/Server.scala
@@ -1,4 +1,5 @@
 import java.net.{ServerSocket, Socket}
+import vbxtrace.VBXTrace
 
 def serve(s: Socket): Unit =
   var index = 0
@@ -6,6 +7,9 @@ def serve(s: Socket): Unit =
   while hasRequest(s) do
-    handle(s)
+    val ctx = VBXTrace.begin(s.getLocalPort, s.getInetAddress.getHostAddress, s.getPort, index)
+    val status = handle(s)
+    VBXTrace.end(ctx, status)
     index += 1
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,2 +3,4 @@ services:
   <service>:
     build: .
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
Exact detection rules

Package C4 (Haskell, OCaml, Julia, R, Scala Native), proposal C4:scala-native, defined in hooks/native/c4/proposals/scala-native.toml.

  • Image matches (regex): ^sbtscala/scala-sbt
  • Dependency on: sbt-scala-native, snunit
  • Files: build.sbt, project/plugins.sbt, build.mill, build.sc

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):

sh
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.