trust-path 0.1.0__tar.gz → 0.2.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.
Files changed (36) hide show
  1. {trust_path-0.1.0 → trust_path-0.2.0}/.github/workflows/test.yml +1 -0
  2. {trust_path-0.1.0 → trust_path-0.2.0}/PKG-INFO +15 -11
  3. {trust_path-0.1.0 → trust_path-0.2.0}/README.md +14 -10
  4. {trust_path-0.1.0 → trust_path-0.2.0}/pyproject.toml +1 -1
  5. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/agent/.github/workflows/triage.yml +2 -0
  6. {trust_path-0.1.0/tests/fixtures/anchors → trust_path-0.2.0/tests/fixtures/tags}/.github/workflows/a.yml +1 -2
  7. {trust_path-0.1.0 → trust_path-0.2.0}/tests/test_analyze.py +83 -3
  8. {trust_path-0.1.0 → trust_path-0.2.0}/tests/test_cli.py +24 -19
  9. {trust_path-0.1.0 → trust_path-0.2.0}/tests/test_yamlsubset.py +48 -9
  10. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path/__init__.py +1 -1
  11. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path/analyze.py +54 -6
  12. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path/cli.py +2 -2
  13. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path/yamlsubset.py +65 -9
  14. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path.egg-info/PKG-INFO +15 -11
  15. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path.egg-info/SOURCES.txt +1 -1
  16. {trust_path-0.1.0 → trust_path-0.2.0}/.github/workflows/release.yml +0 -0
  17. {trust_path-0.1.0 → trust_path-0.2.0}/LICENSE +0 -0
  18. {trust_path-0.1.0 → trust_path-0.2.0}/MANIFEST.in +0 -0
  19. {trust_path-0.1.0 → trust_path-0.2.0}/setup.cfg +0 -0
  20. {trust_path-0.1.0 → trust_path-0.2.0}/tests/__init__.py +0 -0
  21. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/head_checkout/.github/workflows/build.yml +0 -0
  22. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/missing_call/.github/workflows/call.yml +0 -0
  23. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/pr_title/.github/workflows/greet.yml +0 -0
  24. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/reusable/.github/workflows/on-comment.yml +0 -0
  25. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/reusable/.github/workflows/reply.yml +0 -0
  26. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/safe/.github/workflows/echo-title.yml +0 -0
  27. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/safe/.github/workflows/label.yml +0 -0
  28. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/safe/.github/workflows/release.yml +0 -0
  29. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/safe/.github/workflows/test.yml +0 -0
  30. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/workflow_run_chain/.github/workflows/ci.yml +0 -0
  31. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/workflow_run_chain/.github/workflows/publish.yml +0 -0
  32. {trust_path-0.1.0 → trust_path-0.2.0}/tests/fixtures/workflow_run_chain/.github/workflows/stage.yml +0 -0
  33. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path/__main__.py +0 -0
  34. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path.egg-info/dependency_links.txt +0 -0
  35. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path.egg-info/entry_points.txt +0 -0
  36. {trust_path-0.1.0 → trust_path-0.2.0}/trust_path.egg-info/top_level.txt +0 -0
@@ -2,6 +2,7 @@ name: test
2
2
 
3
3
  on:
4
4
  push:
5
+ branches: [main]
5
6
  pull_request:
6
7
 
7
8
  permissions:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trust-path
3
- Version: 0.1.0
3
+ Version: 0.2.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
@@ -76,7 +76,7 @@ pip installs `trust-path` as a console script. Without installing, it runs from
76
76
  4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
77
77
  trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
78
78
  environment and AI agent actions holding a credential.
79
- 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step` and `sink`,
79
+ 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step`, `sink` and `detail`,
80
80
  tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
81
81
  none and 2 on an error, including any refused file.
82
82
 
@@ -100,18 +100,22 @@ trust-path tests/fixtures/agent
100
100
  ```
101
101
 
102
102
  ```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:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action
107
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write
108
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY
103
+ 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
104
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write gate=anyone; tools=action-default
105
+ 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
106
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN gate=anyone; tools=action-default
107
+ 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
108
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write -
109
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY -
110
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN -
109
111
  ```
110
112
 
111
113
  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. Anyone who can open an issue writes
113
- that text, and the agent acts on it while holding the key and can write text into issues that
114
- other workflows and agents read. Run `trust-path .` in a repository checkout to check its workflows.
114
+ in its prompt, an API key and a token that can write issues. The last field shows how the workflow
115
+ sets the agent up: `gate=anyone` because `allowed_non_write_users` is `*`, so the agent runs for
116
+ users without write access, and `tools=action-default` because the workflow does not limit its
117
+ tools. Anyone who can open an issue writes that text, and the agent acts on it while holding the
118
+ 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
119
 
116
120
  ## Documentation
117
121
 
@@ -55,7 +55,7 @@ pip installs `trust-path` as a console script. Without installing, it runs from
55
55
  4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
56
56
  trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
57
57
  environment and AI agent actions holding a credential.
58
- 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step` and `sink`,
58
+ 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step`, `sink` and `detail`,
59
59
  tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
60
60
  none and 2 on an error, including any refused file.
61
61
 
@@ -79,18 +79,22 @@ trust-path tests/fixtures/agent
79
79
  ```
80
80
 
81
81
  ```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:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action
86
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write
87
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY
82
+ 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
83
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write gate=anyone; tools=action-default
84
+ 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
85
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN gate=anyone; tools=action-default
86
+ 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
87
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write -
88
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY -
89
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN -
88
90
  ```
89
91
 
90
92
  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. Anyone who can open an issue writes
92
- that text, and the agent acts on it while holding the key and can write text into issues that
93
- other workflows and agents read. Run `trust-path .` in a repository checkout to check its workflows.
93
+ in its prompt, an API key and a token that can write issues. The last field shows how the workflow
94
+ sets the agent up: `gate=anyone` because `allowed_non_write_users` is `*`, so the agent runs for
95
+ users without write access, and `tools=action-default` because the workflow does not limit its
96
+ tools. Anyone who can open an issue writes that text, and the agent acts on it while holding the
97
+ 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
98
 
95
99
  ## Documentation
96
100
 
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "trust-path"
8
- version = "0.1.0"
8
+ version = "0.2.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"
@@ -14,3 +14,5 @@ jobs:
14
14
  Label this issue:
15
15
  ${{ github.event.issue.body }}
16
16
  anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
17
+ github_token: ${{ secrets.GITHUB_TOKEN }}
18
+ allowed_non_write_users: "*"
@@ -1,7 +1,6 @@
1
1
  on: push
2
2
  jobs:
3
- a: &job
3
+ a: !!map
4
4
  runs-on: ubuntu-latest
5
5
  steps:
6
6
  - run: true
7
- b: *job
@@ -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 [tuple(r) for r in Repo(tmp).analyse()]
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
 
@@ -367,7 +447,7 @@ class ErrorTests(unittest.TestCase):
367
447
 
368
448
  def test_yaml_error_names_file_and_line(self):
369
449
  self.assertEqual(refused(w="on: push\njobs:\n a: !!map {}\n"), [(
370
- ".github/workflows/w.yml", "line 3: anchors, aliases and tags are not supported")])
450
+ ".github/workflows/w.yml", "line 3: tags are not supported")])
371
451
 
372
452
  def test_readable_files_are_still_analysed(self):
373
453
  good = """
@@ -30,14 +30,14 @@ class PathTests(unittest.TestCase):
30
30
  self.assertEqual(code, 1)
31
31
  self.assertEqual(recs, [(
32
32
  "pull_request_target:github.event.pull_request.title",
33
- ".github/workflows/greet.yml", "greet", "Post greeting", "secrets.BOT_TOKEN")])
33
+ ".github/workflows/greet.yml", "greet", "Post greeting", "secrets.BOT_TOKEN", "-")])
34
34
 
35
35
  def test_head_checkout_reaches_later_secret(self):
36
36
  code, recs, _ = records("head_checkout")
37
37
  self.assertEqual(code, 1)
38
38
  self.assertEqual(recs, [(
39
39
  "pull_request_target:checkout of pull request head",
40
- ".github/workflows/build.yml", "build", "Install", "secrets.NPM_TOKEN")])
40
+ ".github/workflows/build.yml", "build", "Install", "secrets.NPM_TOKEN", "-")])
41
41
 
42
42
  def test_workflow_run_chain_reaches_publish_job(self):
43
43
  code, recs, _ = records("workflow_run_chain")
@@ -45,9 +45,9 @@ class PathTests(unittest.TestCase):
45
45
  source = ("pull_request@.github/workflows/ci.yml>workflow_run@.github/workflows/stage.yml"
46
46
  ">workflow_run:github.event.workflow_run.head_branch")
47
47
  self.assertEqual(recs, [
48
- (source, ".github/workflows/publish.yml", "publish", "Tag", "environment:pypi"),
48
+ (source, ".github/workflows/publish.yml", "publish", "Tag", "environment:pypi", "-"),
49
49
  (source, ".github/workflows/publish.yml", "publish", "Tag",
50
- "permissions.id-token:write"),
50
+ "permissions.id-token:write", "-"),
51
51
  ])
52
52
 
53
53
  def test_agent_given_issue_body_with_api_key(self):
@@ -55,15 +55,22 @@ class PathTests(unittest.TestCase):
55
55
  self.assertEqual(code, 1)
56
56
  step = "anthropics/claude-code-action@v1"
57
57
  wf = ".github/workflows/triage.yml"
58
+ agent = "gate=anyone; tools=action-default"
58
59
  self.assertEqual(recs, [
59
60
  ("issues:event text read by agent", wf, "triage", step,
60
- "agent:anthropics/claude-code-action"),
61
- ("issues:event text read by agent", wf, "triage", step, "permissions.issues:write"),
62
- ("issues:event text read by agent", wf, "triage", step, "secrets.ANTHROPIC_API_KEY"),
61
+ "agent:anthropics/claude-code-action", agent),
62
+ ("issues:event text read by agent", wf, "triage", step, "permissions.issues:write",
63
+ agent),
64
+ ("issues:event text read by agent", wf, "triage", step, "secrets.ANTHROPIC_API_KEY",
65
+ agent),
66
+ ("issues:event text read by agent", wf, "triage", step, "secrets.GITHUB_TOKEN",
67
+ agent),
63
68
  ("issues:github.event.issue.body", wf, "triage", step,
64
- "agent:anthropics/claude-code-action"),
65
- ("issues:github.event.issue.body", wf, "triage", step, "permissions.issues:write"),
66
- ("issues:github.event.issue.body", wf, "triage", step, "secrets.ANTHROPIC_API_KEY"),
69
+ "agent:anthropics/claude-code-action", agent),
70
+ ("issues:github.event.issue.body", wf, "triage", step, "permissions.issues:write", "-"),
71
+ ("issues:github.event.issue.body", wf, "triage", step, "secrets.ANTHROPIC_API_KEY",
72
+ "-"),
73
+ ("issues:github.event.issue.body", wf, "triage", step, "secrets.GITHUB_TOKEN", "-"),
67
74
  ])
68
75
 
69
76
  def test_reusable_workflow_input(self):
@@ -72,8 +79,8 @@ class PathTests(unittest.TestCase):
72
79
  source = "issue_comment@.github/workflows/on-comment.yml>workflow_call:inputs.text"
73
80
  wf = ".github/workflows/reply.yml"
74
81
  self.assertEqual(recs, [
75
- (source, wf, "reply", "Reply", "permissions.pull-requests:write"),
76
- (source, wf, "reply", "Reply", "secrets.token"),
82
+ (source, wf, "reply", "Reply", "permissions.pull-requests:write", "-"),
83
+ (source, wf, "reply", "Reply", "secrets.token", "-"),
77
84
  ])
78
85
 
79
86
  def test_safe_workflows_report_nothing(self):
@@ -89,7 +96,7 @@ class OutputTests(unittest.TestCase):
89
96
  code, out, _ = run("--json", os.path.join(FIXTURES, "agent"))
90
97
  self.assertEqual(code, 1)
91
98
  _, recs, _ = records("agent")
92
- self.assertEqual([tuple(r[k] for k in ("source", "workflow", "job", "step", "sink"))
99
+ self.assertEqual([tuple(r[k] for k in ("source", "workflow", "job", "step", "sink", "detail"))
93
100
  for r in json.loads(out)], recs)
94
101
 
95
102
  def test_json_empty(self):
@@ -119,10 +126,9 @@ class OutputTests(unittest.TestCase):
119
126
 
120
127
  class ErrorTests(unittest.TestCase):
121
128
  def test_unsupported_yaml_is_refused(self):
122
- code, out, err = run(os.path.join(FIXTURES, "anchors"))
129
+ code, out, err = run(os.path.join(FIXTURES, "tags"))
123
130
  self.assertEqual((code, out), (2, ""))
124
- self.assertEqual(err, "trust-path: .github/workflows/a.yml: line 3: anchors, aliases and "
125
- "tags are not supported\n")
131
+ self.assertEqual(err, "trust-path: .github/workflows/a.yml: line 3: tags are not supported\n")
126
132
 
127
133
  def test_missing_reusable_workflow(self):
128
134
  code, out, err = run(os.path.join(FIXTURES, "missing_call"))
@@ -134,7 +140,7 @@ class ErrorTests(unittest.TestCase):
134
140
  self.addCleanup(shutil.rmtree, tmp)
135
141
  shutil.copytree(os.path.join(FIXTURES, "pr_title", ".github"), os.path.join(tmp, ".github"))
136
142
  wdir = os.path.join(tmp, ".github", "workflows")
137
- for name, text in (("a.yml", "x: &a 1\n"), ("b.yml", "on: push\n")):
143
+ for name, text in (("a.yml", "x: !!str 1\n"), ("b.yml", "on: push\n")):
138
144
  with open(os.path.join(wdir, name), "w") as f:
139
145
  f.write(text)
140
146
  code, out, err = run(tmp)
@@ -142,8 +148,7 @@ class ErrorTests(unittest.TestCase):
142
148
  self.assertEqual(out, run(os.path.join(FIXTURES, "pr_title"))[1])
143
149
  self.assertTrue(out)
144
150
  self.assertEqual(err.splitlines(), [
145
- "trust-path: .github/workflows/a.yml: line 1: anchors, aliases and tags are not "
146
- "supported",
151
+ "trust-path: .github/workflows/a.yml: line 1: tags are not supported",
147
152
  "trust-path: .github/workflows/b.yml: not a workflow (no 'jobs' mapping)"])
148
153
  code, out, _ = run("--json", tmp)
149
154
  self.assertEqual(code, 2)
@@ -106,6 +106,36 @@ class SupportedTests(unittest.TestCase):
106
106
  self.assertEqual(y("a:\n - |\n x\n y\n"), {"a": ["x\n y\n"]})
107
107
 
108
108
 
109
+ class AnchorTests(unittest.TestCase):
110
+ def test_scalar(self):
111
+ self.assertEqual(load("a: &x 1\nb: *x\n"), {"a": "1", "b": "1"})
112
+ self.assertEqual(load("- &x a\n- *x # again\n"), ["a", "a"])
113
+ self.assertEqual(load("a: &x |\n hi\nb: *x\n"), {"a": "hi\n", "b": "hi\n"})
114
+
115
+ def test_mapping_and_sequence_values(self):
116
+ self.assertEqual(load("a: &x\n b: c\nd: *x\n"), {"a": {"b": "c"}, "d": {"b": "c"}})
117
+ self.assertEqual(load("a: &x # note\n b: c\nd: *x\n"), {"a": {"b": "c"}, "d": {"b": "c"}})
118
+ self.assertEqual(load("a: &x\n- 1\n- 2\nb: *x\n"), {"a": ["1", "2"], "b": ["1", "2"]})
119
+ self.assertEqual(load("a: &x [1, 2]\nb: *x\n"), {"a": ["1", "2"], "b": ["1", "2"]})
120
+
121
+ def test_reused_step(self):
122
+ step = {"uses": "actions/checkout@v4", "with": {"ref": "main"}}
123
+ self.assertEqual(load(textwrap.dedent("""\
124
+ first:
125
+ - &checkout
126
+ uses: actions/checkout@v4
127
+ with:
128
+ ref: main
129
+ - run: make
130
+ second:
131
+ - *checkout
132
+ """)), {"first": [step, {"run": "make"}], "second": [step]})
133
+
134
+ def test_anchor_can_be_redefined(self):
135
+ self.assertEqual(load("a: &x 1\nb: *x\nc: &x 2\nd: *x\n"),
136
+ {"a": "1", "b": "1", "c": "2", "d": "2"})
137
+
138
+
109
139
  class SpecTests(unittest.TestCase):
110
140
  """Expected values from the examples in the YAML 1.2.2 specification."""
111
141
 
@@ -160,16 +190,25 @@ class RefusedTests(unittest.TestCase):
160
190
  y(text)
161
191
  self.assertEqual((cm.exception.line, cm.exception.message), (line, message))
162
192
 
163
- def test_anchor_alias_tag(self):
164
- msg = "anchors, aliases and tags are not supported"
165
- self.refused("a: &x 1\n", 1, msg)
166
- self.refused("a: 1\nb: *x\n", 2, msg)
167
- self.refused("a: !!str 1\n", 1, msg)
168
- self.refused("a:\n - *x\n", 2, msg)
169
- self.refused("- &x a\n", 1, msg)
170
- self.refused("a: &x\n b: c\n", 1, msg)
193
+ def test_tags_and_unsupported_anchor_positions(self):
194
+ self.refused("a: !!str 1\n", 1, "tags are not supported")
171
195
  self.refused("a: [&x b, *x]\n", 1, "anchors, aliases, tags and complex keys are not supported")
172
- self.refused("&x a: b\n", 1, msg)
196
+ self.refused("&x a: b\n", 1, "anchors, aliases and tags on mapping keys are not supported")
197
+ self.refused("a: & 1\n", 1, "expected a name after '&'")
198
+
199
+ def test_alias_errors(self):
200
+ self.refused("a: 1\nb: *x\n", 2, "alias 'x' has no anchor before it")
201
+ self.refused("a:\n - *x\n", 2, "alias 'x' has no anchor before it")
202
+ self.refused("a: &x 1\nb: *x y\n", 2, "unexpected content after alias 'x'")
203
+
204
+ def test_alias_expansion_is_bounded(self):
205
+ text = "a: &a [x, x, x, x, x, x, x, x, x, x]\n"
206
+ for i in range(8):
207
+ new, old = chr(98 + i), chr(97 + i)
208
+ text += "%s: &%s\n" % (new, new) + (" - *%s\n" % old) * 10
209
+ with self.assertRaises(YamlError) as cm:
210
+ load(text)
211
+ self.assertEqual(cm.exception.message, "aliases expand to too many values")
173
212
 
174
213
  def test_other_constructs(self):
175
214
  self.refused("a: 1\n<<: {b: 2}\n", 2, "merge keys are not supported")
@@ -1,3 +1,3 @@
1
1
  """trust-path: map paths from untrusted input to secrets in GitHub Actions workflows."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.2.0"
@@ -1,6 +1,6 @@
1
1
  """Find paths from untrusted input to secrets and credentials in workflows.
2
2
 
3
- A path is reported as a Record(source, workflow, job, step, sink). See
3
+ A path is reported as a Record(source, workflow, job, step, sink, detail). See
4
4
  docs/model.md for the rules this module implements.
5
5
  """
6
6
 
@@ -11,7 +11,7 @@ import subprocess
11
11
 
12
12
  from . import yamlsubset
13
13
 
14
- Record = collections.namedtuple("Record", "source workflow job step sink")
14
+ Record = collections.namedtuple("Record", "source workflow job step sink detail")
15
15
 
16
16
 
17
17
  class AnalysisError(Exception):
@@ -79,6 +79,17 @@ AGENT_ACTIONS = (
79
79
  "warpdotdev/oz-agent-action",
80
80
  )
81
81
 
82
+ # The input by which an agent action lets users without write access start
83
+ # it. Left empty, these actions run only for users with write access.
84
+ AGENT_GATES = {
85
+ "anthropics/claude-code-action": "allowed_non_write_users",
86
+ "openai/codex-action": "allow-users",
87
+ }
88
+ _CLAUDE_FLAGS = re.compile(
89
+ r"--(allowed-?tools|disallowed-?tools|permission-mode|dangerously-skip-permissions)"
90
+ r"(?:(?:\s+|=)(\"[^\"]*\"|'[^']*'|[^\s-]\S*))?", re.I)
91
+ _CLAUDE_NAMES = {"allowedtools": "allowedTools", "disallowedtools": "disallowedTools"}
92
+
82
93
  # Actions that download artifacts from another workflow run.
83
94
  ARTIFACT_ACTIONS = ("actions/download-artifact", "dawidd6/action-download-artifact")
84
95
 
@@ -158,6 +169,39 @@ def _action(uses):
158
169
  return "/".join(uses.split("@")[0].split("/")[:2]).lower()
159
170
 
160
171
 
172
+ def agent_detail(action, with_):
173
+ """What the workflow sets on an agent action: who may start it (gate)
174
+ and what it may do. Values are the workflow's own, not a judgement."""
175
+ def text(key):
176
+ return with_[key].strip() if isinstance(with_.get(key), str) else ""
177
+
178
+ parts = []
179
+ if action in AGENT_GATES:
180
+ gate = text(AGENT_GATES[action])
181
+ parts.append("gate=" + ("write-access" if not gate else "anyone" if gate == "*"
182
+ else "expression" if "${{" in gate else "listed-users"))
183
+ else:
184
+ parts.append("gate=not-modelled")
185
+ if action.startswith("anthropics/"):
186
+ flags = []
187
+ for m in _CLAUDE_FLAGS.finditer(text("claude_args")):
188
+ name = m.group(1).lower().replace("-tools", "tools")
189
+ name = _CLAUDE_NAMES.get(name, name)
190
+ if name == "dangerously-skip-permissions":
191
+ flags.append(name)
192
+ elif m.group(2):
193
+ flags.append("%s=%s" % (name, m.group(2).strip("\"'")))
194
+ parts.extend(sorted(set(flags)) or ["tools=action-default"])
195
+ if text("settings"):
196
+ parts.append("settings=set")
197
+ elif action == "openai/codex-action":
198
+ parts.append("sandbox=" + (text("sandbox") or "action-default"))
199
+ if text("permission-profile"):
200
+ parts.append("permission-profile=" + text("permission-profile"))
201
+ parts.append("safety-strategy=" + (text("safety-strategy") or "drop-sudo"))
202
+ return "; ".join(parts)
203
+
204
+
161
205
  def triggers_of(wf):
162
206
  on = wf.get("on")
163
207
  if isinstance(on, str):
@@ -374,6 +418,7 @@ class Repo(object):
374
418
 
375
419
  # Where untrusted input enters the job: (step index, source).
376
420
  entries = set()
421
+ details = {}
377
422
  if steps:
378
423
  for name in untrusted(contexts(shared_env), ctx.trigger, ctx.tainted_inputs):
379
424
  entries.add((0, name))
@@ -394,22 +439,25 @@ class Repo(object):
394
439
  entries.add((i, "artifact from upstream run"))
395
440
  if action in AGENT_ACTIONS:
396
441
  entries.add((i, "event text read by agent"))
442
+ details[i] = agent_detail(action, with_)
397
443
 
398
444
  for start, what in sorted(entries):
399
445
  source = "%s:%s" % (ctx.chain, what)
446
+ entry = details[start] if what == "event text read by agent" else "-"
400
447
  for sink in job_sinks:
401
- records.add(Record(source, rel, job_id, _label(steps[start], start), sink))
448
+ records.add(Record(source, rel, job_id, _label(steps[start], start), sink, entry))
402
449
  for i in range(start, len(steps)):
403
450
  step = steps[i]
404
451
  held = allowed(secret_names([step.get("run"), step.get("with"),
405
452
  step.get("env")]))
406
453
  for sink in held:
407
- records.add(Record(source, rel, job_id, _label(step, i), sink))
454
+ records.add(Record(source, rel, job_id, _label(step, i), sink, entry))
408
455
  action = _action(step.get("uses"))
409
456
  credential = held or job_sinks & {"permissions.id-token:write"} or \
410
457
  allowed(secret_names(shared_env))
411
458
  if action in AGENT_ACTIONS and credential:
412
- records.add(Record(source, rel, job_id, _label(step, i), "agent:" + action))
459
+ records.add(Record(source, rel, job_id, _label(step, i), "agent:" + action,
460
+ details[i]))
413
461
 
414
462
  def _call(self, rel, job_id, job, ctx, records, stack):
415
463
  uses = job["uses"]
@@ -434,7 +482,7 @@ class Repo(object):
434
482
  for name in sorted(tainted):
435
483
  for sink in sinks:
436
484
  records.add(Record("%s:%s" % (ctx.chain, "with." + name), rel, job_id,
437
- uses, sink))
485
+ uses, sink, "-"))
438
486
  return
439
487
  target = uses[2:].split("@")[0]
440
488
  if target not in self.workflows or target in stack:
@@ -7,11 +7,11 @@ import sys
7
7
  from . import __version__
8
8
  from .analyze import AnalysisError, Repo
9
9
 
10
- FIELDS = ("source", "workflow", "job", "step", "sink")
10
+ FIELDS = ("source", "workflow", "job", "step", "sink", "detail")
11
11
 
12
12
 
13
13
  def _clean(text):
14
- """Keep each record on one line with exactly five fields."""
14
+ """Keep each record on one line with exactly six fields."""
15
15
  return " ".join(str(text).replace("\t", " ").split())
16
16
 
17
17
 
@@ -3,12 +3,15 @@
3
3
  Supported: block mappings and sequences, plain, single-quoted and
4
4
  double-quoted scalars (also over several lines), literal (|) and folded (>)
5
5
  block scalars with chomping and indentation indicators, flow sequences and
6
- mappings, and comments.
7
-
8
- Every scalar is returned as a str; an empty value is None. YAML features
9
- outside the subset (anchors, aliases, tags, complex keys, merge keys,
10
- directives, several documents, tabs in indentation) raise YamlError instead
11
- of being guessed at.
6
+ mappings, comments, and anchors (&name) with aliases (*name) on block
7
+ values and sequence items.
8
+
9
+ Every scalar is returned as a str; an empty value is None. An alias returns
10
+ the anchored value itself, not a copy; a document whose aliases expand to
11
+ more than MAX_ALIAS_NODES values is refused. YAML features outside the subset
12
+ (tags, complex keys, merge keys, anchors on mapping keys or inside flow
13
+ collections, directives, several documents, tabs in indentation) raise
14
+ YamlError instead of being guessed at.
12
15
  """
13
16
 
14
17
  import re
@@ -26,6 +29,21 @@ _ESCAPES = {"0": "\0", "a": "\a", "b": "\b", "t": "\t", "\t": "\t", "n": "\n",
26
29
  "/": "/", "\\": "\\", "N": "\x85", "_": "\xa0", "L": "
",
27
30
  "P": "
"}
28
31
  _HEX = {"x": 2, "u": 4, "U": 8}
32
+ _ANCHOR = re.compile(r"[&*]([^\s\[\]{},]+)(?=\s|$)")
33
+ MAX_ALIAS_NODES = 100000
34
+
35
+
36
+ def _size(value, limit):
37
+ """Number of values in `value`, counting stops once it passes `limit`."""
38
+ count, todo = 0, [value]
39
+ while todo and count <= limit:
40
+ v = todo.pop()
41
+ count += 1
42
+ if isinstance(v, dict):
43
+ todo.extend(v.values())
44
+ elif isinstance(v, list):
45
+ todo.extend(v)
46
+ return count
29
47
 
30
48
 
31
49
  def load(text):
@@ -174,6 +192,8 @@ class _Parser(object):
174
192
  text = text[1:]
175
193
  self.lines = text.replace("\r\n", "\n").replace("\r", "\n").split("\n")
176
194
  self.i = 0
195
+ self.anchors = {}
196
+ self.aliased = 0
177
197
 
178
198
  def err(self, message, n=None):
179
199
  raise YamlError((self.i if n is None else n) + 1, message)
@@ -240,13 +260,18 @@ class _Parser(object):
240
260
  self.err("expected 'key: value'")
241
261
  key_text = body[:c].strip()
242
262
  if key_text[:1] in ("&", "*", "!"):
243
- self.err("anchors, aliases and tags are not supported")
263
+ self.err("anchors, aliases and tags on mapping keys are not supported")
244
264
  key = _unquote(key_text, self.i + 1) if key_text[:1] in ("'", '"') else key_text
245
265
  if key == "<<":
246
266
  self.err("merge keys are not supported")
247
267
  if key in result:
248
268
  self.err("duplicate key %r" % key)
249
269
  rest = body[c + 1:]
270
+ # `key: &name` with the value on the following lines.
271
+ m = _ANCHOR.match(rest.strip())
272
+ anchor = None
273
+ if m and rest.strip()[0] == "&" and _strip_comment(rest.strip()[m.end():].strip()) == "":
274
+ anchor, rest = m.group(1), ""
250
275
  if _strip_comment(rest.strip()) == "":
251
276
  self.i += 1
252
277
  nxt = self.peek()
@@ -257,6 +282,8 @@ class _Parser(object):
257
282
  result[key] = self.sequence(ind)
258
283
  else:
259
284
  result[key] = None
285
+ if anchor is not None:
286
+ self.anchors[anchor] = result[key]
260
287
  else:
261
288
  col = ind + c + 1 + (len(rest) - len(rest.lstrip(" ")))
262
289
  result[key] = self.scalar_value(self.i, col, ind)
@@ -288,8 +315,10 @@ class _Parser(object):
288
315
  self.i = start
289
316
  text = self.lines[start][col:]
290
317
  c = text[:1]
291
- if c in ("&", "*", "!"):
292
- self.err("anchors, aliases and tags are not supported")
318
+ if c == "!":
319
+ self.err("tags are not supported")
320
+ if c in ("&", "*"):
321
+ return self.anchored(start, col, parent_indent, text)
293
322
  if c in ("|", ">"):
294
323
  return self.block_scalar(text, parent_indent)
295
324
  if c in ("'", '"'):
@@ -320,6 +349,33 @@ class _Parser(object):
320
349
  value = _fold(parts)
321
350
  return None if value in ("", "~", "null", "Null", "NULL") else value
322
351
 
352
+ def anchored(self, start, col, parent_indent, text):
353
+ """The value at an anchor (&name value) or an alias (*name)."""
354
+ m = _ANCHOR.match(text)
355
+ if not m:
356
+ self.err("expected a name after %r" % text[:1])
357
+ name, tail = m.group(1), text[m.end():]
358
+ if text[0] == "*":
359
+ if _strip_comment(tail.strip()) != "":
360
+ self.err("unexpected content after alias %r" % name)
361
+ if name not in self.anchors:
362
+ self.err("alias %r has no anchor before it" % name)
363
+ self.aliased += _size(self.anchors[name], MAX_ALIAS_NODES)
364
+ if self.aliased > MAX_ALIAS_NODES:
365
+ self.err("aliases expand to too many values")
366
+ self.i = start + 1
367
+ return self.anchors[name]
368
+ if _strip_comment(tail.strip()) == "":
369
+ self.i = start + 1
370
+ nxt = self.peek()
371
+ deeper = nxt is not None and _indent(nxt) > parent_indent
372
+ value = self.block(parent_indent + 1) if deeper else None
373
+ else:
374
+ value = self.scalar_value(
375
+ start, col + m.end() + len(tail) - len(tail.lstrip(" ")), parent_indent)
376
+ self.anchors[name] = value
377
+ return value
378
+
323
379
  def quoted(self, text):
324
380
  start = self.i
325
381
  while _quote_end(text, 0) < 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trust-path
3
- Version: 0.1.0
3
+ Version: 0.2.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
@@ -76,7 +76,7 @@ pip installs `trust-path` as a console script. Without installing, it runs from
76
76
  4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
77
77
  trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
78
78
  environment and AI agent actions holding a credential.
79
- 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step` and `sink`,
79
+ 5. **Print one record per path.** Each record is `source`, `workflow`, `job`, `step`, `sink` and `detail`,
80
80
  tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
81
81
  none and 2 on an error, including any refused file.
82
82
 
@@ -100,18 +100,22 @@ trust-path tests/fixtures/agent
100
100
  ```
101
101
 
102
102
  ```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:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 agent:anthropics/claude-code-action
107
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write
108
- issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY
103
+ 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
104
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write gate=anyone; tools=action-default
105
+ 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
106
+ issues:event text read by agent .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN gate=anyone; tools=action-default
107
+ 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
108
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 permissions.issues:write -
109
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.ANTHROPIC_API_KEY -
110
+ issues:github.event.issue.body .github/workflows/triage.yml triage anthropics/claude-code-action@v1 secrets.GITHUB_TOKEN -
109
111
  ```
110
112
 
111
113
  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. Anyone who can open an issue writes
113
- that text, and the agent acts on it while holding the key and can write text into issues that
114
- other workflows and agents read. Run `trust-path .` in a repository checkout to check its workflows.
114
+ in its prompt, an API key and a token that can write issues. The last field shows how the workflow
115
+ sets the agent up: `gate=anyone` because `allowed_non_write_users` is `*`, so the agent runs for
116
+ users without write access, and `tools=action-default` because the workflow does not limit its
117
+ tools. Anyone who can open an issue writes that text, and the agent acts on it while holding the
118
+ 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
119
 
116
120
  ## Documentation
117
121
 
@@ -9,7 +9,6 @@ tests/test_analyze.py
9
9
  tests/test_cli.py
10
10
  tests/test_yamlsubset.py
11
11
  tests/fixtures/agent/.github/workflows/triage.yml
12
- tests/fixtures/anchors/.github/workflows/a.yml
13
12
  tests/fixtures/head_checkout/.github/workflows/build.yml
14
13
  tests/fixtures/missing_call/.github/workflows/call.yml
15
14
  tests/fixtures/pr_title/.github/workflows/greet.yml
@@ -19,6 +18,7 @@ tests/fixtures/safe/.github/workflows/echo-title.yml
19
18
  tests/fixtures/safe/.github/workflows/label.yml
20
19
  tests/fixtures/safe/.github/workflows/release.yml
21
20
  tests/fixtures/safe/.github/workflows/test.yml
21
+ tests/fixtures/tags/.github/workflows/a.yml
22
22
  tests/fixtures/workflow_run_chain/.github/workflows/ci.yml
23
23
  tests/fixtures/workflow_run_chain/.github/workflows/publish.yml
24
24
  tests/fixtures/workflow_run_chain/.github/workflows/stage.yml
File without changes
File without changes
File without changes
File without changes