Skip to content

feat(cli): --proxy-user to inject a caller-chosen SOCKS5 username#87

Merged
tito merged 1 commit into
mainfrom
mathieu/feat-proxy-user
Apr 23, 2026
Merged

feat(cli): --proxy-user to inject a caller-chosen SOCKS5 username#87
tito merged 1 commit into
mainfrom
mathieu/feat-proxy-user

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented Apr 23, 2026

Motivation

Today greywall auto-assigns the outbound proxy username based on the wrapped command name (cmdName:proxy), falling back to proxy:proxy. That works well for single-tenant use.

It does not work for orchestrators that run several independent sandboxed agents in parallel on the same machine and want per-agent rules on the upstream proxy (greyproxy). Both agents end up looking identical to the proxy, so a policy like "agent-alpha may reach api.openai.com, agent-beta may not" is impossible to express.

Change

Adds a --proxy-user <name> flag on the root command. When set, <name> is used as the SOCKS5/HTTP proxy username for both cfg.Network.ProxyURL and cfg.Network.HTTPProxyURL, overriding the auto-detected command name.

Precedence (highest wins):

  1. --proxy-user <name> — explicit caller override
  2. cmdName — auto-detected from the wrapped command (existing behaviour)
  3. "proxy" — fallback (gost requires a non-empty user)

The URL rewrite is done once in runCommand before any downstream consumer (proxy bridge, tun2socks, landlock wrapper config) reads the config, so the identity flows through every code path uniformly with no additional plumbing.

Debug logs now also name the source of the chosen username (--proxy-user / command name / default) to make it obvious where the identity came from.

Backwards compatibility

No behavioural change when the flag is unset — the existing `cmdName`-based auto-injection still runs.

Testing

Manual smoke test on Linux + macOS:

```
$ greywall --help | grep proxy-user
--proxy-user string SOCKS5/HTTP proxy username to inject into the configured proxy URL ...

$ greywall --debug --proxy-user myagent -- echo hello
[greywall] Auto-set proxy credentials to "myagent":proxy (source: --proxy-user)

$ greywall --debug -- echo hello
[greywall] Auto-set proxy credentials to "echo":proxy (source: command name)
```

Build: `go build ./...` on both `darwin/arm64` and `linux/arm64` — clean.

Test plan

  • `go build ./...` on darwin/arm64
  • `GOOS=linux GOARCH=arm64 go build ./...`
  • Verify `--help` shows the new flag
  • Verify debug log output with `--proxy-user myagent`
  • Verify default (no-flag) path still uses `cmdName`

Before, greywall auto-set the outbound proxy credentials to `<cmdName>:proxy`
(or `proxy:proxy` when no command name was available). That is handy for
single-tenant setups but makes it impossible for a caller that orchestrates
many sandboxed runs on the same machine to give each run a stable, distinct
identity that the upstream proxy (greyproxy) can key per-rule on.

Typical use-case: an orchestrator runs several independent agents in parallel
sandboxes and wants greyproxy rules like "agent-alpha may reach api.openai.com,
agent-beta may not". Today both agents share whatever `cmdName` auto-injection
produces (or fall back to `proxy:proxy`), making per-agent policy impossible.

Add `--proxy-user <name>` to the root command. When set, its value becomes
the proxy username for both `cfg.Network.ProxyURL` and `cfg.Network.HTTPProxyURL`,
taking precedence over the auto-detected command name. Because the URL rewrite
is done once in `runCommand` before the proxy bridge / tun2socks / config-JSON
consumers read the config, the new identity flows uniformly to every
downstream path — no additional plumbing required.

No behavioural change when the flag is unset: the existing cmdName-based
auto-injection still runs.

The debug log now also names the source of the chosen username ("--proxy-user",
"command name", or "default") to make it easier to see which layer set it.
@tito tito merged commit 57cf0cd into main Apr 23, 2026
4 checks passed
@tito tito deleted the mathieu/feat-proxy-user branch April 23, 2026 00:19
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