shirudo-python 0.1.0rc1__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.
- shirudo_python/__init__.py +24 -0
- shirudo_python/_reader.py +215 -0
- shirudo_python/_summary.py +101 -0
- shirudo_python/py.typed +0 -0
- shirudo_python/report.py +204 -0
- shirudo_python-0.1.0rc1.dist-info/METADATA +71 -0
- shirudo_python-0.1.0rc1.dist-info/RECORD +10 -0
- shirudo_python-0.1.0rc1.dist-info/WHEEL +5 -0
- shirudo_python-0.1.0rc1.dist-info/licenses/LICENSE +24 -0
- shirudo_python-0.1.0rc1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Read saved Shirudo status reports."""
|
|
2
|
+
|
|
3
|
+
from ._reader import MAX_REPORT_BYTES, StatusLimitError, parse_status_bounded, parse_status_report
|
|
4
|
+
from ._summary import (
|
|
5
|
+
StatusFormatError,
|
|
6
|
+
StatusSummary,
|
|
7
|
+
UnsupportedSchemaError,
|
|
8
|
+
parse_status,
|
|
9
|
+
)
|
|
10
|
+
from .report import MISSING, Missing, StatusReport
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"MAX_REPORT_BYTES",
|
|
14
|
+
"MISSING",
|
|
15
|
+
"Missing",
|
|
16
|
+
"StatusFormatError",
|
|
17
|
+
"StatusLimitError",
|
|
18
|
+
"StatusReport",
|
|
19
|
+
"StatusSummary",
|
|
20
|
+
"UnsupportedSchemaError",
|
|
21
|
+
"parse_status",
|
|
22
|
+
"parse_status_bounded",
|
|
23
|
+
"parse_status_report",
|
|
24
|
+
]
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""Decode the wire types declared by the schema-1 status models."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from dataclasses import fields, is_dataclass
|
|
7
|
+
from types import MappingProxyType, UnionType
|
|
8
|
+
from typing import Any, TypeVar, get_args, get_origin
|
|
9
|
+
|
|
10
|
+
from ._summary import (
|
|
11
|
+
StatusFormatError,
|
|
12
|
+
StatusSummary,
|
|
13
|
+
UnsupportedSchemaError,
|
|
14
|
+
_read_summary,
|
|
15
|
+
_reject_constant,
|
|
16
|
+
_unique_object,
|
|
17
|
+
)
|
|
18
|
+
from .report import MISSING, Event, Missing, StatusReport, UpatchTree
|
|
19
|
+
|
|
20
|
+
MAX_REPORT_BYTES = 8 * 1024 * 1024 # Upstream's maximum JSON output buffer.
|
|
21
|
+
MAX_REPORT_DEPTH = 64
|
|
22
|
+
MAX_REPORT_STRUCTURAL_TOKENS = 262_144
|
|
23
|
+
_Record = TypeVar("_Record")
|
|
24
|
+
_SURROGATE = re.compile("[\ud800-\udfff]")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class StatusLimitError(StatusFormatError):
|
|
28
|
+
"""A report exceeds a bounded reader's input limits."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _bounded_text(payload: str | bytes) -> str:
|
|
32
|
+
if not isinstance(payload, (str, bytes)):
|
|
33
|
+
raise TypeError("payload must be str or bytes")
|
|
34
|
+
if len(payload) > MAX_REPORT_BYTES:
|
|
35
|
+
raise StatusLimitError("Status report exceeds the 8 MiB limit")
|
|
36
|
+
if isinstance(payload, bytes):
|
|
37
|
+
return payload.decode("utf-8")
|
|
38
|
+
if not payload.isascii() and len(payload.encode("utf-8")) > MAX_REPORT_BYTES:
|
|
39
|
+
raise StatusLimitError("Status report exceeds the 8 MiB limit")
|
|
40
|
+
return payload
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _check_structure(text: str) -> None:
|
|
44
|
+
# Count before json.loads allocates a list or dict for each container.
|
|
45
|
+
# The JSON decoder handles syntax. Escaped quotes and brackets inside
|
|
46
|
+
# strings must not affect either limit.
|
|
47
|
+
depth = tokens = 0
|
|
48
|
+
in_string = escaped = False
|
|
49
|
+
for char in text:
|
|
50
|
+
if in_string:
|
|
51
|
+
if escaped:
|
|
52
|
+
escaped = False
|
|
53
|
+
elif char == "\\":
|
|
54
|
+
escaped = True
|
|
55
|
+
elif char == '"':
|
|
56
|
+
in_string = False
|
|
57
|
+
elif char == '"':
|
|
58
|
+
in_string = True
|
|
59
|
+
elif char in "{[":
|
|
60
|
+
depth += 1
|
|
61
|
+
tokens += 1
|
|
62
|
+
if depth > MAX_REPORT_DEPTH:
|
|
63
|
+
raise StatusLimitError("Status report exceeds the nesting limit")
|
|
64
|
+
elif char in "}]":
|
|
65
|
+
depth -= 1
|
|
66
|
+
if depth < 0:
|
|
67
|
+
raise StatusFormatError("Unexpected closing bracket in status JSON")
|
|
68
|
+
elif char == ",":
|
|
69
|
+
tokens += 1
|
|
70
|
+
if tokens > MAX_REPORT_STRUCTURAL_TOKENS:
|
|
71
|
+
raise StatusLimitError("Status report exceeds the structural token limit")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _bounded_int(token: str) -> int:
|
|
75
|
+
# Upstream emits at most 64-bit integers. Bound conversion work even on
|
|
76
|
+
# Python builds where the interpreter's decimal conversion cap is disabled.
|
|
77
|
+
if len(token.lstrip("-")) > 128:
|
|
78
|
+
raise StatusLimitError("Status JSON integer exceeds 128 digits")
|
|
79
|
+
return int(token)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _value(spec: Any, value: Any, path: str) -> Any:
|
|
83
|
+
# Model fields use one concrete type, optionally unioned with None and/or
|
|
84
|
+
# Missing. Compare exact scalar types because bool is a subclass of int.
|
|
85
|
+
origin = get_origin(spec)
|
|
86
|
+
args = get_args(spec)
|
|
87
|
+
if origin is UnionType:
|
|
88
|
+
if value is MISSING and Missing in args:
|
|
89
|
+
return MISSING
|
|
90
|
+
if value is None and type(None) in args:
|
|
91
|
+
return None
|
|
92
|
+
spec = next((t for t in args if t not in (Missing, type(None))), None)
|
|
93
|
+
origin = get_origin(spec)
|
|
94
|
+
args = get_args(spec)
|
|
95
|
+
|
|
96
|
+
if value is MISSING:
|
|
97
|
+
raise StatusFormatError(f"Missing field {path}")
|
|
98
|
+
if spec in (str, bool, int):
|
|
99
|
+
if type(value) is spec:
|
|
100
|
+
return value
|
|
101
|
+
raise StatusFormatError(f"{path}: expected {spec.__name__}")
|
|
102
|
+
if origin is tuple:
|
|
103
|
+
if not isinstance(value, list):
|
|
104
|
+
raise StatusFormatError(f"{path}: expected array")
|
|
105
|
+
return tuple(
|
|
106
|
+
_value(args[0], item, f"{path}[{i}]") for i, item in enumerate(value)
|
|
107
|
+
)
|
|
108
|
+
if origin is Mapping:
|
|
109
|
+
if not isinstance(value, dict):
|
|
110
|
+
raise StatusFormatError(f"{path}: expected object")
|
|
111
|
+
# json.loads owns this dict; it is never exposed until the read-only
|
|
112
|
+
# proxy is returned. The two map-valued fields have scalar values.
|
|
113
|
+
for key, item in value.items():
|
|
114
|
+
if type(item) is not args[1]:
|
|
115
|
+
raise StatusFormatError(
|
|
116
|
+
f"{path}[{key[:80]!r}]: expected {args[1].__name__}"
|
|
117
|
+
)
|
|
118
|
+
return MappingProxyType(value)
|
|
119
|
+
if isinstance(spec, type) and is_dataclass(spec):
|
|
120
|
+
return _record(spec, value, path)
|
|
121
|
+
raise StatusFormatError(f"{path}: expected null")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _record(cls: type[_Record], document: Any, path: str, **values: Any) -> _Record:
|
|
125
|
+
if not is_dataclass(cls):
|
|
126
|
+
raise TypeError(f"Expected a report dataclass, got {cls}")
|
|
127
|
+
if not isinstance(document, dict):
|
|
128
|
+
raise StatusFormatError(f"{path}: expected object")
|
|
129
|
+
for field in fields(cls):
|
|
130
|
+
if field.name not in values:
|
|
131
|
+
values[field.name] = _value(
|
|
132
|
+
field.type, document.get(field.name, MISSING), f"{path}.{field.name}"
|
|
133
|
+
)
|
|
134
|
+
record = cls(**values)
|
|
135
|
+
if isinstance(record, Event) and record.type != "unparseable":
|
|
136
|
+
_require_fields(record, path, ("ts", "digest"))
|
|
137
|
+
if isinstance(record, UpatchTree):
|
|
138
|
+
state_fields = (
|
|
139
|
+
"tree_id",
|
|
140
|
+
"generation",
|
|
141
|
+
"last_seq",
|
|
142
|
+
"projection_root",
|
|
143
|
+
"manifest_digest",
|
|
144
|
+
)
|
|
145
|
+
if record.state is MISSING:
|
|
146
|
+
_require_fields(record, path, state_fields)
|
|
147
|
+
elif any(getattr(record, name) is not MISSING for name in state_fields):
|
|
148
|
+
raise StatusFormatError(
|
|
149
|
+
f"{path}.state: null conflicts with tree state fields"
|
|
150
|
+
)
|
|
151
|
+
return record
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _require_fields(record: object, path: str, names: tuple[str, ...]) -> None:
|
|
155
|
+
for name in names:
|
|
156
|
+
if getattr(record, name) is MISSING:
|
|
157
|
+
raise StatusFormatError(f"Missing field {path}.{name}")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _bounded_document(payload: str | bytes) -> object:
|
|
161
|
+
try:
|
|
162
|
+
text = _bounded_text(payload)
|
|
163
|
+
_check_structure(text)
|
|
164
|
+
return json.loads(
|
|
165
|
+
text,
|
|
166
|
+
object_pairs_hook=_unique_object,
|
|
167
|
+
parse_constant=_reject_constant,
|
|
168
|
+
parse_int=_bounded_int,
|
|
169
|
+
)
|
|
170
|
+
except StatusFormatError:
|
|
171
|
+
raise
|
|
172
|
+
except (ValueError, RecursionError) as exc:
|
|
173
|
+
raise StatusFormatError(f"Invalid status JSON: {exc}") from exc
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _check_unicode(value: object) -> None:
|
|
177
|
+
# Python's JSON decoder combines valid surrogate pairs but also accepts
|
|
178
|
+
# isolated halves. Those cannot be represented losslessly in a Go string
|
|
179
|
+
# of UTF-8 text. The structural preflight already bounded this traversal.
|
|
180
|
+
if isinstance(value, str):
|
|
181
|
+
if not value.isascii() and _SURROGATE.search(value):
|
|
182
|
+
raise StatusFormatError("Status JSON contains an isolated surrogate")
|
|
183
|
+
elif isinstance(value, list):
|
|
184
|
+
for item in value:
|
|
185
|
+
_check_unicode(item)
|
|
186
|
+
elif isinstance(value, dict):
|
|
187
|
+
for key, item in value.items():
|
|
188
|
+
_check_unicode(key)
|
|
189
|
+
_check_unicode(item)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def parse_status_bounded(payload: str | bytes) -> StatusSummary:
|
|
193
|
+
"""Read the seven summary fields using the cross-language resource profile."""
|
|
194
|
+
document = _bounded_document(payload)
|
|
195
|
+
_check_unicode(document)
|
|
196
|
+
return _read_summary(document, unsupported=UnsupportedSchemaError)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def parse_status_report(payload: str | bytes) -> StatusReport:
|
|
200
|
+
"""Read a complete schema-1 status report from JSON text or UTF-8 bytes.
|
|
201
|
+
|
|
202
|
+
Additional fields are ignored. Arrays and maps in the result are read-only.
|
|
203
|
+
Malformed documents and inputs exceeding the reader limits raise
|
|
204
|
+
StatusFormatError. An unsupported integer schema raises UnsupportedSchemaError.
|
|
205
|
+
"""
|
|
206
|
+
document = _bounded_document(payload)
|
|
207
|
+
summary = _read_summary(document, unsupported=UnsupportedSchemaError)
|
|
208
|
+
report = _record(StatusReport, document, "$", summary=summary)
|
|
209
|
+
for name, keyring, role in (
|
|
210
|
+
("bpf_keyring", report.bpf_keyring, "primary"),
|
|
211
|
+
("dm_verity_keyring", report.dm_verity_keyring, "config"),
|
|
212
|
+
):
|
|
213
|
+
for index, cert in enumerate(keyring.certs):
|
|
214
|
+
_require_fields(cert, f"$.{name}.certs[{index}]", (role,))
|
|
215
|
+
return report
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Read saved Shirudo status reports."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import NoReturn, TypeVar
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StatusFormatError(ValueError):
|
|
9
|
+
"""The input cannot be read as a Shirudo status document."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class UnsupportedSchemaError(StatusFormatError):
|
|
13
|
+
"""The report declares an unsupported integer schema version."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True, slots=True)
|
|
17
|
+
class StatusSummary:
|
|
18
|
+
"""The identity, roles, and verdict reported by `shirudo status --json`."""
|
|
19
|
+
|
|
20
|
+
schema: int
|
|
21
|
+
version_id: str
|
|
22
|
+
host: str
|
|
23
|
+
status: str
|
|
24
|
+
is_target: bool
|
|
25
|
+
is_operator: bool
|
|
26
|
+
reason: str | None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
|
|
30
|
+
result = {}
|
|
31
|
+
for name, value in pairs:
|
|
32
|
+
if name in result:
|
|
33
|
+
raise StatusFormatError(f"Duplicate JSON key {name[:80]!r}")
|
|
34
|
+
result[name] = value
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _reject_constant(token: str) -> NoReturn:
|
|
39
|
+
raise StatusFormatError(f"Invalid JSON constant {token!r}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def parse_status(payload: str | bytes) -> StatusSummary:
|
|
43
|
+
"""Read a JSON document from text or UTF-8 bytes.
|
|
44
|
+
|
|
45
|
+
Validate the summary fields and ignore additional fields. Raise
|
|
46
|
+
StatusFormatError for malformed documents and unsupported schema versions.
|
|
47
|
+
"""
|
|
48
|
+
if not isinstance(payload, (str, bytes)):
|
|
49
|
+
raise TypeError("payload must be str or bytes")
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
if isinstance(payload, bytes):
|
|
53
|
+
payload = payload.decode("utf-8")
|
|
54
|
+
document = json.loads(
|
|
55
|
+
payload, object_pairs_hook=_unique_object, parse_constant=_reject_constant
|
|
56
|
+
)
|
|
57
|
+
except StatusFormatError:
|
|
58
|
+
raise
|
|
59
|
+
except (ValueError, RecursionError) as exc:
|
|
60
|
+
raise StatusFormatError(f"Invalid status JSON: {exc}") from exc
|
|
61
|
+
|
|
62
|
+
return _read_summary(document)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
_Scalar = TypeVar("_Scalar", str, bool)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _field(document: dict[str, object], name: str, kind: type[_Scalar]) -> _Scalar:
|
|
69
|
+
if name not in document:
|
|
70
|
+
raise StatusFormatError(f"Missing field {name!r}")
|
|
71
|
+
value = document[name]
|
|
72
|
+
if not isinstance(value, kind):
|
|
73
|
+
raise StatusFormatError(f"Invalid type for field {name!r}")
|
|
74
|
+
return value
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _read_summary(
|
|
78
|
+
document: object, *, unsupported: type[StatusFormatError] = StatusFormatError
|
|
79
|
+
) -> StatusSummary:
|
|
80
|
+
if not isinstance(document, dict):
|
|
81
|
+
raise StatusFormatError("Expected a JSON object")
|
|
82
|
+
|
|
83
|
+
if "schema" not in document:
|
|
84
|
+
raise StatusFormatError("Missing field 'schema'")
|
|
85
|
+
schema = document["schema"]
|
|
86
|
+
if type(schema) is not int:
|
|
87
|
+
raise StatusFormatError("Expected 'schema' to be the integer 1")
|
|
88
|
+
if schema != 1:
|
|
89
|
+
raise unsupported("Expected 'schema' to be the integer 1")
|
|
90
|
+
|
|
91
|
+
return StatusSummary(
|
|
92
|
+
schema=schema,
|
|
93
|
+
version_id=_field(document, "version_id", str),
|
|
94
|
+
host=_field(document, "host", str),
|
|
95
|
+
status=_field(document, "status", str),
|
|
96
|
+
is_target=_field(document, "is_target", bool),
|
|
97
|
+
is_operator=_field(document, "is_operator", bool),
|
|
98
|
+
reason=None
|
|
99
|
+
if "reason" in document and document["reason"] is None
|
|
100
|
+
else _field(document, "reason", str),
|
|
101
|
+
)
|
shirudo_python/py.typed
ADDED
|
File without changes
|
shirudo_python/report.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""Immutable projections of Shirudo's schema-1 status document."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from enum import Enum
|
|
6
|
+
from typing import Final, Literal
|
|
7
|
+
|
|
8
|
+
from ._summary import StatusSummary
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Missing(Enum):
|
|
12
|
+
"""A field omitted by the producer. Compare with MISSING by identity."""
|
|
13
|
+
|
|
14
|
+
MISSING = "missing"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
MISSING: Final[Literal[Missing.MISSING]] = Missing.MISSING
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Condition:
|
|
22
|
+
type: str
|
|
23
|
+
status: str
|
|
24
|
+
detail: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True, slots=True)
|
|
28
|
+
class Certificate:
|
|
29
|
+
sha256: str
|
|
30
|
+
fingerprint: str
|
|
31
|
+
primary: bool
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, slots=True)
|
|
35
|
+
class KeyringCertificate:
|
|
36
|
+
sha256: str
|
|
37
|
+
fingerprint: str
|
|
38
|
+
primary: bool | Missing
|
|
39
|
+
config: bool | Missing
|
|
40
|
+
subject: str | None
|
|
41
|
+
algorithm: str | None
|
|
42
|
+
not_before: str | None
|
|
43
|
+
key_serial: int | None
|
|
44
|
+
key_description: str | None
|
|
45
|
+
frozen: bool | None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True, slots=True)
|
|
49
|
+
class KeyringLink:
|
|
50
|
+
serial: int
|
|
51
|
+
type: str | None
|
|
52
|
+
description: str | None
|
|
53
|
+
frozen: bool
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True, slots=True)
|
|
57
|
+
class Keyring:
|
|
58
|
+
present: bool
|
|
59
|
+
serial: int | None
|
|
60
|
+
serial_pinned: int | None
|
|
61
|
+
serial_matches: bool | None
|
|
62
|
+
certs: tuple[KeyringCertificate, ...]
|
|
63
|
+
other_links: tuple[KeyringLink, ...]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass(frozen=True, slots=True)
|
|
67
|
+
class LoadedUpatch:
|
|
68
|
+
name: str
|
|
69
|
+
location: str
|
|
70
|
+
status: str
|
|
71
|
+
n_maps: int
|
|
72
|
+
missed_runs: int | None | Missing
|
|
73
|
+
loaded_at: str
|
|
74
|
+
age_sec: int | None
|
|
75
|
+
payload_sha256: str | None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True, slots=True)
|
|
79
|
+
class Assets:
|
|
80
|
+
root: str
|
|
81
|
+
cert: bool
|
|
82
|
+
signing_key: bool
|
|
83
|
+
eventlog: bool
|
|
84
|
+
eventlog_bytes: int
|
|
85
|
+
upatches: int | None
|
|
86
|
+
bpffs_mounted: bool
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True, slots=True)
|
|
90
|
+
class AttemptCounts:
|
|
91
|
+
total: int
|
|
92
|
+
counters: Mapping[str, int]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(frozen=True, slots=True)
|
|
96
|
+
class ConfigActivation:
|
|
97
|
+
root_hash: str
|
|
98
|
+
activation_pending: bool
|
|
99
|
+
error: str | None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(frozen=True, slots=True)
|
|
103
|
+
class EventUpatch:
|
|
104
|
+
name: str
|
|
105
|
+
payload_sha256: str
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@dataclass(frozen=True, slots=True)
|
|
109
|
+
class Event:
|
|
110
|
+
type: str
|
|
111
|
+
ts: str | Missing
|
|
112
|
+
digest: str | Missing
|
|
113
|
+
set_digest: str | Missing
|
|
114
|
+
upatch: EventUpatch | Missing
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@dataclass(frozen=True, slots=True)
|
|
118
|
+
class EventLog:
|
|
119
|
+
present: bool
|
|
120
|
+
entries: int
|
|
121
|
+
bytes: int
|
|
122
|
+
events: tuple[Event, ...] | Missing
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@dataclass(frozen=True, slots=True)
|
|
126
|
+
class Tpm:
|
|
127
|
+
reachable: bool
|
|
128
|
+
nv_index: str
|
|
129
|
+
chain: str | None
|
|
130
|
+
nv_name: str | None
|
|
131
|
+
register_bound: bool
|
|
132
|
+
register_anchored: bool
|
|
133
|
+
init_records: int
|
|
134
|
+
register_rebound: bool
|
|
135
|
+
pcr: int
|
|
136
|
+
phase_pcr: int
|
|
137
|
+
pcr_before: str | None
|
|
138
|
+
phase_before: str | None
|
|
139
|
+
bound_in: str | None
|
|
140
|
+
chain_matches_eventlog: bool | None
|
|
141
|
+
eventlog: EventLog
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@dataclass(frozen=True, slots=True)
|
|
145
|
+
class UpatchTree:
|
|
146
|
+
configured: bool
|
|
147
|
+
pending: bool
|
|
148
|
+
state: Missing | None
|
|
149
|
+
tree_id: str | Missing
|
|
150
|
+
generation: int | Missing
|
|
151
|
+
last_seq: int | Missing
|
|
152
|
+
projection_root: str | Missing
|
|
153
|
+
manifest_digest: str | Missing
|
|
154
|
+
eventlog_projection_root: str | None
|
|
155
|
+
eventlog_matches_state: bool | None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(frozen=True, slots=True)
|
|
159
|
+
class SystemInventory:
|
|
160
|
+
hostname: str
|
|
161
|
+
os: str
|
|
162
|
+
kernel_release: str
|
|
163
|
+
kernel_version: str
|
|
164
|
+
kernel_build_id: str
|
|
165
|
+
kernel_config: Mapping[str, str]
|
|
166
|
+
architecture: str
|
|
167
|
+
machine_id: str
|
|
168
|
+
boot_id: str
|
|
169
|
+
nproc: int
|
|
170
|
+
mem_total_kb: int
|
|
171
|
+
mem_avail_kb: int
|
|
172
|
+
disk_total_kb: int
|
|
173
|
+
disk_used_kb: int
|
|
174
|
+
uptime_seconds: int
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@dataclass(frozen=True, slots=True)
|
|
178
|
+
class StatusReport:
|
|
179
|
+
"""Host-reported data. The producer supplies all verdicts and measurements."""
|
|
180
|
+
|
|
181
|
+
summary: StatusSummary
|
|
182
|
+
conditions: tuple[Condition, ...]
|
|
183
|
+
lsm_attached: bool
|
|
184
|
+
keyring_mode: str
|
|
185
|
+
keyring_present: bool
|
|
186
|
+
keyring_serial: int | None
|
|
187
|
+
keyring_serial_pinned: int | None
|
|
188
|
+
keyring_serial_matches: bool | None
|
|
189
|
+
cert_present: bool
|
|
190
|
+
certs: tuple[Certificate, ...]
|
|
191
|
+
certs_revoked: int
|
|
192
|
+
certs_unvouched: int
|
|
193
|
+
certs_enrolled: int | None
|
|
194
|
+
bpf_keyring: Keyring
|
|
195
|
+
dm_verity_keyring: Keyring
|
|
196
|
+
signing_key_present: bool
|
|
197
|
+
upatches_loaded: tuple[LoadedUpatch, ...]
|
|
198
|
+
assets: Assets
|
|
199
|
+
tamper_attempts: AttemptCounts | None
|
|
200
|
+
integrity_attempts: AttemptCounts | None | Missing
|
|
201
|
+
config: ConfigActivation | None
|
|
202
|
+
system: SystemInventory | Missing
|
|
203
|
+
tpm: Tpm
|
|
204
|
+
upatch_tree: UpatchTree
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shirudo-python
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: Read Shirudo host status reports in Python
|
|
5
|
+
Author: shirudo-python contributors
|
|
6
|
+
License-Expression: BSD-2-Clause
|
|
7
|
+
Project-URL: Repository, https://github.com/culvert-labs/shirudo-python
|
|
8
|
+
Project-URL: Issues, https://github.com/culvert-labs/shirudo-python/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# shirudo-python
|
|
15
|
+
|
|
16
|
+
[](https://github.com/culvert-labs/shirudo-python/actions/workflows/ci.yml)
|
|
17
|
+
|
|
18
|
+
Read a saved `shirudo status --json` report in Python. Use `parse_status()`
|
|
19
|
+
for the host and verdict, or `parse_status_report()` to inspect the diagnostic
|
|
20
|
+
conditions, measurement state, keyrings, counters and loaded upatches that
|
|
21
|
+
explain the verdict. Both run offline with the Python standard library.
|
|
22
|
+
|
|
23
|
+
This is an independent, unofficial community extension of [Shirudo](https://github.com/shirudo-dev/shirudo), hosted in the `culvert-labs` GitHub organization.
|
|
24
|
+
Development takes place in public here. The small API and documented upstream
|
|
25
|
+
format make individual changes easy for upstream maintainers to evaluate for adoption.
|
|
26
|
+
|
|
27
|
+
## Try it
|
|
28
|
+
|
|
29
|
+
For the first release candidate, see the [0.1.0rc1 notes and wheel installation](docs/releases/0.1.0rc1.md).
|
|
30
|
+
|
|
31
|
+
From a checkout, install with Python 3.10 or newer in your virtual environment.
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
git clone https://github.com/culvert-labs/shirudo-python.git
|
|
35
|
+
cd shirudo-python
|
|
36
|
+
python -m pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Inspect the report captured after loading a signed test upatch in the official
|
|
40
|
+
VM. Run this example from the repository root.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from pathlib import Path
|
|
44
|
+
from shirudo_python import parse_status_report
|
|
45
|
+
|
|
46
|
+
report = parse_status_report(Path("tests/fixtures/upstream/target-loaded.json").read_bytes())
|
|
47
|
+
print(report.summary.status) # ok
|
|
48
|
+
print([patch.name for patch in report.upatches_loaded]) # ['basic']
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To use a real report, capture it on a Shirudo host with
|
|
52
|
+
`shirudo status --json > status.json`, then read that file in the same way.
|
|
53
|
+
The verdict comes from the report's producer. Use upstream attestation tooling
|
|
54
|
+
when you need to establish the state of a remote host.
|
|
55
|
+
|
|
56
|
+
## Documentation and development
|
|
57
|
+
|
|
58
|
+
- [Status API](docs/status.md) covers the fields, accepted inputs and errors.
|
|
59
|
+
- [Shared summary profile](docs/summary-conformance.md) documents bounded summary parsing and the Python/Go conformance vectors.
|
|
60
|
+
- [Full report guide](docs/full-status.md) shows how to inspect a report and distinguish omitted fields from null values.
|
|
61
|
+
- [Full report compatibility decision](docs/decisions/0002-full-status-report.md) maps the model to the upstream producer, tests and format history.
|
|
62
|
+
- [Capture evidence](docs/evidence.md) records the upstream revision, official VM workflow, report hashes and limits of the observations.
|
|
63
|
+
- [Upstream proposal](docs/upstream-proposal.md) describes the operator use case, maintenance strategy and possible adoption paths.
|
|
64
|
+
- [Initial design decision](docs/decisions/0001-offline-status-summary.md) records the compatibility baseline and scope.
|
|
65
|
+
- [Contributing](CONTRIBUTING.md) explains how to run the offline tests and propose changes.
|
|
66
|
+
- [BSD 2-Clause license](LICENSE) covers this project.
|
|
67
|
+
- [Ecosystem roadmap](docs/ecosystem.md) connects operator requirements, upstream contributions and the work planned across the SDKs.
|
|
68
|
+
- [Rust onboarding contract](docs/rust-onboarding.md) explains how an independent implementation can demonstrate compatibility.
|
|
69
|
+
- [Upstream changes](docs/upstream-compatibility.md) explains the weekly check and how to triage a changed producer.
|
|
70
|
+
- [Release rehearsal](docs/release.md) covers reproducible wheels and source distributions, registry ownership and the handoff to a future crate maintainer.
|
|
71
|
+
- [Support summary example](examples/support_summary.py) reads a saved report on stdin and prints alerts, loaded names and counter totals. See the [operator walkthrough](docs/ecosystem.md#using-the-support-summary).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
shirudo_python/__init__.py,sha256=S6ONVowws6mNQ5IesFHefO5xYkFuI0DCiiTEeHGYNK4,570
|
|
2
|
+
shirudo_python/_reader.py,sha256=lNv-vXHjS27j5eD8q1ncivK0A4vhozEbEGr--8jRvBY,8234
|
|
3
|
+
shirudo_python/_summary.py,sha256=YnqQERTJlJ6OV3sFjPxCC9UgOK3E4mRhj7DbdiBIEc0,3142
|
|
4
|
+
shirudo_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
shirudo_python/report.py,sha256=BvoEvz6OgWA2WXKDlksARYsjEUaIlZBgKtcMZrstMDU,4450
|
|
6
|
+
shirudo_python-0.1.0rc1.dist-info/licenses/LICENSE,sha256=O1644gstHzKLVJMQo9_K5Mkktjzk7dbKTtGDbFBkVs0,1297
|
|
7
|
+
shirudo_python-0.1.0rc1.dist-info/METADATA,sha256=IeBF_wgGji5BAPlK7KPr9XnCYhLT3AbL91zSlPWxmU8,4071
|
|
8
|
+
shirudo_python-0.1.0rc1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
9
|
+
shirudo_python-0.1.0rc1.dist-info/top_level.txt,sha256=VPC7JYf6bJ4T90Gu5zfm2YE21tPoRG9avOE2d8h1DPY,15
|
|
10
|
+
shirudo_python-0.1.0rc1.dist-info/RECORD,,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, KidCarmi
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
shirudo_python
|