manta-node 0.6b6.dev840__py3-none-any.whl → 0.6b6.dev846__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.
- manta_node/cli/_version_generated.py +2 -2
- manta_node/infrastructure/config/node_config_manager.py +4 -0
- manta_node/infrastructure/grpc/client.py +43 -0
- manta_node/infrastructure/mqtt/command_handler.py +114 -12
- manta_node/infrastructure/security/broker_certificate.py +132 -0
- manta_node/node_orchestrator.py +71 -2
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/METADATA +2 -2
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/RECORD +12 -11
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/WHEEL +0 -0
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/entry_points.txt +0 -0
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/licenses/LICENSE +0 -0
- {manta_node-0.6b6.dev840.dist-info → manta_node-0.6b6.dev846.dist-info}/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ This file is auto-generated at build time by scripts/generate_version.py.
|
|
|
4
4
|
Do not edit manually.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
__version__ = "2026.11.10.
|
|
7
|
+
__version__ = "2026.11.10.3bb2e6d0"
|
|
8
8
|
__build_date__ = "2026.11.10"
|
|
9
|
-
__commit_id__ = "
|
|
9
|
+
__commit_id__ = "3bb2e6d0"
|
|
10
10
|
__package_version__ = "0.6b6" # release-series base, moved by scripts/bump_version.py
|
|
@@ -156,6 +156,10 @@ class SecurityConfig:
|
|
|
156
156
|
verify_ssl: bool = True
|
|
157
157
|
token_refresh_interval: int = 3600 # seconds
|
|
158
158
|
jwt_refresh_buffer_seconds: int = 300 # renew this far ahead of exp (ADR-0006 D3)
|
|
159
|
+
# Request and use the node's own broker certificate (#546, staging spike).
|
|
160
|
+
node_certificate: bool = False
|
|
161
|
+
# Must differ from cert_folder: MqttBase takes one folder or the other.
|
|
162
|
+
node_certificate_folder: str = "~/.manta/node-certificate"
|
|
159
163
|
|
|
160
164
|
|
|
161
165
|
@dataclass
|
|
@@ -7,10 +7,13 @@ from typing import (
|
|
|
7
7
|
TypeVar,
|
|
8
8
|
)
|
|
9
9
|
|
|
10
|
+
from grpclib.const import Status
|
|
10
11
|
from manta_common.base_client import GrpcClientBase, MetadataDict
|
|
11
12
|
from manta_common.build.common.informations import (
|
|
12
13
|
DatasetOverviews,
|
|
13
14
|
MetricsSnapshot,
|
|
15
|
+
NodeCertificate,
|
|
16
|
+
NodeCertificateRequest,
|
|
14
17
|
NodeOverview,
|
|
15
18
|
NodeStatus,
|
|
16
19
|
Registration,
|
|
@@ -45,6 +48,18 @@ __all__ = ["NodeClient"]
|
|
|
45
48
|
T = TypeVar("T")
|
|
46
49
|
|
|
47
50
|
|
|
51
|
+
# The call's contract (node_service.proto) names UNAVAILABLE as its only
|
|
52
|
+
# retryable status; the others mean the node stays on the password path.
|
|
53
|
+
_NODE_CERTIFICATE_RETRY_POLICY = RetryPolicy(
|
|
54
|
+
max_retries=3,
|
|
55
|
+
initial_delay=0.5,
|
|
56
|
+
max_delay=10.0,
|
|
57
|
+
backoff_factor=2.0,
|
|
58
|
+
jitter_factor=0.2,
|
|
59
|
+
retryable_grpc_statuses={Status.UNAVAILABLE},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
48
63
|
class NodeClient(GrpcClientBase):
|
|
49
64
|
"""
|
|
50
65
|
Node client facilitates management of requests to Manager with retry
|
|
@@ -214,6 +229,34 @@ class NodeClient(GrpcClientBase):
|
|
|
214
229
|
"""
|
|
215
230
|
return await self.call_service_method("renew_node_token", request)
|
|
216
231
|
|
|
232
|
+
async def request_node_certificate(
|
|
233
|
+
self, request: NodeCertificateRequest
|
|
234
|
+
) -> NodeCertificate:
|
|
235
|
+
"""
|
|
236
|
+
Request the node's broker certificate, after registering (#546).
|
|
237
|
+
|
|
238
|
+
The node token in the ``authorization`` metadata names the node; the
|
|
239
|
+
request's CN must equal it. Of the gRPC statuses the call defines, only
|
|
240
|
+
UNAVAILABLE (signing failed or timed out) is retried; transport errors
|
|
241
|
+
and timeouts are retried as for every call.
|
|
242
|
+
|
|
243
|
+
Parameters
|
|
244
|
+
----------
|
|
245
|
+
request : NodeCertificateRequest
|
|
246
|
+
The node's PEM certificate signing request
|
|
247
|
+
|
|
248
|
+
Returns
|
|
249
|
+
-------
|
|
250
|
+
NodeCertificate
|
|
251
|
+
The certificate and its chain
|
|
252
|
+
"""
|
|
253
|
+
return await self.call_service_method(
|
|
254
|
+
"request_node_certificate",
|
|
255
|
+
request,
|
|
256
|
+
retry_policy=_NODE_CERTIFICATE_RETRY_POLICY,
|
|
257
|
+
include_request=False,
|
|
258
|
+
)
|
|
259
|
+
|
|
217
260
|
def update_token(self, token: str) -> None:
|
|
218
261
|
"""
|
|
219
262
|
Replace the credential used in ``authorization`` metadata.
|
|
@@ -6,6 +6,7 @@ import os
|
|
|
6
6
|
import re
|
|
7
7
|
import time
|
|
8
8
|
from collections.abc import Awaitable, Callable
|
|
9
|
+
from dataclasses import dataclass
|
|
9
10
|
from datetime import datetime, timezone
|
|
10
11
|
from logging import getLogger
|
|
11
12
|
from pathlib import Path
|
|
@@ -47,12 +48,27 @@ from ..filesystem.dataset_manager import DatasetManager
|
|
|
47
48
|
from ..grpc.client import NodeClient
|
|
48
49
|
from ..metrics.collector import Collector
|
|
49
50
|
from ..metrics.metrics_collector import MetricsCollectorBase
|
|
51
|
+
from ..security.broker_certificate import BrokerCertificateStore
|
|
50
52
|
|
|
51
53
|
TIMEOUT = 1 # s
|
|
52
54
|
|
|
53
55
|
# Consecutive failed deliveries before a finished task is retired unheard.
|
|
54
56
|
MAX_LOG_UPLOAD_ATTEMPTS = 5
|
|
55
57
|
MAX_MQTT_CONNECT_FAILURES = 3
|
|
58
|
+
# CONNACK reason codes that refuse the client's identity or credentials:
|
|
59
|
+
# client identifier not valid, bad user name or password, not authorized,
|
|
60
|
+
# bad authentication method.
|
|
61
|
+
_CONNACK_IDENTITY_REFUSALS = frozenset({0x85, 0x86, 0x87, 0x8C})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class CertificateBroker:
|
|
66
|
+
"""The certificate-only listener and the folder of the node's certificate."""
|
|
67
|
+
|
|
68
|
+
host: str
|
|
69
|
+
port: int
|
|
70
|
+
folder: Path
|
|
71
|
+
|
|
56
72
|
|
|
57
73
|
# A restarted node replays the request that restarted it until the supervisor
|
|
58
74
|
# answers with the terminal outcome. The supervisor holds the request in flight
|
|
@@ -129,9 +145,9 @@ class CommandHandler(Collector, MqttBase):
|
|
|
129
145
|
node_client: NodeClient
|
|
130
146
|
Node client
|
|
131
147
|
mqtt_broker_host : str
|
|
132
|
-
MQTT broker host
|
|
148
|
+
MQTT broker host of the password listener
|
|
133
149
|
mqtt_broker_port : int
|
|
134
|
-
MQTT broker port
|
|
150
|
+
MQTT broker port of the password listener
|
|
135
151
|
topics : List[str]
|
|
136
152
|
List of topics
|
|
137
153
|
dataset_manager: DatasetManager
|
|
@@ -146,6 +162,11 @@ class CommandHandler(Collector, MqttBase):
|
|
|
146
162
|
Runtime broker role username (caller-sourced; not persisted).
|
|
147
163
|
mqtt_password : Optional[str]
|
|
148
164
|
Runtime broker role password (caller-sourced; not persisted).
|
|
165
|
+
certificate_broker : Optional[CertificateBroker]
|
|
166
|
+
The node's own broker certificate and its listener (#546). When set,
|
|
167
|
+
the handler connects there with the certificate and no username or
|
|
168
|
+
password, and falls back to the password listener when the broker
|
|
169
|
+
does not accept the certificate or it is no longer in date.
|
|
149
170
|
"""
|
|
150
171
|
|
|
151
172
|
def __init__(
|
|
@@ -165,6 +186,7 @@ class CommandHandler(Collector, MqttBase):
|
|
|
165
186
|
max_concurrent_tasks: int = 2,
|
|
166
187
|
task_timeout: int = 3600,
|
|
167
188
|
seam_client: SeamClient | None = None,
|
|
189
|
+
certificate_broker: CertificateBroker | None = None,
|
|
168
190
|
) -> None:
|
|
169
191
|
self.tracer = Tracer(getLogger(__name__))
|
|
170
192
|
# The local seam to a supervisor, when one owns this node (2b). None on a
|
|
@@ -180,7 +202,13 @@ class CommandHandler(Collector, MqttBase):
|
|
|
180
202
|
self.max_concurrent_tasks = max_concurrent_tasks
|
|
181
203
|
self.task_timeout = task_timeout
|
|
182
204
|
self._mqtt_connect_failures = 0
|
|
205
|
+
self._certificate_broker = certificate_broker
|
|
206
|
+
self._password_address = f"{mqtt_broker_host}:{mqtt_broker_port}"
|
|
207
|
+
self._certificate_connect_failures = 0
|
|
208
|
+
self._connected_once = False
|
|
183
209
|
|
|
210
|
+
# Required in certificate mode too: the password listener is the
|
|
211
|
+
# fallback whenever the certificate is not accepted.
|
|
184
212
|
if not mqtt_username or not mqtt_password:
|
|
185
213
|
raise MantaNodeError(
|
|
186
214
|
"MQTT broker username and password must both be provided"
|
|
@@ -191,16 +219,34 @@ class CommandHandler(Collector, MqttBase):
|
|
|
191
219
|
_node_id_from_token(node_client.secured_token)
|
|
192
220
|
or b2x(node_client.secured_token.encode())
|
|
193
221
|
)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
|
|
223
|
+
# A closure, like MqttBase's own client factory: no instance attribute
|
|
224
|
+
# holds the credential, and no repr of a partial can print it.
|
|
225
|
+
def use_password_listener() -> None:
|
|
226
|
+
MqttBase.__init__(
|
|
227
|
+
self,
|
|
228
|
+
mqtt_broker_host=mqtt_broker_host,
|
|
229
|
+
mqtt_broker_port=mqtt_broker_port,
|
|
230
|
+
topics=topics,
|
|
231
|
+
client_id=client_id,
|
|
232
|
+
ssl_cert_folder=ssl_cert_folder,
|
|
233
|
+
username=mqtt_username,
|
|
234
|
+
password=mqtt_password,
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
self._use_password_listener = use_password_listener
|
|
238
|
+
if certificate_broker is None:
|
|
239
|
+
use_password_listener()
|
|
240
|
+
else:
|
|
241
|
+
# MqttBase refuses ssl_cert_folder alongside the certificate folder.
|
|
242
|
+
MqttBase.__init__(
|
|
243
|
+
self,
|
|
244
|
+
mqtt_broker_host=certificate_broker.host,
|
|
245
|
+
mqtt_broker_port=certificate_broker.port,
|
|
246
|
+
topics=topics,
|
|
247
|
+
client_id=client_id,
|
|
248
|
+
client_certificate_folder=certificate_broker.folder,
|
|
249
|
+
)
|
|
204
250
|
|
|
205
251
|
# Route the TaskManager's setup-failure hook to this handler's FAILED
|
|
206
252
|
# publisher (composition: the task manager has no MQTT knowledge).
|
|
@@ -215,6 +261,12 @@ class CommandHandler(Collector, MqttBase):
|
|
|
215
261
|
if inspect.isawaitable(result):
|
|
216
262
|
await result
|
|
217
263
|
|
|
264
|
+
# Before the password-path checks below, which stop the node: in
|
|
265
|
+
# certificate mode no connect error may stop it.
|
|
266
|
+
if self._certificate_broker is not None:
|
|
267
|
+
self._on_certificate_connect_error(exc)
|
|
268
|
+
return
|
|
269
|
+
|
|
218
270
|
reason_code = _mqtt_reason_code(exc)
|
|
219
271
|
if reason_code == 0x85:
|
|
220
272
|
raise MantaNodeError(
|
|
@@ -232,6 +284,55 @@ class CommandHandler(Collector, MqttBase):
|
|
|
232
284
|
"MQTT broker authentication failed repeatedly; stopping the node"
|
|
233
285
|
)
|
|
234
286
|
|
|
287
|
+
def _on_certificate_connect_error(self, exc: Exception) -> None:
|
|
288
|
+
"""Fall back to the password listener when the certificate cannot work.
|
|
289
|
+
|
|
290
|
+
Never stop the node over its certificate: the next start would find the
|
|
291
|
+
same certificate in date and fail again, a crash loop under a supervisor.
|
|
292
|
+
"""
|
|
293
|
+
broker = cast(CertificateBroker, self._certificate_broker)
|
|
294
|
+
if not BrokerCertificateStore(broker.folder).has_usable_certificate():
|
|
295
|
+
self._fall_back_to_password_listener(
|
|
296
|
+
f"the node certificate in {broker.folder} is no longer in date"
|
|
297
|
+
)
|
|
298
|
+
return
|
|
299
|
+
reason_code = _mqtt_reason_code(exc)
|
|
300
|
+
if reason_code in _CONNACK_IDENTITY_REFUSALS:
|
|
301
|
+
self._fall_back_to_password_listener(
|
|
302
|
+
f"the broker at {broker.host}:{broker.port} refused the node "
|
|
303
|
+
f"certificate's identity ({reason_code:#04x})"
|
|
304
|
+
)
|
|
305
|
+
return
|
|
306
|
+
if self._connected_once:
|
|
307
|
+
return
|
|
308
|
+
# Under TLS 1.3 the broker refuses a client certificate after the
|
|
309
|
+
# handshake, and aiomqtt reports only "Operation timed out": a refused
|
|
310
|
+
# certificate and an unreachable broker look the same. So every failure
|
|
311
|
+
# counts until the first connection in this run; a node that has
|
|
312
|
+
# connected retries an outage on the certificate listener.
|
|
313
|
+
self._certificate_connect_failures += 1
|
|
314
|
+
self.tracer.warning(
|
|
315
|
+
f"MQTT connect with the node certificate failed at "
|
|
316
|
+
f"{broker.host}:{broker.port}: {exc}; consecutive failures: "
|
|
317
|
+
f"{self._certificate_connect_failures}/{MAX_MQTT_CONNECT_FAILURES}"
|
|
318
|
+
)
|
|
319
|
+
if self._certificate_connect_failures >= MAX_MQTT_CONNECT_FAILURES:
|
|
320
|
+
self._fall_back_to_password_listener(
|
|
321
|
+
f"the broker at {broker.host}:{broker.port} did not accept the "
|
|
322
|
+
f"node certificate in {broker.folder}"
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
def _fall_back_to_password_listener(self, reason: str) -> None:
|
|
326
|
+
self.tracer.warning(
|
|
327
|
+
f"MQTT: {reason}; using the broker password at {self._password_address}"
|
|
328
|
+
)
|
|
329
|
+
# Re-initialising MqttBase replaces its queue; keep the messages
|
|
330
|
+
# already waiting to be published.
|
|
331
|
+
queue = self.queue
|
|
332
|
+
self._use_password_listener()
|
|
333
|
+
self.queue = queue
|
|
334
|
+
self._certificate_broker = None
|
|
335
|
+
|
|
235
336
|
# -- TaskManager delegation (state + operations) -----------------------
|
|
236
337
|
|
|
237
338
|
@property
|
|
@@ -389,6 +490,7 @@ class CommandHandler(Collector, MqttBase):
|
|
|
389
490
|
`done`, a snapshot taken before either message was processed.
|
|
390
491
|
"""
|
|
391
492
|
self._mqtt_connect_failures = 0
|
|
493
|
+
self._connected_once = True
|
|
392
494
|
try:
|
|
393
495
|
subscribe_task = None
|
|
394
496
|
publish_task = None
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""The node's own broker certificate: its key, its request, and the issued certificate.
|
|
2
|
+
|
|
3
|
+
The folder holds two files, the layout ``MqttBase(client_certificate_folder=...)``
|
|
4
|
+
reads:
|
|
5
|
+
|
|
6
|
+
* ``mqtt.key`` — the node's private key, created once and reused on every start.
|
|
7
|
+
The manager re-delivers the certificate on record to a retry with the same
|
|
8
|
+
key and refuses a different key (``ALREADY_EXISTS``), so replacing the key
|
|
9
|
+
strands the node on the password path.
|
|
10
|
+
* ``mqtt.crt`` — the issued certificate followed by its chain. The broker trusts
|
|
11
|
+
the root only, so a certificate presented without its chain is refused.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from cryptography import x509
|
|
19
|
+
from cryptography.hazmat.primitives import hashes, serialization
|
|
20
|
+
from cryptography.hazmat.primitives.asymmetric import ec
|
|
21
|
+
from cryptography.x509.oid import NameOID
|
|
22
|
+
|
|
23
|
+
__all__ = ["BrokerCertificateStore"]
|
|
24
|
+
|
|
25
|
+
KEY_FILE = "mqtt.key"
|
|
26
|
+
CERTIFICATE_FILE = "mqtt.crt"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _public_bytes(public_key) -> bytes:
|
|
30
|
+
return public_key.public_bytes(
|
|
31
|
+
serialization.Encoding.DER,
|
|
32
|
+
serialization.PublicFormat.SubjectPublicKeyInfo,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class BrokerCertificateStore:
|
|
37
|
+
"""The node's key and broker certificate in one folder.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
folder : Path
|
|
42
|
+
The folder for ``mqtt.key`` and ``mqtt.crt``. It must not be the
|
|
43
|
+
``security.cert_folder`` used for the manager connection.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, folder: Path) -> None:
|
|
47
|
+
self.folder = folder
|
|
48
|
+
self.key_path = folder / KEY_FILE
|
|
49
|
+
self.certificate_path = folder / CERTIFICATE_FILE
|
|
50
|
+
|
|
51
|
+
def has_usable_certificate(self, now: datetime | None = None) -> bool:
|
|
52
|
+
"""Whether the stored certificate exists, is in date, and matches the key."""
|
|
53
|
+
try:
|
|
54
|
+
key = self._load_key()
|
|
55
|
+
certificate = x509.load_pem_x509_certificate(
|
|
56
|
+
self.certificate_path.read_bytes()
|
|
57
|
+
)
|
|
58
|
+
except (OSError, ValueError, TypeError):
|
|
59
|
+
return False
|
|
60
|
+
now = now or datetime.now(timezone.utc)
|
|
61
|
+
if not (
|
|
62
|
+
certificate.not_valid_before_utc <= now < certificate.not_valid_after_utc
|
|
63
|
+
):
|
|
64
|
+
return False
|
|
65
|
+
return _public_bytes(certificate.public_key()) == _public_bytes(
|
|
66
|
+
key.public_key()
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def certificate_request(self, node_id: str) -> str:
|
|
70
|
+
"""A PEM request whose subject is only CN = ``node_id``, signed by the node's key."""
|
|
71
|
+
csr = (
|
|
72
|
+
x509.CertificateSigningRequestBuilder()
|
|
73
|
+
.subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, node_id)]))
|
|
74
|
+
.sign(self._load_or_create_key(), hashes.SHA256())
|
|
75
|
+
)
|
|
76
|
+
return csr.public_bytes(serialization.Encoding.PEM).decode()
|
|
77
|
+
|
|
78
|
+
def store(self, certificate_pem: str, chain_pem: str) -> None:
|
|
79
|
+
"""Write ``mqtt.crt`` as the certificate followed by its chain.
|
|
80
|
+
|
|
81
|
+
Raises
|
|
82
|
+
------
|
|
83
|
+
ValueError
|
|
84
|
+
If either part is empty, or the certificate is not for the node's key.
|
|
85
|
+
"""
|
|
86
|
+
if not certificate_pem or not chain_pem:
|
|
87
|
+
raise ValueError("the certificate and its chain must both be present")
|
|
88
|
+
certificate = x509.load_pem_x509_certificate(certificate_pem.encode())
|
|
89
|
+
if _public_bytes(certificate.public_key()) != _public_bytes(
|
|
90
|
+
self._load_key().public_key()
|
|
91
|
+
):
|
|
92
|
+
raise ValueError("the issued certificate is not for this node's key")
|
|
93
|
+
content = certificate_pem.rstrip("\n") + "\n" + chain_pem.rstrip("\n") + "\n"
|
|
94
|
+
# Replace, never rewrite in place: a crash mid-write must not leave a
|
|
95
|
+
# truncated mqtt.crt that the next start would present.
|
|
96
|
+
partial = self.certificate_path.with_suffix(".crt.partial")
|
|
97
|
+
partial.write_text(content)
|
|
98
|
+
os.replace(partial, self.certificate_path)
|
|
99
|
+
|
|
100
|
+
def _load_key(self) -> ec.EllipticCurvePrivateKey:
|
|
101
|
+
key = serialization.load_pem_private_key(
|
|
102
|
+
self.key_path.read_bytes(), password=None
|
|
103
|
+
)
|
|
104
|
+
if not isinstance(key, ec.EllipticCurvePrivateKey):
|
|
105
|
+
raise TypeError(f"{self.key_path} is not an EC private key")
|
|
106
|
+
return key
|
|
107
|
+
|
|
108
|
+
def _load_or_create_key(self) -> ec.EllipticCurvePrivateKey:
|
|
109
|
+
if self.key_path.exists():
|
|
110
|
+
return self._load_key()
|
|
111
|
+
self.folder.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
112
|
+
key = ec.generate_private_key(ec.SECP256R1())
|
|
113
|
+
pem = key.private_bytes(
|
|
114
|
+
serialization.Encoding.PEM,
|
|
115
|
+
serialization.PrivateFormat.PKCS8,
|
|
116
|
+
serialization.NoEncryption(),
|
|
117
|
+
)
|
|
118
|
+
# 0600 from creation, so no other user can read it at any point. A
|
|
119
|
+
# process-mode task runs as the node's own user and still can (#459).
|
|
120
|
+
# Written aside and renamed: a failed write must never leave a partial
|
|
121
|
+
# mqtt.key, which every later start would fail to load.
|
|
122
|
+
partial = self.key_path.with_suffix(".key.partial")
|
|
123
|
+
partial.unlink(missing_ok=True)
|
|
124
|
+
fd = os.open(partial, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
125
|
+
try:
|
|
126
|
+
with os.fdopen(fd, "wb") as key_file:
|
|
127
|
+
key_file.write(pem)
|
|
128
|
+
os.replace(partial, self.key_path)
|
|
129
|
+
except BaseException:
|
|
130
|
+
partial.unlink(missing_ok=True)
|
|
131
|
+
raise
|
|
132
|
+
return key
|
manta_node/node_orchestrator.py
CHANGED
|
@@ -13,10 +13,12 @@ from grpclib.exceptions import GRPCError
|
|
|
13
13
|
from grpclib.server import Server
|
|
14
14
|
from manta_common.build.common.informations import (
|
|
15
15
|
ExecutionMode,
|
|
16
|
+
NodeCertificateRequest,
|
|
16
17
|
NodeOverview,
|
|
17
18
|
NodeStatus,
|
|
18
19
|
NodeStatusEnum,
|
|
19
20
|
NodeUpdatePath,
|
|
21
|
+
Registration,
|
|
20
22
|
)
|
|
21
23
|
from manta_common.build.common.system import Empty
|
|
22
24
|
from manta_common.conversions import HEX_SIZE, ID, oid
|
|
@@ -35,9 +37,10 @@ from .infrastructure.grpc.client import NodeClient
|
|
|
35
37
|
from .infrastructure.grpc.local_servicer import LocalServicer
|
|
36
38
|
from .infrastructure.grpc.world_servicer import WorldServicer
|
|
37
39
|
from .infrastructure.metrics.metrics_collector import GenericMetricsCollector
|
|
38
|
-
from .infrastructure.mqtt.command_handler import CommandHandler
|
|
40
|
+
from .infrastructure.mqtt.command_handler import CertificateBroker, CommandHandler
|
|
39
41
|
from .infrastructure.process.executor import ProcessExecutor
|
|
40
|
-
from .infrastructure.security.auth_agent import AuthAgent
|
|
42
|
+
from .infrastructure.security.auth_agent import AuthAgent, node_id_from_token
|
|
43
|
+
from .infrastructure.security.broker_certificate import BrokerCertificateStore
|
|
41
44
|
from .infrastructure.security.token_provider import InMemoryTokenProvider
|
|
42
45
|
from .seam import UPDATING_ENV, seam_socket_path
|
|
43
46
|
from .supervisor.seam import SocketSeamClient
|
|
@@ -573,6 +576,19 @@ class Node:
|
|
|
573
576
|
)
|
|
574
577
|
self.auth_agent.start(node_token)
|
|
575
578
|
|
|
579
|
+
# After the node client holds the node token: the certificate call
|
|
580
|
+
# names the node by that token.
|
|
581
|
+
certificate_folder = await self._node_certificate_folder(
|
|
582
|
+
registration, node_token
|
|
583
|
+
)
|
|
584
|
+
certificate_broker = None
|
|
585
|
+
if certificate_folder is not None:
|
|
586
|
+
certificate_broker = CertificateBroker(
|
|
587
|
+
host=registration.mqtt_certificate_broker_host,
|
|
588
|
+
port=registration.mqtt_certificate_broker_port,
|
|
589
|
+
folder=certificate_folder,
|
|
590
|
+
)
|
|
591
|
+
|
|
576
592
|
# Ensure light service port is assigned
|
|
577
593
|
self._ensure_light_service_port()
|
|
578
594
|
|
|
@@ -615,6 +631,7 @@ class Node:
|
|
|
615
631
|
# relay's client for the Manager path (2d). Absent when no
|
|
616
632
|
# supervisor serves the socket, so the relay stays inert.
|
|
617
633
|
seam_client=_seam_client_if_served(),
|
|
634
|
+
certificate_broker=certificate_broker,
|
|
618
635
|
)
|
|
619
636
|
|
|
620
637
|
# Start the server for docker communications through
|
|
@@ -682,6 +699,58 @@ class Node:
|
|
|
682
699
|
await self.stop()
|
|
683
700
|
raise NodeFatalError(f"[ERROR] {message}") from exc
|
|
684
701
|
|
|
702
|
+
async def _node_certificate_folder(
|
|
703
|
+
self, registration: Registration, node_token: str
|
|
704
|
+
) -> Path | None:
|
|
705
|
+
"""The folder of a usable node certificate, or None for the password path.
|
|
706
|
+
|
|
707
|
+
With ``security.node_certificate`` on, a node that holds no usable
|
|
708
|
+
certificate requests one over its node token (#546). Every failure
|
|
709
|
+
returns None: the node then connects with the broker password, as with
|
|
710
|
+
the flag off.
|
|
711
|
+
"""
|
|
712
|
+
if not self.config.security.node_certificate:
|
|
713
|
+
return None
|
|
714
|
+
if not (
|
|
715
|
+
registration.mqtt_certificate_broker_host
|
|
716
|
+
and registration.mqtt_certificate_broker_port
|
|
717
|
+
):
|
|
718
|
+
self.tracer.info(
|
|
719
|
+
"The manager offers no certificate listener; using the broker password"
|
|
720
|
+
)
|
|
721
|
+
return None
|
|
722
|
+
|
|
723
|
+
store = BrokerCertificateStore(
|
|
724
|
+
Path(self.config.security.node_certificate_folder).expanduser()
|
|
725
|
+
)
|
|
726
|
+
if store.has_usable_certificate():
|
|
727
|
+
self.tracer.info(f"Using the node certificate in {store.folder}")
|
|
728
|
+
return store.folder
|
|
729
|
+
|
|
730
|
+
node_id = node_id_from_token(node_token)
|
|
731
|
+
if node_id is None:
|
|
732
|
+
self.tracer.warning(
|
|
733
|
+
"The node token carries no node id; using the broker password"
|
|
734
|
+
)
|
|
735
|
+
return None
|
|
736
|
+
try:
|
|
737
|
+
request = NodeCertificateRequest(
|
|
738
|
+
certificate_request_pem=store.certificate_request(node_id)
|
|
739
|
+
)
|
|
740
|
+
issued = await self.node_client.request_node_certificate(request)
|
|
741
|
+
# NodeCertificate.node_token is left unset in the spike; the node
|
|
742
|
+
# keeps the token it holds.
|
|
743
|
+
store.store(
|
|
744
|
+
issued.certificate_pem or "", issued.certificate_chain_pem or ""
|
|
745
|
+
)
|
|
746
|
+
except (MantaError, OSError, ValueError, TypeError) as error:
|
|
747
|
+
self.tracer.warning(
|
|
748
|
+
f"No node certificate ({error}); using the broker password"
|
|
749
|
+
)
|
|
750
|
+
return None
|
|
751
|
+
self.tracer.info(f"Node certificate issued and stored in {store.folder}")
|
|
752
|
+
return store.folder
|
|
753
|
+
|
|
685
754
|
async def stop(self) -> None:
|
|
686
755
|
"""Stop the node"""
|
|
687
756
|
async with self._stop_lock:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: manta_node
|
|
3
|
-
Version: 0.6b6.
|
|
3
|
+
Version: 0.6b6.dev846
|
|
4
4
|
Summary: Node side software of the Manta platform. It is responsible for the communication with the Manta Core and the execution of the tasks.
|
|
5
5
|
Author-email: Hugo Miralles <hugo.miralles@manta-tech.io>, Matthew Thompson <matthew.thompson@manta-tech.io>
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -28,7 +28,7 @@ Requires-Dist: pyyaml
|
|
|
28
28
|
Requires-Dist: psutil
|
|
29
29
|
Requires-Dist: msgpack
|
|
30
30
|
Requires-Dist: aiomqtt<3.0,>=2.5.1
|
|
31
|
-
Requires-Dist: manta-common-core==0.6b6.
|
|
31
|
+
Requires-Dist: manta-common-core==0.6b6.dev838
|
|
32
32
|
Requires-Dist: toml
|
|
33
33
|
Requires-Dist: tomli; python_version < "3.11"
|
|
34
34
|
Requires-Dist: tomli-w
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
manta_node/__init__.py,sha256=bgGWXH3yQVhNf0v1ZGUBAy5Y51fqb0Y-EaLnocbcino,153
|
|
2
2
|
manta_node/__main__.py,sha256=SjrJyuMg_ZFKV6WOVe3MrtWM8Qmu065dkKZYl4n2YLw,1665
|
|
3
|
-
manta_node/node_orchestrator.py,sha256=
|
|
3
|
+
manta_node/node_orchestrator.py,sha256=7pPDYFgTUCMJnkfV7eLPF3Lo1mZA0k8vHYFkaK-NokU,32936
|
|
4
4
|
manta_node/seam.py,sha256=nGLjNVlSrnRJPdrp7L8piyJai1bQveiqT5JDBWeFeGI,6501
|
|
5
5
|
manta_node/task_manager.py,sha256=xRE-yKdUW0FFR8vtX1jDwl1AxTbqVD_JS7QVR62GA00,38002
|
|
6
6
|
manta_node/tasks.py,sha256=o837Hi-KFVJg9LF5iOtE8oD6UuTOfrEPWR-JOdhRGeY,6983
|
|
7
7
|
manta_node/update_path.py,sha256=6N_bN9z8MqnyWWfGTe1-aJFijf2tSy_IvO6VHvNSQVU,1667
|
|
8
8
|
manta_node/utils.py,sha256=Hw4Iw2jYQYsfVLVJuBMt-_rMFBeml3nCDE2jiiXc8YM,1155
|
|
9
9
|
manta_node/cli/__init__.py,sha256=arzO3mXDJ-E2yeeytbZfN7mCswwxdQ43_QjyeL2E5yE,134
|
|
10
|
-
manta_node/cli/_version_generated.py,sha256=
|
|
10
|
+
manta_node/cli/_version_generated.py,sha256=TnJT-Dw3DTO5FBfZd7vudq_lbbjicHTJEbc3n3TSO3o,332
|
|
11
11
|
manta_node/cli/config_manager.py,sha256=BCju9zqzraviL3KrzRnB-vZQUY__Q5kuEqb7EdB8YdI,4409
|
|
12
12
|
manta_node/cli/main.py,sha256=dZa6zrypWBvpN8hd4qpxevvlyNFhxKINCg1537NJ36w,4318
|
|
13
13
|
manta_node/cli/version.py,sha256=L4lNTz-Uw_ejumy1tXJcJhcjhb-5FRcRQ6ogZM5N1Xo,5136
|
|
@@ -26,7 +26,7 @@ manta_node/domain/value_objects/network.py,sha256=Q1lUUieqdf3H3Dqaf74bs0t0y_dUD9
|
|
|
26
26
|
manta_node/infrastructure/__init__.py,sha256=yM60jKhdaD18BOsLb-0aR9D2XxGvrTnV92oOT7Kor2w,297
|
|
27
27
|
manta_node/infrastructure/executor.py,sha256=wbH5-G4Y3iNTPr8ROWRDT-bWD-CYl1YFlZQ8dd9tpW4,2636
|
|
28
28
|
manta_node/infrastructure/config/__init__.py,sha256=VnKidPAVfzlZMb5WM-MggtsDLM8tdAFFWlB7WSiawzc,617
|
|
29
|
-
manta_node/infrastructure/config/node_config_manager.py,sha256=
|
|
29
|
+
manta_node/infrastructure/config/node_config_manager.py,sha256=kqq0fexl6xnW3xkvxtNfFPNm4llm8IWk4iZ4fFwmYJg,35481
|
|
30
30
|
manta_node/infrastructure/container/__init__.py,sha256=ACDyzGvtM7nfTsBXDAYFjkKgU2yu4Umj3CQ_rlRfw1I,300
|
|
31
31
|
manta_node/infrastructure/container/docker_adapter.py,sha256=hI5YenhcZwn19_chA8UM2RT6cmcnknzVcmu7AeHrkWo,24221
|
|
32
32
|
manta_node/infrastructure/container/executor.py,sha256=0aTFXDv-oXz81qwGi6zl_4qtkFriPWzn7iiiTRg7KJM,7274
|
|
@@ -35,14 +35,14 @@ manta_node/infrastructure/container/manager.py,sha256=kylDl-5VZk01tzSXVrWI9VPn8m
|
|
|
35
35
|
manta_node/infrastructure/filesystem/__init__.py,sha256=nf6Fakp3wuFKjSAm_oihI6WE_yyUY6Uelr7A1GwSvXs,145
|
|
36
36
|
manta_node/infrastructure/filesystem/dataset_manager.py,sha256=sW7vPKYBLjwbtju1yzFEob9GlY1v0VI-xu6gxF9KM90,15075
|
|
37
37
|
manta_node/infrastructure/grpc/__init__.py,sha256=6I-yzQM42gdBfcZ1FPVEKF2-pgJMdW-UssDHgz2EFcc,254
|
|
38
|
-
manta_node/infrastructure/grpc/client.py,sha256=
|
|
38
|
+
manta_node/infrastructure/grpc/client.py,sha256=3g1ZtQpCNwV9PUsEmK7Zs80Q0hoCSFcIojo_xMXquGE,16208
|
|
39
39
|
manta_node/infrastructure/grpc/local_servicer.py,sha256=9PFAwpKKFGy3P7HZfx2BHwhOgZhWwkwEja-eUTnMfpw,4217
|
|
40
40
|
manta_node/infrastructure/grpc/world_servicer.py,sha256=nmyrMzYxzGDlZ1-oOeyALgd76mbeOmAOsjzoVN6f0SA,8222
|
|
41
41
|
manta_node/infrastructure/metrics/__init__.py,sha256=ODGAj9s63F5jba2c3dQRMfNK6I4WvMdcJUS_xApUN5Y,272
|
|
42
42
|
manta_node/infrastructure/metrics/collector.py,sha256=9ESw__Pc2tV6ldG5yhos2IS7T5Td59KxTIwDRZc_G4w,3067
|
|
43
43
|
manta_node/infrastructure/metrics/metrics_collector.py,sha256=osIYrNzU3g9WCAxVQ14isM9YEQ3eJ7F3QgKBbpgeMJs,13077
|
|
44
44
|
manta_node/infrastructure/mqtt/__init__.py,sha256=riXo1sXgO4YV6DHCmWRqK61BAmuGLdHiVdQFunAJadA,140
|
|
45
|
-
manta_node/infrastructure/mqtt/command_handler.py,sha256=
|
|
45
|
+
manta_node/infrastructure/mqtt/command_handler.py,sha256=X2fu_ZLIZNbXrDCOUaVkf82o2m25R9S5w0Ev3ZO5V-c,43321
|
|
46
46
|
manta_node/infrastructure/network/__init__.py,sha256=On3XLgycFQoc-fBCa5hFuFDfEJjmFy7Wl2CK3D2LkdI,478
|
|
47
47
|
manta_node/infrastructure/network/event_registry.py,sha256=iWEfUJRzDnWjOrDinpYqVyIUpGKJjp7RZkjMDPfpplM,1661
|
|
48
48
|
manta_node/infrastructure/network/factory.py,sha256=-LvHbBp5nBpQ7fyQT1T0pvK3aczZqWc9QNDW37brBeU,3897
|
|
@@ -52,6 +52,7 @@ manta_node/infrastructure/process/__init__.py,sha256=MpKkA3k-6ND-Nb7uyzrpw8MdQss
|
|
|
52
52
|
manta_node/infrastructure/process/executor.py,sha256=Ab1XvNuelEGCD5KdZLgYYnpjYZ5dpKRKOzRWL68AxQg,11601
|
|
53
53
|
manta_node/infrastructure/security/__init__.py,sha256=lI6vkbUmfmt0m363iO4HzuzVNoQAc7Clp2R5vAhZbgE,64
|
|
54
54
|
manta_node/infrastructure/security/auth_agent.py,sha256=WkPTg_g0gix7xomb_on_Ft3TNX0FpeqS7gwgJW9mTvk,11037
|
|
55
|
+
manta_node/infrastructure/security/broker_certificate.py,sha256=xY2T7CF7sxGXVp7nZeQpHw34PS9Ylz4_JYrtOD2xzKg,5341
|
|
55
56
|
manta_node/infrastructure/security/token_provider.py,sha256=u3bcbQYNBskFzunO-wOSZpGkDN_CU1BCB5HUbZTC4Vg,1832
|
|
56
57
|
manta_node/supervisor/__init__.py,sha256=kgdoNce1tM4e7jvdxkdmnNJV1L92-NI2cRfYSdm9vsw,542
|
|
57
58
|
manta_node/supervisor/bounds.py,sha256=MlUfj0tYY-US348JsxYA-Ph5pSpgoOPlRdVTwmrPtZA,3181
|
|
@@ -63,9 +64,9 @@ manta_node/supervisor/records.py,sha256=O1YjNN2bH1xzOJo_3l1G6FRvWo1CmdAfvSDJBj6s
|
|
|
63
64
|
manta_node/supervisor/seam.py,sha256=4kczRku5Ctn4xRvXS-pyzaDFau7LnX5bYOn6IRNKRyE,9665
|
|
64
65
|
manta_node/supervisor/sequence.py,sha256=eYu7rrk1ecc4Y2jQhhJ7CopPz3m0lOsFLJj5lT2PwBw,1685
|
|
65
66
|
manta_node/supervisor/switch.py,sha256=PbWLNnRwQFhOBDAUSLcDwZsIW5jPHq_zNKIyS7Hd8C0,22342
|
|
66
|
-
manta_node-0.6b6.
|
|
67
|
-
manta_node-0.6b6.
|
|
68
|
-
manta_node-0.6b6.
|
|
69
|
-
manta_node-0.6b6.
|
|
70
|
-
manta_node-0.6b6.
|
|
71
|
-
manta_node-0.6b6.
|
|
67
|
+
manta_node-0.6b6.dev846.dist-info/licenses/LICENSE,sha256=9mBgLhiB9goQPQjg9XQJ6FjgVxYw9Q8lyOZYkPGwF_c,34484
|
|
68
|
+
manta_node-0.6b6.dev846.dist-info/METADATA,sha256=ANDWeMJw_E0rXfhV1vf-I7lDqgmjgUUOkYCuxb8vzc8,4937
|
|
69
|
+
manta_node-0.6b6.dev846.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
70
|
+
manta_node-0.6b6.dev846.dist-info/entry_points.txt,sha256=uCwggRApalLEsYs1YxwTBN0-e9oMJAkMoBp01HaSdoY,110
|
|
71
|
+
manta_node-0.6b6.dev846.dist-info/top_level.txt,sha256=nbT5J5WETuXM9UPoQckl29uUOq8wMYdRb9QDx5kAFeo,11
|
|
72
|
+
manta_node-0.6b6.dev846.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|