Skip to content

[fix] Allow Postgres egress for agent-sandbox controller and proxy - #374

Merged
westrik merged 1 commit into
mainfrom
r2_allow_postgres_egress
Sep 15, 2026
Merged

westrik merged 1 commit into
mainfrom
r2_allow_postgres_egress

Conversation

@westrik

@westrik westrik commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

With rr.agentSandbox.networkPolicy.enabled: true, the controller's only open-Internet egress was 0.0.0.0/0 restricted to ports 443/6443 and the proxy's allow-all rule subtracted blockedRanges (all of RFC 1918) — so STATE_BACKEND: postgres was unreachable.

Add destination-scoped Postgres egress rules, shared by both policies (retool.agentSandbox.postgresEgressRules):

  • inherited in-cluster subchart → automatic podSelector rule
  • postgresAllowlist→ CIDR strings or podSelector/namespaceSelector maps
  • postgresAllowAny → opt-in any-destination escape hatch for urlSecretName DSNs

The rule port mirrors postgresUrlEnv's precedence so the policy always matches what the pods dial (retool.agentSandbox.postgresEgressPort): postgres.port on the fields path, the inherited backend port on the inherit path, and postgresPort (default 5432, null to disable) only for DSNs (postgres.url / urlSecretName) whose port Helm cannot read.

A NOTES.txt warning fires when the policy is on but no destination is allowed. This fails closed, since NetworkPolicy rules add together and a blanket port-only rule would reopen all of blockedRanges on that port.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5  ·  View in Greptile

The PR appears safe to merge. The latest change makes the policy port match the port that the pods use.

No new blocking issue remains. Both earlier threads were manually resolved without an explanatory reply.

Important Files Changed

Filename Overview
charts/retool/templates/_helpers.tpl postgresEgressPort now picks the port from the active Postgres connection path. It fixes the earlier mismatch for custom postgres.port values.
charts/retool/templates/agent_sandbox_networkpolicy.yaml The controller and proxy share destination-scoped Postgres egress rules. No new issue was found in the latest changes.
charts/retool/values.yaml Documents the Postgres egress port, allowlist, and explicit allow-any switch.
values.yaml Keeps the published defaults in sync with charts/retool/values.yaml.
charts/retool/templates/NOTES.txt Warns when the agent sandbox policy has no allowed Postgres destination.
charts/retool/Chart.yaml Raises the chart version for the template change.

Reviews (3): Last reviewed commit: "Allow Postgres egress for agent-sandbox ..." | Re-trigger Greptile

@westrik
westrik force-pushed the r2_allow_postgres_egress branch from fb99473 to 09f54f2 Compare September 14, 2026 21:12
Comment thread charts/retool/templates/_helpers.tpl Resolved
With `rr.agentSandbox.networkPolicy.enabled: true`, the controller's
only open-Internet egress was `0.0.0.0/0` restricted to ports 443/6443
and the proxy's allow-all rule subtracted `blockedRanges` (all of
RFC 1918) — so `STATE_BACKEND: postgres` was unreachable.

Add destination-scoped Postgres egress rules, shared by both policies
(`retool.agentSandbox.postgresEgressRules`):
  - inherited in-cluster subchart  -> automatic podSelector rule
  - `postgresAllowlist`            -> CIDR strings or
                                      podSelector/namespaceSelector maps
  - `postgresAllowAny`             -> opt-in any-destination escape
                                      hatch for urlSecretName DSNs

The rule port mirrors `postgresUrlEnv`'s precedence so the policy always
matches what the pods dial (`retool.agentSandbox.postgresEgressPort`):
`postgres.port` on the fields path, the inherited backend port on the
inherit path, and `postgresPort` (default 5432, null to disable) only
for DSNs (`postgres.url` / `urlSecretName`) whose port Helm cannot read.

A NOTES.txt warning fires when the policy is on but no destination is
allowed — fail-closed, since NetworkPolicy rules add together and a
blanket port-only rule would reopen all of blockedRanges on that port.
@westrik
westrik force-pushed the r2_allow_postgres_egress branch from 09f54f2 to 376bc84 Compare September 14, 2026 21:18
@westrik
westrik marked this pull request as ready for review September 14, 2026 21:21
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.

3 participants