securebox-cli 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.
- securebox_cli/__init__.py +3 -0
- securebox_cli/api.py +86 -0
- securebox_cli/config.py +85 -0
- securebox_cli/hook.py +78 -0
- securebox_cli/ignore.py +141 -0
- securebox_cli/main.py +403 -0
- securebox_cli/output.py +87 -0
- securebox_cli/rules/starter.yml +509 -0
- securebox_cli/scan.py +291 -0
- securebox_cli/snapshot.py +221 -0
- securebox_cli/tools.py +229 -0
- securebox_cli-0.1.0.dist-info/LICENSE +202 -0
- securebox_cli-0.1.0.dist-info/METADATA +109 -0
- securebox_cli-0.1.0.dist-info/RECORD +17 -0
- securebox_cli-0.1.0.dist-info/WHEEL +5 -0
- securebox_cli-0.1.0.dist-info/entry_points.txt +2 -0
- securebox_cli-0.1.0.dist-info/top_level.txt +1 -0
securebox_cli/tools.py
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""The scanners the CLI runs, downloaded once per version into the user's cache and checked
|
|
2
|
+
against pinned SHA-256 digests (the same releases the SecureBox worker uses). Nothing is run
|
|
3
|
+
before its digest matches; `--use-path` uses copies already installed instead."""
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
import shutil
|
|
9
|
+
import tarfile
|
|
10
|
+
import tempfile
|
|
11
|
+
import zipfile
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import httpx
|
|
16
|
+
|
|
17
|
+
GITLEAKS, OPENGREP, TRIVY = "8.30.1", "2.0.0", "0.74.0"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Asset:
|
|
22
|
+
url: str
|
|
23
|
+
sha256: str
|
|
24
|
+
member: str | None # the file inside an archive; None: the download is the binary
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _plat() -> str:
|
|
28
|
+
system = platform.system().lower()
|
|
29
|
+
machine = platform.machine().lower()
|
|
30
|
+
arch = {"arm64": "arm64", "aarch64": "arm64", "x86_64": "x64", "amd64": "x64"}.get(machine)
|
|
31
|
+
return f"{system}-{arch}" if arch else f"{system}-{machine or 'unknown'}"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _gl(file: str) -> str:
|
|
35
|
+
return f"https://github.com/gitleaks/gitleaks/releases/download/v{GITLEAKS}/{file}"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _og(file: str) -> str:
|
|
39
|
+
return f"https://github.com/opengrep/opengrep/releases/download/v{OPENGREP}/{file}"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _tv(file: str) -> str:
|
|
43
|
+
return f"https://github.com/aquasecurity/trivy/releases/download/v{TRIVY}/{file}"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# SHA-256 of each release file, from the projects' published checksums (2026-12-01).
|
|
47
|
+
ASSETS: dict[str, dict[str, Asset]] = {
|
|
48
|
+
"gitleaks": {
|
|
49
|
+
"darwin-arm64": Asset(
|
|
50
|
+
_gl(f"gitleaks_{GITLEAKS}_darwin_arm64.tar.gz"),
|
|
51
|
+
"b40ab0ae55c505963e365f271a8d3846efbc170aa17f2607f13df610a9aeb6a5", "gitleaks"),
|
|
52
|
+
"darwin-x64": Asset(
|
|
53
|
+
_gl(f"gitleaks_{GITLEAKS}_darwin_x64.tar.gz"),
|
|
54
|
+
"dfe101a4db2255fc85120ac7f3d25e4342c3c20cf749f2c20a18081af1952709", "gitleaks"),
|
|
55
|
+
"linux-arm64": Asset(
|
|
56
|
+
_gl(f"gitleaks_{GITLEAKS}_linux_arm64.tar.gz"),
|
|
57
|
+
"e4a487ee7ccd7d3a7f7ec08657610aa3606637dab924210b3aee62570fb4b080", "gitleaks"),
|
|
58
|
+
"linux-x64": Asset(
|
|
59
|
+
_gl(f"gitleaks_{GITLEAKS}_linux_x64.tar.gz"),
|
|
60
|
+
"551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb", "gitleaks"),
|
|
61
|
+
"windows-x64": Asset(
|
|
62
|
+
_gl(f"gitleaks_{GITLEAKS}_windows_x64.zip"),
|
|
63
|
+
"d29144deff3a68aa93ced33dddf84b7fdc26070add4aa0f4513094c8332afc4e", "gitleaks.exe"),
|
|
64
|
+
},
|
|
65
|
+
"opengrep": {
|
|
66
|
+
"darwin-arm64": Asset(
|
|
67
|
+
_og("opengrep_osx_arm64"),
|
|
68
|
+
"b51b3d83f165a2e0934497b8f1b08abb1c3041ef20ef911c97e04cb39af1ad55", None),
|
|
69
|
+
"darwin-x64": Asset(
|
|
70
|
+
_og("opengrep_osx_x86"),
|
|
71
|
+
"51d2f918d7aad0afc1426bb4fbf56e32fc70c3ffd5ddb78e32e7d61e51c029a2", None),
|
|
72
|
+
"linux-arm64": Asset(
|
|
73
|
+
_og("opengrep_linux_aarch64"),
|
|
74
|
+
"6257b65423a744b704af2ff9beeb8f222c2f6925236af386b56b031d4c06d6d8", None),
|
|
75
|
+
"linux-x64": Asset(
|
|
76
|
+
_og("opengrep_linux_x86"),
|
|
77
|
+
"37e93f4da5fd04a18c5c1febbdd12f7e98dfccd4d0c9cf2593bcb25eeb462da0", None),
|
|
78
|
+
"windows-x64": Asset(
|
|
79
|
+
_og("opengrep_windows_x86.zip"),
|
|
80
|
+
"899a17e2b15863367cfd15032c93cdf482fd4e7ec8719c69de46f4f38b227864", "opengrep.exe"),
|
|
81
|
+
},
|
|
82
|
+
"trivy": {
|
|
83
|
+
"darwin-arm64": Asset(
|
|
84
|
+
_tv(f"trivy_{TRIVY}_macOS-ARM64.tar.gz"),
|
|
85
|
+
"1caada5e0e2091909357c7525d3aa76f4b660b13821bc143b190c7483e31cc11", "trivy"),
|
|
86
|
+
"darwin-x64": Asset(
|
|
87
|
+
_tv(f"trivy_{TRIVY}_macOS-64bit.tar.gz"),
|
|
88
|
+
"472816f6888dda689d075c30254d4210b4d1035acf365aa72332f584c2f60485", "trivy"),
|
|
89
|
+
"linux-arm64": Asset(
|
|
90
|
+
_tv(f"trivy_{TRIVY}_Linux-ARM64.tar.gz"),
|
|
91
|
+
"b94ce1976bbf3c15b514b605ee88be7c6d94a29be2302847ff01cb794d47aad5", "trivy"),
|
|
92
|
+
"linux-x64": Asset(
|
|
93
|
+
_tv(f"trivy_{TRIVY}_Linux-64bit.tar.gz"),
|
|
94
|
+
"2ae6fe3ee734b7fdf11335663e18c75ea12dccc76062f09f164a3b0f8be4371a", "trivy"),
|
|
95
|
+
"windows-x64": Asset(
|
|
96
|
+
_tv(f"trivy_{TRIVY}_windows-64bit.zip"),
|
|
97
|
+
"94c40e0696e4b907a74b7b2e1438d5d72ebaca83115817407f568a002d520842", "trivy.exe"),
|
|
98
|
+
},
|
|
99
|
+
} # fmt: skip
|
|
100
|
+
# Gitleaks' default rules, passed explicitly so a repository's .gitleaks.toml cannot turn rules
|
|
101
|
+
# off (as on the server).
|
|
102
|
+
GITLEAKS_CONFIG = Asset(
|
|
103
|
+
f"https://raw.githubusercontent.com/gitleaks/gitleaks/v{GITLEAKS}/config/gitleaks.toml",
|
|
104
|
+
"e163e53b9e7e8a8511e77271e2b323ed057759542a6d988258afe3a1fa329caf",
|
|
105
|
+
None,
|
|
106
|
+
)
|
|
107
|
+
VERSIONS = {"gitleaks": GITLEAKS, "opengrep": OPENGREP, "trivy": TRIVY}
|
|
108
|
+
MAX_DOWNLOAD_BYTES = 400 * 1024 * 1024
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class ToolError(Exception):
|
|
112
|
+
"""A scanner that cannot be made available; the message is safe to show."""
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def cache_dir() -> Path:
|
|
116
|
+
base = os.environ.get("SECUREBOX_CACHE") or os.environ.get("XDG_CACHE_HOME")
|
|
117
|
+
if base:
|
|
118
|
+
return Path(base) / "securebox"
|
|
119
|
+
if platform.system() == "Windows":
|
|
120
|
+
return Path(os.environ.get("LOCALAPPDATA", Path.home())) / "securebox" / "cache"
|
|
121
|
+
if platform.system() == "Darwin":
|
|
122
|
+
return Path.home() / "Library" / "Caches" / "securebox"
|
|
123
|
+
return Path.home() / ".cache" / "securebox"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _sha256(path: Path) -> str:
|
|
127
|
+
digest = hashlib.sha256()
|
|
128
|
+
with path.open("rb") as handle:
|
|
129
|
+
for chunk in iter(lambda: handle.read(1 << 20), b""):
|
|
130
|
+
digest.update(chunk)
|
|
131
|
+
return digest.hexdigest()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _download(asset: Asset, client: httpx.Client) -> bytes:
|
|
135
|
+
try:
|
|
136
|
+
with client.stream("GET", asset.url) as response:
|
|
137
|
+
if response.status_code != 200:
|
|
138
|
+
raise ToolError(f"Download failed ({response.status_code}): {asset.url}")
|
|
139
|
+
data = bytearray()
|
|
140
|
+
for chunk in response.iter_bytes():
|
|
141
|
+
data += chunk
|
|
142
|
+
if len(data) > MAX_DOWNLOAD_BYTES:
|
|
143
|
+
raise ToolError(f"Download too large: {asset.url}")
|
|
144
|
+
except httpx.HTTPError as exc:
|
|
145
|
+
raise ToolError(f"Could not download {asset.url}: {type(exc).__name__}") from exc
|
|
146
|
+
if hashlib.sha256(data).hexdigest() != asset.sha256:
|
|
147
|
+
raise ToolError(f"Checksum mismatch for {asset.url}: refusing to use it.")
|
|
148
|
+
return bytes(data)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _place(target: Path, data: bytes, executable: bool = False) -> None:
|
|
152
|
+
"""Write next to the target under a unique name, then rename into place (concurrent runs
|
|
153
|
+
never see or mix a partial file)."""
|
|
154
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
155
|
+
fd, tmp = tempfile.mkstemp(dir=target.parent, prefix=f".{target.name}.")
|
|
156
|
+
try:
|
|
157
|
+
with os.fdopen(fd, "wb") as handle:
|
|
158
|
+
handle.write(data)
|
|
159
|
+
if executable:
|
|
160
|
+
os.chmod(tmp, 0o755) # noqa: S103 - a program the user runs
|
|
161
|
+
os.replace(tmp, target)
|
|
162
|
+
finally:
|
|
163
|
+
if os.path.exists(tmp):
|
|
164
|
+
os.unlink(tmp)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _verified(asset: Asset, target: Path, client: httpx.Client | None) -> Path:
|
|
168
|
+
"""The download at `target`, its pinned digest checked now (fetched again if missing or
|
|
169
|
+
changed: a cached file is never trusted because it is there)."""
|
|
170
|
+
if target.is_file() and _sha256(target) == asset.sha256:
|
|
171
|
+
return target
|
|
172
|
+
own = client is None
|
|
173
|
+
http = client or httpx.Client(timeout=120, follow_redirects=True)
|
|
174
|
+
try:
|
|
175
|
+
data = _download(asset, http)
|
|
176
|
+
finally:
|
|
177
|
+
if own:
|
|
178
|
+
http.close()
|
|
179
|
+
_place(target, data, executable=asset.member is None)
|
|
180
|
+
return target
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _members(archive: Path, wanted: str, everything: bool) -> dict[str, bytes]:
|
|
184
|
+
"""The binary (or, for Windows Opengrep, every file: it needs its DLLs) of a verified
|
|
185
|
+
archive, by base name (no folders: nothing can be written outside the target folder)."""
|
|
186
|
+
found: dict[str, bytes] = {}
|
|
187
|
+
if zipfile.is_zipfile(archive):
|
|
188
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
189
|
+
for info in bundle.infolist():
|
|
190
|
+
name = Path(info.filename).name
|
|
191
|
+
if not info.is_dir() and name and (everything or name == wanted):
|
|
192
|
+
found[name] = bundle.read(info)
|
|
193
|
+
else:
|
|
194
|
+
with tarfile.open(archive, mode="r:gz") as bundle:
|
|
195
|
+
for item in bundle.getmembers():
|
|
196
|
+
name = Path(item.name).name
|
|
197
|
+
if item.isfile() and name == wanted and (handle := bundle.extractfile(item)):
|
|
198
|
+
found[name] = handle.read()
|
|
199
|
+
if wanted not in found:
|
|
200
|
+
raise ToolError(f"{wanted} not found in the download")
|
|
201
|
+
return found
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def ensure(name: str, use_path: bool = False, client: httpx.Client | None = None) -> str:
|
|
205
|
+
"""The path of a scanner to run: downloaded, its digest checked on every use (and the
|
|
206
|
+
extracted binary checked against the verified archive), or (use_path) the installed one."""
|
|
207
|
+
if use_path:
|
|
208
|
+
found = shutil.which(name)
|
|
209
|
+
if not found:
|
|
210
|
+
raise ToolError(f"{name} is not installed (drop --use-path to let securebox fetch it).")
|
|
211
|
+
return found
|
|
212
|
+
asset = ASSETS[name].get(_plat())
|
|
213
|
+
if asset is None:
|
|
214
|
+
raise ToolError(f"No {name} build for this platform ({_plat()}); use --use-path.")
|
|
215
|
+
folder = cache_dir() / "bin" / f"{name}-{VERSIONS[name]}"
|
|
216
|
+
download = _verified(asset, folder / asset.url.rsplit("/", 1)[-1], client)
|
|
217
|
+
if asset.member is None:
|
|
218
|
+
return str(download) # the download is the binary: just verified
|
|
219
|
+
files = _members(download, asset.member, everything=name == "opengrep")
|
|
220
|
+
unpacked = folder / "bin"
|
|
221
|
+
for file_name, data in files.items():
|
|
222
|
+
target = unpacked / file_name
|
|
223
|
+
if not target.is_file() or _sha256(target) != hashlib.sha256(data).hexdigest():
|
|
224
|
+
_place(target, data, executable=file_name == asset.member)
|
|
225
|
+
return str(unpacked / asset.member)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def gitleaks_config(client: httpx.Client | None = None) -> Path:
|
|
229
|
+
return _verified(GITLEAKS_CONFIG, cache_dir() / "rules" / f"gitleaks-{GITLEAKS}.toml", client)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: securebox-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SecureBox on your machine: secrets, code rules and dependencies before you push
|
|
5
|
+
Author: GTools
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://securebox.gtools.in
|
|
8
|
+
Keywords: security,sast,secrets,pre-commit,gitleaks,opengrep,trivy
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: httpx<1,>=0.27
|
|
23
|
+
Requires-Dist: pyyaml<7,>=6.0.1
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest==8.3.4; extra == "dev"
|
|
26
|
+
Requires-Dist: ruff==0.8.4; extra == "dev"
|
|
27
|
+
Requires-Dist: mypy==1.14.1; extra == "dev"
|
|
28
|
+
Requires-Dist: types-PyYAML==6.0.12.20241230; extra == "dev"
|
|
29
|
+
|
|
30
|
+
# securebox: SecureBox on your machine and in CI
|
|
31
|
+
|
|
32
|
+
Checks a repository for leaked secrets, insecure code patterns and vulnerable or malicious
|
|
33
|
+
dependencies with the same scanners and rules as SecureBox: before you commit, before you
|
|
34
|
+
push, or in a CI pipeline. Code never leaves your machine for `scan`.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pipx install securebox-cli # or: pip install securebox-cli
|
|
38
|
+
securebox scan # the whole folder
|
|
39
|
+
securebox hook install # check staged changes before every commit
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
| Command | What it does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `securebox scan [PATH]` | Secrets (Gitleaks), code rules (Opengrep) and dependencies (Trivy) of a folder. `--format json\|sarif --output FILE` for reports. |
|
|
47
|
+
| `securebox scan --staged` | Only what is about to be committed, exactly as staged (not what is in your editor): secrets on the lines the commit adds, code rules on staged files, dependencies when a manifest or lockfile changed. This is what the hook runs. |
|
|
48
|
+
| `securebox hook install` / `uninstall` | Adds or removes the repository's pre-commit hook. It will not replace another tool's hook or a linked hook, nor write into a shared `core.hooksPath` folder (use `--force`, or add `securebox scan --staged` to it yourself). Uninstall removes only the hook it wrote. Skip once with `git commit --no-verify`. |
|
|
49
|
+
| `securebox login` | Stores an organization API key (Organization → Settings → API Keys, scope `read`) in `~/.config/securebox/config.json`, readable by you only. The server URL must be `https://` (`http://` only for `localhost`). |
|
|
50
|
+
| `securebox link [PROJECT_ID]` | Ties the repository to its SecureBox project (`git config securebox.project`). |
|
|
51
|
+
| `securebox ci` | Starts a SecureBox code scan of the project's branch (as it is on the server, not this checkout; waits while another scan of the project runs) and fails on new findings at the project's level. Needs `SECUREBOX_API_KEY` (scopes `read`, `scans`) and `SECUREBOX_PROJECT`. |
|
|
52
|
+
|
|
53
|
+
Exit codes: `0` nothing blocking, `1` blocking findings, `2` the check could not run or did
|
|
54
|
+
not finish (a scanner failed, the report could not be written): never treated as a pass.
|
|
55
|
+
|
|
56
|
+
## What is checked
|
|
57
|
+
|
|
58
|
+
`scan` checks a copy of the files git would commit: tracked files and new files that are not
|
|
59
|
+
git-ignored (a local `.env` you never commit is left out; outside a git repository, every
|
|
60
|
+
file). Scanner settings in the repository (`.semgrepignore`, `.trivyignore`, `trivy.yaml`,
|
|
61
|
+
`.gitleaks.toml`, `.gitleaksignore`) are not honoured, as on the SecureBox server: use
|
|
62
|
+
`.securebox.yml` to ignore paths or rules. Test files are left out of the code rules as on
|
|
63
|
+
the server. Symbolic links are not followed.
|
|
64
|
+
|
|
65
|
+
## What blocks
|
|
66
|
+
|
|
67
|
+
Every secret, and findings at or above the failure level: `--fail-on`, else the linked
|
|
68
|
+
project's pull-request setting, else `high`.
|
|
69
|
+
|
|
70
|
+
## With an API key
|
|
71
|
+
|
|
72
|
+
Without a key the CLI uses a small public starter set of rules. With a key and a linked
|
|
73
|
+
project it uses SecureBox's full rules, the project's own rules, and stays quiet about
|
|
74
|
+
findings your team closed in SecureBox as false positive or accepted risk (secrets excepted).
|
|
75
|
+
The repository's `.securebox.yml` ignores apply with or without a key.
|
|
76
|
+
|
|
77
|
+
## Scanners
|
|
78
|
+
|
|
79
|
+
Gitleaks 8.30.1, Opengrep 2.0.0 and Trivy 0.74.0 are downloaded once into your cache folder
|
|
80
|
+
and checked against pinned SHA-256 digests before they run (`--use-path` uses copies you
|
|
81
|
+
installed); a cached copy is checked again before every run and fetched again if it changed.
|
|
82
|
+
Trivy downloads its vulnerability database on first use. Repository code is only read, never
|
|
83
|
+
run (git runs with the repository's fsmonitor, hooks, external diff and pager switched off),
|
|
84
|
+
and secret values never appear in the output (`--redact`). Rules from the server are cached
|
|
85
|
+
per version and used when SecureBox cannot be reached (`--offline` never calls it).
|
|
86
|
+
|
|
87
|
+
## Other hook managers
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
# .pre-commit-config.yaml
|
|
91
|
+
repos:
|
|
92
|
+
- repo: local
|
|
93
|
+
hooks:
|
|
94
|
+
- id: securebox
|
|
95
|
+
name: SecureBox
|
|
96
|
+
entry: securebox scan --staged
|
|
97
|
+
language: system
|
|
98
|
+
pass_filenames: false
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
// package.json (husky / lint-staged): .husky/pre-commit
|
|
103
|
+
securebox scan --staged
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Licence
|
|
107
|
+
|
|
108
|
+
Apache-2.0 (see `LICENSE`). The scanners it downloads keep their own licences: Gitleaks (MIT),
|
|
109
|
+
Opengrep (LGPL-2.1), Trivy (Apache-2.0).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
securebox_cli/__init__.py,sha256=-7XiGIOhgsAkegjxT01dK46_rNmLKWhEVRNLl1Ozm_8,86
|
|
2
|
+
securebox_cli/api.py,sha256=U1OUPVdshjphfhjHoYiPE2LWm5VkI9UPiUpjotLfyoc,3545
|
|
3
|
+
securebox_cli/config.py,sha256=IQmdYgKFhexVgcbgGvTJXcjrdQco-U5bUq-bHEGAztk,3264
|
|
4
|
+
securebox_cli/hook.py,sha256=s20jC0BAOKRRrNnTgj88kAmOkaYAmU9kpECsE9XrNxY,2929
|
|
5
|
+
securebox_cli/ignore.py,sha256=mLpy_FxsO8QMqPhkcAL343OmYfN8hPjmtOQ9T2CmoOg,5792
|
|
6
|
+
securebox_cli/main.py,sha256=mS9FVxSs58Px8ZkjxsSxC1jvjAbu8qa0B7C-E__woA8,17001
|
|
7
|
+
securebox_cli/output.py,sha256=SHs4C05vDKVq2Szdt_qfbN49lz4txH114cweNLejpdE,4160
|
|
8
|
+
securebox_cli/scan.py,sha256=MqRbv-2US77xBbPcwF8PbdVu71vnicLAav52g8ro6tI,13827
|
|
9
|
+
securebox_cli/snapshot.py,sha256=QJH9OJ9vzgs-YtAC6SPCbgKfItP01lxcScnQbYtDfI8,9271
|
|
10
|
+
securebox_cli/tools.py,sha256=JOePEcm4ZC0pqUwNmAHR3s7q8k737pM2TRgxAcu0BDc,9721
|
|
11
|
+
securebox_cli/rules/starter.yml,sha256=6wmgQghcb32JNS9HNzHLWULTfwB9l67dym1gL7_LqI4,18710
|
|
12
|
+
securebox_cli-0.1.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
13
|
+
securebox_cli-0.1.0.dist-info/METADATA,sha256=RaQzQUr0-2CA9C27QGadlRVW1Epky0jOND1ORB1IZlM,5428
|
|
14
|
+
securebox_cli-0.1.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
15
|
+
securebox_cli-0.1.0.dist-info/entry_points.txt,sha256=Y8HqB8TOAZ_byzY_nB4e1g1KnzEMcUrhbLkob7XS9dk,54
|
|
16
|
+
securebox_cli-0.1.0.dist-info/top_level.txt,sha256=Y9QQoxKcki_9ljj8WT7pPdpiwunAc5pditi4vXBINv4,14
|
|
17
|
+
securebox_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
securebox_cli
|