Hook cheat sheet: Haskell
How to add a vulnboxd runtime hook to a Haskell 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.
Haskell
| Setup | Use this when | Change | Hub automation |
|---|---|---|---|
| vulnboxd hook for Warp / WAI (Haskell) | Depends on warp, wai, servant-server, yesod, yesod-core or 2 more (in its manifest) | source, rebuild | partly |
With source access
These change the service's code or Dockerfile, then it is rebuilt.
vulnboxd hook for Warp / WAI (Haskell)
- Use this when: Haskell service that depends on
warp,wai,servant-server,yesod,yesod-coreor 2 more (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 vbxtrace cabal package and wraps the WAI application in its middleware: request boundaries with the exact per-connection request index, and exact links for processes, connections and files the handlers report.
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:
- copy
/usr/local/lib/vulnboxd/trace/native/haskell/vbxtraceinto<service>/vendor/vbxtrace - copy
native/c/vbxhook.c,native/c/vbxhook.handinclude/vbxtrace.hfrom the hook directory into<service>/vendor/vbxtrace/cbits/ - add
vendor/vbxtraceto the packages ofcabal.project(orstack.yaml) andvbxtraceto the executable'sbuild-depends - create the hook state with
newVbx <port>, pass Warp's settings throughvbxSettingsand wrap theApplicationwithvbxMiddleware(Servant:serve api server; Yesod:toWaiApp; Scotty:scottyApp) - optional: in handlers, report spawned processes (
spawnedHandle), outgoing sockets (connectedSocket) and opened files (opened+openFlags) withvbxContext req - mount the hook directory read-only at
/opt/vbxtracein the service's compose entry
Example change on a sample service (hooks/native/c4/proposals/haskell-warp.diff):
# Example: a Warp service (app/Main.hs, <service>.cabal, cabal.project) after vendoring vendor/vbxtrace.
--- a/cabal.project
+++ b/cabal.project
@@ -1 +1,2 @@
packages: .
+ vendor/vbxtrace
--- a/<service>.cabal
+++ b/<service>.cabal
@@ -10,3 +10,4 @@ executable <service>
build-depends: base, wai, warp, http-types
+ , vbxtrace
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,9 +1,13 @@
module Main (main) where
import Network.Wai.Handler.Warp (defaultSettings, runSettings, setPort)
+import VBXTrace.Wai (newVbx, vbxMiddleware, vbxSettings)
main :: IO ()
-main = runSettings (setPort 8080 defaultSettings) app
+main = do
+ vbx <- newVbx 8080
+ runSettings (vbxSettings vbx (setPort 8080 defaultSettings)) (vbxMiddleware vbx app)
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,2 +3,4 @@ services:
<service>:
build: .
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roExact detection rules
Package C4 (Haskell, OCaml, Julia, R, Scala Native), proposal C4:haskell, defined in hooks/native/c4/proposals/haskell.toml.
- Image matches (regex):
^haskell:,^fpco/stack-build,^benz0li/ghc-musl - Dependency on:
warp,wai,servant-server,yesod,yesod-core,scotty,Spock - Files:
*.cabal,cabal.project,stack.yaml,package.yaml
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.