Skip to content

Fix threat detection AWF run missing --copilot-api-target and GHE domains on data residency#21527

Merged
lpcox merged 7 commits intomainfrom
copilot/fix-threat-detection-run
Mar 18, 2026
Merged

Fix threat detection AWF run missing --copilot-api-target and GHE domains on data residency#21527
lpcox merged 7 commits intomainfrom
copilot/fix-threat-detection-run

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

On GHE Cloud with data residency, the main agent AWF invocation correctly receives --copilot-api-target and GHE-specific domains in --allow-domains, but the inline threat detection AWF invocation does not — causing it to fail with exit code 1 even when the agent itself succeeds.

Root cause

In buildDetectionEngineExecutionStep, the detectionEngineConfig was built by copying only ID, Model, Version, Env, Config, and Args from the engine config — APITarget was silently dropped. The AWF builder uses APITarget to emit both --copilot-api-target and the derived GHE hostnames in --allow-domains, so both were absent from the detection run.

Changes

  • pkg/workflow/threat_detection.go — copy APITarget into the detection engine config struct; add fallback to inherit from the main engine config when the threat-detection-specific engine config omits it (preserving override semantics when it's explicitly set)
  • pkg/workflow/threat_detection_test.go — unit tests covering direct propagation, inheritance when detection config has no APITarget, detection config taking precedence over the main config, and the no-APITarget baseline
  • pkg/workflow/allowed_domains_sanitization_test.go — integration test compiling a GHE workflow and asserting --copilot-api-target appears in both AWF invocations and that every --allow-domains line includes the expected GHE hostnames
  • pkg/workflow/awf_helpers.go — add GetCopilotAPITarget() helper that resolves the Copilot API target from engine.api-target (explicit, takes precedence) or GITHUB_COPILOT_BASE_URL in engine.env (fallback), mirroring the OPENAI_BASE_URL--openai-api-target and ANTHROPIC_BASE_URL--anthropic-api-target patterns used by Codex and Claude
  • pkg/workflow/copilot_engine_execution.go and pkg/workflow/domains.go — use GetCopilotAPITarget() so GITHUB_COPILOT_BASE_URL is also reflected in --allow-domains and GH_AW_ALLOWED_DOMAINS
  • docs/src/content/docs/reference/engines.md — document GITHUB_COPILOT_BASE_URL alongside OPENAI_BASE_URL and ANTHROPIC_BASE_URL in the "Custom API Endpoints via Environment Variables" section

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ains on data residency

When engine.api-target is configured for GHE Cloud with data residency,
propagate the APITarget from the main engine config to the detection
engine config so the threat detection AWF invocation receives the same
--copilot-api-target flag and GHE-specific domains in --allow-domains.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix threat detection AWF run missing flags and domains Fix threat detection AWF run missing --copilot-api-target and GHE domains on data residency Mar 18, 2026
Copilot AI requested a review from lpcox March 18, 2026 04:38
@lpcox lpcox marked this pull request as ready for review March 18, 2026 13:55
Copilot AI review requested due to automatic review settings March 18, 2026 13:55
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 ensures threat detection’s inline AWF execution inherits the main engine’s engine.api-target, so custom/GHE endpoints receive the same --copilot-api-target behavior as the primary agent run.

Changes:

  • Propagate EngineConfig.APITarget into the threat detection engine execution configuration (with inheritance from the main engine config when unset).
  • Add unit + integration regression tests validating --copilot-api-target propagation into threat detection AWF invocations.
  • Add a patch changeset describing the behavioral fix.

Reviewed changes

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

File Description
pkg/workflow/threat_detection.go Copies/inherits APITarget into the threat detection engine config used for AWF execution.
pkg/workflow/threat_detection_test.go Adds unit test coverage for APITarget propagation precedence/inheritance.
pkg/workflow/allowed_domains_sanitization_test.go Adds integration regression test validating lockfile includes --copilot-api-target for both main + threat detection invocations.
.changeset/patch-threat-detection-ghe-api-target.md Documents the patch-level behavior change.

💡 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.

@pelikhan
Copy link
Contributor

@lpcox we should add support for env vars in a future PR

lpcox and others added 3 commits March 18, 2026 07:44
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…api-target

- Fix TestAPITargetDomainsInThreatDetectionStep to use api.contoso-aw.ghe.com
  (copilot-api. prefix does not trigger base-domain derivation in GetAPITargetDomains)
- Add GetCopilotAPITarget() helper: resolves --copilot-api-target from engine.api-target
  (explicit) or GITHUB_COPILOT_BASE_URL in engine.env (fallback), mirroring the
  OPENAI_BASE_URL/ANTHROPIC_BASE_URL pattern for Codex/Claude
- Update awf_helpers.go, copilot_engine_execution.go, and domains.go to use the helper
- Add unit tests for GetCopilotAPITarget and engine execution step
- Add integration test TestGitHubCopilotBaseURLInCompiledWorkflow
- Update engines.md docs to document GITHUB_COPILOT_BASE_URL

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…' into copilot/fix-threat-detection-run

# Conflicts:
#	pkg/workflow/allowed_domains_sanitization_test.go
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

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 /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE 64/bin/go git rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE 64/bin/go git (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw test@example.comrev-parse /usr/bin/git git rev-�� --show-toplevel git /usr/bin/git re --log-level=egit iptables /usr/bin/git git (http block)
  • https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha --noprofile git /home/REDACTED/node_modules/.bin/node --show-toplevel go /usr/bin/git node /hom�� --write **/*.cjs /home/REDACTED/work/gh-aw/node_modules/.bin/sh **/*.json --ignore-path ../../../.pretti--show-toplevel sh (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v3
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha .js&#39; --ignore-path .prettierignore --log-level=error git ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet --show-toplevel go /usr/bin/git ache/go/1.25.0/x64/pkg/tool/linux_amd64/vet tion�� -m Add GITHUB_COPILOT_BASE_URL env var support and fix integration -d son ignore go /usr/bin/git bash (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v5
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha 9318107/b410/_pkGOINSECURE GO111MODULE 64/bin/go GOINSECURE b/gh-aw/pkg/fileenv GOMODCACHE go env Be1c/MG_s_CsRVnQGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE 9318107/b410/impGOPROXY (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha -json GO111MODULE /home/REDACTED/.config/composer/vendor/bin/bash GOINSECURE GOMOD GOMODCACHE bash --no�� --noprofile GOPROXY /usr/bin/git GOSUMDB GOWORK 64/bin/go git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel node /usr/bin/git prettier --check 64/bin/go git rev-�� --show-toplevel go /usr/bin/git -json GO111MODULE 64/bin/go git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v6
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha -json GO111MODULE sh GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha -json GO111MODULE ache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel sh /usr/bin/git npx prettier --cgit GOPROXY 64/bin/go git rev-�� --show-toplevel sh /usr/bin/git &#34;prettier&#34; --chegit /opt/hostedtoolcrev-parse 64/bin/go git (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v8
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -json GO111MODULE iptables GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -json GO111MODULE ash GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -json GO111MODULE ache/go/1.25.0/x64/pkg/tool/linux_amd64/compile GOINSECURE GOMOD GOMODCACHE ache/go/1.25.0/x64/pkg/tool/linux_amd64/compile env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
  • https://api.github.com/repos/actions/setup-go/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha -json GO111MODULE tnet/tools/bash GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha rite &#39;../../../**/*.json&#39; &#39;!../../../pkg/workflow/js/**/*.json&#39; --ignore-path git tnet/tools/bash s.go nly /usr/bin/git bash --no�� --noprofile git /home/REDACTED/work/_temp/uv-python-dir/sh ./../.prettieriggit go /usr/bin/git sh (http block)
  • https://api.github.com/repos/actions/setup-node/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha -json GO111MODULE nfig/composer/vendor/bin/bash GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha rite &#39;../../../**/*.json&#39; &#39;!../../../pkg/workflow/js/**/*.json&#39; --ignore-path --auto nfig/composer/vendor/bin/bash --detach nly /usr/bin/git bash --no�� --noprofile git /node_modules/.bin/sh ./../.prettieriggit go /usr/bin/git sh (http block)
  • https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha --show-toplevel at-detection-run ndor/bin/sh --show-toplevel /opt/hostedtoolcrev-parse /usr/bin/git git show�� */*.ts&#39; &#39;**/*.json&#39; --ignore-path ../../../.prettierignore git bin/node --show-toplevel go /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.0.0 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.0.0 --jq .object.sha ix-threat-detection-run git ache/go/1.25.0/x64/bin/bash --show-toplevel /opt/hostedtoolcrev-parse /usr/bin/git git tion�� 26f6c9fd5c21313e74a8c1e68f2f9894af1a3700:pkg/workflow/allowed_domains_sanitization_test.go git bin/sh --show-toplevel go /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.2.3 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.2.3 --jq .object.sha ix-threat-detection-run git bin/node --show-toplevel /opt/hostedtoolcrev-parse /usr/bin/git git tion�� 26f6c9fd5c21313e74a8c1e68f2f9894af1a3700:pkg/workflow/allowed_domains_sanitization_test.go git de_modules/.bin/sh --show-toplevel go /usr/bin/git git (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go env e=false GO111MODULE 64/bin/go GOINSECURE %H %ct %D 74a8c1e68f2f9894-json go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha --show-toplevel fix integration -d /usr/bin/infocmp168.63.129.16 -json GO111MODULE /opt/hostedtoolc--write infocmp -1 ath ../../../.pr**/*.json go de/node/bin/git -json GO111MODULE /usr/local/.ghcu&#34;prettier&#34; --write &#39;../../../**/*.json&#39; &#39;!../../../pkg/workflow/js/**/*.json&#39; --ignore-path ../../../.prettierignore git (http block)
  • https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go env e=false GO111MODULE 64/bin/go GOINSECURE %H %ct %D GOMODCACHE go (http block)
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha --show-toplevel fix integration -d /usr/bin/git -json GO111MODULE /opt/hostedtoolc--write yyKn1Aq/pAaEiNMP**/*.cjs rev-�� ath ../../../.pr**/*.json go 911ed2738d52e8dc../../../.prettierignore -json GO111MODULE /usr/local/sbin/&#34;prettier&#34; --write &#39;../../../**/*.json&#39; &#39;!../../../pkg/workflow/js/**/*.json&#39; --ignore-path ../../../.prettierignore git (http block)

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

Copilot AI requested a review from pelikhan March 18, 2026 14:56
@pelikhan
Copy link
Contributor

@lpcox I messed up this PR

@lpcox
Copy link
Collaborator

lpcox commented Mar 18, 2026

@pelikhan copilot is trying to figure out why ci failed

Copilot AI and others added 2 commits March 18, 2026 08:29
… files (#21609)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
* docs: add GH_HOST and RUNNER_TEMP to glossary (daily scan 2026-03-18) (#21553)

* docs: update GHES CLI docs and add Copilot GHES troubleshooting guide (#21528)

* Fix list height not updating on terminal resize (#21555)

* fix(daily-workflow-updater): unblock PR creation by setting protected-files: allowed (#21554)

* chore: bump MCP Gateway v0.1.15→v0.1.17 (#21552)

* feat: custom Huh theme mapped from pkg/styles Dracula palette (#21557)

* Add top-level `github-app` frontmatter as universal fallback for token minting (#21510)

* feat: add GitHub App-only permissions support (#21511)

* fix: fall back to existing remote tracking ref when incremental patch fetch fails (#21568)

* Add weekly blog post writer agentic workflow (#21575)

* ci: add timeout-minutes to all 25 jobs lacking explicit limits (#21601)

* fix: add setupGlobals in generate_aw_info step to fix staged mode ReferenceError (#21602)

* Disable lockdown mode for weekly blog post generator (#21598)

* fix: replace git push with GraphQL signed commits to satisfy required_signatures rulesets (#21576)

* docs: add weekly update blog post for 2026-03-18 (#21608)

Covers v0.58.0 through v0.61.0 (7 releases this week),
notable PRs, and auto-triage-issues as Agent of the Week.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix failing CI: merge main to include setupGlobals in generate_aw_info step and update golden files

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox lpcox merged commit f8b8402 into main Mar 18, 2026
54 checks passed
@lpcox lpcox deleted the copilot/fix-threat-detection-run branch March 18, 2026 16:18
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.

Threat detection AWF run missing --copilot-api-target and GHE domains on data residency

4 participants