github-security-report 0.26.0__py3-none-any.whl → 0.28.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.
- github_security_report/_version.py +2 -2
- github_security_report/classify.py +5 -3
- github_security_report/cli/__init__.py +6 -0
- github_security_report/cli/app.py +24 -28
- github_security_report/cli/boundary.py +50 -8
- github_security_report/cli/guard.py +125 -0
- github_security_report/cli/modes.py +40 -6
- github_security_report/cli/outputs.py +7 -4
- github_security_report/cli/preflight.py +86 -87
- github_security_report/cli/preflight_messages.py +31 -12
- github_security_report/cli/remediation.py +4 -2
- github_security_report/cli/serialise.py +3 -0
- github_security_report/cli/token_scopes.py +223 -0
- github_security_report/client/__init__.py +2 -0
- github_security_report/client/alerts.py +12 -5
- github_security_report/client/batch_errors.py +2 -2
- github_security_report/client/errors.py +47 -0
- github_security_report/client/failures.py +78 -2
- github_security_report/client/repo_parser.py +8 -0
- github_security_report/client/retry.py +57 -0
- github_security_report/client/transport.py +30 -42
- github_security_report/client/writes.py +53 -7
- github_security_report/collect/workflow_runs.py +1 -0
- github_security_report/config/blocks.py +1 -0
- github_security_report/config/key_notes.py +3 -0
- github_security_report/config/schema.py +5 -0
- github_security_report/config/workflow_runs.py +3 -0
- github_security_report/contribution_refs.py +109 -0
- github_security_report/layout.py +2 -2
- github_security_report/models.py +41 -97
- github_security_report/remediate/__init__.py +76 -12
- github_security_report/remediate/model.py +6 -2
- github_security_report/render/html.py +1 -1
- github_security_report/render/markdown.py +2 -2
- github_security_report/render/slack.py +5 -4
- github_security_report/render/terminal.py +1 -101
- github_security_report/render/terminal_remediation.py +137 -0
- github_security_report/report/aggregate.py +2 -1
- github_security_report/report/signals.py +29 -2
- github_security_report/report/tables.py +18 -0
- github_security_report/runner.py +61 -24
- github_security_report/summary.py +25 -1
- github_security_report/workflow_runs/tables.py +42 -5
- {github_security_report-0.26.0.dist-info → github_security_report-0.28.0.dist-info}/METADATA +167 -55
- {github_security_report-0.26.0.dist-info → github_security_report-0.28.0.dist-info}/RECORD +48 -43
- {github_security_report-0.26.0.dist-info → github_security_report-0.28.0.dist-info}/WHEEL +0 -0
- {github_security_report-0.26.0.dist-info → github_security_report-0.28.0.dist-info}/entry_points.txt +0 -0
- {github_security_report-0.26.0.dist-info → github_security_report-0.28.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.
|
|
22
|
-
__version_tuple__ = version_tuple = (0,
|
|
21
|
+
__version__ = version = '0.28.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 28, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -13,7 +13,7 @@ Pure, transport-free logic encoding every Phase 0 finding
|
|
|
13
13
|
- secret scanning 404 = disabled, 200 [] = enabled-clean;
|
|
14
14
|
- Dependabot ``hasVulnerabilityAlertsEnabled == false`` = disabled;
|
|
15
15
|
- Scorecard prefers the external aggregate score, else code-scanning findings;
|
|
16
|
-
- 403 / indeterminate ->
|
|
16
|
+
- 403 / indeterminate, or a failed tool probe -> unknown, never clean or nag;
|
|
17
17
|
- a repository holding no fuzzable language is not applicable to fuzzing,
|
|
18
18
|
never nagged (ADR-0009);
|
|
19
19
|
- an alert read that failed (even part-way, keeping the alerts it had
|
|
@@ -170,6 +170,8 @@ def _code_scanning_tool_signal(
|
|
|
170
170
|
facts.code_scanning_status == 200 and tool_name in facts.code_scanning_tools
|
|
171
171
|
)
|
|
172
172
|
if not enabled:
|
|
173
|
+
if tool_name in facts.code_scanning_unread: # a failed probe: no evidence
|
|
174
|
+
return RepoSignal(repo, signal, RepoState.UNKNOWN, detail="indeterminate")
|
|
173
175
|
detail = (
|
|
174
176
|
"code scanning disabled"
|
|
175
177
|
if facts.code_scanning_status == 404
|
|
@@ -314,12 +316,12 @@ def classify_scorecard(
|
|
|
314
316
|
# An indeterminate external request (a 403 forbidden/blocked, a 5xx
|
|
315
317
|
# including the synthetic 503 a transport failure produces, or a forbidden
|
|
316
318
|
# code-scanning probe) is unknown, not a definitive nag. Only a clean 404
|
|
317
|
-
# with no code-scanning Scorecard data means "no results". A
|
|
319
|
+
# with no code-scanning Scorecard data means "no results". A failed
|
|
318
320
|
# Scorecard probe settles nothing either, as for the other tools.
|
|
319
321
|
if (
|
|
320
322
|
facts.code_scanning_status == 403
|
|
321
323
|
or facts.scorecard_status not in (200, 404)
|
|
322
|
-
or CODE_SCANNING_TOOLS[SignalType.SCORECARD] in facts.
|
|
324
|
+
or CODE_SCANNING_TOOLS[SignalType.SCORECARD] in facts.code_scanning_unread
|
|
323
325
|
):
|
|
324
326
|
return RepoSignal(
|
|
325
327
|
repo, SignalType.SCORECARD, RepoState.UNKNOWN, detail="indeterminate"
|
|
@@ -13,6 +13,7 @@ The command surface is split across:
|
|
|
13
13
|
- :mod:`cli.modes` -- the org, repo and remediate run modes
|
|
14
14
|
- :mod:`cli.config_cmd` -- the ``config check`` and ``config keys`` commands
|
|
15
15
|
- :mod:`cli.config_source` -- reading a configuration, reporting its errors
|
|
16
|
+
- :mod:`cli.guard` -- the exit-7 handler every command runs inside
|
|
16
17
|
- :mod:`cli.options` -- what a run takes from the command line
|
|
17
18
|
- :mod:`cli.publish` -- the Pages files, Slack digest and job summary
|
|
18
19
|
- :mod:`cli.outputs` -- offender limits, category visibility, file writing
|
|
@@ -21,6 +22,7 @@ The command surface is split across:
|
|
|
21
22
|
|
|
22
23
|
from __future__ import annotations
|
|
23
24
|
|
|
25
|
+
from github_security_report.cli import guard
|
|
24
26
|
from github_security_report.cli.app import (
|
|
25
27
|
_version_callback,
|
|
26
28
|
app,
|
|
@@ -49,6 +51,10 @@ from github_security_report.cli.serialise import _org_to_dict, _table_to_dict
|
|
|
49
51
|
# Registered here rather than in cli.app, which holds the run commands; the
|
|
50
52
|
# entry point is this package's ``app``, so the group is always present.
|
|
51
53
|
app.add_typer(config_app, name="config")
|
|
54
|
+
# Every command, these and any added later, reports an unexpected error as
|
|
55
|
+
# exit 7 rather than a traceback and exit 1. Importing cli.app, as the module
|
|
56
|
+
# form of the entry point does, runs this package first.
|
|
57
|
+
guard.install(app)
|
|
52
58
|
|
|
53
59
|
# The package façade: every name the module split moved is still importable
|
|
54
60
|
# from ``github_security_report.cli``, including the private helpers the tests
|
|
@@ -67,11 +67,6 @@ def main(
|
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def _supplied(flags: dict[str, bool]) -> list[str]:
|
|
71
|
-
"""The names of the flags a caller supplied, for the repo-mode refusal."""
|
|
72
|
-
return [name for name, supplied in flags.items() if supplied]
|
|
73
|
-
|
|
74
|
-
|
|
75
70
|
def _console(no_color: bool) -> Console:
|
|
76
71
|
"""A console that drops colour in CI, when piped, or on request.
|
|
77
72
|
|
|
@@ -138,6 +133,9 @@ def report(
|
|
|
138
133
|
"--fail-threshold",
|
|
139
134
|
help="none|low|medium|high|critical|any (repo mode).",
|
|
140
135
|
),
|
|
136
|
+
fail_on_unknown: bool = typer.Option(
|
|
137
|
+
False, "--fail-on-unknown", help="Also fail on unreadable signals (repo mode)."
|
|
138
|
+
),
|
|
141
139
|
force_notify: bool = typer.Option(
|
|
142
140
|
False, "--force-notify", help="Post to Slack regardless of report_day."
|
|
143
141
|
),
|
|
@@ -250,6 +248,7 @@ def report(
|
|
|
250
248
|
|
|
251
249
|
if mode is runner.Mode.ORG:
|
|
252
250
|
assert cfg is not None
|
|
251
|
+
boundary.reject_repo_only(console, {"--fail-on-unknown": fail_on_unknown})
|
|
253
252
|
boundary.check_releases_exclude(console, cfg, releases_exclude)
|
|
254
253
|
options = OrgRunOptions(
|
|
255
254
|
output_dir=Path(output_dir) if output_dir else None,
|
|
@@ -272,29 +271,25 @@ def report(
|
|
|
272
271
|
# into the run, so what repo mode accepts is what repo mode applies.
|
|
273
272
|
# The run-store flags are among the refused: one repository's week is
|
|
274
273
|
# read afresh each time, so they would be accepted and do nothing.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"--refresh-runs": refresh_runs,
|
|
295
|
-
}
|
|
296
|
-
),
|
|
297
|
-
)
|
|
274
|
+
org_only = {
|
|
275
|
+
"--output-dir": output_dir is not None,
|
|
276
|
+
"--pages-url": pages_url is not None,
|
|
277
|
+
"--slack-channel": slack_channel is not None,
|
|
278
|
+
"--force-notify": force_notify,
|
|
279
|
+
"--top-n-slack": top_n_slack is not None,
|
|
280
|
+
"--repo-min-age-days": repo_min_age_days is not None,
|
|
281
|
+
"--release-max-age-days": release_max_age_days is not None,
|
|
282
|
+
"--releases-exclude": bool(releases_exclude),
|
|
283
|
+
"--no-gating": no_gating,
|
|
284
|
+
"--include-archived": include_archived,
|
|
285
|
+
"--include-test": include_test,
|
|
286
|
+
"--graph-batch": graph_batch is not None,
|
|
287
|
+
"--concurrency": concurrency is not None,
|
|
288
|
+
"--no-run-cache": no_run_cache,
|
|
289
|
+
"--run-cache-dir": run_cache_dir is not None,
|
|
290
|
+
"--refresh-runs": refresh_runs,
|
|
291
|
+
}
|
|
292
|
+
boundary.reject_org_only(console, org_only)
|
|
298
293
|
code = boundary.run_guarded(
|
|
299
294
|
console,
|
|
300
295
|
_run_repo(
|
|
@@ -303,6 +298,7 @@ def report(
|
|
|
303
298
|
token_env=token_env or "GITHUB_TOKEN",
|
|
304
299
|
console=console,
|
|
305
300
|
fail_threshold=fail_threshold,
|
|
301
|
+
fail_on_unknown=fail_on_unknown,
|
|
306
302
|
report_cfg=cfg.report if cfg is not None else None,
|
|
307
303
|
limits=limits,
|
|
308
304
|
hidden=hidden,
|
|
@@ -17,7 +17,7 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import asyncio
|
|
19
19
|
import re
|
|
20
|
-
from collections.abc import Coroutine, Sequence
|
|
20
|
+
from collections.abc import Coroutine, Mapping, Sequence
|
|
21
21
|
from typing import Any
|
|
22
22
|
|
|
23
23
|
import typer
|
|
@@ -25,8 +25,18 @@ from rich.console import Console
|
|
|
25
25
|
|
|
26
26
|
from github_security_report import gitctx, runner
|
|
27
27
|
from github_security_report.categories import CategoryKey
|
|
28
|
-
from github_security_report.cli.modes import
|
|
29
|
-
|
|
28
|
+
from github_security_report.cli.modes import (
|
|
29
|
+
_abort_auth,
|
|
30
|
+
_abort_graph_rate_limit,
|
|
31
|
+
_abort_network,
|
|
32
|
+
_abort_rate_limit,
|
|
33
|
+
)
|
|
34
|
+
from github_security_report.client import (
|
|
35
|
+
AuthError,
|
|
36
|
+
GraphBatchError,
|
|
37
|
+
NetworkError,
|
|
38
|
+
RateLimitError,
|
|
39
|
+
)
|
|
30
40
|
from github_security_report.config import Config
|
|
31
41
|
from github_security_report.matching import compile_patterns
|
|
32
42
|
|
|
@@ -115,7 +125,7 @@ def resolve_hidden(console: Console, hide: list[str] | None) -> frozenset[Catego
|
|
|
115
125
|
return frozenset(valid[name] for name in hide)
|
|
116
126
|
|
|
117
127
|
|
|
118
|
-
def reject_org_only(console: Console,
|
|
128
|
+
def reject_org_only(console: Console, flags: Mapping[str, bool]) -> None:
|
|
119
129
|
"""Refuse organisation-only flags once the run has resolved to repo mode.
|
|
120
130
|
|
|
121
131
|
Repo mode renders a single repository to the terminal and the job summary:
|
|
@@ -123,8 +133,10 @@ def reject_org_only(console: Console, supplied: Sequence[str]) -> None:
|
|
|
123
133
|
Releases/Tagging table, so none of these flags has anything to act on.
|
|
124
134
|
Accepting them silently is the one failure mode worth ruling out -- the
|
|
125
135
|
caller would have no signal that the run ignored what they asked for -- so
|
|
126
|
-
they are rejected with the flags named rather than dropped.
|
|
136
|
+
they are rejected with the flags named rather than dropped. ``flags``
|
|
137
|
+
maps each flag to whether the caller supplied it.
|
|
127
138
|
"""
|
|
139
|
+
supplied = [name for name, given in flags.items() if given]
|
|
128
140
|
if not supplied:
|
|
129
141
|
return
|
|
130
142
|
console.print(
|
|
@@ -137,6 +149,27 @@ def reject_org_only(console: Console, supplied: Sequence[str]) -> None:
|
|
|
137
149
|
raise typer.Exit(2)
|
|
138
150
|
|
|
139
151
|
|
|
152
|
+
def reject_repo_only(console: Console, flags: Mapping[str, bool]) -> None:
|
|
153
|
+
"""Refuse repo-mode-only flags once the run has resolved to organisation mode.
|
|
154
|
+
|
|
155
|
+
The counterpart of :func:`reject_org_only`: organisation mode has no
|
|
156
|
+
repo-mode gate for these flags to act on, so they are rejected with the
|
|
157
|
+
flags named rather than accepted and ignored. ``flags`` maps each flag to
|
|
158
|
+
whether the caller supplied it.
|
|
159
|
+
"""
|
|
160
|
+
supplied = [name for name, given in flags.items() if given]
|
|
161
|
+
if not supplied:
|
|
162
|
+
return
|
|
163
|
+
console.print(
|
|
164
|
+
f"{', '.join(supplied)} apply to repo mode only, but this run resolved "
|
|
165
|
+
"to organisation mode. Drop the flag, or pass --scope repo with the "
|
|
166
|
+
"repository to gate.",
|
|
167
|
+
style="red",
|
|
168
|
+
markup=False,
|
|
169
|
+
)
|
|
170
|
+
raise typer.Exit(2)
|
|
171
|
+
|
|
172
|
+
|
|
140
173
|
def check_patterns(console: Console, name: str, patterns: Sequence[str] | None) -> None:
|
|
141
174
|
"""Reject an empty or uncompilable name pattern given on the command line.
|
|
142
175
|
|
|
@@ -224,13 +257,22 @@ def resolve_mode(
|
|
|
224
257
|
def run_guarded(console: Console, coro: Coroutine[Any, Any, int]) -> int:
|
|
225
258
|
"""Run a mode coroutine, turning credential and network failures into exits.
|
|
226
259
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
"retry later" without
|
|
260
|
+
Every mode needs the same handlers, and they distinguish the causes by
|
|
261
|
+
exit code so an automated caller can tell "rotate the token" (4) from
|
|
262
|
+
"wait for the rate limit to reset" (6) and "retry later" (3) without
|
|
263
|
+
parsing the message. A spent rate limit exits 6 whichever API reported
|
|
264
|
+
it: a REST read refused by its budget, or a GraphQL prefetch refused by
|
|
265
|
+
a GraphQL rate limit.
|
|
230
266
|
"""
|
|
231
267
|
try:
|
|
232
268
|
return asyncio.run(coro)
|
|
233
269
|
except AuthError as exc:
|
|
234
270
|
_abort_auth(console, exc)
|
|
271
|
+
except RateLimitError as exc:
|
|
272
|
+
_abort_rate_limit(console, exc)
|
|
273
|
+
except GraphBatchError as exc:
|
|
274
|
+
if exc.rate_limited:
|
|
275
|
+
_abort_graph_rate_limit(console, exc)
|
|
276
|
+
_abort_network(console, exc)
|
|
235
277
|
except NetworkError as exc:
|
|
236
278
|
_abort_network(console, exc)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
"""The net beneath every command: an unexpected error exits 7, not 1.
|
|
4
|
+
|
|
5
|
+
Exit 1 means "findings met the repo-mode gate", so a traceback that escaped
|
|
6
|
+
to the interpreter would read to an automated caller as a failed gate. Every
|
|
7
|
+
command runs inside :meth:`GuardedGroup.invoke`, the root group's dispatch,
|
|
8
|
+
so a command added later is covered without registering anything.
|
|
9
|
+
|
|
10
|
+
What already has a meaning passes through untouched: Typer's own exits,
|
|
11
|
+
aborts and usage errors keep their codes, and ``KeyboardInterrupt`` and
|
|
12
|
+
``asyncio.CancelledError`` are not :class:`Exception` subclasses at all.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import errno
|
|
18
|
+
import traceback
|
|
19
|
+
from collections.abc import Sequence
|
|
20
|
+
from typing import TYPE_CHECKING, Any
|
|
21
|
+
|
|
22
|
+
import typer
|
|
23
|
+
from rich.console import Console
|
|
24
|
+
|
|
25
|
+
# Typer vendors Click; this is the base of its usage errors in every release
|
|
26
|
+
# the project and its type-checking hook pin.
|
|
27
|
+
from typer._click.exceptions import ClickException
|
|
28
|
+
from typer.core import TyperGroup
|
|
29
|
+
|
|
30
|
+
from github_security_report.cli.progress import interactive
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from typer._click import Context
|
|
34
|
+
|
|
35
|
+
INTERNAL_ERROR = 7
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _passes_through(exc: Exception) -> bool:
|
|
39
|
+
"""Whether ``exc`` already carries its own exit code and message."""
|
|
40
|
+
if isinstance(exc, typer.Exit | typer.Abort | ClickException):
|
|
41
|
+
return True
|
|
42
|
+
# A closed pipe has its own quiet handling in Typer's main loop.
|
|
43
|
+
return isinstance(exc, OSError) and exc.errno == errno.EPIPE
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _no_color(args: Sequence[str]) -> bool:
|
|
47
|
+
"""Whether the subcommand's own arguments ask for ``--no-color``."""
|
|
48
|
+
if "--" in args:
|
|
49
|
+
args = args[: list(args).index("--")]
|
|
50
|
+
return "--no-color" in args
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def report_internal_error(
|
|
54
|
+
console: Console, exc: Exception, *, command: str | None, verbose: bool
|
|
55
|
+
) -> None:
|
|
56
|
+
"""Print the short internal-error message, and with ``verbose`` the trace.
|
|
57
|
+
|
|
58
|
+
The traceback is formatted without frame locals: a frame on the request
|
|
59
|
+
path can hold a token.
|
|
60
|
+
"""
|
|
61
|
+
if verbose:
|
|
62
|
+
console.print(
|
|
63
|
+
"".join(traceback.format_exception(exc)).rstrip(),
|
|
64
|
+
markup=False,
|
|
65
|
+
highlight=False,
|
|
66
|
+
emoji=False,
|
|
67
|
+
soft_wrap=True,
|
|
68
|
+
)
|
|
69
|
+
detail = str(exc).strip()
|
|
70
|
+
lines = [
|
|
71
|
+
f"Internal error: {type(exc).__name__}"
|
|
72
|
+
+ (f": {detail.splitlines()[0]}" if detail else ""),
|
|
73
|
+
"This is an unexpected failure in github-security-report, not a "
|
|
74
|
+
"finding. Output files this run wrote may be incomplete: do not "
|
|
75
|
+
"publish them.",
|
|
76
|
+
]
|
|
77
|
+
if command == "remediate":
|
|
78
|
+
lines.append(
|
|
79
|
+
"Changes remediate made before the error stand: check what the "
|
|
80
|
+
"run printed above before re-running."
|
|
81
|
+
)
|
|
82
|
+
if not verbose:
|
|
83
|
+
lines.append("Re-run with --verbose to see the traceback.")
|
|
84
|
+
console.print(
|
|
85
|
+
"\n".join(lines),
|
|
86
|
+
style="red",
|
|
87
|
+
markup=False,
|
|
88
|
+
highlight=False,
|
|
89
|
+
emoji=False,
|
|
90
|
+
soft_wrap=True,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class GuardedGroup(TyperGroup):
|
|
95
|
+
"""The root command group: turns an unexpected error into exit 7."""
|
|
96
|
+
|
|
97
|
+
def invoke(self, ctx: Context) -> Any:
|
|
98
|
+
"""Dispatch to the subcommand, reporting any error nothing handled."""
|
|
99
|
+
# Read before dispatch, which empties ctx.args: what follows the
|
|
100
|
+
# subcommand's name, so the message honours its --no-color.
|
|
101
|
+
no_color = _no_color(ctx.args)
|
|
102
|
+
try:
|
|
103
|
+
return super().invoke(ctx)
|
|
104
|
+
except Exception as exc:
|
|
105
|
+
if _passes_through(exc):
|
|
106
|
+
raise
|
|
107
|
+
# Built as every command builds its own, on the same stream.
|
|
108
|
+
console = Console(no_color=no_color or not interactive(), highlight=False)
|
|
109
|
+
report_internal_error(
|
|
110
|
+
console,
|
|
111
|
+
exc,
|
|
112
|
+
command=ctx.invoked_subcommand,
|
|
113
|
+
verbose=bool(ctx.params.get("verbose")),
|
|
114
|
+
)
|
|
115
|
+
raise typer.Exit(INTERNAL_ERROR) from None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def install(app: typer.Typer) -> None:
|
|
119
|
+
"""Route every command of ``app`` through :class:`GuardedGroup`.
|
|
120
|
+
|
|
121
|
+
Also turns off frame locals in Typer's own exception rendering, whatever
|
|
122
|
+
this Typer version's default, for anything that still reaches it.
|
|
123
|
+
"""
|
|
124
|
+
app.info.cls = GuardedGroup
|
|
125
|
+
app.pretty_exceptions_show_locals = False
|
|
@@ -41,9 +41,16 @@ from github_security_report.cli.outputs import (
|
|
|
41
41
|
show,
|
|
42
42
|
windows,
|
|
43
43
|
)
|
|
44
|
+
from github_security_report.cli.preflight_messages import spent_budget_message
|
|
44
45
|
from github_security_report.cli.progress import make_tracker
|
|
45
46
|
from github_security_report.cli.summary import RunSummary, print_run_summary
|
|
46
|
-
from github_security_report.client import
|
|
47
|
+
from github_security_report.client import (
|
|
48
|
+
AuthError,
|
|
49
|
+
GitHubClient,
|
|
50
|
+
GraphBatchError,
|
|
51
|
+
NetworkError,
|
|
52
|
+
RateLimitError,
|
|
53
|
+
)
|
|
47
54
|
from github_security_report.collect.context import CollectExtras
|
|
48
55
|
from github_security_report.collect.workflow_runs import (
|
|
49
56
|
attach_workflow_failures,
|
|
@@ -145,6 +152,29 @@ def _abort_auth(console: Console, exc: AuthError) -> NoReturn:
|
|
|
145
152
|
raise typer.Exit(4)
|
|
146
153
|
|
|
147
154
|
|
|
155
|
+
def _abort_rate_limit(console: Console, exc: RateLimitError) -> NoReturn:
|
|
156
|
+
"""Abort the run on a read refused because a rate limit is spent.
|
|
157
|
+
|
|
158
|
+
Exits with the pre-flight's rate-limit code (6), mid-run as before it:
|
|
159
|
+
every later read would be refused the same way, and a report made of
|
|
160
|
+
unknowns would be published over the last good one.
|
|
161
|
+
"""
|
|
162
|
+
message = spent_budget_message(exc, dt.datetime.now(dt.UTC))
|
|
163
|
+
console.print(message, style="red", markup=False)
|
|
164
|
+
raise typer.Exit(preflight.EXIT_RATE_LIMITED)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _abort_graph_rate_limit(console: Console, exc: GraphBatchError) -> NoReturn:
|
|
168
|
+
"""Abort on a GraphQL prefetch refused for a spent GraphQL rate limit.
|
|
169
|
+
|
|
170
|
+
The message is the batch error's own; only the exit code (6) differs from
|
|
171
|
+
any other failed prefetch (3), so a rate limit reads the same whichever
|
|
172
|
+
API reported it.
|
|
173
|
+
"""
|
|
174
|
+
console.print(str(exc), style="red", markup=False)
|
|
175
|
+
raise typer.Exit(preflight.EXIT_RATE_LIMITED)
|
|
176
|
+
|
|
177
|
+
|
|
148
178
|
async def _collect_reports(
|
|
149
179
|
cfg: Config,
|
|
150
180
|
*,
|
|
@@ -284,6 +314,7 @@ async def _run_repo(
|
|
|
284
314
|
token_env: str,
|
|
285
315
|
console: Console,
|
|
286
316
|
fail_threshold: str,
|
|
317
|
+
fail_on_unknown: bool = False,
|
|
287
318
|
report_cfg: ReportConfig | None = None,
|
|
288
319
|
limits: TopNLimits | None = None,
|
|
289
320
|
hidden: frozenset[CategoryKey] = frozenset(),
|
|
@@ -371,16 +402,17 @@ async def _run_repo(
|
|
|
371
402
|
windows=windows(cfg, "report"),
|
|
372
403
|
)
|
|
373
404
|
)
|
|
374
|
-
|
|
405
|
+
decision = runner.gate(signals, fail_threshold, fail_on_unknown=fail_on_unknown)
|
|
406
|
+
outputs = repo_outputs(signals, decision)
|
|
375
407
|
# Keep the action's declared outputs stable across modes.
|
|
376
408
|
outputs["should_notify"] = "false"
|
|
377
409
|
outputs["slack_payload"] = ""
|
|
378
410
|
runner.write_github_output(outputs)
|
|
379
411
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return 0
|
|
412
|
+
# markup=False: a signal's recorded reason is printed literally.
|
|
413
|
+
for reason in decision.reasons:
|
|
414
|
+
console.print(f"Failing: {reason}", style="red", markup=False)
|
|
415
|
+
return 1 if decision.failed else 0
|
|
384
416
|
|
|
385
417
|
|
|
386
418
|
# The remediate mode lives in its own module; re-exported so the command and
|
|
@@ -392,7 +424,9 @@ from github_security_report.cli.remediation import ( # noqa: E402
|
|
|
392
424
|
|
|
393
425
|
__all__ = [
|
|
394
426
|
"_abort_auth",
|
|
427
|
+
"_abort_graph_rate_limit",
|
|
395
428
|
"_abort_network",
|
|
429
|
+
"_abort_rate_limit",
|
|
396
430
|
"_check_selection",
|
|
397
431
|
"_collect_reports",
|
|
398
432
|
"_load_config",
|
|
@@ -17,7 +17,7 @@ from github_security_report.models import RepoSignal
|
|
|
17
17
|
from github_security_report.render import html as html_render
|
|
18
18
|
from github_security_report.render import markdown as md_render
|
|
19
19
|
from github_security_report.report import FooterOptions, LimitFor, OrgReport, WindowsFor
|
|
20
|
-
from github_security_report.runner import
|
|
20
|
+
from github_security_report.runner import GateDecision
|
|
21
21
|
|
|
22
22
|
# Keep filenames within output_dir: a channel value containing "/" or ".."
|
|
23
23
|
# (misconfiguration or hostile input) must not escape the directory.
|
|
@@ -312,8 +312,11 @@ def write_org_files(
|
|
|
312
312
|
)
|
|
313
313
|
|
|
314
314
|
|
|
315
|
-
def repo_outputs(signals: list[RepoSignal],
|
|
316
|
-
"""The GitHub Actions outputs a repo-mode run publishes.
|
|
315
|
+
def repo_outputs(signals: list[RepoSignal], decision: GateDecision) -> dict[str, str]:
|
|
316
|
+
"""The GitHub Actions outputs a repo-mode run publishes.
|
|
317
|
+
|
|
318
|
+
``failed`` comes from the same gate decision as the exit code.
|
|
319
|
+
"""
|
|
317
320
|
outputs = {s.signal.value + "_open": str(s.counts.total) for s in signals}
|
|
318
|
-
outputs["failed"] = "true" if
|
|
321
|
+
outputs["failed"] = "true" if decision.failed else "false"
|
|
319
322
|
return outputs
|