Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions versioned_docs/version-4.0.0/running-keploy/java-tls-capture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
id: java-tls-capture
title: Enable Java TLS Capture in Kubernetes
sidebar_label: Java TLS Capture
description: Why Java HTTPS calls need Keploy's in-JVM JSSE agent in Kubernetes, how to enable it in the k8s-proxy Helm chart, how to re-record in the dashboard, and how to verify capture.
tags:
- kubernetes
- k8s proxy
- java
- tls
- recording
- troubleshooting
keywords:
- keploy java tls capture
- java_tls_not_captured
- keploy jsse javaagent
- k8s-proxy jvmAgent
- java https recording kubernetes
- sunjsse tls capture
---

import ProductTier from '@site/src/components/ProductTier';

<ProductTier tiers="Enterprise" offerings="Self-Hosted, Dedicated" />

When Keploy records traffic in Kubernetes with eBPF, native TLS libraries
(OpenSSL, BoringSSL, Go `crypto/tls`) are captured directly at the library
boundary. Java's built-in TLS stack (SunJSSE / `javax.net.ssl`) encrypts
payloads inside the JVM before bytes reach the kernel socket, so native eBPF
uprobes cannot read plaintext Java HTTPS calls.

To capture HTTPS traffic from Java workloads, Keploy attaches a lightweight
in-JVM agent (`keploy-jsse-agent.jar`) via `-javaagent` when recorded pods
start. If a recorded Java pod makes outbound HTTPS calls without that agent
active (or unable to reach the Keploy capture listener), Keploy reports a
`java_tls_not_captured` capture warning and pauses auto-replay for the affected
test sets so incomplete mocks do not cause false failures.

---

## Enable Java TLS capture in the Helm chart

### DaemonSet mode (`daemonset.enabled=true`)

Java TLS capture is **enabled by default** in the `k8s-proxy` chart
(`daemonset.jvmAgent.enabled: true`):

- **At pod admission (recommended):** the `k8s-proxy` mutating webhook mounts a
read-only ConfigMap volume at `/keploy-jsse` containing
`keploy-jsse-agent.jar` and sets `-javaagent` in `_JAVA_OPTIONS` on recorded
containers (leaving your image's `JAVA_TOOL_OPTIONS` untouched). Non-JVM
processes ignore `_JAVA_OPTIONS`.
- **At container startup (fallback):** the DaemonSet node agent also injects
the jar and preload constructor into matched JVM containers when the cgroup is
created.

If a Java workload is reporting `java_tls_not_captured`, make sure Java TLS
capture and admission preload are enabled in your Helm release:

```bash
helm upgrade <release> keploy/k8s-proxy -n <keploy-namespace> \
--reuse-values \
--set daemonset.jvmAgent.enabled=true \
--set daemonset.scheduling.webhook.install=true
```

Check the following cluster settings that can prevent injection or delivery:

1. **Admission preload disabled:** admission injection stays off when
`daemonset.namespaced=true`, `rbac.create=false`, `recording.readOnly=true`,
`daemonset.scheduling.webhook.install=false`, or
`daemonset.jvmAgent.enabled=false`, or if `KEPLOY_DS_JVM_PRELOAD=false` is
set on the `k8s-proxy` control-plane Deployment.
2. **Per-pod opt-out annotation:** remove `keploy.io/jsse-inject: "false"` from
any pod template whose Java HTTPS traffic you want recorded.
3. **Loopback port conflict:** by default (`daemonset.jvmAgent.podListener.enabled: true`),
each recorded JVM sends captured plaintext over a per-pod transport
(`127.0.0.1:16790` loopback, or a Unix socket in the pod's `/dev/shm` when
the DaemonSet runs without `CAP_SYS_ADMIN`). Because traffic stays local to
the pod, cluster NetworkPolicies do not block it. Keploy opens the loopback
listener on `127.0.0.1:16790` **before your application starts** (and keeps
it bound for the life of the pod's network namespace, so a container restart
does not release it); if your application needs port `16790`, set
`--set daemonset.jvmAgent.podListener.port=<free-port>`.
4. **Node-listener fallback and NetworkPolicies:** sandboxed runtimes (such as
Kata or gVisor) or clusters that set
`daemonset.jvmAgent.podListener.enabled=false` fall back to sending captured
TLS plaintext to the node's DaemonSet listener. In that setup, ensure your
NetworkPolicy or host firewall allows pod-to-own-node egress to the
DaemonSet JSSE listener port.

### Sidecar mode (`daemonset.enabled=false`)

In Sidecar mode with low-latency recording enabled, the `k8s-proxy` admission
webhook automatically stages `keploy-jsse-agent.jar` into a shared `emptyDir`
volume and injects `-javaagent` into the application container when it detects a
JVM workload and recording starts. If your JVM isn't detected (for example,
behind a custom entrypoint), set `keploy.io/jsse-inject: "true"` on the pod
template. Ensure the pod is not opted out with `keploy.io/jsse-inject: "false"`
and that the deployment rolls onto the mutated pod when you start recording.

---

## Re-record from the Keploy Dashboard

Java TLS capture is configured on the cluster rather than as a per-run UI
toggle. Because a JVM only loads `-javaagent` at process startup, pods that were
already running before Java TLS capture was enabled must be re-recorded:

1. Open the **Recordings** page in the Keploy Dashboard and stop the affected
recording if it is still running.
2. Start a new recording for the Java deployment. Keploy restarts the targeted
pods under capture so each JVM starts with `keploy-jsse-agent.jar` attached.
3. If you intentionally want to replay an older paused recording without its
missing Java HTTPS mocks, open the **Auto-replay paused** notice in the
dashboard and select **Replay anyway**.

---

## Verify Java TLS capture is active

### 1. Check the recorded Java pod

Inspect a pod running under an active recording:

```bash
kubectl exec -n <app-namespace> <pod-name> -- sh -c '
env | grep -E "JAVA_TOOL_OPTIONS|_JAVA_OPTIONS"
ls -l /keploy-jsse/ /keploy/ 2>/dev/null
'
```

You should see `-javaagent:...keploy-jsse-agent.jar` in `_JAVA_OPTIONS`
(admission injection) or `JAVA_TOOL_OPTIONS` (node preload), with
`keploy-jsse-agent.jar` present in `/keploy-jsse/` or `/keploy/`.

### 2. Check the DaemonSet agent logs

In DaemonSet mode, inspect the data-plane agent logs on the pod's node:

```bash
kubectl logs -n <keploy-namespace> -l app.kubernetes.io/component=data-plane --tail=100 \
| grep -iE "JSSE|JVM PRELOAD"
```

At startup, the agent logs `JSSE: per-pod capture transports` confirming that
`podLoopback` or `podUnixSocket` is ready. If the preload could not attach
`-javaagent`, the log reports `JVM PRELOAD DECLINED` or
`JVM PRELOAD BAIL OBSERVED` along with the reason (for example, JVM option
limits or missing permissions).

### 3. Confirm clean capture in the dashboard

Send HTTPS requests through the recorded Java service and verify that:

- Outbound HTTPS dependencies appear as mocks in the newly recorded test set.
- No `java_tls_not_captured` warning or **Auto-replay paused** banner appears
for the new recording.

---

## Related

- [Kubernetes Live Record & Replay using Keploy Proxy](/docs/quickstart/k8s-proxy/)
- [K8s Proxy DaemonSet Architecture & Auto-Replay Environments](/docs/running-keploy/k8s-proxy-daemonset-architecture/)
- [Fix "could not record an app's bytes" warnings](/docs/running-keploy/capture-loss/)
3 changes: 2 additions & 1 deletion versioned_sidebars/version-4.0.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
"quickstart/k8s-proxy-developer-workflow",
"quickstart/k8s-proxy-llm-workflow",
"keploy-cloud/smart-set-agent",
"running-keploy/k8s-proxy-daemonset-architecture"
"running-keploy/k8s-proxy-daemonset-architecture",
"running-keploy/java-tls-capture"
]
},
{
Expand Down
Loading