Skip to content

Attaching a debugger to a running PaaS container

A bug only reproduces in production traffic, the logs aren't enough, and you need a live debugger inside the running container. Here are the port-forward patterns that work on PaaS and the security implications of leaving them open.

The bug only reproduces in production. The exception is NullPointerException somewhere deep in a request handler, the stack trace points at line 274 of a class that has fifteen branches, and you’ve stared at it for an hour. You need a breakpoint on a real request, on a real connection pool, on a real session. Locally there’s no traffic that triggers it. The remote debugger is your tool — but the PaaS container only exposes ports 80 and 443 to the internet, and you don’t want to. So how do you get a debugger session in without poking a hole in the firewall.

What’s happening

Every common runtime ships a remote debug protocol: the JVM has JDWP on a TCP port, Node.js has Chrome DevTools Protocol on --inspect=...:9229, Python has debugpy on a configurable port, .NET has vsdbg. The runtime listens on that port and waits for an IDE to attach. The protocols are powerful — full breakpoint control, variable inspection, expression evaluation — and almost universally completely unauthenticated. Anyone who can reach the port can read every secret in process memory, change values, and execute arbitrary code through the eval surface. On a PaaS, the container has a private IP reachable from inside the environment but not from the internet, and the platform’s edge proxy only forwards 80/443. That’s the constraint that keeps you safe. The pattern is to enable the debug port bound to localhost inside the container, then tunnel to it over the platform’s encrypted control channel — typically an SSH gateway provided by the PaaS — so the debug port is never exposed beyond a single IDE session on a single laptop.

How to verify

First confirm the runtime is willing to listen for a debugger. For a JVM application, check current flags:

# Via the platform API exec endpoint or web SSH terminal
ps -ef | grep -E 'java|node|python' | grep -v grep

If you see no -agentlib:jdwp=... for JVM, no --inspect= for Node, the runtime won’t accept attaches without a restart. Plan for that — the next request after enabling will be the first one debuggable, and the restart blip needs to fit in your error budget.

Confirm the platform offers an SSH gateway. Most PaaS environments give each container an SSH endpoint reachable through a single gateway host:

ssh -p 3022 node184372-prod-api@gate.cloud.example.com whoami
# expected: jelastic-user or similar container user

If that works, you have a tunnel surface.

The fix

Enable the debug port inside the container, then tunnel.

For a JVM application, set the start command (via the platform’s environment variables or stack template) to include:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005

Bind to 127.0.0.1 — never 0.0.0.0. The other-side-of-firewall protection is the loopback bind, not the firewall. Restart the application; the JVM now listens on 127.0.0.1:5005 inside the container.

Open the SSH tunnel from your laptop:

ssh -p 3022 -N -L 5005:127.0.0.1:5005 node184372-prod-api@gate.cloud.example.com

In IntelliJ / Eclipse, configure a Remote JVM Debug run target pointing at localhost:5005. Attach. Breakpoints work, hot-swap works, variable inspection works. The traffic between your laptop and the gateway is the SSH tunnel; the traffic between the gateway and the container is the platform’s internal network. The debug port itself never crosses the public internet unencrypted.

For Node.js, set the start command to:

node --inspect=127.0.0.1:9229 server.js

Tunnel the same way:

ssh -p 3022 -N -L 9229:127.0.0.1:9229 node184372-prod-api@gate.cloud.example.com

Open chrome://inspect in Chrome, click Configure, add localhost:9229, then click inspect on the discovered target. The DevTools-protocol surface gives you breakpoints, the heap snapshot, CPU profiling, and the same eval risks — be careful.

For Python applications already using debugpy:

# Wire this once, gated on env var, then deploy.
import os, debugpy
if os.environ.get("DEBUGPY") == "1":
    debugpy.listen(("127.0.0.1", 5678))
    print("debugpy listening on 127.0.0.1:5678")

Set DEBUGPY=1 in the environment and restart, tunnel, attach from VS Code with the standard Python: Remote Attach configuration.

Three security rules. One, never leave the debug port enabled past the end of the session. Every minute it’s listening is a minute where any SSH-key-equipped engineer can dump heap memory. Set a calendar reminder, or wire a 30-minute at job to revert the start command. Two, audit who has SSH access to the container before you start. The PaaS gateway maps an SSH key to a platform user account; the same key opens any container that user can reach. Three, for compliance-bound workloads (PCI, HIPAA, SOC 2 in scope), get the change approved through your change-management process and capture it in the audit log — a debug session against a production node is a privileged change, not a routine operation.

We run debug-session runbooks against managed PaaS as part of environment management under managed PaaS with the security review and audit trail in place — book a triage call when the bug only reproduces in prod.