@@ -332,6 +332,48 @@ build_gosu_env_cmd() {
332332 exec gosu " $user " env " HOME=$DEVA_HOME " " PATH=$PATH " " $@ "
333333}
334334
335+ # Container-scoped CA trust for cctrace MITM (#414). The container is the
336+ # blast radius: the CA key already lives in the container-readable home, so
337+ # trusting the cert system-wide adds convenience, not attack surface. Runs
338+ # each start: installs when tracing, removes otherwise — trust exists only
339+ # in traced sessions.
340+ setup_trace_ca () {
341+ local crt=/usr/local/share/ca-certificates/cctrace-mitm.crt
342+
343+ if [ " ${DEVA_TRACE:- } " != " 1" ]; then
344+ if [ -f " $crt " ]; then
345+ rm -f " $crt "
346+ if ! update-ca-certificates > /dev/null 2>&1 ; then
347+ echo " [entrypoint] warning: trust-store update failed; cctrace MITM CA may still be trusted" >&2
348+ fi
349+ fi
350+ return 0
351+ fi
352+
353+ if ! command -v cctrace > /dev/null 2>&1 ; then
354+ echo " [entrypoint] warning: DEVA_TRACE=1 but cctrace not found; skipping CA trust" >&2
355+ return 0
356+ fi
357+
358+ # --print-ca generates the CA on first use; it must run as the deva user
359+ # so the key lands under $DEVA_HOME/.local/share/cctrace with sane ownership.
360+ local ca_path
361+ ca_path=$( gosu " $DEVA_USER " env " HOME=$DEVA_HOME " " PATH=$PATH " cctrace --print-ca 2> /dev/null | tail -1)
362+ if [ -z " $ca_path " ] || [ ! -f " $ca_path " ]; then
363+ echo " [entrypoint] warning: cctrace --print-ca gave no usable path; skipping CA trust" >&2
364+ return 0
365+ fi
366+
367+ cp " $ca_path " " $crt "
368+ chmod 644 " $crt "
369+ if update-ca-certificates > /dev/null 2>&1 ; then
370+ [ " $VERBOSE " = " true" ] && echo " [entrypoint] cctrace MITM CA trusted container-wide: $crt "
371+ else
372+ echo " [entrypoint] warning: trust-store update failed; container-wide CA trust incomplete (cctrace env-scoped trust still applies)" >&2
373+ fi
374+ return 0
375+ }
376+
335377ensure_agent_binaries () {
336378 case " $DEVA_AGENT " in
337379 claude)
@@ -385,6 +427,7 @@ main() {
385427 setup_claude_chrome_bridge
386428 fix_rust_permissions
387429 fix_docker_socket_permissions
430+ setup_trace_ca
388431 ensure_agent_binaries
389432
390433 if [ $# -eq 0 ]; then
0 commit comments