Skip to content

Allow sandbox agents to reach declared service ports - #51842

Merged
pelikhan merged 10 commits into
mainfrom
copilot/fix-services-ports-reachable
Aug 11, 2026
Merged

Allow sandbox agents to reach declared service ports#51842
pelikhan merged 10 commits into
mainfrom
copilot/fix-services-ports-reachable

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Sandboxed agents could not reach GitHub Actions services: ports because --allow-host-ports was only emitted in legacy security mode and only with a hardcoded default list. Workflows with databases or other service containers failed silently inside the agent loop.

  • Compiler behavior

    • Derives host TCP ports from services: port mappings.
    • Emits --allow-host-ports in strict security mode when service or explicit host ports are present.
    • Keeps --enable-host-access legacy-only.
  • Explicit escape hatch

    • Adds sandbox.agent.allow-host-ports for host daemons not declared as services:.
    • Validates explicit ports are within 1..65535.
  • Deterministic output

    • Merges default ports, service-derived ports, and explicit ports.
    • Dedupes and sorts the final allowlist.
    • Warns when the pinned AWF version is too old to support --allow-host-ports.

Example:

services:
  postgres:
    image: postgres:18
    ports:
      - 5432:5432

sandbox:
  agent:
    allow-host-ports: [9200]

Compiles to an allowlist including 5432 and 9200 without enabling legacy host access.


Run URL: https://github.com/github/gh-aw/actions/runs/31450173394> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 24.1 AIC · ⌖ 5.21 AIC · ⊞ 6.1K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 22.1 AIC · ⌖ 6.79 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/31454952282> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 15.9 AIC · ⌖ 5.21 AIC · ⊞ 8.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14.3 AIC · ⌖ 5.17 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.8 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unreachable services: ports from sandboxed agent Allow sandbox agents to reach declared service ports Aug 10, 2026
Copilot AI requested a review from pelikhan August 10, 2026 17:37
@pelikhan
pelikhan marked this pull request as ready for review August 10, 2026 17:38
Copilot AI balanced review requested due to automatic review settings August 10, 2026 17:38
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel failed during test quality analysis.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer failed. Please review the logs for details.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by Ponytail Reviewer for #51842

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ failed during design decision gate check.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds service-derived and explicit host-port allowlists for sandboxed agents.

Changes:

  • Parses, validates, sorts, and emits host ports.
  • Adds sandbox.agent.allow-host-ports.
  • Updates tests, documentation, schema, autocomplete, and generated workflow.
Show a summary per file
File Description
pkg/workflow/service_ports.go Extracts host ports from services.
pkg/workflow/sandbox.go Stores explicit host ports.
pkg/workflow/sandbox_validation.go Validates port ranges.
pkg/workflow/sandbox_validation_test.go Tests validation.
pkg/workflow/frontmatter_extraction_security.go Parses the new setting.
pkg/workflow/frontmatter_extraction_security_test.go Tests parsing.
pkg/workflow/awf_command_builder.go Emits the AWF allowlist.
pkg/workflow/awf_command_builder_test.go Tests command generation.
pkg/parser/schemas/main_workflow_schema.json Defines the schema.
docs/src/content/docs/reference/sandbox.md Documents service access.
docs/src/content/docs/reference/frontmatter-full.md Documents frontmatter syntax.
docs/src/content/docs/guides/upgrading.md Adds upgrade guidance.
docs/public/editor/autocomplete-data.json Adds editor autocomplete.
.github/workflows/smoke-service-ports.lock.yml Regenerates the smoke workflow.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 14/14 changed files
  • Comments generated: 5
  • Review effort level: Balanced

Comment thread pkg/workflow/awf_command_builder.go Outdated
Comment thread pkg/workflow/sandbox_validation.go
Comment thread pkg/workflow/service_ports.go Outdated
Comment thread pkg/workflow/service_ports.go Outdated
Comment thread pkg/workflow/service_ports.go Outdated
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Addressed all 5 review threads by reverting --allow-host-ports to legacy-security-only (AWF requires --enable-host-access for this flag and permanently blocks dangerous ports like 5432/6379/9200 through it regardless of mode, per AWF's DANGEROUS_PORTS policy). Removed the buggy service-port derivation code entirely — services are correctly reached via the pre-existing --allow-host-service-ports mechanism (legacy-security only), which resolves dynamic host ports at runtime. Added dangerous-port validation to the explicit allow-host-ports escape hatch and updated docs/schema/tests accordingly. Pushed in commit fixing strict-mode host-port allowlist.

@pelikhan

Copy link
Copy Markdown
Collaborator

/review

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel failed during test quality analysis.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test quality analysis by Test Quality Sentinel

@pelikhan

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /tdd, /codebase-design, and /grill-with-docs — requesting changes on three moderate issues.

📋 Key Themes & Highlights

Issues

  1. Misleading test fixtures (frontmatter_extraction_security_test.go) — extraction test uses 5432 and 9200, which are in awfDangerousHostPorts. Parsing-layer tests are correct, but the examples imply these ports are valid end-to-end values for users.

  2. Missing defense-in-depth in collectAllowedHostPorts — dangerous ports are only filtered in validation, not in the builder. If validation is ever bypassed or the call order changes, a dangerous port could silently appear in --allow-host-ports.

  3. Undocumented drift risk in awfDangerousHostPorts — the hardcoded list mirrors an upstream firewall list with no automated sync anchor. A version/commit reference comment or a minimum unit test would reduce the risk of silent drift.

  4. PR description vs. docs contradiction (sandbox.md line 68) — the docs correctly state that reaching service ports requires legacy-security: enable, but the PR description's top-level example omits it. This is a minor documentation inconsistency that could confuse users reading the description later.

Positive Highlights

  • ✅ Clear separation between --allow-host-service-ports (runtime, dynamic) and --allow-host-ports (static, legacy-only) — the architecture choice is well-reasoned.
  • ✅ Deterministic port output (dedup + sort) is a good correctness property.
  • ✅ Version-gate warning with specific minimum version is excellent UX.
  • ✅ Test coverage is thorough: strict-mode warning, version-too-old path, and merge-and-deduplicate all covered.
  • awfDangerousHostPorts list is appropriately conservative and well-commented.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 45.9 AIC · ⌖ 10.4 AIC · ⊞ 7.1K
Comment /matt to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: the latest maintainer-requested follow-up review appears acknowledged, but this PR still has multiple unresolved review threads on the host-port model. Please reconcile the curr...

Reconciled all 5 threads against the current branch — all are superseded, no further action needed:

  • discussion_r3751937492 (strict-mode --allow-host-ports invalid) — superseded: --allow-host-ports is now only emitted inside the isLegacy branch alongside --enable-host-access (awf_command_builder.go), never in strict mode.
  • discussion_r3751937535 (dangerous explicit ports accepted) — superseded: validateAllowHostPorts now rejects any port in awfDangerousHostPorts at compile time (sandbox_validation.go:504), plus defense-in-depth filtering in collectAllowedHostPorts.
  • discussion_r3751937560 (non-TCP suffixes widen allowlist) — superseded: the buggy service-port-derivation code this comment targeted was removed entirely; services are reached via the pre-existing --allow-host-service-ports mechanism instead.
  • discussion_r3751937590 (bare service port treated as static host port) — superseded: same removal — static allowlisting of service ports is gone, dynamic resolution via job.services.<id>.ports[...] is used.
  • discussion_r3751937621 (host port ranges dropped) — superseded: same removal, no longer applicable since there's no static range-parsing path.

go build ./... and go test ./pkg/workflow/... both pass on the current branch. No code changes were needed this round.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage: your last reconciliation says the remaining host-port review threads are superseded, but they still appear unresolved from a maintainer triage perspective. Please run the pr-finisher skill, reply directly on each still-open thread with the specific superseding code path or resolution status, and return a concise maintainer-facing summary once the thread state matches the branch.

Branch refresh was requested. Run: https://github.com/github/gh-aw/actions/runs/31454952282

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 15.9 AIC · ⌖ 5.21 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: your last reconciliation says the remaining host-port review threads are superseded, but they still appear unresolved from a maintainer triage perspective. Please run the pr-fin...

Replied directly on each of the 5 threads with the specific superseding code path:

  • discussion_r3751937492 (strict-mode --allow-host-ports invalid) → resolved by gating the flag inside the isLegacy branch in awf_command_builder.go.
  • discussion_r3751937535 (dangerous explicit ports accepted too late) → resolved by validateAllowHostPorts compile-time rejection + defense-in-depth filtering in collectAllowedHostPorts.
  • discussion_r3751937560 (non-TCP suffixes widen allowlist) → resolved by removing the static service-port-derivation code entirely.
  • discussion_r3751937590 (bare service port treated as static host port) → resolved by the same removal; dynamic resolution via --allow-host-service-ports is used instead.
  • discussion_r3751937621 (host port ranges dropped) → resolved by the same removal.

Branch verified: go build ./... and go test ./pkg/workflow/... both pass. No code changes were required this round — thread text on GitHub was stale relative to the branch, now clarified per-thread.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage: the branch now appears aligned with the superseding fixes you described, but the PR is still not easy for a maintainer to clear quickly because the thread state and blocking review state lag the code. Please run the pr-finisher skill, verify every still-open review thread has a direct maintainer-friendly resolution on-thread, confirm whether all remaining change-request signals can now be cleared, and return a concise summary of what is resolved vs what still needs human action.

Branch refresh was requested. Run: https://github.com/github/gh-aw/actions/runs/31456898570

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14.3 AIC · ⌖ 5.17 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: the branch now appears aligned with the superseding fixes you described, but the PR is still not easy for a maintainer to clear quickly because the thread state and blocking rev...

Verified current state, no further code changes needed:

  • Threads: all 5 review threads already carry a direct, maintainer-facing resolution reply pointing at the exact superseding code path (isLegacy gating in awf_command_builder.go, awfDangerousHostPorts rejection in sandbox_validation.go/collectAllowedHostPorts, and removal of the static service-port-derivation code in favor of --allow-host-service-ports/ExtractServicePortExpressions). I don't have a tool that can flip GitHub's thread isResolved flag from this session — that "Resolve conversation" click needs a maintainer/collaborator with write access, but the content resolution is already posted on each thread.
  • Change-request signals: there is no blocking CHANGES_REQUESTED review on the PR. The initial automated review is COMMENTED (its 5 comments are the threads above, already answered) and the Matt Pocock skills review is DISMISSED. Nothing currently needs clearing at the review-decision level.
  • Local validation: go build ./... and go test ./pkg/workflow/... (host-port/service-port/sandbox suites) pass on d7595f4; gofmt -l is clean on the changed files.

Still needed from a human: click "Resolve conversation" on the 5 threads (content already answered) and re-approve/re-run required checks to clear the blocked mergeable state — that requires a maintainer with write access, not further agent changes.

@pelikhan

Copy link
Copy Markdown
Collaborator

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage: CI is currently failing on lint-go for this branch.

Please fix the failing check and then run the pr-finisher skill. For maintainer handoff, keep the response concise and include:

  • whether the lint-go failure is fully addressed,
  • whether the 5 already-answered review threads can now be considered fully resolved in branch state,
  • whether anything remains besides human thread-resolution / approval / CI rerun.

Failed checks:

Branch refresh was requested.
Run: https://github.com/github/gh-aw/actions/runs/31459045198

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.8 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix https://github.com/github/gh-aw/actions/runs/31457247318/job/93677346709#step:7:1

Fixed in de288a2: the golint-incremental job failed on copyloopvar in pkg/cli/codemod_engine_env_secrets_pure_test.go and pkg/cli/codemod_messages_effective_tokens_suffix_to_ai_credits_suffix_pure_test.go (redundant tt := tt loop-var copies). That fix already landed on main via #51907; this branch was 2 commits behind, so I merged main in. golangci-lint run ./pkg/cli/... and make golint-incremental BASE_REF=origin/main both report 0 issues now, and go build ./... / targeted go test still pass.

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage: CI is currently failing on lint-go for this branch.

Please fix the failing check and then run the pr-finisher skill. For maintainer handoff, keep the response concise and i...

Status:

  • lint-go: already fixed in de288a2 (merged main to pick up the copyloopvar fix from Prevent raw observability log loss during artifact extraction #51907). Re-verified just now: golangci-lint run ./pkg/cli/... → 0 issues, make golint-incremental BASE_REF=origin/main → 0 issues, go build ./... and targeted go test all pass. The linked failing run (31457247318) predates that merge commit; it will show green once CI re-runs on de288a2.
  • 5 review threads: branch state is unchanged since the last pass — each already has a direct on-thread reply naming its superseding code path (isLegacy gating, awfDangerousHostPorts rejection + defense-in-depth filter, and removal of static service-port derivation in favor of --allow-host-service-ports). No further branch changes needed for these.
  • Remaining: only human actions — clicking "Resolve conversation" on the 5 threads and re-triggering CI (agent pushes don't retrigger workflow runs), then approval/merge.

@pelikhan
pelikhan merged commit 6b43574 into main Aug 11, 2026
28 checks passed
@pelikhan
pelikhan deleted the copilot/fix-services-ports-reachable branch August 11, 2026 05:03
github-actions Bot added a commit that referenced this pull request Aug 11, 2026
Add two new terms based on recent commits (#51842, #51870):
- Host Service Ports (services:) — AWF sandbox access to GitHub
  Actions services containers via --allow-host-service-ports
- MCP Gateway Mount-Roots Allowlist (MCP_GATEWAY_ALLOWED_MOUNT_ROOTS) —
  compiler-computed mount policy allowlist for MCP backend containers

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

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

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.

BUG: services: ports are unreachable from the sandboxed agent — --allow-host-ports is hardcoded and allowHostServicePorts is never emitted

5 participants