Skip to content

Commit 02c0ded

Browse files
authored
Deduplicate derived guard-policy accept entries (#80757)
1 parent 88f9bb5 commit 02c0ded

7 files changed

Lines changed: 73 additions & 13 deletions

File tree

‎pkg/workflow/enclave_github_proxy_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ func TestDynamicEnclaveWriteSinkPolicyUsesWorkflowDestinationVisibility(t *testi
170170
}
171171
}
172172

173+
func TestStaticEnclaveWriteSinkPolicyDeduplicatesAcceptEntries(t *testing.T) {
174+
workflowData := enclaveGitHubToolsWorkflowData()
175+
workflowData.Tools["github"] = false
176+
workflowData.Enclaves[0].Agent.Tools.GitHub.AllowedRepos = GitHubReposScope{
177+
"octo-org/*",
178+
"octo-org/private-service",
179+
"octo-org/*",
180+
}
181+
182+
assert.Equal(t, map[string]any{
183+
"write-sink": map[string]any{
184+
"accept": []string{"private:octo-org", "private:octo-org/private-service"},
185+
"sink-visibility": sinkVisibilityRuntimeExpr,
186+
},
187+
}, staticEnclaveWriteSinkGuardPolicy(workflowData))
188+
}
189+
173190
// TestCompileDynamicGitHubEnclaveDisabledPrimaryGitHub compiles a workflow matching the
174191
// gh-aw#59523 fixture: tools.github: false with a dynamic GitHub repository enclave. It
175192
// asserts the compiler generates a usable lock file without manual edits (guard policy,

‎pkg/workflow/mcp_github_config.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ package workflow
6464
import (
6565
"fmt"
6666
"maps"
67-
"sort"
67+
"slices"
6868
"strconv"
6969
"strings"
7070

7171
"github.com/github/gh-aw/pkg/constants"
7272
"github.com/github/gh-aw/pkg/logger"
7373
"github.com/github/gh-aw/pkg/setutil"
74+
"github.com/github/gh-aw/pkg/sliceutil"
7475
"github.com/github/gh-aw/pkg/typeutil"
7576
)
7677

@@ -100,7 +101,7 @@ func dynamicEnclaveGitHubGuardRepos(workflowData *WorkflowData) []string {
100101
for _, owner := range enclave.Dynamic.AllowedOwners {
101102
add(owner + "/*") //nolint:manualpathconcat // GitHub owner/repo guard patterns are not filesystem paths.
102103
}
103-
sort.Strings(repos)
104+
slices.Sort(repos)
104105
return repos
105106
}
106107

@@ -212,7 +213,7 @@ func writeSinkAcceptLabelsForRepos(repos []string) []string {
212213
for _, repo := range repos {
213214
accept = append(accept, transformRepoPattern(repo))
214215
}
215-
return accept
216+
return sliceutil.Deduplicate(accept)
216217
}
217218

218219
func writeSinkGuardPolicy(accept []string) map[string]any {
@@ -661,7 +662,7 @@ func deriveSafeOutputsGuardPolicyFromGitHub(githubTool map[string]any) map[strin
661662
}
662663

663664
writeSink := map[string]any{
664-
"accept": acceptList,
665+
"accept": sliceutil.Deduplicate(acceptList),
665666
"sink-visibility": sinkVisibilityRuntimeExpr,
666667
}
667668

‎pkg/workflow/safeoutputs_guard_policy_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@ func TestDeriveSafeOutputsGuardPolicyFromGitHub(t *testing.T) {
111111
expectNil: false,
112112
description: "github.repository expression should map to runtime repository scope",
113113
},
114+
{
115+
name: "duplicate allowed repos as []any",
116+
githubTool: map[string]any{
117+
"allowed-repos": []any{"github/*", "microsoft/copilot", "github/*", "microsoft/copilot"},
118+
"min-integrity": "approved",
119+
},
120+
expectedPolicies: map[string]any{
121+
"write-sink": map[string]any{
122+
"accept": []string{"private:github", "private:microsoft/copilot"},
123+
"sink-visibility": sinkVisibilityExpr,
124+
},
125+
},
126+
description: "Duplicate transformed patterns should be removed in first-seen order",
127+
},
128+
{
129+
name: "duplicate allowed repos as []string",
130+
githubTool: map[string]any{
131+
"allowed-repos": []string{"github/gh-aw", "github/copilot*", "github/gh-aw"},
132+
"min-integrity": "approved",
133+
},
134+
expectedPolicies: map[string]any{
135+
"write-sink": map[string]any{
136+
"accept": []string{"private:github/gh-aw", "private:github/copilot*"},
137+
"sink-visibility": sinkVisibilityExpr,
138+
},
139+
},
140+
description: "Duplicate string patterns should be removed in first-seen order",
141+
},
114142
{
115143
name: "multiple repo patterns as []any",
116144
githubTool: map[string]any{

‎scratchpad/github-mcp-access-control-specification.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88
# GitHub MCP Server Access Control Specification
99

1010
**Version**: 1.1.0
11-
**Status**: Draft
11+
**Status**: Implemented in part (compiler-side; runtime enforcement is external; Complete Conformance deferred)<br>
1212
**Latest Version**: [github-mcp-access-control-specification](/gh-aw/scratchpad/github-mcp-access-control-specification/)
1313
**JSON Schema**: [mcp-gateway-config.schema.json](/gh-aw/schemas/mcp-gateway-config.schema.json)
1414
**Editors**: GitHub Agentic Workflows Team
@@ -21,7 +21,7 @@ This specification defines access control extensions for the GitHub MCP (Model C
2121

2222
## Status of This Document
2323

24-
This section describes the status of this document at the time of publication. This is a draft specification and may be updated, replaced, or made obsolete by other documents at any time.
24+
The compiler-side guard-policy integration is implemented; runtime enforcement is provided by the external MCP Gateway. Complete Conformance remains deferred as described in §2.1.
2525

2626
This document is governed by the GitHub Agentic Workflows project specifications process.
2727

@@ -149,8 +149,11 @@ A **Complete Conforming Implementation** MUST satisfy Basic Conformance and:
149149
- Enforce all access controls at runtime through gateway middleware
150150
- Support all configuration fields in combination
151151

152-
These are normative target requirements, not a claim that the local `gh-aw`
153-
compiler implements every field. As verified on 2026-11-16, `roles` and
152+
These are normative target requirements. The local `gh-aw` compiler implements
153+
the configuration and validation portions of Basic Conformance; runtime
154+
enforcement and standardized responses depend on the external MCP Gateway, so
155+
this document does not claim end-to-end Basic Conformance for the compiler.
156+
Complete Conformance is not claimed. As verified on 2026-11-16, `roles` and
154157
`private-repos` remain deferred in the local compiler; use of either field is
155158
rejected rather than silently ignored. Track local support in
156159
[issue #78412](https://github.com/github/gh-aw/issues/78412). The local

‎scratchpad/guard-policies-specification.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ When GitHub guard policies are configured, the compiler automatically derives a
156156
- **MUST derive a `write-sink` guard policy** for the safe-outputs MCP server whenever a GitHub guard policy (`allowed-repos` or `min-integrity`) is present in the workflow frontmatter. The derived policy MUST be applied before the workflow is executed.
157157
- **MUST map `allowed-repos: "all"` or `allowed-repos: "public"` to `accept: ["*"]`**, allowing all safe output operations. Implementations MUST NOT restrict the write-sink scope when the GitHub guard policy already permits all repositories.
158158
- **MUST transform each repository pattern** in an `allowed-repos` array to a `private:`-prefixed accept entry. Owner-wildcard patterns (`owner/*`) MUST be transformed to `private:owner` (the trailing `/*` is stripped). Prefix-wildcard patterns (`owner/prefix*`) MUST be transformed to `private:owner/prefix*` (the prefix is preserved). Exact repository patterns (`owner/repo`) MUST be transformed to `private:owner/repo`.
159-
- **MUST NOT include duplicate accept entries** in the derived `write-sink` policy. If multiple input patterns resolve to the same `private:` value, the implementation MUST deduplicate before emitting the accept list.
159+
- **MUST NOT include duplicate accept entries** in the derived `write-sink` policy. If multiple input patterns resolve to the same `private:` value, the implementation MUST deduplicate before emitting the accept list, preserving first-seen order.
160+
- **MUST emit `sink-visibility: "${GH_AW_SINK_VISIBILITY}"`** in the derived `write-sink` policy. The environment variable supplies the destination repository visibility at runtime.
160161
- **SHOULD log a debug-level message** when a guard policy is derived, identifying the source GitHub `allowed-repos` value and the resulting accept list. This assists operators in diagnosing unexpected policy behavior.
161162
- **MUST return `nil`** (no derived policy) when no GitHub guard policy fields are present on the tool configuration. The absence of a guard policy MUST NOT be treated as an implicit `accept: ["*"]` — the decision to omit the policy is intentional and MUST be preserved.
162163

@@ -181,7 +182,8 @@ Generates safeoutputs guard-policy:
181182
```json
182183
{
183184
"write-sink": {
184-
"accept": ["*"]
185+
"accept": ["*"],
186+
"sink-visibility": "${GH_AW_SINK_VISIBILITY}"
185187
}
186188
}
187189
```
@@ -204,7 +206,8 @@ Generates safeoutputs guard-policy:
204206
"accept": [
205207
"private:github",
206208
"private:microsoft/copilot"
207-
]
209+
],
210+
"sink-visibility": "${GH_AW_SINK_VISIBILITY}"
208211
}
209212
}
210213
```
@@ -590,7 +593,7 @@ covered by `pkg/workflow/tools_validation_test.go`.
590593
|---|---|---|
591594
| GP-05 through GP-08 | Deriving the safe-outputs `write-sink` policy from GitHub guard policy | `pkg/workflow/mcp_github_config.go` (`deriveSafeOutputsGuardPolicyFromGitHub`) |
592595
| GP-06 scalar mapping | `"all"` / `"public"` → `accept: ["*"]` mapping | `pkg/workflow/mcp_github_config.go` (`deriveSafeOutputsGuardPolicyFromGitHub`) |
593-
| GP-07 pattern transformation | Array patterns → `private:`-prefixed accept entries | `pkg/workflow/mcp_github_config.go` (`normalizeGitHubRepositoryInReposScope`) |
596+
| GP-07 pattern transformation | Array patterns → deduplicated `private:`-prefixed accept entries | `pkg/workflow/mcp_github_config.go` (`deriveSafeOutputsGuardPolicyFromGitHub`) |
594597
| GP-05 through GP-08 tests | Derivation tests including nil-return, scalar, and array cases | `pkg/workflow/safeoutputs_guard_policy_test.go` (`TestDeriveSafeOutputsGuardPolicyFromGitHub`) |
595598

596599
### Legacy `repos` Field Migration

‎specs/advisory-handoff/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ This model describes the maintainer-driven handoff to a temporary private GitHub
99
3. Run `gh aw advisory inspect <GHSA-ID> --print-patch` in a private terminal and type `yes` to review the untrusted patch and the destination. The flag requires terminal stdin and stdout. Omit it for metadata and the digest in scripts or CI. The digest identifies the handoff; it does not attest that the fix passed tests.
1010
4. Run `gh aw advisory transfer <GHSA-ID> --approve <digest>`. Transfer verifies the handoff again and attempts to create only the destination branch. Open the PR from the advisory page. If transfer warns about base drift, check whether the branch already exists before rebasing and retesting.
1111

12+
Recording requires an existing temporary private advisory fork unless `--create-fork` is supplied. If the fork is missing, the error hints to use `advisory record --create-fork` or create it in GitHub.
13+
1214
## Model boundary
1315

1416
`sideReady` represents the verified side repository. Each GHSA has independent fork, record, review, transfer, and branch state. `ClaimFork` persists the local marker; `SendForkRequest` and `ProvisionFork` separate requesting the fork from its appearance. Retrying an identical record is a stuttering step.

‎specs/workflow-security/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,13 @@ failed/stopped workflows are terminal; no liveness or fairness theorem is made.
831831
### Connect source to compiled jobs
832832

833833
The compile-only seed uses fictitious credentials and a fake dependency.
834-
Never dispatch it. Compile a copy into a new temporary directory:
834+
Never dispatch it.
835+
836+
The expected checkout-token and GitHub App safe-output counts in the header of
837+
`fixtures/cross-repo.md` are parsed and asserted by `check.py` against the
838+
compiled lock. Update the counts when the fixture's expected bindings change.
839+
840+
Compile a copy into a new temporary directory:
835841

836842
```bash
837843
make build

0 commit comments

Comments
 (0)