trust-path 0.1.0__tar.gz → 0.3.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.1.0 → trust_path-0.3.0}/.github/workflows/test.yml +1 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/MANIFEST.in +2 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/PKG-INFO +20 -13
- {trust_path-0.1.0 → trust_path-0.3.0}/README.md +19 -12
- trust_path-0.3.0/benchmark/corpus.json +10 -0
- trust_path-0.3.0/benchmark/expected.json +17 -0
- trust_path-0.3.0/benchmark/run.py +147 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/pyproject.toml +1 -1
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/agent/.github/workflows/triage.yml +2 -0
- {trust_path-0.1.0/tests/fixtures/anchors → trust_path-0.3.0/tests/fixtures/tags}/.github/workflows/a.yml +1 -2
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/test_analyze.py +156 -19
- trust_path-0.3.0/tests/test_benchmark.py +98 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/test_cli.py +24 -19
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/test_yamlsubset.py +48 -9
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path/__init__.py +1 -1
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path/analyze.py +90 -12
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path/cli.py +2 -2
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path/yamlsubset.py +65 -9
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path.egg-info/PKG-INFO +20 -13
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path.egg-info/SOURCES.txt +5 -1
- {trust_path-0.1.0 → trust_path-0.3.0}/.github/workflows/release.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/LICENSE +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/setup.cfg +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/__init__.py +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/head_checkout/.github/workflows/build.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/missing_call/.github/workflows/call.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/pr_title/.github/workflows/greet.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/reusable/.github/workflows/on-comment.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/reusable/.github/workflows/reply.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/safe/.github/workflows/echo-title.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/safe/.github/workflows/label.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/safe/.github/workflows/release.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/safe/.github/workflows/test.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/workflow_run_chain/.github/workflows/ci.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/workflow_run_chain/.github/workflows/publish.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/tests/fixtures/workflow_run_chain/.github/workflows/stage.yml +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path/__main__.py +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path.egg-info/dependency_links.txt +0 -0
- {trust_path-0.1.0 → trust_path-0.3.0}/trust_path.egg-info/entry_points.txt +0 -0
- {trust_path-0.1.0 → trust_path-0.3.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.3.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,12 +71,13 @@ 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.
|
|
79
|
-
5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step` and `
|
|
80
|
+
5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step`, `sink` and `detail`,
|
|
80
81
|
tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
|
|
81
82
|
none and 2 on an error, including any refused file.
|
|
82
83
|
|
|
@@ -100,18 +101,22 @@ trust-path tests/fixtures/agent
|
|
|
100
101
|
```
|
|
101
102
|
|
|
102
103
|
```text
|
|
103
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action
|
|
104
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write
|
|
105
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY
|
|
106
|
-
issues:
|
|
107
|
-
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1
|
|
108
|
-
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1
|
|
104
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action gate=anyone; tools=action-default
|
|
105
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write gate=anyone; tools=action-default
|
|
106
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY gate=anyone; tools=action-default
|
|
107
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN gate=anyone; tools=action-default
|
|
108
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action gate=anyone; tools=action-default
|
|
109
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write -
|
|
110
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY -
|
|
111
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN -
|
|
109
112
|
```
|
|
110
113
|
|
|
111
114
|
The workflow runs when an issue is opened and gives `anthropics/claude-code-action` the issue body
|
|
112
|
-
in its prompt, an API key and a token that can write issues.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
in its prompt, an API key and a token that can write issues. The last field shows how the workflow
|
|
116
|
+
sets the agent up: `gate=anyone` because `allowed_non_write_users` is `*`, so the agent runs for
|
|
117
|
+
users without write access, and `tools=action-default` because the workflow does not limit its
|
|
118
|
+
tools. Anyone who can open an issue writes that text, and the agent acts on it while holding the
|
|
119
|
+
key and can write text into issues that other workflows and agents read. Run `trust-path .` in a repository checkout to check its workflows.
|
|
115
120
|
|
|
116
121
|
## Documentation
|
|
117
122
|
|
|
@@ -119,6 +124,8 @@ other workflows and agents read. Run `trust-path .` in a repository checkout to
|
|
|
119
124
|
list and the YAML subset.
|
|
120
125
|
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
121
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
|
|
122
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
|
|
123
130
|
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
124
131
|
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
@@ -50,12 +50,13 @@ 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.
|
|
58
|
-
5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step` and `
|
|
59
|
+
5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step`, `sink` and `detail`,
|
|
59
60
|
tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
|
|
60
61
|
none and 2 on an error, including any refused file.
|
|
61
62
|
|
|
@@ -79,18 +80,22 @@ trust-path tests/fixtures/agent
|
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
```text
|
|
82
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action
|
|
83
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write
|
|
84
|
-
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY
|
|
85
|
-
issues:
|
|
86
|
-
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1
|
|
87
|
-
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1
|
|
83
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action gate=anyone; tools=action-default
|
|
84
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write gate=anyone; tools=action-default
|
|
85
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY gate=anyone; tools=action-default
|
|
86
|
+
issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN gate=anyone; tools=action-default
|
|
87
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action gate=anyone; tools=action-default
|
|
88
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write -
|
|
89
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY -
|
|
90
|
+
issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN -
|
|
88
91
|
```
|
|
89
92
|
|
|
90
93
|
The workflow runs when an issue is opened and gives `anthropics/claude-code-action` the issue body
|
|
91
|
-
in its prompt, an API key and a token that can write issues.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
in its prompt, an API key and a token that can write issues. The last field shows how the workflow
|
|
95
|
+
sets the agent up: `gate=anyone` because `allowed_non_write_users` is `*`, so the agent runs for
|
|
96
|
+
users without write access, and `tools=action-default` because the workflow does not limit its
|
|
97
|
+
tools. Anyone who can open an issue writes that text, and the agent acts on it while holding the
|
|
98
|
+
key and can write text into issues that other workflows and agents read. Run `trust-path .` in a repository checkout to check its workflows.
|
|
94
99
|
|
|
95
100
|
## Documentation
|
|
96
101
|
|
|
@@ -98,6 +103,8 @@ other workflows and agents read. Run `trust-path .` in a repository checkout to
|
|
|
98
103
|
list and the YAML subset.
|
|
99
104
|
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
100
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
|
|
101
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
|
|
102
109
|
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
103
110
|
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
@@ -0,0 +1,147 @@
|
|
|
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 compare what they report per workflow file.
|
|
4
|
+
|
|
5
|
+
python3 benchmark/run.py [--corpus FILE] [--expected FILE] [--cache DIR] [--update]
|
|
6
|
+
|
|
7
|
+
Exit status: 0 the trust-path counts match the expected file, 1 they differ,
|
|
8
|
+
2 a repository could not be fetched or a tool failed.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import collections
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
import tempfile
|
|
20
|
+
|
|
21
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
22
|
+
ZIZMOR = ["zizmor", "--offline", "--no-config", "--persona", "auditor", "--format", "json"]
|
|
23
|
+
_WORKFLOW = re.compile(r"workflows/([\w.-]+\.ya?ml)")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def category(source):
|
|
27
|
+
"""The kind of entry a trust-path source field names."""
|
|
28
|
+
what = source.rsplit(":", 1)[-1]
|
|
29
|
+
if what == "event text read by agent":
|
|
30
|
+
return "agent"
|
|
31
|
+
if what.endswith("of pull request head"):
|
|
32
|
+
return "head-code"
|
|
33
|
+
if what == "artifact from upstream run":
|
|
34
|
+
return "artifact"
|
|
35
|
+
return "expression"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def summarise(records, refused):
|
|
39
|
+
"""The counts kept in the expected file for one repository."""
|
|
40
|
+
by = collections.Counter(category(r["source"]) for r in records)
|
|
41
|
+
return {"records": len(records), "refused": refused, "by_category": dict(sorted(by.items()))}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def injection_files(records):
|
|
45
|
+
"""Workflow files where trust-path reports pasted text or fork code."""
|
|
46
|
+
return set(os.path.basename(r["workflow"]) for r in records
|
|
47
|
+
if category(r["source"]) in ("expression", "head-code"))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def agent_files(records):
|
|
51
|
+
return set(os.path.basename(r["workflow"]) for r in records
|
|
52
|
+
if category(r["source"]) == "agent")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def zizmor_files(findings, ident="template-injection"):
|
|
56
|
+
"""Workflow files where zizmor reports a finding of kind `ident`."""
|
|
57
|
+
out = set()
|
|
58
|
+
for f in findings:
|
|
59
|
+
if f.get("ident") == ident:
|
|
60
|
+
out.update(_WORKFLOW.findall(json.dumps(f.get("locations", []))))
|
|
61
|
+
return out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def compare(ours, theirs):
|
|
65
|
+
return {"both": len(ours & theirs), "trust-path only": len(ours - theirs),
|
|
66
|
+
"zizmor only": len(theirs - ours)}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _run(cmd, cwd=None, ok=(0,)):
|
|
70
|
+
p = subprocess.run(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
71
|
+
universal_newlines=True)
|
|
72
|
+
if p.returncode not in ok:
|
|
73
|
+
raise RuntimeError("%s: exit %d: %s" % (" ".join(cmd[:2]), p.returncode,
|
|
74
|
+
p.stderr.strip()[:200]))
|
|
75
|
+
return p
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def fetch(url, commit, dest):
|
|
79
|
+
"""Check out .github/workflows of `url` at `commit` into `dest`."""
|
|
80
|
+
if os.path.isdir(os.path.join(dest, ".github", "workflows")):
|
|
81
|
+
return
|
|
82
|
+
os.makedirs(dest)
|
|
83
|
+
_run(["git", "init", "-q"], dest)
|
|
84
|
+
_run(["git", "fetch", "-q", "--depth", "1", "--filter=blob:none", url, commit], dest)
|
|
85
|
+
_run(["git", "checkout", "-q", "FETCH_HEAD", "--", ".github/workflows"], dest)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def main(argv=None):
|
|
89
|
+
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
90
|
+
parser.add_argument("--corpus", default=os.path.join(HERE, "corpus.json"))
|
|
91
|
+
parser.add_argument("--expected", default=os.path.join(HERE, "expected.json"))
|
|
92
|
+
parser.add_argument("--cache", help="directory to keep the fetched workflows in")
|
|
93
|
+
parser.add_argument("--update", action="store_true", help="rewrite the expected file")
|
|
94
|
+
args = parser.parse_args(argv)
|
|
95
|
+
with open(args.corpus) as f:
|
|
96
|
+
corpus = json.load(f)
|
|
97
|
+
cache = args.cache or tempfile.mkdtemp()
|
|
98
|
+
have_zizmor = shutil.which("zizmor") is not None
|
|
99
|
+
actual = {}
|
|
100
|
+
try:
|
|
101
|
+
if have_zizmor:
|
|
102
|
+
print("zizmor: %s" % _run(["zizmor", "--version"]).stdout.strip())
|
|
103
|
+
else:
|
|
104
|
+
print("zizmor: not installed, comparison skipped")
|
|
105
|
+
for repo in corpus:
|
|
106
|
+
name = repo["url"].rstrip("/").split("/")[-1]
|
|
107
|
+
dest = os.path.join(cache, name + "-" + repo["commit"][:12])
|
|
108
|
+
fetch(repo["url"], repo["commit"], dest)
|
|
109
|
+
p = _run([sys.executable, "-m", "trust_path", "--json", dest],
|
|
110
|
+
cwd=os.path.dirname(HERE), ok=(0, 1, 2))
|
|
111
|
+
records = json.loads(p.stdout)
|
|
112
|
+
refused = len(p.stderr.splitlines())
|
|
113
|
+
actual[name] = summarise(records, refused)
|
|
114
|
+
files = os.listdir(os.path.join(dest, ".github", "workflows"))
|
|
115
|
+
print("\n%s @ %s (%d workflow files)" % (name, repo["commit"][:12], len(files)))
|
|
116
|
+
print(" trust-path: %(records)d records, %(refused)d files refused, "
|
|
117
|
+
"%(by_category)s" % actual[name])
|
|
118
|
+
print(" trust-path: %d files with an agent path" % len(agent_files(records)))
|
|
119
|
+
if have_zizmor:
|
|
120
|
+
findings = json.loads(_run(ZIZMOR + [dest], ok=tuple(range(15))).stdout or "[]")
|
|
121
|
+
print(" injection, by workflow file: %s" % compare(
|
|
122
|
+
injection_files(records), zizmor_files(findings)))
|
|
123
|
+
except (RuntimeError, OSError, ValueError) as e:
|
|
124
|
+
sys.stderr.write("benchmark: %s\n" % e)
|
|
125
|
+
return 2
|
|
126
|
+
finally:
|
|
127
|
+
if not args.cache:
|
|
128
|
+
shutil.rmtree(cache, ignore_errors=True)
|
|
129
|
+
if args.update:
|
|
130
|
+
with open(args.expected, "w") as f:
|
|
131
|
+
json.dump(actual, f, indent=2, sort_keys=True)
|
|
132
|
+
f.write("\n")
|
|
133
|
+
return 0
|
|
134
|
+
with open(args.expected) as f:
|
|
135
|
+
expected = json.load(f)
|
|
136
|
+
if actual != expected:
|
|
137
|
+
print("\nDIFFERENT from %s:" % args.expected)
|
|
138
|
+
for name in sorted(set(actual) | set(expected)):
|
|
139
|
+
if actual.get(name) != expected.get(name):
|
|
140
|
+
print(" %s: expected %s, got %s" % (name, expected.get(name), actual.get(name)))
|
|
141
|
+
return 1
|
|
142
|
+
print("\ntrust-path counts match %s" % os.path.basename(args.expected))
|
|
143
|
+
return 0
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if __name__ == "__main__":
|
|
147
|
+
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.3.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"
|
|
@@ -9,7 +9,9 @@ from trust_path.analyze import AnalysisError, Repo
|
|
|
9
9
|
|
|
10
10
|
def analyse(**workflows):
|
|
11
11
|
"""Analyse a repository made of the given name=text workflow files and
|
|
12
|
-
return its records as (source, workflow, job, step, sink) tuples
|
|
12
|
+
return its records as (source, workflow, job, step, sink) tuples; with
|
|
13
|
+
detail=True, as (source, workflow, job, step, sink, detail) tuples."""
|
|
14
|
+
width = 6 if workflows.pop("detail", False) else 5
|
|
13
15
|
tmp = tempfile.mkdtemp()
|
|
14
16
|
try:
|
|
15
17
|
wdir = os.path.join(tmp, ".github", "workflows")
|
|
@@ -17,11 +19,89 @@ def analyse(**workflows):
|
|
|
17
19
|
for name, text in workflows.items():
|
|
18
20
|
with open(os.path.join(wdir, name + ".yml"), "w") as f:
|
|
19
21
|
f.write(textwrap.dedent(text))
|
|
20
|
-
return
|
|
22
|
+
return sorted(set(tuple(r)[:width] for r in Repo(tmp).analyse()))
|
|
21
23
|
finally:
|
|
22
24
|
shutil.rmtree(tmp)
|
|
23
25
|
|
|
24
26
|
|
|
27
|
+
def details(recs):
|
|
28
|
+
return sorted(set(r[5] for r in recs))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
AGENT = """
|
|
32
|
+
on: issue_comment
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write
|
|
35
|
+
jobs:
|
|
36
|
+
j:
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
steps:
|
|
39
|
+
- uses: %s
|
|
40
|
+
with:
|
|
41
|
+
%s
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def agent(uses, *inputs):
|
|
46
|
+
lines = "\n".join(" " + line for line in inputs or ("x: y",))
|
|
47
|
+
return details(analyse(w=AGENT % (uses, lines), detail=True))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class AgentDetailTests(unittest.TestCase):
|
|
51
|
+
def test_default_gate_is_write_access(self):
|
|
52
|
+
self.assertEqual(agent("anthropics/claude-code-action@v1"),
|
|
53
|
+
["gate=write-access; tools=action-default"])
|
|
54
|
+
self.assertEqual(agent("openai/codex-action@v1"),
|
|
55
|
+
["gate=write-access; sandbox=action-default; safety-strategy=drop-sudo"])
|
|
56
|
+
|
|
57
|
+
def test_gate_open_to_anyone(self):
|
|
58
|
+
self.assertEqual(agent("anthropics/claude-code-action@v1", 'allowed_non_write_users: "*"'),
|
|
59
|
+
["gate=anyone; tools=action-default"])
|
|
60
|
+
self.assertEqual(agent("openai/codex-action@v1", 'allow-users: "*"', "sandbox: read-only"),
|
|
61
|
+
["gate=anyone; sandbox=read-only; safety-strategy=drop-sudo"])
|
|
62
|
+
|
|
63
|
+
def test_gate_listed_users_and_expression(self):
|
|
64
|
+
self.assertEqual(agent("anthropics/claude-code-action@v1", "allowed_non_write_users: a,b"),
|
|
65
|
+
["gate=listed-users; tools=action-default"])
|
|
66
|
+
self.assertEqual(agent("openai/codex-action@v1", "allow-users: ${{ vars.USERS }}"),
|
|
67
|
+
["gate=expression; sandbox=action-default; safety-strategy=drop-sudo"])
|
|
68
|
+
|
|
69
|
+
def test_gate_not_modelled_for_other_actions(self):
|
|
70
|
+
self.assertEqual(agent("google-github-actions/run-gemini-cli@v0"), ["gate=not-modelled"])
|
|
71
|
+
self.assertEqual(agent("anthropics/claude-code-base-action@v1"),
|
|
72
|
+
["gate=not-modelled; tools=action-default"])
|
|
73
|
+
|
|
74
|
+
def test_claude_tool_flags(self):
|
|
75
|
+
self.assertEqual(agent(
|
|
76
|
+
"anthropics/claude-code-action@v1", "claude_args: |",
|
|
77
|
+
" --permission-mode auto", ' --disallowedTools "WebFetch,Write"',
|
|
78
|
+
" --allowed-tools=Read", " --model some-model", "settings: s.json"),
|
|
79
|
+
["gate=write-access; allowedTools=Read; disallowedTools=WebFetch,Write; "
|
|
80
|
+
"permission-mode=auto; settings=set"])
|
|
81
|
+
self.assertEqual(agent("anthropics/claude-code-action@v1",
|
|
82
|
+
"claude_args: --dangerously-skip-permissions --max-turns 3"),
|
|
83
|
+
["gate=write-access; dangerously-skip-permissions"])
|
|
84
|
+
|
|
85
|
+
def test_codex_profile_and_strategy(self):
|
|
86
|
+
self.assertEqual(agent("openai/codex-action@v1", "permission-profile: triage",
|
|
87
|
+
"safety-strategy: unsafe"),
|
|
88
|
+
["gate=write-access; sandbox=action-default; permission-profile=triage; "
|
|
89
|
+
"safety-strategy=unsafe"])
|
|
90
|
+
|
|
91
|
+
def test_other_records_have_no_detail(self):
|
|
92
|
+
recs = analyse(detail=True, w="""
|
|
93
|
+
on: pull_request_target
|
|
94
|
+
jobs:
|
|
95
|
+
j:
|
|
96
|
+
runs-on: ubuntu-latest
|
|
97
|
+
steps:
|
|
98
|
+
- run: echo "${{ github.event.pull_request.title }}"
|
|
99
|
+
env:
|
|
100
|
+
T: ${{ secrets.T }}
|
|
101
|
+
""")
|
|
102
|
+
self.assertEqual(details(recs), ["-"])
|
|
103
|
+
|
|
104
|
+
|
|
25
105
|
def sinks(recs):
|
|
26
106
|
return sorted(set(r[4] for r in recs))
|
|
27
107
|
|
|
@@ -86,26 +166,83 @@ class SourceTests(unittest.TestCase):
|
|
|
86
166
|
""")
|
|
87
167
|
self.assertEqual(recs, [])
|
|
88
168
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
169
|
+
ENV = """
|
|
170
|
+
on: issues
|
|
171
|
+
permissions: {}
|
|
172
|
+
jobs:
|
|
173
|
+
j:
|
|
174
|
+
runs-on: ubuntu-latest
|
|
175
|
+
env:
|
|
176
|
+
TITLE: ${{ github.event.issue.title }}
|
|
177
|
+
steps:
|
|
178
|
+
- name: first
|
|
179
|
+
run: %s
|
|
180
|
+
- name: second
|
|
181
|
+
run: %s
|
|
96
182
|
env:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
183
|
+
T: ${{ secrets.T }}%s
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
def test_env_variable_alone_is_not_an_entry(self):
|
|
187
|
+
# The recommended pattern: the text reaches the script as data.
|
|
188
|
+
self.assertEqual(analyse(w=self.ENV % ("true", 'echo "$TITLE"', "")), [])
|
|
189
|
+
self.assertEqual(analyse(w=self.ENV % (
|
|
190
|
+
"true", 'echo "$BODY"', "\n BODY: ${{ github.event.issue.body }}")), [])
|
|
191
|
+
|
|
192
|
+
def test_env_expression_is_an_entry_where_it_is_expanded(self):
|
|
193
|
+
recs = analyse(w=self.ENV % ("true", "echo ${{ env.TITLE }}", ""))
|
|
194
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
195
|
+
[("issues:github.event.issue.title", "second", "secrets.T")])
|
|
196
|
+
recs = analyse(w=self.ENV % ("echo ${{ env.title }}", "./x", ""))
|
|
106
197
|
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
107
198
|
[("issues:github.event.issue.title", "second", "secrets.T")])
|
|
108
199
|
|
|
200
|
+
def test_step_env_expression_and_override(self):
|
|
201
|
+
recs = analyse(w=self.ENV % (
|
|
202
|
+
"true", "echo ${{ env.BODY }}",
|
|
203
|
+
"\n BODY: ${{ github.event.issue.body }}"))
|
|
204
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs],
|
|
205
|
+
[("issues:github.event.issue.body", "second", "secrets.T")])
|
|
206
|
+
# A step that sets the variable to a fixed value no longer carries the title.
|
|
207
|
+
self.assertEqual(analyse(w=self.ENV % (
|
|
208
|
+
"true", "echo ${{ env.TITLE }}", "\n TITLE: fixed")), [])
|
|
209
|
+
|
|
210
|
+
FILES = """
|
|
211
|
+
on: %s
|
|
212
|
+
jobs:
|
|
213
|
+
j:
|
|
214
|
+
runs-on: ubuntu-latest
|
|
215
|
+
steps:
|
|
216
|
+
- id: Changed
|
|
217
|
+
uses: %s
|
|
218
|
+
- name: list
|
|
219
|
+
run: for f in ${{ steps.changed.outputs.%s }}; do echo "$f"; done
|
|
220
|
+
env:
|
|
221
|
+
T: ${{ secrets.T }}%s
|
|
222
|
+
"""
|
|
223
|
+
|
|
224
|
+
def test_changed_file_names_are_an_entry(self):
|
|
225
|
+
for action in ("tj-actions/changed-files@v40", "Ana06/get-changed-files@v2",
|
|
226
|
+
"jitterbit/get-changed-files@v1"):
|
|
227
|
+
recs = analyse(w=self.FILES % ("pull_request_target", action, "all_changed_files", ""))
|
|
228
|
+
self.assertEqual([(r[0], r[3], r[4]) for r in recs], [
|
|
229
|
+
("pull_request_target:changed file names", "list", "permissions:default"),
|
|
230
|
+
("pull_request_target:changed file names", "list", "secrets.T")])
|
|
231
|
+
|
|
232
|
+
def test_changed_file_counts_and_other_steps_are_not(self):
|
|
233
|
+
for output in ("all_changed_files_count", "any_changed", "only_modified"):
|
|
234
|
+
self.assertEqual(analyse(w=self.FILES % (
|
|
235
|
+
"pull_request_target", "tj-actions/changed-files@v40", output, "")), [])
|
|
236
|
+
self.assertEqual(analyse(w=self.FILES % (
|
|
237
|
+
"pull_request_target", "actions/setup-python@v5", "all_changed_files", "")), [])
|
|
238
|
+
|
|
239
|
+
def test_changed_file_names_through_env_are_data(self):
|
|
240
|
+
text = (self.FILES % ("pull_request_target", "tj-actions/changed-files@v40", "x", "")
|
|
241
|
+
).replace("${{ steps.changed.outputs.x }}", '"$FILES"').replace(
|
|
242
|
+
"T: ${{ secrets.T }}",
|
|
243
|
+
"T: ${{ secrets.T }}\n FILES: ${{ steps.changed.outputs.all }}")
|
|
244
|
+
self.assertEqual(analyse(w=text), [])
|
|
245
|
+
|
|
109
246
|
def test_secret_before_entry_is_not_reached(self):
|
|
110
247
|
recs = analyse(w="""
|
|
111
248
|
on: pull_request_target
|
|
@@ -367,7 +504,7 @@ class ErrorTests(unittest.TestCase):
|
|
|
367
504
|
|
|
368
505
|
def test_yaml_error_names_file_and_line(self):
|
|
369
506
|
self.assertEqual(refused(w="on: push\njobs:\n a: !!map {}\n"), [(
|
|
370
|
-
".github/workflows/w.yml", "line 3:
|
|
507
|
+
".github/workflows/w.yml", "line 3: tags are not supported")])
|
|
371
508
|
|
|
372
509
|
def test_readable_files_are_still_analysed(self):
|
|
373
510
|
good = """
|