Skip to content

fix(security): Unauthenticated unrestricted postgres-mcp and pgweb published on public sandbox tunnels - #863

Closed
scale-avr[bot] wants to merge 5 commits into
mainfrom
avr-sast/6cab746a35fa
Closed

scale-avr[bot] wants to merge 5 commits into
mainfrom
avr-sast/6cab746a35fa

Conversation

@scale-avr

@scale-avr scale-avr Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Findings Files Proof
1 of 1 2 1 of 1 sandbox PoC fail before and pass after

Merge risk: High. Review impact before merge.

Signal Grade Why
Alignment Poor The fix gave no security delta; 19 of 49 files named by the finding or the fix; not named: src/agent_env/agents/README.md and 29 more
Impact Large Touches dependencies, infrastructure; 49 files
Verification Decent The PoC fails before the fix and passes after; AVR did not finish every check; no recording yet
Rollback cost Medium Changes infrastructure or CI files
Error detection Poor No alert, metric or log line reported for a failure of this change

Not checked: The reproduction of an earlier fix reproduces on the new code and on the code before this change. This change did not undo that fix. Review must confirm that the earlier fix still holds.

Finding: High · CWE-306 · src/agent_env/providers/env_state/local_postgres.py:287-303

Root cause: One failing check is caused by this PR, and I fixed it. A source-scan test (provider_capabilities_test) bans isinstance checks on the sandbox provider class. The PR's deploy code used one to choose local console host ports. It now reads the provider's declared ON_THIS_MACHINE flag, and the matching…

Details: proof ladder, not fixed, files

How sure is this fix?

Level Result Evidence
Sandbox PoC (gVisor, no network) before: fail, after: pass .avr/tests/sql_console_binding.py written by AVR's accepted proof. Before the fix it ran src/agent_env/providers/env_state/local_postgres.py:263-276, 280-285, 287-302, 304 (the finding's code: src/agent_env/providers/env_state/local_postgres.py….
Repository check passed python3 -m py_compile src/agent_env/providers/env_providers/env_gateway_provider.py
Repository check error uv run --offline pytest tst/unit/providers/compose_host_port_publish_test.py tst/unit/providers/env_providers/env_gateway_provider_test.py tst/unit/providers/en

Not fixed by this PR

  • The two test_agent_clock_images letta-code unit failures (KeyError 'startretries' and the supervisord listener test) are in files this PR does not touch. The PR did not cause them.
  • The Integration Tests CodeBuild failure has no readable log. No integration test reads the removed db_mcp_url or db_web_url values from a deploy.

Files changed (2)

  • src/agent_env/providers/env_providers/env_gateway_provider.py
  • tst/unit/providers/env_providers/env_gateway_provider_test.py

RetriggerView in GreptileConfidence Score: 4/5

Fix the remote-provider test before merging.

Fix All in CursorFindings

  1. P1 Remote provider test fails ▶
Fix with agent prompt
### Issue 1
src/agent_env/providers/env_providers/env_gateway_provider.py:891
The new `ON_THIS_MACHINE` check breaks `test_deploy_via_vm_asks_for_no_tunnel_to_the_sql_consoles`. That test creates an unconfigured `MagicMock`, whose `ON_THIS_MACHINE` attribute is truthy. Both console ports therefore enter `exposed_ports`, and the assertions excluding them fail. Set `ON_THIS_MACHINE=False` on the test's provider mock so it represents a remote provider.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR removes public SQL-console tunnels and keeps direct VM console bindings on loopback.

  • SQL consoles stay behind the gateway instead of public tunnels.

Reviews (4) · Last reviewed commit: "test(gateway): expect the ON_THIS_MACHIN..." · Reviewed by Greptile

@scale-avr
scale-avr Bot requested a review from a team as a code owner November 21, 2026 05:06
@earakely-scale

Copy link
Copy Markdown
Collaborator

🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review.

Context from outside this diff: an open PR already makes most of this change, and it is deliberately being held back.

The overlap. #823 ("reach pgweb and db-mcp only through the gateway's /svc routes") changes the same five files this PR does — env_gateway_provider.py, env_state/local_postgres.py, compose_host_port_publish_test.py, env_gateway_provider_test.py, stack_layout_test.py — and the same functions:

this PR #823
VM create_vm(exposed_ports=…) drops DB_WEB_PORT/DB_MCP_PORT except on the local provider exposes only the gateway's port
_provision_sidecar expose_externally=False (env_gateway_provider.py:1436) expose_externally=False (its :1416)
_provision_mcp expose_externally=False (:1537) not changed
db_web_url / db_mcp_url set to None (:1026-1027, :1201-1202) removed from DeployedGateway entirely
render_sidecar_containers keeps the publish, pinned to 127.0.0.1 deletes the ports: block, so nothing is published

The last row is a direct contradiction, and both PRs encode it as an assertion in the same test file: this PR's test_postgres_sidecar_fragment_defaults_to_identity expects "127.0.0.1:{DB_WEB_PORT}:{DB_WEB_PORT}" to be emitted, while #823 removes the binding so no such line exists. Whichever merges second will conflict there.

The hold. #823 carries an explicit "DO NOT MERGE" and a merge-order note: it is meant to merge last, after consumers of db_web_url/db_mcp_url have moved to the db_web_gateway_url/db_mcp_gateway_url fields that #821 (merged) added, and after envs on older gateway images have expired — "Merging it earlier breaks every caller that still uses the old console URLs." This PR nulls those same two fields on both the VM and container paths with no such sequencing, so merging it lands #823's consumer-visible half ahead of that plan.

Not a view on which version is right — the two differ in real ways (this PR also covers _provision_mcp; #823 goes further on the compose publish). Only that the overlap and the hold on #823 aren't visible from this diff alone.


Generated by Claude Code

vm_kwargs["memory"] = memory_mb
# The SQL consoles are never tunnelled: the gateway serves them behind its control token. Only the local
# provider gets a host port for them (its own free port, published on 127.0.0.1), so two local envs don't clash.
console_ports = [DB_WEB_PORT, DB_MCP_PORT] if sandbox_provider.ON_THIS_MACHINE else []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Remote provider test fails

The new ON_THIS_MACHINE check breaks test_deploy_via_vm_asks_for_no_tunnel_to_the_sql_consoles. That test creates an unconfigured MagicMock, whose ON_THIS_MACHINE attribute is truthy. Both console ports therefore enter exposed_ports, and the assertions excluding them fail. Set ON_THIS_MACHINE=False on the test's provider mock so it represents a remote provider.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/providers/env_providers/env_gateway_provider.py
Line: 891

Comment:
**Remote provider test fails**

The new `ON_THIS_MACHINE` check breaks `test_deploy_via_vm_asks_for_no_tunnel_to_the_sql_consoles`. That test creates an unconfigured `MagicMock`, whose `ON_THIS_MACHINE` attribute is truthy. Both console ports therefore enter `exposed_ports`, and the assertions excluding them fail. Set `ON_THIS_MACHINE=False` on the test's provider mock so it represents a remote provider.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Cursor Fix in Claude Code Fix in Codex

@earakely-scale

Copy link
Copy Markdown
Collaborator

Superseded by #823 (released in v0.9.1624), which makes the same fix: pgweb and db-mcp get no public tunnel or published port on any provider, the container sidecars are created with expose_externally=False, and deploys no longer record the tunnel URLs. Both consoles are served only through the gateway's /svc routes behind the control token.

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.

1 participant