trust-path 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trust_path-0.2.0 → trust_path-0.4.0}/MANIFEST.in +2 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/PKG-INFO +6 -3
- {trust_path-0.2.0 → trust_path-0.4.0}/README.md +5 -2
- trust_path-0.4.0/benchmark/agents-only.json +5 -0
- trust_path-0.4.0/benchmark/corpus.json +13 -0
- trust_path-0.4.0/benchmark/expected.json +31 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/claude-gated.yml +15 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/claude-open.yml +17 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/claude-restricted.yml +20 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/codex-gated.yml +16 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/codex-read-only.yml +17 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/gemini-author-check.yml +16 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/gemini.yml +15 -0
- trust_path-0.4.0/benchmark/fixtures/agents/.github/workflows/no-credential.yml +13 -0
- trust_path-0.4.0/benchmark/run.py +164 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/pyproject.toml +1 -1
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/test_analyze.py +113 -19
- trust_path-0.4.0/tests/test_benchmark.py +133 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path/__init__.py +1 -1
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path/analyze.py +59 -11
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path.egg-info/PKG-INFO +6 -3
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path.egg-info/SOURCES.txt +13 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/.github/workflows/release.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/.github/workflows/test.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/LICENSE +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/setup.cfg +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/__init__.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/agent/.github/workflows/triage.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/head_checkout/.github/workflows/build.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/missing_call/.github/workflows/call.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/pr_title/.github/workflows/greet.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/reusable/.github/workflows/on-comment.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/reusable/.github/workflows/reply.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/safe/.github/workflows/echo-title.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/safe/.github/workflows/label.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/safe/.github/workflows/release.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/safe/.github/workflows/test.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/tags/.github/workflows/a.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/workflow_run_chain/.github/workflows/ci.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/workflow_run_chain/.github/workflows/publish.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/workflow_run_chain/.github/workflows/stage.yml +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/test_cli.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/tests/test_yamlsubset.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path/__main__.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path/cli.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path/yamlsubset.py +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path.egg-info/dependency_links.txt +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path.egg-info/entry_points.txt +0 -0
- {trust_path-0.2.0 → trust_path-0.4.0}/trust_path.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trust-path
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: List the paths by which untrusted input can reach secrets and publishing credentials in GitHub Actions workflows.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://github.com/jacob-adm/trust-path
|
|
@@ -71,8 +71,9 @@ pip installs `trust-path` as a console script. Without installing, it runs from
|
|
|
71
71
|
workflow or after a `pull_request` workflow (followed through chains), or when it is a local
|
|
72
72
|
reusable workflow called from such a run.
|
|
73
73
|
3. **Find where input enters each job.** A step enters untrusted input when it uses a context such
|
|
74
|
-
as `github.event.pull_request.title` in `run
|
|
75
|
-
request's head, downloads an artifact from the upstream run,
|
|
74
|
+
as `github.event.pull_request.title` in `run:` or `with:` (directly, or through
|
|
75
|
+
`${{ env.NAME }}`), checks out or fetches the pull request's head, downloads an artifact from the upstream run, expands the changed file names of a pull
|
|
76
|
+
request, or is an AI agent action.
|
|
76
77
|
4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
|
|
77
78
|
trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
|
|
78
79
|
environment and AI agent actions holding a credential.
|
|
@@ -123,6 +124,8 @@ key and can write text into issues that other workflows and agents read. Run `tr
|
|
|
123
124
|
list and the YAML subset.
|
|
124
125
|
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
125
126
|
- [Limitations and security](https://github.com/jacob-adm/trust-path/blob/main/docs/limitations-and-security.md): what trust-path does not see, read or do.
|
|
127
|
+
- [Benchmark](https://github.com/jacob-adm/trust-path/blob/main/docs/benchmark.md): a repeatable run on pinned public workflows, with a
|
|
128
|
+
per-file comparison against zizmor
|
|
126
129
|
- [Using it with other tools](https://github.com/jacob-adm/trust-path/blob/main/docs/other-tools.md): a tested stack with git surface
|
|
127
130
|
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
128
131
|
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
@@ -50,8 +50,9 @@ pip installs `trust-path` as a console script. Without installing, it runs from
|
|
|
50
50
|
workflow or after a `pull_request` workflow (followed through chains), or when it is a local
|
|
51
51
|
reusable workflow called from such a run.
|
|
52
52
|
3. **Find where input enters each job.** A step enters untrusted input when it uses a context such
|
|
53
|
-
as `github.event.pull_request.title` in `run
|
|
54
|
-
request's head, downloads an artifact from the upstream run,
|
|
53
|
+
as `github.event.pull_request.title` in `run:` or `with:` (directly, or through
|
|
54
|
+
`${{ env.NAME }}`), checks out or fetches the pull request's head, downloads an artifact from the upstream run, expands the changed file names of a pull
|
|
55
|
+
request, or is an AI agent action.
|
|
55
56
|
4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
|
|
56
57
|
trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
|
|
57
58
|
environment and AI agent actions holding a credential.
|
|
@@ -102,6 +103,8 @@ key and can write text into issues that other workflows and agents read. Run `tr
|
|
|
102
103
|
list and the YAML subset.
|
|
103
104
|
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
104
105
|
- [Limitations and security](https://github.com/jacob-adm/trust-path/blob/main/docs/limitations-and-security.md): what trust-path does not see, read or do.
|
|
106
|
+
- [Benchmark](https://github.com/jacob-adm/trust-path/blob/main/docs/benchmark.md): a repeatable run on pinned public workflows, with a
|
|
107
|
+
per-file comparison against zizmor
|
|
105
108
|
- [Using it with other tools](https://github.com/jacob-adm/trust-path/blob/main/docs/other-tools.md): a tested stack with git surface
|
|
106
109
|
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
107
110
|
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"url": "https://github.com/messypoutine/gravy-overflow",
|
|
4
|
+
"commit": "cbff1a67a804d10e2fe00e18e9c4b2f4bf9d89ce"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"url": "https://github.com/step-security/github-actions-goat",
|
|
8
|
+
"commit": "4da23c8602b4589bacdf7de77240113e02cdb884"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "fixtures/agents"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"agents": {
|
|
3
|
+
"agent_files_by_gate": {
|
|
4
|
+
"anyone": 3,
|
|
5
|
+
"none": 2,
|
|
6
|
+
"write-access": 2
|
|
7
|
+
},
|
|
8
|
+
"by_category": {
|
|
9
|
+
"agent": 23
|
|
10
|
+
},
|
|
11
|
+
"records": 23,
|
|
12
|
+
"refused": 0
|
|
13
|
+
},
|
|
14
|
+
"github-actions-goat": {
|
|
15
|
+
"agent_files_by_gate": {},
|
|
16
|
+
"by_category": {
|
|
17
|
+
"head-code": 2
|
|
18
|
+
},
|
|
19
|
+
"records": 2,
|
|
20
|
+
"refused": 0
|
|
21
|
+
},
|
|
22
|
+
"gravy-overflow": {
|
|
23
|
+
"agent_files_by_gate": {},
|
|
24
|
+
"by_category": {
|
|
25
|
+
"expression": 52,
|
|
26
|
+
"head-code": 19
|
|
27
|
+
},
|
|
28
|
+
"records": 71,
|
|
29
|
+
"refused": 1
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The action's default: only users with write access start the agent.
|
|
2
|
+
name: claude-gated
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
permissions:
|
|
7
|
+
contents: write
|
|
8
|
+
pull-requests: write
|
|
9
|
+
jobs:
|
|
10
|
+
assist:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: anthropics/claude-code-action@v1
|
|
14
|
+
with:
|
|
15
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Any user can start the agent; its tools are not limited.
|
|
2
|
+
name: claude-open
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types: [opened]
|
|
6
|
+
permissions:
|
|
7
|
+
issues: write
|
|
8
|
+
jobs:
|
|
9
|
+
triage:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: anthropics/claude-code-action@v1
|
|
13
|
+
with:
|
|
14
|
+
prompt: Label issue ${{ github.event.issue.number }}.
|
|
15
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
16
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
17
|
+
allowed_non_write_users: "*"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Any user can start the agent; the workflow limits its tools.
|
|
2
|
+
name: claude-restricted
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types: [opened]
|
|
6
|
+
permissions:
|
|
7
|
+
issues: write
|
|
8
|
+
jobs:
|
|
9
|
+
triage:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: anthropics/claude-code-action@v1
|
|
13
|
+
with:
|
|
14
|
+
prompt: Label issue ${{ github.event.issue.number }}.
|
|
15
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
16
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
17
|
+
allowed_non_write_users: "*"
|
|
18
|
+
claude_args: |
|
|
19
|
+
--permission-mode auto
|
|
20
|
+
--disallowedTools "WebFetch,WebSearch,Write,Edit"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# The action's default gate, and a sandbox that can write the workspace.
|
|
2
|
+
name: codex-gated
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
permissions:
|
|
7
|
+
contents: write
|
|
8
|
+
jobs:
|
|
9
|
+
assist:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: openai/codex-action@v1
|
|
13
|
+
with:
|
|
14
|
+
prompt: Help with issue ${{ github.event.issue.number }}.
|
|
15
|
+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
|
|
16
|
+
sandbox: workspace-write
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Any user can start the agent; it runs in a read-only sandbox.
|
|
2
|
+
name: codex-read-only
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types: [opened]
|
|
6
|
+
permissions:
|
|
7
|
+
issues: read
|
|
8
|
+
jobs:
|
|
9
|
+
classify:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: openai/codex-action@v1
|
|
13
|
+
with:
|
|
14
|
+
prompt: Classify issue ${{ github.event.issue.number }}.
|
|
15
|
+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
|
|
16
|
+
allow-users: "*"
|
|
17
|
+
sandbox: read-only
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# The action has no gate of its own; the job's condition tests the author.
|
|
2
|
+
name: gemini-author-check
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
issues: write
|
|
9
|
+
jobs:
|
|
10
|
+
assist:
|
|
11
|
+
if: contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: google-github-actions/run-gemini-cli@v0
|
|
15
|
+
with:
|
|
16
|
+
prompt: Help with issue ${{ github.event.issue.number }}.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The action has no gate of its own and the workflow adds none.
|
|
2
|
+
name: gemini
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
issues: write
|
|
9
|
+
jobs:
|
|
10
|
+
assist:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: google-github-actions/run-gemini-cli@v0
|
|
14
|
+
with:
|
|
15
|
+
prompt: Help with issue ${{ github.event.issue.number }}.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# An agent that holds nothing: no secret, no token scope. Nothing to report.
|
|
2
|
+
name: no-credential
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types: [opened]
|
|
6
|
+
permissions: {}
|
|
7
|
+
jobs:
|
|
8
|
+
summarise:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/ai-inference@v1
|
|
12
|
+
with:
|
|
13
|
+
prompt: Summarise issue ${{ github.event.issue.number }}.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Run trust-path, and zizmor when it is installed, on pinned commits of
|
|
3
|
+
public repositories and on the agent workflows kept beside this script, and
|
|
4
|
+
compare what they report per workflow file.
|
|
5
|
+
|
|
6
|
+
python3 benchmark/run.py [--corpus FILE] [--expected FILE] [--cache DIR] [--update]
|
|
7
|
+
|
|
8
|
+
Exit status: 0 the trust-path counts match the expected file, 1 they differ,
|
|
9
|
+
2 a repository could not be fetched or a tool failed.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import collections
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import shutil
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
|
|
22
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
23
|
+
ZIZMOR = ["zizmor", "--offline", "--no-config", "--persona", "auditor", "--format", "json"]
|
|
24
|
+
_WORKFLOW = re.compile(r"workflows/([\w.-]+\.ya?ml)")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def category(source):
|
|
28
|
+
"""The kind of entry a trust-path source field names."""
|
|
29
|
+
what = source.rsplit(":", 1)[-1]
|
|
30
|
+
if what == "event text read by agent":
|
|
31
|
+
return "agent"
|
|
32
|
+
if what.endswith("of pull request head"):
|
|
33
|
+
return "head-code"
|
|
34
|
+
if what == "artifact from upstream run":
|
|
35
|
+
return "artifact"
|
|
36
|
+
return "expression"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def summarise(records, refused):
|
|
40
|
+
"""The counts kept in the expected file for one repository."""
|
|
41
|
+
by = collections.Counter(category(r["source"]) for r in records)
|
|
42
|
+
return {"records": len(records), "refused": refused, "by_category": dict(sorted(by.items())),
|
|
43
|
+
"agent_files_by_gate": agent_gates(records)}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def agent_gates(records):
|
|
47
|
+
"""Number of workflow files with an agent path, for each gate value."""
|
|
48
|
+
gates = collections.defaultdict(set)
|
|
49
|
+
for r in records:
|
|
50
|
+
if category(r["source"]) == "agent":
|
|
51
|
+
gate = r.get("detail", "").split(";")[0].replace("gate=", "") or "unknown"
|
|
52
|
+
gates[gate].add(os.path.basename(r["workflow"]))
|
|
53
|
+
return dict((g, len(files)) for g, files in sorted(gates.items()))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def injection_files(records):
|
|
57
|
+
"""Workflow files where trust-path reports pasted text or fork code."""
|
|
58
|
+
return set(os.path.basename(r["workflow"]) for r in records
|
|
59
|
+
if category(r["source"]) in ("expression", "head-code"))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def agent_files(records):
|
|
63
|
+
return set(os.path.basename(r["workflow"]) for r in records
|
|
64
|
+
if category(r["source"]) == "agent")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def zizmor_files(findings, ident="template-injection"):
|
|
68
|
+
"""Workflow files where zizmor reports a finding of kind `ident`."""
|
|
69
|
+
out = set()
|
|
70
|
+
for f in findings:
|
|
71
|
+
if f.get("ident") == ident:
|
|
72
|
+
out.update(_WORKFLOW.findall(json.dumps(f.get("locations", []))))
|
|
73
|
+
return out
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def compare(ours, theirs):
|
|
77
|
+
return {"both": len(ours & theirs), "trust-path only": len(ours - theirs),
|
|
78
|
+
"zizmor only": len(theirs - ours)}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _run(cmd, cwd=None, ok=(0,)):
|
|
82
|
+
p = subprocess.run(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
83
|
+
universal_newlines=True)
|
|
84
|
+
if p.returncode not in ok:
|
|
85
|
+
raise RuntimeError("%s: exit %d: %s" % (" ".join(cmd[:2]), p.returncode,
|
|
86
|
+
p.stderr.strip()[:200]))
|
|
87
|
+
return p
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def fetch(url, commit, dest):
|
|
91
|
+
"""Check out .github/workflows of `url` at `commit` into `dest`."""
|
|
92
|
+
if os.path.isdir(os.path.join(dest, ".github", "workflows")):
|
|
93
|
+
return
|
|
94
|
+
os.makedirs(dest)
|
|
95
|
+
_run(["git", "init", "-q"], dest)
|
|
96
|
+
_run(["git", "fetch", "-q", "--depth", "1", "--filter=blob:none", url, commit], dest)
|
|
97
|
+
_run(["git", "checkout", "-q", "FETCH_HEAD", "--", ".github/workflows"], dest)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main(argv=None):
|
|
101
|
+
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
102
|
+
parser.add_argument("--corpus", default=os.path.join(HERE, "corpus.json"))
|
|
103
|
+
parser.add_argument("--expected", default=os.path.join(HERE, "expected.json"))
|
|
104
|
+
parser.add_argument("--cache", help="directory to keep the fetched workflows in")
|
|
105
|
+
parser.add_argument("--update", action="store_true", help="rewrite the expected file")
|
|
106
|
+
args = parser.parse_args(argv)
|
|
107
|
+
with open(args.corpus) as f:
|
|
108
|
+
corpus = json.load(f)
|
|
109
|
+
cache = args.cache or tempfile.mkdtemp()
|
|
110
|
+
have_zizmor = shutil.which("zizmor") is not None
|
|
111
|
+
actual = {}
|
|
112
|
+
try:
|
|
113
|
+
if have_zizmor:
|
|
114
|
+
print("zizmor: %s" % _run(["zizmor", "--version"]).stdout.strip())
|
|
115
|
+
else:
|
|
116
|
+
print("zizmor: not installed, comparison skipped")
|
|
117
|
+
for repo in corpus:
|
|
118
|
+
if "path" in repo: # workflows kept beside the corpus file
|
|
119
|
+
name, at = os.path.basename(repo["path"]), "local"
|
|
120
|
+
dest = os.path.join(os.path.dirname(os.path.abspath(args.corpus)), repo["path"])
|
|
121
|
+
else:
|
|
122
|
+
name, at = repo["url"].rstrip("/").split("/")[-1], repo["commit"][:12]
|
|
123
|
+
dest = os.path.join(cache, name + "-" + at)
|
|
124
|
+
fetch(repo["url"], repo["commit"], dest)
|
|
125
|
+
p = _run([sys.executable, "-m", "trust_path", "--json", dest],
|
|
126
|
+
cwd=os.path.dirname(HERE), ok=(0, 1, 2))
|
|
127
|
+
records = json.loads(p.stdout)
|
|
128
|
+
refused = len(p.stderr.splitlines())
|
|
129
|
+
actual[name] = summarise(records, refused)
|
|
130
|
+
files = os.listdir(os.path.join(dest, ".github", "workflows"))
|
|
131
|
+
print("\n%s @ %s (%d workflow files)" % (name, at, len(files)))
|
|
132
|
+
print(" trust-path: %(records)d records, %(refused)d files refused, "
|
|
133
|
+
"%(by_category)s" % actual[name])
|
|
134
|
+
print(" trust-path: %d files with an agent path, by gate %s" % (
|
|
135
|
+
len(agent_files(records)), actual[name]["agent_files_by_gate"]))
|
|
136
|
+
if have_zizmor:
|
|
137
|
+
findings = json.loads(_run(ZIZMOR + [dest], ok=tuple(range(15))).stdout or "[]")
|
|
138
|
+
print(" injection, by workflow file: %s" % compare(
|
|
139
|
+
injection_files(records), zizmor_files(findings)))
|
|
140
|
+
except (RuntimeError, OSError, ValueError) as e:
|
|
141
|
+
sys.stderr.write("benchmark: %s\n" % e)
|
|
142
|
+
return 2
|
|
143
|
+
finally:
|
|
144
|
+
if not args.cache:
|
|
145
|
+
shutil.rmtree(cache, ignore_errors=True)
|
|
146
|
+
if args.update:
|
|
147
|
+
with open(args.expected, "w") as f:
|
|
148
|
+
json.dump(actual, f, indent=2, sort_keys=True)
|
|
149
|
+
f.write("\n")
|
|
150
|
+
return 0
|
|
151
|
+
with open(args.expected) as f:
|
|
152
|
+
expected = json.load(f)
|
|
153
|
+
if actual != expected:
|
|
154
|
+
print("\nDIFFERENT from %s:" % args.expected)
|
|
155
|
+
for name in sorted(set(actual) | set(expected)):
|
|
156
|
+
if actual.get(name) != expected.get(name):
|
|
157
|
+
print(" %s: expected %s, got %s" % (name, expected.get(name), actual.get(name)))
|
|
158
|
+
return 1
|
|
159
|
+
print("\ntrust-path counts match %s" % os.path.basename(args.expected))
|
|
160
|
+
return 0
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if __name__ == "__main__":
|
|
164
|
+
sys.exit(main())
|
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "trust-path"
|
|
8
|
-
version = "0.
|
|
8
|
+
version = "0.4.0"
|
|
9
9
|
description = "List the paths by which untrusted input can reach secrets and publishing credentials in GitHub Actions workflows."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.9"
|
|
@@ -66,10 +66,47 @@ class AgentDetailTests(unittest.TestCase):
|
|
|
66
66
|
self.assertEqual(agent("openai/codex-action@v1", "allow-users: ${{ vars.USERS }}"),
|
|
67
67
|
["gate=expression; sandbox=action-default; safety-strategy=drop-sudo"])
|
|
68
68
|
|
|
69
|
-
def
|
|
70
|
-
self.assertEqual(agent("google-github-actions/run-gemini-cli@v0"), ["gate=
|
|
69
|
+
def test_gate_of_other_actions(self):
|
|
70
|
+
self.assertEqual(agent("google-github-actions/run-gemini-cli@v0"), ["gate=none"])
|
|
71
|
+
self.assertEqual(agent("actions/ai-inference@v1"), ["gate=none"])
|
|
71
72
|
self.assertEqual(agent("anthropics/claude-code-base-action@v1"),
|
|
72
|
-
["gate=
|
|
73
|
+
["gate=none; tools=action-default"])
|
|
74
|
+
self.assertEqual(agent("warpdotdev/oz-agent-action@v1"), ["gate=not-modelled"])
|
|
75
|
+
|
|
76
|
+
CONDITION = """
|
|
77
|
+
on: issue_comment
|
|
78
|
+
permissions:
|
|
79
|
+
id-token: write
|
|
80
|
+
jobs:
|
|
81
|
+
j:
|
|
82
|
+
runs-on: ubuntu-latest%s
|
|
83
|
+
steps:
|
|
84
|
+
- uses: google-github-actions/run-gemini-cli@v0%s
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
def conditions(self, job="", step=""):
|
|
88
|
+
job = job and "\n if: " + job
|
|
89
|
+
step = step and "\n if: " + step
|
|
90
|
+
return details(analyse(w=self.CONDITION % (job, step), detail=True))
|
|
91
|
+
|
|
92
|
+
def test_if_conditions_that_test_who_started_the_run(self):
|
|
93
|
+
self.assertEqual(self.conditions(), ["gate=none"])
|
|
94
|
+
self.assertEqual(self.conditions(
|
|
95
|
+
job="contains(fromJSON('[\"OWNER\",\"MEMBER\"]'), "
|
|
96
|
+
"github.event.comment.author_association)"),
|
|
97
|
+
["gate=none; if=author_association"])
|
|
98
|
+
self.assertEqual(self.conditions(step="${{ github.actor == 'octocat' }}"),
|
|
99
|
+
["gate=none; if=actor"])
|
|
100
|
+
self.assertEqual(self.conditions(
|
|
101
|
+
job="github.event.sender.login == 'octocat'",
|
|
102
|
+
step="github.event.comment.author_association == 'OWNER'"),
|
|
103
|
+
["gate=none; if=actor+author_association"])
|
|
104
|
+
|
|
105
|
+
def test_other_if_conditions_are_not_reported(self):
|
|
106
|
+
self.assertEqual(self.conditions(job="github.event_name == 'issue_comment'"),
|
|
107
|
+
["gate=none"])
|
|
108
|
+
self.assertEqual(self.conditions(step="contains(github.event.comment.body, '@bot')"),
|
|
109
|
+
["gate=none"])
|
|
73
110
|
|
|
74
111
|
def test_claude_tool_flags(self):
|
|
75
112
|
self.assertEqual(agent(
|
|
@@ -166,26 +203,83 @@ class SourceTests(unittest.TestCase):
|
|
|
166
203
|
""")
|
|
167
204
|
self.assertEqual(recs, [])
|
|
168
205
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
206
|
+
ENV = """
|
|
207
|
+
on: issues
|
|
208
|
+
permissions: {}
|
|
209
|
+
jobs:
|
|
210
|
+
j:
|
|
211
|
+
runs-on: ubuntu-latest
|
|
212
|
+
env:
|
|
213
|
+
TITLE: ${{ github.event.issue.title }}
|
|
214
|
+
steps:
|
|
215
|
+
- name: first
|
|
216
|
+
run: %s
|
|
217
|
+
- name: second
|
|
218
|
+
run: %s
|
|
176
219
|
env:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
220
|
+
T: ${{ secrets.T }}%s
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
def test_env_variable_alone_is_not_an_entry(self):
|
|
224
|
+
# The recommended pattern: the text reaches the script as data.
|
|
225
|
+
self.assertEqual(analyse(w=self.ENV % ("true", 'echo "$TITLE"', "")), [])
|
|
226
|
+
self.assertEqual(analyse(w=self.ENV % (
|
|
227
|
+
"true", 'echo "$BODY"', "\n BODY: ${{ github.event.issue.body }}")), [])
|
|
228
|
+
|
|
229
|
+
def test_env_expression_is_an_entry_where_it_is_expanded(self):
|
|
230
|
+
recs = analyse(w=self.ENV % ("true", "echo ${{ env.TITLE }}", ""))
|
|
231
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
232
|
+
[("issues:github.event.issue.title", "second", "secrets.T")])
|
|
233
|
+
recs = analyse(w=self.ENV % ("echo ${{ env.title }}", "./x", ""))
|
|
186
234
|
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
187
235
|
[("issues:github.event.issue.title", "second", "secrets.T")])
|
|
188
236
|
|
|
237
|
+
def test_step_env_expression_and_override(self):
|
|
238
|
+
recs = analyse(w=self.ENV % (
|
|
239
|
+
"true", "echo ${{ env.BODY }}",
|
|
240
|
+
"\n BODY: ${{ github.event.issue.body }}"))
|
|
241
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
242
|
+
[("issues:github.event.issue.body", "second", "secrets.T")])
|
|
243
|
+
# A step that sets the variable to a fixed value no longer carries the title.
|
|
244
|
+
self.assertEqual(analyse(w=self.ENV % (
|
|
245
|
+
"true", "echo ${{ env.TITLE }}", "\n TITLE: fixed")), [])
|
|
246
|
+
|
|
247
|
+
FILES = """
|
|
248
|
+
on: %s
|
|
249
|
+
jobs:
|
|
250
|
+
j:
|
|
251
|
+
runs-on: ubuntu-latest
|
|
252
|
+
steps:
|
|
253
|
+
- id: Changed
|
|
254
|
+
uses: %s
|
|
255
|
+
- name: list
|
|
256
|
+
run: for f in ${{ steps.changed.outputs.%s }}; do echo "$f"; done
|
|
257
|
+
env:
|
|
258
|
+
T: ${{ secrets.T }}%s
|
|
259
|
+
"""
|
|
260
|
+
|
|
261
|
+
def test_changed_file_names_are_an_entry(self):
|
|
262
|
+
for action in ("tj-actions/changed-files@v40", "Ana06/get-changed-files@v2",
|
|
263
|
+
"jitterbit/get-changed-files@v1"):
|
|
264
|
+
recs = analyse(w=self.FILES % ("pull_request_target", action, "all_changed_files", ""))
|
|
265
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs], [
|
|
266
|
+
("pull_request_target:changed file names", "list", "permissions:default"),
|
|
267
|
+
("pull_request_target:changed file names", "list", "secrets.T")])
|
|
268
|
+
|
|
269
|
+
def test_changed_file_counts_and_other_steps_are_not(self):
|
|
270
|
+
for output in ("all_changed_files_count", "any_changed", "only_modified"):
|
|
271
|
+
self.assertEqual(analyse(w=self.FILES % (
|
|
272
|
+
"pull_request_target", "tj-actions/changed-files@v40", output, "")), [])
|
|
273
|
+
self.assertEqual(analyse(w=self.FILES % (
|
|
274
|
+
"pull_request_target", "actions/setup-python@v5", "all_changed_files", "")), [])
|
|
275
|
+
|
|
276
|
+
def test_changed_file_names_through_env_are_data(self):
|
|
277
|
+
text = (self.FILES % ("pull_request_target", "tj-actions/changed-files@v40", "x", "")
|
|
278
|
+
).replace("${{ steps.changed.outputs.x }}", '"$FILES"').replace(
|
|
279
|
+
"T: ${{ secrets.T }}",
|
|
280
|
+
"T: ${{ secrets.T }}\n FILES: ${{ steps.changed.outputs.all }}")
|
|
281
|
+
self.assertEqual(analyse(w=text), [])
|
|
282
|
+
|
|
189
283
|
def test_secret_before_entry_is_not_reached(self):
|
|
190
284
|
recs = analyse(w="""
|
|
191
285
|
on: pull_request_target
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import importlib.util
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
|
|
10
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
11
|
+
spec = importlib.util.spec_from_file_location(
|
|
12
|
+
"benchmark_run", os.path.join(ROOT, "benchmark", "run.py"))
|
|
13
|
+
bench = importlib.util.module_from_spec(spec)
|
|
14
|
+
spec.loader.exec_module(bench)
|
|
15
|
+
|
|
16
|
+
WORKFLOW = """\
|
|
17
|
+
on: pull_request_target
|
|
18
|
+
jobs:
|
|
19
|
+
j:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- run: echo "${{ github.event.pull_request.title }}"
|
|
23
|
+
env:
|
|
24
|
+
T: ${{ secrets.T }}
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def rec(source, workflow=".github/workflows/a.yml"):
|
|
29
|
+
return {"source": source, "workflow": workflow}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PureTests(unittest.TestCase):
|
|
33
|
+
def test_category(self):
|
|
34
|
+
self.assertEqual(bench.category("issues:event text read by agent"), "agent")
|
|
35
|
+
self.assertEqual(bench.category("pull_request_target:checkout of pull request head"),
|
|
36
|
+
"head-code")
|
|
37
|
+
self.assertEqual(bench.category("pull_request_target:fetch of pull request head"),
|
|
38
|
+
"head-code")
|
|
39
|
+
self.assertEqual(bench.category("a@b>workflow_run:artifact from upstream run"), "artifact")
|
|
40
|
+
self.assertEqual(bench.category("issues:github.event.issue.title"), "expression")
|
|
41
|
+
|
|
42
|
+
def test_summarise(self):
|
|
43
|
+
records = [rec("issues:github.event.issue.title"), rec("issues:event text read by agent")]
|
|
44
|
+
self.assertEqual(bench.summarise(records, 1), {
|
|
45
|
+
"records": 2, "refused": 1, "by_category": {"agent": 1, "expression": 1},
|
|
46
|
+
"agent_files_by_gate": {"unknown": 1}})
|
|
47
|
+
|
|
48
|
+
def test_agent_gates_count_files(self):
|
|
49
|
+
def agent(workflow, detail):
|
|
50
|
+
return {"source": "issues:event text read by agent", "workflow": workflow,
|
|
51
|
+
"detail": detail}
|
|
52
|
+
records = [agent("a.yml", "gate=anyone; tools=action-default"),
|
|
53
|
+
agent("a.yml", "gate=anyone; tools=action-default"),
|
|
54
|
+
agent("b.yml", "gate=anyone; sandbox=read-only"),
|
|
55
|
+
agent("c.yml", "gate=write-access"),
|
|
56
|
+
{"source": "issues:github.event.issue.title", "workflow": "d.yml",
|
|
57
|
+
"detail": "-"}]
|
|
58
|
+
self.assertEqual(bench.agent_gates(records), {"anyone": 2, "write-access": 1})
|
|
59
|
+
|
|
60
|
+
def test_files_and_compare(self):
|
|
61
|
+
records = [rec("issues:github.event.issue.title", ".github/workflows/a.yml"),
|
|
62
|
+
rec("issues:event text read by agent", ".github/workflows/b.yml")]
|
|
63
|
+
self.assertEqual(bench.injection_files(records), {"a.yml"})
|
|
64
|
+
self.assertEqual(bench.agent_files(records), {"b.yml"})
|
|
65
|
+
findings = [
|
|
66
|
+
{"ident": "template-injection",
|
|
67
|
+
"locations": [{"symbolic": {"key": {"Local": {"given_path": "x/.github/workflows/c.yaml"}}}}]},
|
|
68
|
+
{"ident": "unpinned-uses",
|
|
69
|
+
"locations": [{"symbolic": {"key": {"Local": {"given_path": "x/.github/workflows/a.yml"}}}}]},
|
|
70
|
+
]
|
|
71
|
+
self.assertEqual(bench.zizmor_files(findings), {"c.yaml"})
|
|
72
|
+
self.assertEqual(bench.compare({"a.yml", "b.yml"}, {"b.yml", "c.yml"}),
|
|
73
|
+
{"both": 1, "trust-path only": 1, "zizmor only": 1})
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class LocalCorpusTests(unittest.TestCase):
|
|
77
|
+
def test_shipped_agent_workflows_match_the_expected_file(self):
|
|
78
|
+
"""The agent workflows beside the script need no network."""
|
|
79
|
+
tmp = tempfile.mkdtemp()
|
|
80
|
+
self.addCleanup(shutil.rmtree, tmp)
|
|
81
|
+
here = os.path.join(ROOT, "benchmark")
|
|
82
|
+
corpus = os.path.join(here, "agents-only.json")
|
|
83
|
+
with open(os.path.join(here, "expected.json")) as f:
|
|
84
|
+
expected = {"agents": json.load(f)["agents"]}
|
|
85
|
+
with open(os.path.join(tmp, "expected.json"), "w") as f:
|
|
86
|
+
json.dump(expected, f)
|
|
87
|
+
out = io.StringIO()
|
|
88
|
+
with contextlib.redirect_stdout(out):
|
|
89
|
+
code = bench.main(["--corpus", corpus, "--expected",
|
|
90
|
+
os.path.join(tmp, "expected.json")])
|
|
91
|
+
self.assertEqual(code, 0, out.getvalue())
|
|
92
|
+
self.assertEqual(expected["agents"]["agent_files_by_gate"],
|
|
93
|
+
{"anyone": 3, "none": 2, "write-access": 2})
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class RunTests(unittest.TestCase):
|
|
97
|
+
"""main() on a workflow already in the cache, so nothing is fetched."""
|
|
98
|
+
|
|
99
|
+
def setUp(self):
|
|
100
|
+
self.tmp = tempfile.mkdtemp()
|
|
101
|
+
self.addCleanup(shutil.rmtree, self.tmp)
|
|
102
|
+
commit = "0123456789abcdef0123"
|
|
103
|
+
wdir = os.path.join(self.tmp, "cache", "repo-" + commit[:12], ".github", "workflows")
|
|
104
|
+
os.makedirs(wdir)
|
|
105
|
+
with open(os.path.join(wdir, "w.yml"), "w") as f:
|
|
106
|
+
f.write(WORKFLOW)
|
|
107
|
+
self.corpus = os.path.join(self.tmp, "corpus.json")
|
|
108
|
+
with open(self.corpus, "w") as f:
|
|
109
|
+
json.dump([{"url": "https://example.invalid/owner/repo", "commit": commit}], f)
|
|
110
|
+
self.expected = os.path.join(self.tmp, "expected.json")
|
|
111
|
+
|
|
112
|
+
def run_main(self, *extra):
|
|
113
|
+
out = io.StringIO()
|
|
114
|
+
with contextlib.redirect_stdout(out):
|
|
115
|
+
code = bench.main(["--corpus", self.corpus, "--expected", self.expected,
|
|
116
|
+
"--cache", os.path.join(self.tmp, "cache")] + list(extra))
|
|
117
|
+
return code, out.getvalue()
|
|
118
|
+
|
|
119
|
+
def test_update_then_match_then_differ(self):
|
|
120
|
+
self.assertEqual(self.run_main("--update")[0], 0)
|
|
121
|
+
with open(self.expected) as f:
|
|
122
|
+
self.assertEqual(json.load(f), {"repo": {
|
|
123
|
+
"records": 2, "refused": 0, "by_category": {"expression": 2},
|
|
124
|
+
"agent_files_by_gate": {}}})
|
|
125
|
+
code, out = self.run_main()
|
|
126
|
+
self.assertEqual(code, 0)
|
|
127
|
+
self.assertIn("trust-path counts match", out)
|
|
128
|
+
with open(self.expected, "w") as f:
|
|
129
|
+
json.dump({"repo": {"records": 3, "refused": 0, "by_category": {"expression": 3},
|
|
130
|
+
"agent_files_by_gate": {}}}, f)
|
|
131
|
+
code, out = self.run_main()
|
|
132
|
+
self.assertEqual(code, 1)
|
|
133
|
+
self.assertIn("DIFFERENT", out)
|
|
@@ -85,11 +85,31 @@ AGENT_GATES = {
|
|
|
85
85
|
"anthropics/claude-code-action": "allowed_non_write_users",
|
|
86
86
|
"openai/codex-action": "allow-users",
|
|
87
87
|
}
|
|
88
|
+
# Agent actions with no input or check of their own for who starts them:
|
|
89
|
+
# whoever can trigger the workflow starts the agent.
|
|
90
|
+
AGENT_UNGATED = (
|
|
91
|
+
"actions/ai-inference",
|
|
92
|
+
"anthropics/claude-code-base-action",
|
|
93
|
+
"google-github-actions/run-gemini-cli",
|
|
94
|
+
)
|
|
95
|
+
# What an `if:` condition tests when it restricts who started the run.
|
|
96
|
+
_IF_TESTS = (
|
|
97
|
+
("actor", re.compile(r"github\.(triggering_)?actor\b|\b(sender|user)\.login\b")),
|
|
98
|
+
("author_association", re.compile(r"\bauthor_association\b")),
|
|
99
|
+
)
|
|
88
100
|
_CLAUDE_FLAGS = re.compile(
|
|
89
101
|
r"--(allowed-?tools|disallowed-?tools|permission-mode|dangerously-skip-permissions)"
|
|
90
102
|
r"(?:(?:\s+|=)(\"[^\"]*\"|'[^']*'|[^\s-]\S*))?", re.I)
|
|
91
103
|
_CLAUDE_NAMES = {"allowedtools": "allowedTools", "disallowedtools": "disallowedTools"}
|
|
92
104
|
|
|
105
|
+
# Actions whose outputs list the names of the files a pull request changes.
|
|
106
|
+
# The author of the pull request chooses those names.
|
|
107
|
+
FILENAME_ACTIONS = (
|
|
108
|
+
"ana06/get-changed-files",
|
|
109
|
+
"jitterbit/get-changed-files",
|
|
110
|
+
"tj-actions/changed-files",
|
|
111
|
+
)
|
|
112
|
+
|
|
93
113
|
# Actions that download artifacts from another workflow run.
|
|
94
114
|
ARTIFACT_ACTIONS = ("actions/download-artifact", "dawidd6/action-download-artifact")
|
|
95
115
|
|
|
@@ -101,7 +121,7 @@ WRITE_SCOPES = ("actions", "contents", "discussions", "id-token", "issues", "pac
|
|
|
101
121
|
|
|
102
122
|
_EXPR = re.compile(r"\$\{\{(.*?)\}\}", re.S)
|
|
103
123
|
_CONTEXT = re.compile(
|
|
104
|
-
r"(?<![\w.-])(github|inputs|secrets)((?:\.[A-Za-z_*][\w*-]*|\[[^\]]*\])*)")
|
|
124
|
+
r"(?<![\w.-])(github|inputs|secrets|env|steps)((?:\.[A-Za-z_*][\w*-]*|\[[^\]]*\])*)")
|
|
105
125
|
|
|
106
126
|
|
|
107
127
|
def _norm(name):
|
|
@@ -169,9 +189,11 @@ def _action(uses):
|
|
|
169
189
|
return "/".join(uses.split("@")[0].split("/")[:2]).lower()
|
|
170
190
|
|
|
171
191
|
|
|
172
|
-
def agent_detail(action, with_):
|
|
173
|
-
"""What the workflow sets on an agent action: who may start it (gate)
|
|
174
|
-
|
|
192
|
+
def agent_detail(action, with_, conditions=()):
|
|
193
|
+
"""What the workflow sets on an agent action: who may start it (gate),
|
|
194
|
+
what the job's and step's `if:` conditions test about the person who
|
|
195
|
+
started the run, and what the agent may do. Values are the workflow's
|
|
196
|
+
own, not a judgement; conditions are not evaluated."""
|
|
175
197
|
def text(key):
|
|
176
198
|
return with_[key].strip() if isinstance(with_.get(key), str) else ""
|
|
177
199
|
|
|
@@ -181,7 +203,11 @@ def agent_detail(action, with_):
|
|
|
181
203
|
parts.append("gate=" + ("write-access" if not gate else "anyone" if gate == "*"
|
|
182
204
|
else "expression" if "${{" in gate else "listed-users"))
|
|
183
205
|
else:
|
|
184
|
-
parts.append("gate=not-modelled")
|
|
206
|
+
parts.append("gate=none" if action in AGENT_UNGATED else "gate=not-modelled")
|
|
207
|
+
text_if = " ".join(c for c in conditions if isinstance(c, str))
|
|
208
|
+
tests = [name for name, pattern in _IF_TESTS if pattern.search(text_if)]
|
|
209
|
+
if tests:
|
|
210
|
+
parts.append("if=" + "+".join(tests))
|
|
185
211
|
if action.startswith("anthropics/"):
|
|
186
212
|
flags = []
|
|
187
213
|
for m in _CLAUDE_FLAGS.finditer(text("claude_args")):
|
|
@@ -416,16 +442,38 @@ class Repo(object):
|
|
|
416
442
|
job_sinks.add("environment:" + env)
|
|
417
443
|
job_sinks |= allowed(secret_names(shared_env))
|
|
418
444
|
|
|
445
|
+
def tainted(env):
|
|
446
|
+
"""Environment variable name -> the untrusted contexts its value
|
|
447
|
+
expands. A variable only carries the text as data; it becomes an
|
|
448
|
+
entry where a ${{ env.NAME }} expression pastes it into a step."""
|
|
449
|
+
out = {}
|
|
450
|
+
for key in sorted(env) if isinstance(env, dict) else ():
|
|
451
|
+
out[key.upper()] = untrusted(contexts(env[key]), ctx.trigger, ctx.tainted_inputs)
|
|
452
|
+
return out
|
|
453
|
+
|
|
454
|
+
shared = {}
|
|
455
|
+
for env in shared_env:
|
|
456
|
+
shared.update(tainted(env))
|
|
457
|
+
|
|
419
458
|
# Where untrusted input enters the job: (step index, source).
|
|
420
459
|
entries = set()
|
|
421
460
|
details = {}
|
|
422
|
-
if
|
|
423
|
-
|
|
424
|
-
entries.add((0, name))
|
|
461
|
+
listers = set(s["id"].lower() for s in steps if isinstance(s.get("id"), str)
|
|
462
|
+
and _action(s.get("uses")) in FILENAME_ACTIONS)
|
|
425
463
|
for i, step in enumerate(steps):
|
|
426
|
-
|
|
427
|
-
|
|
464
|
+
variables = dict(shared, **tainted(step.get("env")))
|
|
465
|
+
used = contexts([step.get("run"), step.get("with")])
|
|
466
|
+
for name in untrusted(used, ctx.trigger, ctx.tainted_inputs):
|
|
428
467
|
entries.add((i, name))
|
|
468
|
+
for name in used:
|
|
469
|
+
if name.startswith("env."):
|
|
470
|
+
for origin in variables.get(name[4:].upper(), ()):
|
|
471
|
+
entries.add((i, origin))
|
|
472
|
+
part = name.lower().split(".")
|
|
473
|
+
if part[0] == "steps" and len(part) > 3 and part[1] in listers and \
|
|
474
|
+
part[2] == "outputs" and not part[3].endswith("_count") and \
|
|
475
|
+
not part[3].startswith(("any_", "only_")):
|
|
476
|
+
entries.add((i, "changed file names"))
|
|
429
477
|
action = _action(step.get("uses"))
|
|
430
478
|
with_ = step.get("with") if isinstance(step.get("with"), dict) else {}
|
|
431
479
|
head = ctx.trigger not in _REVIEW
|
|
@@ -439,7 +487,7 @@ class Repo(object):
|
|
|
439
487
|
entries.add((i, "artifact from upstream run"))
|
|
440
488
|
if action in AGENT_ACTIONS:
|
|
441
489
|
entries.add((i, "event text read by agent"))
|
|
442
|
-
details[i] = agent_detail(action, with_)
|
|
490
|
+
details[i] = agent_detail(action, with_, (job.get("if"), step.get("if")))
|
|
443
491
|
|
|
444
492
|
for start, what in sorted(entries):
|
|
445
493
|
source = "%s:%s" % (ctx.chain, what)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trust-path
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: List the paths by which untrusted input can reach secrets and publishing credentials in GitHub Actions workflows.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://github.com/jacob-adm/trust-path
|
|
@@ -71,8 +71,9 @@ pip installs `trust-path` as a console script. Without installing, it runs from
|
|
|
71
71
|
workflow or after a `pull_request` workflow (followed through chains), or when it is a local
|
|
72
72
|
reusable workflow called from such a run.
|
|
73
73
|
3. **Find where input enters each job.** A step enters untrusted input when it uses a context such
|
|
74
|
-
as `github.event.pull_request.title` in `run
|
|
75
|
-
request's head, downloads an artifact from the upstream run,
|
|
74
|
+
as `github.event.pull_request.title` in `run:` or `with:` (directly, or through
|
|
75
|
+
`${{ env.NAME }}`), checks out or fetches the pull request's head, downloads an artifact from the upstream run, expands the changed file names of a pull
|
|
76
|
+
request, or is an AI agent action.
|
|
76
77
|
4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
|
|
77
78
|
trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
|
|
78
79
|
environment and AI agent actions holding a credential.
|
|
@@ -123,6 +124,8 @@ key and can write text into issues that other workflows and agents read. Run `tr
|
|
|
123
124
|
list and the YAML subset.
|
|
124
125
|
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
125
126
|
- [Limitations and security](https://github.com/jacob-adm/trust-path/blob/main/docs/limitations-and-security.md): what trust-path does not see, read or do.
|
|
127
|
+
- [Benchmark](https://github.com/jacob-adm/trust-path/blob/main/docs/benchmark.md): a repeatable run on pinned public workflows, with a
|
|
128
|
+
per-file comparison against zizmor
|
|
126
129
|
- [Using it with other tools](https://github.com/jacob-adm/trust-path/blob/main/docs/other-tools.md): a tested stack with git surface
|
|
127
130
|
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
128
131
|
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
@@ -4,8 +4,21 @@ README.md
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
.github/workflows/release.yml
|
|
6
6
|
.github/workflows/test.yml
|
|
7
|
+
benchmark/agents-only.json
|
|
8
|
+
benchmark/corpus.json
|
|
9
|
+
benchmark/expected.json
|
|
10
|
+
benchmark/run.py
|
|
11
|
+
benchmark/fixtures/agents/.github/workflows/claude-gated.yml
|
|
12
|
+
benchmark/fixtures/agents/.github/workflows/claude-open.yml
|
|
13
|
+
benchmark/fixtures/agents/.github/workflows/claude-restricted.yml
|
|
14
|
+
benchmark/fixtures/agents/.github/workflows/codex-gated.yml
|
|
15
|
+
benchmark/fixtures/agents/.github/workflows/codex-read-only.yml
|
|
16
|
+
benchmark/fixtures/agents/.github/workflows/gemini-author-check.yml
|
|
17
|
+
benchmark/fixtures/agents/.github/workflows/gemini.yml
|
|
18
|
+
benchmark/fixtures/agents/.github/workflows/no-credential.yml
|
|
7
19
|
tests/__init__.py
|
|
8
20
|
tests/test_analyze.py
|
|
21
|
+
tests/test_benchmark.py
|
|
9
22
|
tests/test_cli.py
|
|
10
23
|
tests/test_yamlsubset.py
|
|
11
24
|
tests/fixtures/agent/.github/workflows/triage.yml
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/head_checkout/.github/workflows/build.yml
RENAMED
|
File without changes
|
{trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/missing_call/.github/workflows/call.yml
RENAMED
|
File without changes
|
|
File without changes
|
{trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/reusable/.github/workflows/on-comment.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/workflow_run_chain/.github/workflows/ci.yml
RENAMED
|
File without changes
|
|
File without changes
|
{trust_path-0.2.0 → trust_path-0.4.0}/tests/fixtures/workflow_run_chain/.github/workflows/stage.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|