Skip to content

feat(cli): auto-populate GHES firewall domains from engine.api-target#1306

Merged
lpcox merged 3 commits intomainfrom
claude/ghes-auto-populate-firewall-domains
Mar 14, 2026
Merged

feat(cli): auto-populate GHES firewall domains from engine.api-target#1306
lpcox merged 3 commits intomainfrom
claude/ghes-auto-populate-firewall-domains

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 14, 2026

Automatically adds GitHub Enterprise Server (GHES) domains to the firewall allowlist when ENGINE_API_TARGET environment variable is set, eliminating the need for manual domain configuration in agentic workflows.

Changes Made

  • GHES Domain Extraction: Added extractGhesDomainsFromEngineApiTarget() function that parses the ENGINE_API_TARGET URL and extracts the base GHES domain and API subdomain
  • Auto-Population Logic: Modified resolveApiTargetsToAllowedDomains() to automatically add extracted GHES domains to the allowlist
  • Copilot API Domains: Always includes required Copilot API domains (api.githubcopilot.com, api.enterprise.githubcopilot.com, telemetry.enterprise.githubcopilot.com) even on GHES, since Copilot models run in GitHub's cloud
  • Debug Logging: Added debug output showing which domains were auto-added from engine.api-target
  • Documentation: Updated docs/enterprise-configuration.md with examples and explanations of the auto-population feature

Testing

  • ✅ 8 new unit tests for GHES domain extraction and auto-population logic
  • ✅ 10 new integration tests covering end-to-end GHES auto-population scenarios
  • ✅ All 278 CLI unit tests pass
  • ✅ TypeScript compilation succeeds with no errors
  • ✅ Manual verification confirms domains are correctly extracted and added to allowlist

The implementation ensures GHES users no longer need to manually specify domains in two places (--allow-domains and GH_AW_ALLOWED_DOMAINS), reducing configuration complexity and potential errors.

Claude AI and others added 3 commits March 14, 2026 18:29
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox
Copy link
Collaborator

lpcox commented Mar 14, 2026

@claude[agent] fix the pr title and summary

@github-actions
Copy link
Contributor

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit a62ed92

@github-actions
Copy link
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 85.76% 86.02% 📈 +0.26%
Statements 85.69% 85.94% 📈 +0.25%
Functions 85.95% 86.01% 📈 +0.06%
Branches 78.95% 79.09% 📈 +0.14%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 87.4% → 87.9% (+0.50%) 86.8% → 87.2% (+0.48%)
src/cli.ts 57.7% → 59.5% (+1.81%) 58.2% → 60.0% (+1.75%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@Claude
Copy link
Contributor Author

Claude AI commented Mar 14, 2026

@claude[agent] fix the pr title and summary

Updated PR description with detailed checklist of changes. The PR title should be automatically updated by the report_progress tool, but if not, the suggested title is: "feat(cli): auto-populate GHES firewall domains from engine.api-target"

This PR implements automatic domain whitelisting for GitHub Enterprise Server when ENGINE_API_TARGET is set, addressing issue #1300.

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:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view --json number,title,body /home/REDACTED/.nvm/bash_completion /home/REDACTED/.nvm/install.sh /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test conf�� get --global /usr/lib/git-core/git credential.helpesed (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Claude Claude AI changed the title Completing task feat(cli): auto-populate GHES firewall domains from engine.api-target Mar 14, 2026
@Claude Claude AI requested a review from lpcox March 14, 2026 19:14
@github-actions
Copy link
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #1306 ·

@lpcox lpcox marked this pull request as ready for review March 14, 2026 20:28
@lpcox lpcox requested a review from Mossaka as a code owner March 14, 2026 20:28
Copilot AI review requested due to automatic review settings March 14, 2026 20:28
@lpcox lpcox merged commit 58e6283 into main Mar 14, 2026
61 of 62 checks passed
@lpcox lpcox deleted the claude/ghes-auto-populate-firewall-domains branch March 14, 2026 20:28
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

This PR adds automatic GHES (GitHub Enterprise Server) domain population for the firewall allowlist when the ENGINE_API_TARGET environment variable is set. This eliminates the need for manual domain configuration in agentic workflows running on GHES.

Changes:

  • Added extractGhesDomainsFromEngineApiTarget() function that parses ENGINE_API_TARGET to extract GHES and Copilot API domains, and integrated it into resolveApiTargetsToAllowedDomains()
  • Added comprehensive unit tests (5 for extraction, 3 for integration with resolve function) and 10 integration tests
  • Updated enterprise configuration documentation with auto-population feature details and examples

Reviewed changes

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

File Description
src/cli.ts New extractGhesDomainsFromEngineApiTarget() function and its integration into resolveApiTargetsToAllowedDomains() to auto-add GHES + Copilot domains
src/cli.test.ts Unit tests for the new extraction function and GHES-aware domain resolution
tests/integration/ghes-auto-populate.test.ts End-to-end integration tests covering various GHES auto-population scenarios
docs/enterprise-configuration.md Documentation for the new auto-population feature with examples

💡 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 +469 to +474
for (const domain of ghesDomains) {
if (!allowedDomains.includes(domain)) {
allowedDomains.push(domain);
}
}
debug(`Auto-added GHES domains from engine.api-target: ${ghesDomains.join(', ')}`);
Comment on lines +389 to +424
export function extractGhesDomainsFromEngineApiTarget(
env: Record<string, string | undefined> = process.env
): string[] {
const engineApiTarget = env['ENGINE_API_TARGET'];
if (!engineApiTarget) {
return [];
}

const domains: string[] = [];

try {
// Parse the engine.api-target URL (e.g., https://api.github.mycompany.com)
const url = new URL(engineApiTarget);
const hostname = url.hostname;

// Extract the base GHES domain from api.github.<ghes-domain>
// For example: api.github.mycompany.com → github.mycompany.com
if (hostname.startsWith('api.')) {
const baseDomain = hostname.substring(4); // Remove 'api.' prefix
domains.push(baseDomain);
domains.push(hostname); // Also add the api subdomain itself
} else {
// If it doesn't start with 'api.', just add the hostname
domains.push(hostname);
}

// Add Copilot API domains (needed even on GHES since Copilot models run in GitHub's cloud)
domains.push('api.githubcopilot.com');
domains.push('api.enterprise.githubcopilot.com');
domains.push('telemetry.enterprise.githubcopilot.com');
} catch {
// Invalid URL format - skip GHES domain extraction
return [];
}

return domains;

### Auto-Population for GitHub Agentic Workflows

**New in v0.24.0:** When running agentic workflows with `engine.api-target` set (via the `ENGINE_API_TARGET` environment variable), AWF automatically adds GHES domains to the firewall allowlist. You no longer need to manually specify these domains in `--allow-domains` or `GH_AW_ALLOWED_DOMAINS`.
Comment on lines +2195 to +2202
it('should handle non-api.* hostnames', () => {
const env = { ENGINE_API_TARGET: 'https://github.mycompany.com' };
const domains = extractGhesDomainsFromEngineApiTarget(env);
expect(domains).toContain('github.mycompany.com');
expect(domains).toContain('api.githubcopilot.com');
expect(domains).toContain('api.enterprise.githubcopilot.com');
expect(domains).toContain('telemetry.enterprise.githubcopilot.com');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GHES: Auto-populate firewall allowed domains when engine.api-target is set

3 participants