Skip to content

Compiler: auto-add GHES domains to --allow-domains when engine.api-target is set#21301

Merged
lpcox merged 5 commits intomainfrom
copilot/fix-auto-add-ghes-domains
Mar 17, 2026
Merged

Compiler: auto-add GHES domains to --allow-domains when engine.api-target is set#21301
lpcox merged 5 commits intomainfrom
copilot/fix-auto-add-ghes-domains

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

When engine.api-target is set for a GHES instance, the compiler correctly passed --copilot-api-target to AWF but never added the GHES hostnames to the firewall allow-lists — meaning every recompile silently broke GHES workflows by blocking API traffic.

Changes

  • domains.go: Added GetAPITargetDomains(apiTarget) which derives the API domain and, only when the target starts with api., the base hostname (e.g. api.acme.ghe.com["api.acme.ghe.com", "acme.ghe.com"]; copilot.corp.example.com["copilot.corp.example.com"]). This scoping prevents unintended egress broadening for non-api. targets. Added mergeAPITargetDomains helper to merge these into an existing domain string. Updated computeAllowedDomainsForSanitization to include api-target domains in GH_AW_ALLOWED_DOMAINS.

  • Engine files (copilot_engine_execution.go, claude_engine.go, codex_engine.go, gemini_engine.go): Each now merges api-target domains into allowedDomains after the base domain computation, keeping --allow-domains and GH_AW_ALLOWED_DOMAINS in sync.

  • Tests (allowed_domains_sanitization_test.go, domains_test.go): Extended TestComputeAllowedDomainsForSanitization with api-target cases. Added integration test TestAPITargetDomainsInCompiledWorkflow that compiles a full workflow with engine.api-target and asserts both --allow-domains and GH_AW_ALLOWED_DOMAINS in the lock file contain the expected domains.

Example

engine:
  id: copilot
  api-target: api.acme.ghe.com

Now automatically produces in the compiled lock file:

--allow-domains "...,acme.ghe.com,api.acme.ghe.com,..."
GH_AW_ALLOWED_DOMAINS: "...,acme.ghe.com,api.acme.ghe.com,..."

No manual lock file edits required, and the domains survive recompile.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…rget is set

When engine.api-target is set (e.g., "api.acme.ghe.com" for a GHES instance),
both the API domain and the base hostname are now automatically added to:
- --allow-domains (AWF firewall flag)
- GH_AW_ALLOWED_DOMAINS (environment variable for sanitization)

This prevents the need for manual lock file edits after every recompile."

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compiler to auto-add GHES domains to --allow-domains Compiler: auto-add GHES domains to --allow-domains when engine.api-target is set Mar 16, 2026
Copilot AI requested a review from lpcox March 16, 2026 23:08
@lpcox lpcox marked this pull request as ready for review March 17, 2026 00:27
Copilot AI review requested due to automatic review settings March 17, 2026 00:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes GHES/GHEC engine.api-target workflows getting blocked after recompile by automatically adding the relevant API target hostnames into the runtime AWF --allow-domains list and the compiler-side GH_AW_ALLOWED_DOMAINS sanitization allowlist.

Changes:

  • Added GetAPITargetDomains() and mergeAPITargetDomains() to derive and merge api-target-related domains into allowlists.
  • Updated computeAllowedDomainsForSanitization() to include api-target domains so sanitization stays in sync with firewall configuration.
  • Updated Copilot/Claude/Codex/Gemini engines to merge api-target domains into the AWF --allow-domains value used at runtime.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/workflow/domains.go Adds api-target domain derivation/merge helpers; includes api-target domains in compiler-side allowed-domain computation for sanitization.
pkg/workflow/domains_test.go Adds unit tests for GetAPITargetDomains() and mergeAPITargetDomains().
pkg/workflow/copilot_engine_execution.go Merges api-target domains into Copilot’s runtime --allow-domains.
pkg/workflow/claude_engine.go Merges api-target domains into Claude’s runtime --allow-domains.
pkg/workflow/codex_engine.go Merges api-target domains into Codex’s runtime --allow-domains.
pkg/workflow/gemini_engine.go Merges api-target domains into Gemini’s runtime --allow-domains.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +727 to +732
// Add GHES/custom API target domains so GH_AW_ALLOWED_DOMAINS stays in sync with --allow-domains
if data.EngineConfig != nil && data.EngineConfig.APITarget != "" {
base = mergeAPITargetDomains(base, data.EngineConfig.APITarget)
}

return base
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added regression tests in commit 0872ff5:

  • Extended TestComputeAllowedDomainsForSanitization with two new table-driven cases: one asserting api.acme.ghe.com + acme.ghe.com appear in the sanitization domain set, and one asserting the base hostname is not added for non-api. prefixed targets.
  • Added TestAPITargetDomainsInCompiledWorkflow (integration, //go:build integration) that compiles a full workflow with engine.api-target configured and verifies both --allow-domains in the AWF command and GH_AW_ALLOWED_DOMAINS in the env block contain the expected domains. Uses exact CSV-membership checks (via extractQuotedCSV helper) for the "not present" assertions to avoid substring false-positives.

lpcox and others added 2 commits March 16, 2026 17:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Extend TestComputeAllowedDomainsForSanitization with api-target test cases
  (GHES and non-api. prefix hostname), with exact-membership checks for
  the "not present" assertions to avoid false positives from substring matching.
- Add integration test TestAPITargetDomainsInCompiledWorkflow that compiles
  a full workflow with engine.api-target and asserts both --allow-domains
  and GH_AW_ALLOWED_DOMAINS in the lock file contain the expected domains.
- Add extractQuotedCSV helper for exact domain membership checking."

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox lpcox merged commit 810cd46 into main Mar 17, 2026
@lpcox lpcox deleted the copilot/fix-auto-add-ghes-domains branch March 17, 2026 01:09
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.

Compiler should auto-add GHES domains to --allow-domains when engine.api-target is set

3 participants