Propagate DIFC proxy TLS CA trust to git/gh/curl via process environment#4042
Propagate DIFC proxy TLS CA trust to git/gh/curl via process environment#4042
Conversation
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/3bd624f8-e072-4062-b1f9-22dde46c5b34 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/3bd624f8-e072-4062-b1f9-22dde46c5b34 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/3bd624f8-e072-4062-b1f9-22dde46c5b34 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/3bd624f8-e072-4062-b1f9-22dde46c5b34 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/3bd624f8-e072-4062-b1f9-22dde46c5b34 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR propagates the DIFC proxy’s generated TLS CA certificate to common HTTPS clients (git/gh/curl/etc) by setting standard CA-related environment variables, including automatic propagation to downstream GitHub Actions steps via GITHUB_ENV.
Changes:
- Set multiple CA trust env vars (
NODE_EXTRA_CA_CERTS,SSL_CERT_FILE,GIT_SSL_CAINFO,CURL_CA_BUNDLE,REQUESTS_CA_BUNDLE) whenawmg proxy --tlsgenerates a CA. - Append the same env vars to the GitHub Actions environment file (
GITHUB_ENV) when present. - Add unit tests and update proxy mode documentation with the additional exports.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/proxy.go | Adds TLS trust env propagation + best-effort GITHUB_ENV appending and updates connection hints. |
| internal/cmd/proxy_test.go | Adds tests covering env propagation, GITHUB_ENV append behavior, and newline rejection. |
| docs/PROXY_MODE.md | Documents CA env setup for gh+git and notes automatic GITHUB_ENV propagation. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
| // Best-effort append: the proxy should still start even if GITHUB_ENV cannot be opened. | ||
| f, err := os.OpenFile(githubEnvPath, os.O_APPEND|os.O_WRONLY, 0o644) | ||
| if err != nil { | ||
| logger.LogWarn("startup", "Skipping GITHUB_ENV TLS trust export: open failed for %s: %v", githubEnvPath, err) | ||
| return nil | ||
| } | ||
| defer f.Close() | ||
|
|
||
| for _, key := range tlsTrustEnvKeys { | ||
| if _, err := io.WriteString(f, key+"="+caCertPath+"\n"); err != nil { | ||
| return fmt.Errorf("failed writing %s to GITHUB_ENV file: %w", key, err) | ||
| } |
There was a problem hiding this comment.
configureTLSTrustEnvironment treats opening GITHUB_ENV as best-effort (logs a warning and continues), but write failures currently return an error and will abort proxy startup. This conflicts with the intended/ documented behavior of not failing startup when GITHUB_ENV is unavailable/unwritable. Consider making write failures best-effort too (log a warning and continue/return nil), or at least gate it behind the same best-effort policy as open failures.
| } | ||
|
|
||
| // Best-effort append: the proxy should still start even if GITHUB_ENV cannot be opened. | ||
| f, err := os.OpenFile(githubEnvPath, os.O_APPEND|os.O_WRONLY, 0o644) |
There was a problem hiding this comment.
os.OpenFile(githubEnvPath, os.O_APPEND|os.O_WRONLY, 0o644) does not use the provided permissions unless os.O_CREATE is set, so 0o644 is effectively ignored here. To avoid implying that permissions are being applied, consider passing 0 (or adding os.O_CREATE if you actually want to create the file when missing).
| f, err := os.OpenFile(githubEnvPath, os.O_APPEND|os.O_WRONLY, 0o644) | |
| f, err := os.OpenFile(githubEnvPath, os.O_APPEND|os.O_WRONLY, 0) |
| } | ||
| }) | ||
|
|
||
| t.Run("skips GITHUB_ENV append when env var is unset", func(t *testing.T) { |
There was a problem hiding this comment.
Subtest name says "env var is unset" but the test uses t.Setenv("GITHUB_ENV", ""), which sets it to an empty string rather than truly unsetting it. Since os.Getenv treats unset and empty equivalently this still exercises the code path, but the name is misleading; consider renaming to "unset or empty" (or use os.Unsetenv if you specifically want to test "unset").
| t.Run("skips GITHUB_ENV append when env var is unset", func(t *testing.T) { | |
| t.Run("skips GITHUB_ENV append when env var is unset or empty", func(t *testing.T) { |
|
@copilot update the pr with review feedback #4042 (review) |
|
@copilot don't rely on GITHUB_ENV |
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/8c6049c3-8a7e-4abf-93b8-615d1b4fb45a Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/8c6049c3-8a7e-4abf-93b8-615d1b4fb45a Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Implemented the requested review updates in |
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/6579536c-4790-47dc-8c0c-eed5aaaf2030 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/6579536c-4790-47dc-8c0c-eed5aaaf2030 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/6579536c-4790-47dc-8c0c-eed5aaaf2030 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Updated as requested in Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
gh repo clone/git clonefailed through the DIFC TLS proxy (https://localhost:18443/...) because clients could not validate the proxy’s generated certificate chain. This change propagates the generated proxy CA to the toolchains that perform HTTPS validation in agent workflows.Proxy startup: propagate CA trust to common clients
awmg proxy --tls, set process env vars to the generatedca.crt:NODE_EXTRA_CA_CERTSSSL_CERT_FILEGIT_SSL_CAINFOCURL_CA_BUNDLEREQUESTS_CA_BUNDLEgh,git,curl, and other TLS consumers that honor standard CA env settings.No
GITHUB_ENVdependencyGITHUB_ENV.Operator-facing output and docs
SSL_CERT_FILE,GIT_SSL_CAINFO).docs/PROXY_MODE.mddocuments CA setup forgh+gitwithoutGITHUB_ENVautomation.Focused unit coverage
GITHUB_ENV(including asserting the file remains unchanged)> [!WARNING]
>
>