trust-path 0.1.0__py3-none-any.whl
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/__init__.py +3 -0
- trust_path/__main__.py +5 -0
- trust_path/analyze.py +444 -0
- trust_path/cli.py +58 -0
- trust_path/yamlsubset.py +491 -0
- trust_path-0.1.0.dist-info/METADATA +129 -0
- trust_path-0.1.0.dist-info/RECORD +11 -0
- trust_path-0.1.0.dist-info/WHEEL +5 -0
- trust_path-0.1.0.dist-info/entry_points.txt +2 -0
- trust_path-0.1.0.dist-info/licenses/LICENSE +202 -0
- trust_path-0.1.0.dist-info/top_level.txt +1 -0
trust_path/yamlsubset.py
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
"""A YAML reader for the subset of YAML that GitHub Actions workflows use.
|
|
2
|
+
|
|
3
|
+
Supported: block mappings and sequences, plain, single-quoted and
|
|
4
|
+
double-quoted scalars (also over several lines), literal (|) and folded (>)
|
|
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.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class YamlError(Exception):
|
|
18
|
+
def __init__(self, line, message):
|
|
19
|
+
Exception.__init__(self, "line %d: %s" % (line, message))
|
|
20
|
+
self.line = line
|
|
21
|
+
self.message = message
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_ESCAPES = {"0": "\0", "a": "\a", "b": "\b", "t": "\t", "\t": "\t", "n": "\n",
|
|
25
|
+
"v": "\v", "f": "\f", "r": "\r", "e": "\x1b", " ": " ", '"': '"',
|
|
26
|
+
"/": "/", "\\": "\\", "N": "\x85", "_": "\xa0", "L": "
",
|
|
27
|
+
"P": "
"}
|
|
28
|
+
_HEX = {"x": 2, "u": 4, "U": 8}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load(text):
|
|
32
|
+
"""Parse one YAML document and return dicts, lists, str and None."""
|
|
33
|
+
parser = _Parser(text)
|
|
34
|
+
try:
|
|
35
|
+
return parser.document()
|
|
36
|
+
except RecursionError:
|
|
37
|
+
raise YamlError(parser.i + 1, "nesting is too deep")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _indent(line):
|
|
41
|
+
return len(line) - len(line.lstrip(" "))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _is_marker(line):
|
|
45
|
+
"""True for a '---' or '...' document marker line."""
|
|
46
|
+
return line[:3] in ("---", "...") and line[3:4] in ("", " ")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _is_blank(line):
|
|
50
|
+
s = line.strip()
|
|
51
|
+
return not s or s.startswith("#")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _strip_comment(s):
|
|
55
|
+
"""Remove a trailing ' #...' comment from a plain (unquoted) value."""
|
|
56
|
+
if s.startswith("#"):
|
|
57
|
+
return ""
|
|
58
|
+
m = re.search(r"\s#", s)
|
|
59
|
+
return (s[:m.start()] if m else s).rstrip()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _find_colon(s):
|
|
63
|
+
"""Index of the ': ' (or final ':') that ends a mapping key, or -1."""
|
|
64
|
+
if s[:1] in ("\"", "'"):
|
|
65
|
+
end = _quote_end(s, 0)
|
|
66
|
+
if end < 0:
|
|
67
|
+
return -1
|
|
68
|
+
rest = s[end + 1:]
|
|
69
|
+
if rest.lstrip().startswith(":"):
|
|
70
|
+
i = end + 1 + (len(rest) - len(rest.lstrip()))
|
|
71
|
+
nxt = s[i + 1:i + 2]
|
|
72
|
+
return i if nxt in ("", " ") else -1
|
|
73
|
+
return -1
|
|
74
|
+
if s[:1] in ("[", "{"):
|
|
75
|
+
return -1
|
|
76
|
+
for m in re.finditer(r":(?= |$)", s):
|
|
77
|
+
if " #" in s[:m.start()]:
|
|
78
|
+
return -1
|
|
79
|
+
return m.start()
|
|
80
|
+
return -1
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _quote_end(s, start):
|
|
84
|
+
"""Index of the quote closing the quoted scalar at s[start], or -1."""
|
|
85
|
+
q = s[start]
|
|
86
|
+
i = start + 1
|
|
87
|
+
while i < len(s):
|
|
88
|
+
c = s[i]
|
|
89
|
+
if q == '"' and c == "\\":
|
|
90
|
+
i += 2
|
|
91
|
+
continue
|
|
92
|
+
if c == q:
|
|
93
|
+
if q == "'" and s[i + 1:i + 2] == "'":
|
|
94
|
+
i += 2
|
|
95
|
+
continue
|
|
96
|
+
return i
|
|
97
|
+
i += 1
|
|
98
|
+
return -1
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
_ODD_BACKSLASHES = re.compile(r"(?<!\\)(\\\\)*\\$")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _fold(parts, joined=()):
|
|
105
|
+
"""Fold trimmed lines into one value: a line break becomes a space, and
|
|
106
|
+
each blank line becomes a newline. A line break after a line whose index
|
|
107
|
+
is in `joined` (an escaped line break) becomes nothing."""
|
|
108
|
+
out = ""
|
|
109
|
+
blanks = 0
|
|
110
|
+
last = 0
|
|
111
|
+
for n, part in enumerate(parts):
|
|
112
|
+
if part == "" and n:
|
|
113
|
+
blanks += 1
|
|
114
|
+
continue
|
|
115
|
+
if n:
|
|
116
|
+
out += "\n" * blanks if blanks or last in joined else " "
|
|
117
|
+
out += part
|
|
118
|
+
blanks = 0
|
|
119
|
+
last = n
|
|
120
|
+
return out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _rtrim(line):
|
|
124
|
+
"""Strip trailing spaces and tabs, but not one escaped by a backslash."""
|
|
125
|
+
t = line.rstrip(" \t")
|
|
126
|
+
if len(t) < len(line) and _ODD_BACKSLASHES.search(t):
|
|
127
|
+
t = line[:len(t) + 1]
|
|
128
|
+
return t
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _unquote(raw, lineno):
|
|
132
|
+
"""Value of a complete quoted scalar (raw includes both quotes)."""
|
|
133
|
+
q, body = raw[0], raw[1:-1]
|
|
134
|
+
lines = body.split("\n")
|
|
135
|
+
joined = set()
|
|
136
|
+
if len(lines) > 1:
|
|
137
|
+
lines = [lines[0]] + [ln.lstrip(" \t") for ln in lines[1:]]
|
|
138
|
+
for n in range(len(lines) - 1):
|
|
139
|
+
if q == '"' and _ODD_BACKSLASHES.search(lines[n]):
|
|
140
|
+
# An escaped line break: keep the text before the backslash.
|
|
141
|
+
lines[n] = lines[n][:-1]
|
|
142
|
+
joined.add(n)
|
|
143
|
+
else:
|
|
144
|
+
lines[n] = _rtrim(lines[n])
|
|
145
|
+
folded = _fold(lines, joined)
|
|
146
|
+
if q == "'":
|
|
147
|
+
return folded.replace("''", "'")
|
|
148
|
+
out = []
|
|
149
|
+
i = 0
|
|
150
|
+
while i < len(folded):
|
|
151
|
+
c = folded[i]
|
|
152
|
+
if c != "\\":
|
|
153
|
+
out.append(c)
|
|
154
|
+
i += 1
|
|
155
|
+
continue
|
|
156
|
+
e = folded[i + 1:i + 2]
|
|
157
|
+
if e in _ESCAPES:
|
|
158
|
+
out.append(_ESCAPES[e])
|
|
159
|
+
i += 2
|
|
160
|
+
elif e in _HEX:
|
|
161
|
+
digits = folded[i + 2:i + 2 + _HEX[e]]
|
|
162
|
+
if len(digits) != _HEX[e] or not re.match(r"^[0-9A-Fa-f]+$", digits):
|
|
163
|
+
raise YamlError(lineno, "bad escape in double-quoted string")
|
|
164
|
+
out.append(chr(int(digits, 16)))
|
|
165
|
+
i += 2 + _HEX[e]
|
|
166
|
+
else:
|
|
167
|
+
raise YamlError(lineno, "unknown escape \\%s in double-quoted string" % e)
|
|
168
|
+
return "".join(out)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class _Parser(object):
|
|
172
|
+
def __init__(self, text):
|
|
173
|
+
if text.startswith(""):
|
|
174
|
+
text = text[1:]
|
|
175
|
+
self.lines = text.replace("\r\n", "\n").replace("\r", "\n").split("\n")
|
|
176
|
+
self.i = 0
|
|
177
|
+
|
|
178
|
+
def err(self, message, n=None):
|
|
179
|
+
raise YamlError((self.i if n is None else n) + 1, message)
|
|
180
|
+
|
|
181
|
+
def peek(self):
|
|
182
|
+
"""Skip blank and comment lines; return the next line or None."""
|
|
183
|
+
while self.i < len(self.lines) and _is_blank(self.lines[self.i]):
|
|
184
|
+
self.i += 1
|
|
185
|
+
if self.i >= len(self.lines):
|
|
186
|
+
return None
|
|
187
|
+
if self.lines[self.i].lstrip(" ").startswith("\t"):
|
|
188
|
+
self.err("tabs in indentation are not supported")
|
|
189
|
+
return self.lines[self.i]
|
|
190
|
+
|
|
191
|
+
def document(self):
|
|
192
|
+
line = self.peek()
|
|
193
|
+
if line is not None and line.startswith("%"):
|
|
194
|
+
self.err("directives are not supported")
|
|
195
|
+
if line is not None and line.rstrip() == "---":
|
|
196
|
+
self.i += 1
|
|
197
|
+
elif line is not None and line.startswith("---"):
|
|
198
|
+
self.err("content on the '---' line is not supported")
|
|
199
|
+
if self.peek() is None:
|
|
200
|
+
return None
|
|
201
|
+
node = self.block(0)
|
|
202
|
+
line = self.peek()
|
|
203
|
+
if line is not None and line.rstrip() == "...":
|
|
204
|
+
self.i += 1
|
|
205
|
+
line = self.peek()
|
|
206
|
+
if line is not None:
|
|
207
|
+
if _is_marker(line):
|
|
208
|
+
self.err("several documents in one file are not supported")
|
|
209
|
+
self.err("unexpected content")
|
|
210
|
+
return node
|
|
211
|
+
|
|
212
|
+
def block(self, min_indent, parent_indent=None):
|
|
213
|
+
line = self.peek()
|
|
214
|
+
if line is None or _indent(line) < min_indent:
|
|
215
|
+
return None
|
|
216
|
+
ind = _indent(line)
|
|
217
|
+
body = line[ind:]
|
|
218
|
+
if body == "-" or body.startswith("- "):
|
|
219
|
+
return self.sequence(ind)
|
|
220
|
+
if _find_colon(body) >= 0 or body == "?" or body.startswith("? "):
|
|
221
|
+
return self.mapping(ind)
|
|
222
|
+
return self.scalar_value(
|
|
223
|
+
self.i, ind, ind - 1 if parent_indent is None else parent_indent)
|
|
224
|
+
|
|
225
|
+
def mapping(self, ind):
|
|
226
|
+
result = {}
|
|
227
|
+
while True:
|
|
228
|
+
line = self.peek()
|
|
229
|
+
if line is None or _indent(line) < ind or _is_marker(line):
|
|
230
|
+
return result
|
|
231
|
+
if _indent(line) > ind:
|
|
232
|
+
self.err("unexpected indentation")
|
|
233
|
+
body = line[ind:]
|
|
234
|
+
if body.startswith("- ") or body == "-":
|
|
235
|
+
return result
|
|
236
|
+
if body.startswith("? ") or body == "?":
|
|
237
|
+
self.err("complex mapping keys are not supported")
|
|
238
|
+
c = _find_colon(body)
|
|
239
|
+
if c < 0:
|
|
240
|
+
self.err("expected 'key: value'")
|
|
241
|
+
key_text = body[:c].strip()
|
|
242
|
+
if key_text[:1] in ("&", "*", "!"):
|
|
243
|
+
self.err("anchors, aliases and tags are not supported")
|
|
244
|
+
key = _unquote(key_text, self.i + 1) if key_text[:1] in ("'", '"') else key_text
|
|
245
|
+
if key == "<<":
|
|
246
|
+
self.err("merge keys are not supported")
|
|
247
|
+
if key in result:
|
|
248
|
+
self.err("duplicate key %r" % key)
|
|
249
|
+
rest = body[c + 1:]
|
|
250
|
+
if _strip_comment(rest.strip()) == "":
|
|
251
|
+
self.i += 1
|
|
252
|
+
nxt = self.peek()
|
|
253
|
+
if nxt is not None and _indent(nxt) > ind:
|
|
254
|
+
result[key] = self.block(ind + 1)
|
|
255
|
+
elif nxt is not None and _indent(nxt) == ind and (
|
|
256
|
+
nxt[ind:].startswith("- ") or nxt[ind:].rstrip() == "-"):
|
|
257
|
+
result[key] = self.sequence(ind)
|
|
258
|
+
else:
|
|
259
|
+
result[key] = None
|
|
260
|
+
else:
|
|
261
|
+
col = ind + c + 1 + (len(rest) - len(rest.lstrip(" ")))
|
|
262
|
+
result[key] = self.scalar_value(self.i, col, ind)
|
|
263
|
+
|
|
264
|
+
def sequence(self, ind):
|
|
265
|
+
result = []
|
|
266
|
+
while True:
|
|
267
|
+
line = self.peek()
|
|
268
|
+
if line is None or _indent(line) < ind or _is_marker(line):
|
|
269
|
+
return result
|
|
270
|
+
if _indent(line) > ind:
|
|
271
|
+
self.err("unexpected indentation")
|
|
272
|
+
body = line[ind:]
|
|
273
|
+
if not (body.startswith("- ") or body.rstrip() == "-"):
|
|
274
|
+
return result
|
|
275
|
+
rest = body[1:]
|
|
276
|
+
if _strip_comment(rest.strip()) == "":
|
|
277
|
+
self.i += 1
|
|
278
|
+
result.append(self.block(ind + 1))
|
|
279
|
+
continue
|
|
280
|
+
col = ind + 1 + (len(rest) - len(rest.lstrip(" ")))
|
|
281
|
+
# Read the item as if it started on its own line at its column.
|
|
282
|
+
self.lines[self.i] = " " * col + rest.lstrip(" ")
|
|
283
|
+
result.append(self.block(col, ind))
|
|
284
|
+
|
|
285
|
+
def scalar_value(self, start, col, parent_indent):
|
|
286
|
+
"""Parse the value at column `col` of line `start`; following lines
|
|
287
|
+
indented more than parent_indent may continue it."""
|
|
288
|
+
self.i = start
|
|
289
|
+
text = self.lines[start][col:]
|
|
290
|
+
c = text[:1]
|
|
291
|
+
if c in ("&", "*", "!"):
|
|
292
|
+
self.err("anchors, aliases and tags are not supported")
|
|
293
|
+
if c in ("|", ">"):
|
|
294
|
+
return self.block_scalar(text, parent_indent)
|
|
295
|
+
if c in ("'", '"'):
|
|
296
|
+
return self.quoted(text)
|
|
297
|
+
if c in ("[", "{"):
|
|
298
|
+
return self.flow(text)
|
|
299
|
+
if c in ("@", "`", "%"):
|
|
300
|
+
self.err("a plain value cannot start with %r" % c)
|
|
301
|
+
first = _strip_comment(text)
|
|
302
|
+
parts = [first.strip()]
|
|
303
|
+
commented = first != text.rstrip()
|
|
304
|
+
self.i += 1
|
|
305
|
+
while self.i < len(self.lines):
|
|
306
|
+
ln = self.lines[self.i]
|
|
307
|
+
if ln.strip() and (_indent(ln) <= parent_indent or ln.lstrip().startswith("#")
|
|
308
|
+
or _is_marker(ln)):
|
|
309
|
+
break
|
|
310
|
+
if ln.strip() and commented:
|
|
311
|
+
self.err("a value cannot continue after a comment")
|
|
312
|
+
part = _strip_comment(ln.strip())
|
|
313
|
+
if _find_colon(part) >= 0:
|
|
314
|
+
self.err("unexpected indentation")
|
|
315
|
+
commented = part != ln.strip()
|
|
316
|
+
parts.append(part)
|
|
317
|
+
self.i += 1
|
|
318
|
+
while len(parts) > 1 and parts[-1] == "":
|
|
319
|
+
parts.pop()
|
|
320
|
+
value = _fold(parts)
|
|
321
|
+
return None if value in ("", "~", "null", "Null", "NULL") else value
|
|
322
|
+
|
|
323
|
+
def quoted(self, text):
|
|
324
|
+
start = self.i
|
|
325
|
+
while _quote_end(text, 0) < 0:
|
|
326
|
+
self.i += 1
|
|
327
|
+
if self.i >= len(self.lines):
|
|
328
|
+
self.err("unterminated quoted string", start)
|
|
329
|
+
text += "\n" + self.lines[self.i]
|
|
330
|
+
end = _quote_end(text, 0)
|
|
331
|
+
if _strip_comment(text[end + 1:].strip()) != "":
|
|
332
|
+
self.err("unexpected text after quoted string")
|
|
333
|
+
self.i += 1
|
|
334
|
+
return _unquote(text[:end + 1], start + 1)
|
|
335
|
+
|
|
336
|
+
def block_scalar(self, header, parent_indent):
|
|
337
|
+
start = self.i
|
|
338
|
+
m = re.match(r"^([|>])(?:([1-9])([+-]?)|([+-]?)([1-9]?))\s*(#.*)?$", header)
|
|
339
|
+
if not m:
|
|
340
|
+
self.err("block scalar header %r is not supported" % header.strip())
|
|
341
|
+
style = m.group(1)
|
|
342
|
+
chomp = m.group(3) or m.group(4)
|
|
343
|
+
explicit = m.group(2) or m.group(5)
|
|
344
|
+
self.i += 1
|
|
345
|
+
lines = []
|
|
346
|
+
while self.i < len(self.lines):
|
|
347
|
+
ln = self.lines[self.i]
|
|
348
|
+
if ln.strip() and _indent(ln) <= parent_indent:
|
|
349
|
+
break
|
|
350
|
+
lines.append(ln)
|
|
351
|
+
self.i += 1
|
|
352
|
+
end = self.i
|
|
353
|
+
while lines and not lines[-1].strip():
|
|
354
|
+
lines.pop()
|
|
355
|
+
# Line breaks after the last content line (or the header, when there
|
|
356
|
+
# is none). The file's last line has none.
|
|
357
|
+
first = start + len(lines) if lines else start + 1
|
|
358
|
+
breaks = len([n for n in range(first, end) if n < len(self.lines) - 1])
|
|
359
|
+
if not lines:
|
|
360
|
+
return "\n" * breaks if chomp == "+" else ""
|
|
361
|
+
if explicit:
|
|
362
|
+
ind = max(parent_indent, 0) + int(explicit)
|
|
363
|
+
else:
|
|
364
|
+
ind = _indent(next(ln for ln in lines if ln.strip()))
|
|
365
|
+
for n, ln in enumerate(lines):
|
|
366
|
+
if ln.strip() and _indent(ln) < ind:
|
|
367
|
+
if ln[_indent(ln)] == "\t":
|
|
368
|
+
self.err("tabs in indentation are not supported", start + 1 + n)
|
|
369
|
+
self.err("block scalar line is less indented than the first", start + 1 + n)
|
|
370
|
+
body = [ln[ind:] for ln in lines]
|
|
371
|
+
if style == "|":
|
|
372
|
+
text = "\n".join(body)
|
|
373
|
+
else:
|
|
374
|
+
# Folded: lines join with a space; blank and more-indented lines
|
|
375
|
+
# keep their line breaks.
|
|
376
|
+
text = body[0]
|
|
377
|
+
for prev, ln in zip(body, body[1:]):
|
|
378
|
+
normal = prev != "" and not prev.startswith(" ")
|
|
379
|
+
if normal and ln != "" and not ln.startswith(" "):
|
|
380
|
+
text += " " + ln
|
|
381
|
+
elif normal and ln == "":
|
|
382
|
+
text += ln
|
|
383
|
+
else:
|
|
384
|
+
text += "\n" + ln
|
|
385
|
+
if chomp == "-":
|
|
386
|
+
return text
|
|
387
|
+
if chomp == "+":
|
|
388
|
+
return text + "\n" * breaks
|
|
389
|
+
return text + "\n" * min(breaks, 1)
|
|
390
|
+
|
|
391
|
+
def flow(self, text):
|
|
392
|
+
start = self.i
|
|
393
|
+
while True:
|
|
394
|
+
try:
|
|
395
|
+
value, end = _Flow(text, start + 1).parse()
|
|
396
|
+
break
|
|
397
|
+
except _Incomplete:
|
|
398
|
+
self.i += 1
|
|
399
|
+
if self.i >= len(self.lines):
|
|
400
|
+
self.err("unterminated flow collection", start)
|
|
401
|
+
text += "\n" + self.lines[self.i]
|
|
402
|
+
if _strip_comment(text[end:].strip()) != "":
|
|
403
|
+
self.err("unexpected text after flow collection")
|
|
404
|
+
self.i += 1
|
|
405
|
+
return value
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class _Incomplete(Exception):
|
|
409
|
+
pass
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
class _Flow(object):
|
|
413
|
+
"""Parser for flow collections: [a, b] and {a: b}."""
|
|
414
|
+
|
|
415
|
+
def __init__(self, text, lineno):
|
|
416
|
+
self.s = text
|
|
417
|
+
self.k = 0
|
|
418
|
+
self.lineno = lineno
|
|
419
|
+
|
|
420
|
+
def ws(self):
|
|
421
|
+
while self.k < len(self.s):
|
|
422
|
+
if self.s[self.k] in " \t\n":
|
|
423
|
+
self.k += 1
|
|
424
|
+
elif self.s[self.k] == "#" and (self.k == 0 or self.s[self.k - 1] in " \t\n"):
|
|
425
|
+
nl = self.s.find("\n", self.k)
|
|
426
|
+
if nl < 0:
|
|
427
|
+
raise _Incomplete()
|
|
428
|
+
self.k = nl
|
|
429
|
+
else:
|
|
430
|
+
return
|
|
431
|
+
raise _Incomplete()
|
|
432
|
+
|
|
433
|
+
def parse(self):
|
|
434
|
+
v = self.node()
|
|
435
|
+
return v, self.k
|
|
436
|
+
|
|
437
|
+
def node(self):
|
|
438
|
+
self.ws()
|
|
439
|
+
c = self.s[self.k]
|
|
440
|
+
if c == "[":
|
|
441
|
+
self.k += 1
|
|
442
|
+
items = []
|
|
443
|
+
while True:
|
|
444
|
+
self.ws()
|
|
445
|
+
if self.s[self.k] == "]":
|
|
446
|
+
self.k += 1
|
|
447
|
+
return items
|
|
448
|
+
items.append(self.node())
|
|
449
|
+
self.ws()
|
|
450
|
+
if self.s[self.k] == ",":
|
|
451
|
+
self.k += 1
|
|
452
|
+
elif self.s[self.k] != "]":
|
|
453
|
+
raise YamlError(self.lineno, "expected ',' or ']'")
|
|
454
|
+
if c == "{":
|
|
455
|
+
self.k += 1
|
|
456
|
+
result = {}
|
|
457
|
+
while True:
|
|
458
|
+
self.ws()
|
|
459
|
+
if self.s[self.k] == "}":
|
|
460
|
+
self.k += 1
|
|
461
|
+
return result
|
|
462
|
+
key = self.node()
|
|
463
|
+
self.ws()
|
|
464
|
+
if self.s[self.k] != ":":
|
|
465
|
+
raise YamlError(self.lineno, "expected ':' in flow mapping")
|
|
466
|
+
self.k += 1
|
|
467
|
+
self.ws()
|
|
468
|
+
val = None if self.s[self.k] in ",}" else self.node()
|
|
469
|
+
if not isinstance(key, str) or key in result:
|
|
470
|
+
raise YamlError(self.lineno, "bad or duplicate key in flow mapping")
|
|
471
|
+
result[key] = val
|
|
472
|
+
self.ws()
|
|
473
|
+
if self.s[self.k] == ",":
|
|
474
|
+
self.k += 1
|
|
475
|
+
elif self.s[self.k] != "}":
|
|
476
|
+
raise YamlError(self.lineno, "expected ',' or '}'")
|
|
477
|
+
if c in "\"'":
|
|
478
|
+
end = _quote_end(self.s, self.k)
|
|
479
|
+
if end < 0:
|
|
480
|
+
raise _Incomplete()
|
|
481
|
+
raw = self.s[self.k:end + 1]
|
|
482
|
+
self.k = end + 1
|
|
483
|
+
return _unquote(raw, self.lineno)
|
|
484
|
+
if c in "&*!?":
|
|
485
|
+
raise YamlError(self.lineno, "anchors, aliases, tags and complex keys are not supported")
|
|
486
|
+
m = re.compile(r"(?:[^,\[\]{}:\n#]|:(?![ ,\]}\n])|(?<! )#)+").match(self.s, self.k)
|
|
487
|
+
if not m:
|
|
488
|
+
raise YamlError(self.lineno, "unexpected %r in flow collection" % c)
|
|
489
|
+
self.k = m.end()
|
|
490
|
+
v = m.group(0).strip()
|
|
491
|
+
return None if v in ("", "~", "null") else v
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trust-path
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: List the paths by which untrusted input can reach secrets and publishing credentials in GitHub Actions workflows.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/jacob-adm/trust-path
|
|
7
|
+
Project-URL: Documentation, https://github.com/jacob-adm/trust-path/tree/main/docs
|
|
8
|
+
Project-URL: Source, https://github.com/jacob-adm/trust-path
|
|
9
|
+
Project-URL: Issues, https://github.com/jacob-adm/trust-path/issues
|
|
10
|
+
Keywords: github-actions,security,secrets,ci,supply-chain,cli
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Security
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# trust-path
|
|
23
|
+
|
|
24
|
+
trust-path lists the paths by which untrusted input can reach a secret or a publishing credential
|
|
25
|
+
in a repository's GitHub Actions workflows. Untrusted input is text or code that anyone can supply:
|
|
26
|
+
a pull request title, an issue body, a comment, a fork's branch name or code. A sink is what that
|
|
27
|
+
input can reach: a secret, an OIDC token (`id-token: write`), a write permission of the workflow
|
|
28
|
+
token, a deployment environment, or an AI agent action holding a credential.
|
|
29
|
+
|
|
30
|
+
Attacks in 2026 used these paths. A crafted pull request title made AI agent actions leak their
|
|
31
|
+
secrets, text in issues steered agents, and a worm read OIDC publish tokens from runner memory and
|
|
32
|
+
published packages with them. trust-path shows where such paths exist, including paths that cross
|
|
33
|
+
from one workflow to another through `workflow_run` and reusable workflows. It reports; it does not
|
|
34
|
+
change workflows or decide what to do about a path.
|
|
35
|
+
|
|
36
|
+
[zizmor](https://github.com/zizmorcore/zizmor) and [poutine](https://github.com/boostsecurityio/poutine)
|
|
37
|
+
check many more things. They report an untrusted input, a broad secret or a broad permission at the
|
|
38
|
+
place in a file where it appears. trust-path adds three things: it pairs each source with the
|
|
39
|
+
secret, permission or environment it reaches; it follows a source from one workflow to the next
|
|
40
|
+
through `workflow_run` chains and local reusable workflows; and it treats AI agent actions as
|
|
41
|
+
sinks. See [Using it with other tools](https://github.com/jacob-adm/trust-path/blob/main/docs/other-tools.md).
|
|
42
|
+
|
|
43
|
+
## Requirements
|
|
44
|
+
|
|
45
|
+
- Python 3.9 or later, standard library only.
|
|
46
|
+
- Written for Linux, macOS and Windows. The tests have been run on macOS with Python 3.9 and
|
|
47
|
+
3.14; `.github/workflows/test.yml` runs them on all three systems with Python 3.9 and 3.13
|
|
48
|
+
where GitHub Actions is enabled.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
From a clone:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
git clone https://github.com/jacob-adm/trust-path
|
|
56
|
+
cd trust-path
|
|
57
|
+
pip install .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
pip installs `trust-path` as a console script. Without installing, it runs from a clone as
|
|
61
|
+
`python3 -m trust_path`.
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
1. **Read the workflows.** trust-path reads every `.yml` and `.yaml` file in
|
|
66
|
+
`DIR/.github/workflows` with its own YAML reader, which refuses any construct it does not read
|
|
67
|
+
rather than guess. A refused file is named on standard error with the reason, the other files
|
|
68
|
+
are still checked, and the exit status is 2.
|
|
69
|
+
2. **Find untrusted runs.** A workflow runs with untrusted input when it has a trigger such as
|
|
70
|
+
`pull_request_target`, `issues` or `issue_comment`, when it runs on `workflow_run` after such a
|
|
71
|
+
workflow or after a `pull_request` workflow (followed through chains), or when it is a local
|
|
72
|
+
reusable workflow called from such a run.
|
|
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:`, `with:` or `env:`, checks out or fetches the pull
|
|
75
|
+
request's head, downloads an artifact from the upstream run, or is an AI agent action.
|
|
76
|
+
4. **Collect what it reaches.** The entry step and every later step of the same job are reached.
|
|
77
|
+
trust-path collects the secrets they use and the job's write permissions, `id-token: write`,
|
|
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`,
|
|
80
|
+
tab-separated and sorted. Like `grep`, trust-path exits 1 when it finds a path, 0 when it finds
|
|
81
|
+
none and 2 on an error, including any refused file.
|
|
82
|
+
|
|
83
|
+
## Commands
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
trust-path [--json] DIR
|
|
87
|
+
trust-path [--json] --ref REF [DIR]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`--json` writes the records as a JSON array. `--ref REF` reads the workflows from git at a branch,
|
|
91
|
+
tag or commit without checking it out; it is the only option that runs git. See [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md) for the fields and
|
|
92
|
+
exit status.
|
|
93
|
+
|
|
94
|
+
## Quick start
|
|
95
|
+
|
|
96
|
+
From a clone, run it on the test fixture with an AI agent action:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
trust-path tests/fixtures/agent
|
|
100
|
+
```
|
|
101
|
+
|
|
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
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
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.
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
- [How trust-path finds paths](https://github.com/jacob-adm/trust-path/blob/main/docs/model.md): sources, entry points, sinks, the AI agent action
|
|
119
|
+
list and the YAML subset.
|
|
120
|
+
- [Command](https://github.com/jacob-adm/trust-path/blob/main/docs/commands.md): output fields, JSON, exit status and an example across workflows.
|
|
121
|
+
- [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.
|
|
122
|
+
- [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
|
+
and git-overlap, and what zizmor and poutine cover and what trust-path adds.
|
|
124
|
+
- [Contributing](https://github.com/jacob-adm/trust-path/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
125
|
+
- [Reporting a vulnerability](https://github.com/jacob-adm/trust-path/blob/main/SECURITY.md)
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
Apache License 2.0; see [LICENSE](https://github.com/jacob-adm/trust-path/blob/main/LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
trust_path/__init__.py,sha256=labEoWw-0G5VXnYSG3gPZvrH9B30GcSxb9BJiERMp8Y,112
|
|
2
|
+
trust_path/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
trust_path/analyze.py,sha256=826qpQvK2DW5kVmWNjYMmHQ7E--JDmWUXRCFwMVmKiE,18983
|
|
4
|
+
trust_path/cli.py,sha256=9OmJWPIq9vxFhG5wfzxNYaCb8-f7RifvV5RnGeYJZRw,2306
|
|
5
|
+
trust_path/yamlsubset.py,sha256=100PCEjGOaGriPaBgFRv9RDdrnFie8WUdXB3LIyBcXw,17477
|
|
6
|
+
trust_path-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
7
|
+
trust_path-0.1.0.dist-info/METADATA,sha256=Cm5Pu4hSlPuN8MoERlO0S_sqK_Hfa5__5Uwzp0c00X0,7145
|
|
8
|
+
trust_path-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
trust_path-0.1.0.dist-info/entry_points.txt,sha256=NlftNOAX7PKdj-O8A7axBkiDM_tdjTR0TxTaqX8hBdA,51
|
|
10
|
+
trust_path-0.1.0.dist-info/top_level.txt,sha256=CqCRoYHYZru1JWWZ-Rs354JNRkXgSeS9wF-Ay5jJci0,11
|
|
11
|
+
trust_path-0.1.0.dist-info/RECORD,,
|