Skip to content

fix(cli): export Java trust-store settings to all shells - #108

Closed
atirna wants to merge 1 commit into
VirtusLab:masterfrom
atirna:fix/java-trust-store-shell-env
Closed

atirna wants to merge 1 commit into
VirtusLab:masterfrom
atirna:fix/java-trust-store-shell-env

Conversation

@atirna

@atirna atirna commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Moved the Java trust-store exports out of .bashrc into a guarded profile script. The entrypoint sources it after refreshing the writable trust store, so the agent process and shells it starts inherit JAVA_HOME and JAVA_TOOL_OPTIONS.

Why

JVM tools launched through non-interactive shells can now use the mitmproxy-aware trust store instead of failing TLS validation.

Verification

  • bash --noprofile --norc profile probe: a child shell receives the Java home and copied trust-store options when both are present; non-JVM shells remain unconfigured.

Fixes #102

@shejnowicz

Copy link
Copy Markdown
Collaborator

Thank you for this contribution, @atirna — it's a well-built fix for #102: the guarded /etc/profile.d script, sourcing it from the entrypoint after the trust-store refresh, and naming it to match the existing sandcat-*.sh sourcing block in /etc/bash.bashrc all fit the codebase neatly. The tests are good too (probing shell inheritance with env -i rather than grepping files).

I verified it hands-on in a real container with --stacks java: the agent process (PID1) environment carries both variables, a spawned JVM fetches HTTPS through the proxy with your trust store (HTTP 200), and the same fetch with JAVA_TOOL_OPTIONS removed reproduces the exact PKIX path building failed from #102. Works exactly as described.

Since fork PRs need a maintainer to approve each CI run, I've carried your work in #109 with your commit cherry-picked as-is (you stay the author), plus one cosmetic follow-up on top: the SANDCAT_HOME override is renamed to SANDCAT_USER_HOME, because install.sh already uses SANDCAT_HOME to mean the host CLI install dir. Closing this one in favor of #109 — thanks again, and contributions like this are very welcome.

@shejnowicz shejnowicz closed this Sep 7, 2026
@atirna
atirna deleted the fix/java-trust-store-shell-env branch September 7, 2026 09:32
shejnowicz added a commit that referenced this pull request Sep 8, 2026
Fixes #102. Carries #108 by @atirna — the original commit is
cherry-picked with authorship preserved; opened from an in-repo branch
so CI runs without the fork-approval step. On top of it there is one
cosmetic follow-up commit renaming the test-seam variable `SANDCAT_HOME`
→ `SANDCAT_USER_HOME` (the former already means "host CLI install dir"
in `install.sh`, so one name carried two meanings).

## Summary (from #108)

Java trust-store exports move out of `.bashrc` into a guarded
`/etc/profile.d/sandcat-java.sh`. The entrypoint sources it after
`app-user-init.sh` refreshes the writable trust store, so the agent
process — and everything it spawns — inherits `JAVA_HOME` and
`JAVA_TOOL_OPTIONS`. Login shells get it via `/etc/profile`, VS Code
terminals via the existing `sandcat-*.sh` sourcing block in
`/etc/bash.bashrc`.

## Verification

- bats: init 162/162, run 9/9 (incl. the PR's three new tests)
- Hands-on integration on a real container with `--stacks java` (temurin
via devbox):
- PID1 (agent process) environment contains both `JAVA_HOME` and
`JAVA_TOOL_OPTIONS` (`/proc/1/environ`)
- end-to-end: a JVM child with the inherited env fetches
`https://example.com` **through the proxy → HTTP 200** (mitmproxy CA
honored via the sandcat trust store)
- negative control: same fetch with `env -u JAVA_TOOL_OPTIONS` → `PKIX
path building failed` — the exact #102 symptom
- login shell exports present; `cacerts` refreshed by app-user-init;
baseline (GET 200 / POST 403 / no sudoers / no CA private key)
unregressed
- Reviewer note: `docker compose exec … printenv` can NOT observe these
variables — `docker exec` always gets the image's Config.Env, never the
entrypoint's; `/proc/1/environ` is the correct probe.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Atirna <288419661+atirna@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@atirna

atirna commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the detailed read, and for verifying it hands-on. glad the shape fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JAVA_TOOL_OPTIONS trust-store export is invisible to non-interactive shells (agent-spawned JVMs fail PKIX)

2 participants